Command Returning The Help Message From plugin.yml Issue

Discussion in 'Plugin Development' started by SuperPyroManiac, Aug 13, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    SuperPyroManiac

    Well I am working on my first plugin, there is no errors, but for some reason when I run the command in game it just puts in white text how to use the plugin.

    Code:
    package SuperPyroManiac.First;
     
    import org.bukkit.GameMode;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class First extends JavaPlugin {
     
        public void onEnable(){
            getLogger().info("Your plugin has been enabled!");
        }
     
        public void onDisable(){
            getLogger().info("Your plugin has been disabled.");
        }
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, int[] args, String args1[]) throws InterruptedException{
            if(cmd.getName().equalsIgnoreCase("punish")){
                //Variables
                Player s = (Player)sender;
                Player target = s.getServer().getPlayer(args1[0]);
                Integer time = args[1];
                //The Good Stuff     
                if (time == null) {
                    target.setGameMode(GameMode.ADVENTURE);                           
                }
                else {
                target.setGameMode(GameMode.ADVENTURE);
                Thread.sleep(time*1000*60);
                target.setGameMode(GameMode.SURVIVAL);
                    }
                return true;
                }
            //Second Command
            if(cmd.getName().equalsIgnoreCase("unpunish")){
                //Variables
                Player s = (Player)sender;
                Player target = s.getServer().getPlayer(args1[0]);
                //The Good Stuff
                target.setGameMode(GameMode.SURVIVAL);
                return true;
                }
            return false;
        }
    }
    Here is the plugin.yml

    Code:
    name: First
    main: SuperPyroManiac.First.First
    version: 1
    commands:
      punish:
          description: This punishes the one listed!
          usage: /<command> [player] [time]
          permission: <plugin name>.punish
          permission-message: You don't have <permission>!
      unpunish:
          description: This unpunishes the one listed!
          usage: /<command> [player]
          permission: <plugin name>.unpunish
          permission-message: You don't have <permission>!
     
  2. Offline

    TheSmallBones

    Return true instead of false.
     
  3. Offline

    SuperPyroManiac

    Tried that, did not work. Same problem.
     
  4. Offline

    Rockslide

    This is bad bad bad:

    Thread.sleep(time*1000*60);

    Never put the main thread to sleep. It will freeze your server

    To answer your question:
    instead of

    cmd.getName().equalsIg....

    do

    commandLabel.equalsIg....
     
  5. Offline

    SuperPyroManiac


    What could I do for the wait?
     
  6. Offline

    toothplck1

    for the wait:
    Code:
                getServer().getScheduler().scheduleSyncDelayedTask(getServer().getPluginManager().getPlugin("YourPlugin"), new Runnable() {
                      public void run() {
                                  //Do stuff here
                      }
                }, 120L);  // this number determines the wait time
     
  7. Offline

    jacklin213

    whats that mean 120L
     
  8. Offline

    SuperPyroManiac

    Could you explain how long the 120L is? Is it seconds, minutes, etc.
     
  9. Offline

    toothplck1

    Server ticks. SO at 20ticks per sec, 120 is 5 seconds so this would do that code 5 seconds later
     
  10. Offline

    SuperPyroManiac

    Alright well no errors, console shows nothing, but yet the commands still just print the how to use command from plugin.yml.
    Here is what the code is now.

    Code:
    package SuperPyroManiac.First;
     
    import org.bukkit.GameMode;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class First extends JavaPlugin {
     
        public void onEnable(){
            getLogger().info("Your plugin has been enabled!");
        }
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, int[] args, String args1[]) throws InterruptedException{
            if(commandLabel.equalsIgnoreCase("punish")){
                //Variables
                Player s = (Player)sender;
                final Player target = s.getServer().getPlayer(args1[0]);
                Integer time = args[1];
                //The Good Stuff     
                if (time == null) {
                    target.setGameMode(GameMode.ADVENTURE);                           
                }
                else {
                target.setGameMode(GameMode.ADVENTURE);
                getServer().getScheduler().scheduleSyncDelayedTask(getServer().getPluginManager().getPlugin("First"), new Runnable() {
                    public void run() {
                        target.setGameMode(GameMode.SURVIVAL);
                    }
              }, 120L);  // this number determines the wait time
                    }
                }
            //Second Command
            if(commandLabel.equalsIgnoreCase("unpunish")){
                //Variables
                Player s = (Player)sender;
                Player target = s.getServer().getPlayer(args1[0]);
                //The Good Stuff
                target.setGameMode(GameMode.SURVIVAL);
                }
            return true;
        }
    }
    Thanks to everyone for the help! Really is great, as I am still new with Java.
     
  11. Offline

    toothplck1


    throw this above your onCOmmand
    @Override
     
Thread Status:
Not open for further replies.

Share This Page