(HELP ME) CODE NOT WORKING

Discussion in 'Plugin Development' started by ilethz, Jun 6, 2013.

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

    ilethz

    What is wrog here?? i do /serverinformation... and nothing happends!
    Code:
    package net.si.src;
     
    import java.util.logging.Logger;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class SiMsG extends JavaPlugin{
        public static SiMsG plugin;
        public final Logger logger = Logger.getLogger("Minecraft");
       
            public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
                Player player = (Player) sender;
                if(args. length == 0){
                if(cmd.getName().equalsIgnoreCase("serverinfo")){ // If the player typed /basic then do the following...
                    player.sendMessage(ChatColor.GREEN + ">******" + ChatColor.BOLD + ChatColor.DARK_BLUE + "Server Information" + ChatColor.AQUA + "******<");
                    player.sendMessage(ChatColor.GREEN + ">*" + ChatColor.GRAY + " PUT HERE YOUR INFORMATION" + ChatColor.GREEN + "*");
               
                }
                }
     
                        return false;
                        }
     
    }
    
    i do /serverinformation and nothing happends!
     
  2. Offline

    Rprrr

    ilethz
    I DONT KNOW
    PERHAPS YOU SHOULD TELL WHAT IS NOT WORKING????
    I DO NOT LIKE TO FIGURE IT OUT WHEN YOU'RE THE ONE THAT'S ASKING FOR HELP!
    ALSO, WHAT IS WRONG WITH ALL CAPS MESSAGES?
    BYE!
     
    RainoBoy97 likes this.
  3. Offline

    Windy Day

    You don't need the "args.length==0" before the command and I would recommend making an onEnable() and onDisable(). However, these may or may not be the reasons it doesn't work.
     
  4. Offline

    Bammerbom

    Change your code into this
    Code:
    package net.si.src;
     
    import java.util.logging.Logger;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class SiMsG extends JavaPlugin{
        public static SiMsG plugin;
        public final Logger logger = Logger.getLogger("Minecraft");
     
            public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
                Player player = (Player) sender;
                if(args. length == 0){
                    if(cmd.getName().equalsIgnoreCase("serverinfo")){ // If the player typed /basic then do the following...
                        player.sendMessage(ChatColor.GREEN + ">******" + ChatColor.BOLD + ChatColor.DARK_BLUE + "Server Information" + ChatColor.AQUA + "******<");
                        player.sendMessage(ChatColor.GREEN + ">*" + ChatColor.GRAY + " PUT HERE YOUR INFORMATION" + ChatColor.GREEN + "*");
         
                    }
                }
     
                return false;
            }
     
    }
     
  5. Offline

    Rocoty

    Are you surprised that nothing happens when you type /serverinformation, while the command you are checking for is "serverinfo"?
     
    Minnymin3 and WiredWingzzz like this.
  6. Offline

    ilethz

    no.. i type /serverinformation
    but nothing happends
     
  7. Offline

    Henzz

    ilethz
    1. I believe you cannot add ChatColors together
    2. You've set your command to serverinfo NOT serverinformation
    3. Have you added the command in your plugin.yml file?
    4. Have you registered your command in onEnable?
     
  8. Offline

    ilethz

    yes, i try /serverinfo and /serverinformation...
    yes i have plugin.yml
    ........
     
  9. Offline

    Henzz

    ilethz

    Woops, didn't properly read the first post.

    You haven't invoked onEnable and onDisable methods.
    Put them above your onCommand and add this inside the onEnable method.

    Code:java
    1. this.getCommand("serverinfo").setExecutor(this);
     
  10. Offline

    Rocoty

    Henzz That won't fix it for two reasons.

    1. When using the onCommand method from JavaPlugin you don't need to set the executor for commands.
    2. setExecutor() takes a CommandExecutor as argument, which that class isn't.
     
    Minnymin3 likes this.
  11. Offline

    Rockett8855

    Do you have a plugin.yml It is CRUCIAL that you have a plugin.yml
     
  12. Offline

    Henzz

    Rocoty

    Yes you do..

    You have to register the command in onEnable.
    And setExecutor takes an instance of CommandExecutor which he is currently using in his main class, so you use "this".
     
  13. Offline

    Rockett8855

    Henzz
    You actually don't have to, try it out, I guarantee it works.
     
    Minnymin3 likes this.
  14. Offline

    brord

    "i do /serverinformation and nothing happends!"
    --> f(cmd.getName().equalsIgnoreCase("serverinfo")){ // If the player typed /basic then do the following...

    serverinformation != serverinfo
     
  15. Offline

    Minnymin3

  16. Offline

    Rocoty

    His class does not implement CommandExecutor, neither does JavaPlugin
     
  17. Offline

    kreashenz

    If it's the main class, you don't need to set the executor.. When it's extending JavaPlugin, it's basically all of it together, except Listeners.

    ilethz It might be because you're putting if(args.length == 0) BEFORE the command. Try putting it after the command name, and then see if it works.
     
  18. Offline

    Rocoty

    I think it's an issue with how the command is registered in the plugin.yml.....send us that please?
     
  19. Offline

    EcMiner

    Have you added the command to the plugin.yml?
     
  20. Offline

    Henzz

    kreashenz

    Well you learn something new everyday.

    Rocoty

    Yeah since CommandExecutor is apart of JavaPlugin which I though you'd have to refer this to the current class.
     
  21. Offline

    Rocoty

    Henzz Sorry, my bad. CommandExecutor actually is some levels up in JavaPlugin's inheritance diagram
     
  22. Offline

    ilethz

    YES!!
    omg... somebody can just say what is wrong??
     
  23. Offline

    EcMiner


    Hmm.... it's pretty weird... I copied your code to my project and it worked fine with me, maybe you are doing something wrong when you export?
     
Thread Status:
Not open for further replies.

Share This Page