Question Buggy Strings?

Discussion in 'Bukkit Help' started by Tim->mrgum13, Apr 11, 2015.

?

What is up with my string comparison?

  1. Write the code new

    0 vote(s)
    0.0%
  2. I don´t know

    0 vote(s)
    0.0%
Multiple votes are allowed.
Thread Status:
Not open for further replies.
  1. Offline

    Tim->mrgum13

    Hi, I am writing my 2. Plugin and I got a Mistake, wich I am not able to explain:
    i wrote this to declare a new command:
    Code:
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if(cmd.getName().equalsIgnoreCase("challenge")){
                if(sender instanceof Player){
                    Debug("the sender is a Player");
                }else{
                    Debug("the sender is no Player");
                    System.out.println("this command is only executable by players");
                    return true;
                }
                Player p = (Player) sender;
                if(args.length < 2){
                    p.sendMessage(ChatColor.RED+"too little Arguments");
                    return true;
                }
                Debug("The Command "+cmd+" will be executed");
                Debug("The Arguments:  "+args[0]+args[1]);
                Debug("Command parts:Sender: "+sender.getName()+" Command:"+cmd.getName()+" label"+ label+" Argumente: "+args);
                if(args[0] != "invite"){
                    Debug("the firs argument is not invite");
                    Debug(args[0]+ " != invite");
                }
    ...
    }
    the debug() method is only:
    Code:
    public String Debug(String str){
            if(Debug==true){
                Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN+"[Debug LuckyLobby] "+ChatColor.BLACK+str);
            }
            if(DebugChat==true){
                Player p = Bukkit.getPlayer("mrgum13");
                if(p != null){
                    Bukkit.getPlayer("mrgum13").sendMessage(ChatColor.GREEN+"[Debug LuckyLobby] "+ChatColor.WHITE+str);
                }
            }
            return "";
        }
    I loaded my plugin and executed: /challenge invite mrgum13
    the argument 0 (args[0]) = invite
    and if it isn´t invite it will say me that, but: (server log)
    Code:
    [21:52:06 INFO]: mrgum13 issued server command: /challenge invite mrgum13
    [21:52:06 INFO]: [Debug LuckyLobby] Der Sender ist ein Spieler
    [21:52:06 INFO]: [Debug LuckyLobby] The Command org.bukkit.command.PluginCommand(challenge, LuckyLobby v1.0) will be executed
    [21:52:06 INFO]: [Debug LuckyLobby] the arguments: invitemrgum13
    [21:52:06 INFO]: [Debug LuckyLobby] Command parts:Sender: mrgum13 Command:challenge labelchallenge Argumente: [Ljava.lang.String;@5b073e42
    [21:52:06 INFO]: [Debug LuckyLobby] the 1. argument isn?t invite
    [21:52:06 INFO]: [Debug LuckyLobby] invite != invite
    
    Can me anyone say what is wrong
    The plugin.yml is right, i tested it before this "mistake"
    the log wrote: [21:52:06 INFO]: [Debug LuckyLobby] invite != invite
    the first invite is the argument, the second a string!
    I´m helpless please help me!
     
  2. Offline

    teej107

    == compares the object in memory. Use .equals() as it compares value.
     
Thread Status:
Not open for further replies.

Share This Page