Command args help

Discussion in 'Plugin Development' started by DREAM_MACHINE, Jan 15, 2013.

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

    DREAM_MACHINE

    Could anyone tell me why this is not working? It should display a message on the screen when the player types "/sspm yes" and "/sspm no" but it does not
    Code:
    package me.m277772.SSPM;
     
    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.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class SSPMM extends JavaPlugin{
       
        public final Logger logger = Logger.getLogger("Minecraft");
        public static SSPMM plugin;
        boolean q1 = false;
        boolean q2 = false;
        boolean q3 = false;
        boolean q4 = false;
        boolean q5 = false;
        String args1;
       
        @Override
        public void onDisable()
        {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " " + pdfFile.getVersion() + " Has been disabled!");
        }
       
        @Override
        public void onEnable()
        {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " " + pdfFile.getVersion() + " Has been enabled!");
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
        {
            Player player = (Player) sender;
            if(commandLabel.equalsIgnoreCase("sspm"))
            {
                q1 = true;
                if(args.length > 0)
                {
                    args1 = args[0];
                    if(args1 == "no")
                    {
                        player.sendMessage(ChatColor.BLUE + "[SSPM]" + ChatColor.DARK_AQUA + "Test");
                    }
                   
                    if(args1 == "yes")
                    {
                        player.sendMessage(ChatColor.BLUE + "[SSPM]" + ChatColor.DARK_AQUA + "Test2");
                    }
                }
               
                if(q1 == true && (args.length == 0))
                {
                    player.sendMessage(ChatColor.BLUE + "[SSPM]" + ChatColor.AQUA + "Are you going to greif this server? (Type /sspm [YOUR ANSWER] to answer.)");
                }
            }
            return false;
        }
    }
     
  2. Offline

    Craftiii4

    With strings you can not use ==, you must use .equals(""), I also recommend using .equalsIgnoreCase("") for args as you never know what the user might type in.

    == Works with things like ints, however with strings you can only really use == for checking if they are null etc.
     
  3. Offline

    DREAM_MACHINE

    Thanks so much :)
     
  4. Offline

    Ivan

    == works with the exact string
     
  5. Offline

    Plaze_Demon

    Doesn't that class need to implement command executor aswell?
     
  6. Offline

    Craftiii4



    He has done it in the main file, no need to;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
     
  7. Offline

    devilquak

    DREAM_MACHINE

    Does no one read the wiki anymore?

    It's sort of bad practice to use a logger named "Minecraft". Take a look at the bottom of the Bukkit wiki's etiquette page.
     
  8. Offline

    Craftiii4

    He is clearly new, don't be to harsh ;)
     
  9. Offline

    devilquak

    Lol, that wasn't harsh at all :eek:

    Compared to some of the attitudes I got from here and on the IRC when I was learning this stuff, I'm a saint, sadly enough.
     
  10. Offline

    Craftiii4

    True point :p, you are forgiven :3
     
    devilquak likes this.
Thread Status:
Not open for further replies.

Share This Page