2 different codes in the chat at the same time

Discussion in 'Spigot Plugin Development' started by rickerd120, Jul 8, 2015.

  1. hi,

    i have a really crazy problem and maybe it is because i am learning java but i have to ""things"" in my class with different commands i think it better to let you see it than you understand it.

    code; http://pastebin.com/ZiT4TPvd

    so when i do /playerinfo ? then it gives my the list. but i gives my olso in the chat the code under it (with the player info) but not the whole message i get the line with ----------------[playerinfo]------------ and under it that an internal error occured while....

    but when i do the normal command /playerinfo <Username> it works fine i get the playerinfo

    so my question is why when i /playerinfo ? it gives olso the /playerinfo <Username> line but then that it was crashst.

    please help me i dont get it.
     
    • Winner Winner x 1
  2. Serializator

    Supporter

    Can we see the console output?
     
  3. Is this possible?
    PHP:

    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
               Player player = (Player) sender;
               if(args.length == 0){
                      player.sendMessage(ChatColor.RED + "Usage: /playerinfo ?");
     
    EDIT: + i don't think making 2 threads will make a difference
     
    #3 Yazio, Jul 8, 2015
    Last edited: Jul 8, 2015
  4. What are you trying to achieve with your code because you are missing return statements the code will be executed from start to the end
     
  5. It thinks ? is a player because you never check what the first argument is
    Here's what I edited and I fixed a couple of things and added something for if you want info of an offline player
    PHP:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            Player player = (Player) sender;
            if (args.length == 0) {
                player.sendMessage(ChatColor.RED + "Usage: /playerinfo ?");
            } else if (args.length == 1) {
                if (player.isOp()) {
                    if(args[0].equalsIgnoreCase("?")) {
                        sender.sendMessage(ChatColor.GREEN + "----- " + ChatColor.BOLD + "PlayerInfo Commands" + ChatColor.GREEN + " -----");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo CMDList");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo CreateTag <Tag Name>");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo TagList");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo EditTag <Tag Number> <New Tag Text>");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo DeleteTag <Tag Number>");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo SetTag <Player Name> <Tag Number>");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo SetNickname <Player Name> <Nickname>");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo SetChatColor <Player Name> <Chat Color(s)>");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo SetJoinMSG <Player Name> <Join Message>");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo SetQuitMSG <Player Name> <Quit Message>");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo SetDefaultJoinMSG <Join Message>");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo SetDefaultQuitMSG <Quit Message>");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo ToggleAdminChat");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo ClearChat");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo Broadcast <Message>");
                    }
                    else if(!args[0].equalsIgnoreCase("?")) {
                        OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]);
                        player.sendMessage(ChatColor.DARK_GRAY + "---------------------[" + ChatColor.GOLD + "PlayerInfo" + ChatColor.DARK_GRAY + "]----------------------");
                        player.sendMessage("Username: " + ChatColor.GREEN + target.getName());
                        player.sendMessage("Online: " + ChatColor.GREEN + target.isOnline());
                        player.sendMessage("Op: " + ChatColor.GREEN + target.isOp());
                        player.sendMessage("Banned: " + ChatColor.GREEN + target.isBanned());
                        if(target.isOnline()){
                            Player onlineTarget = Bukkit.getPlayer(target.getName());
                            player.sendMessage("IP: " + ChatColor.GREEN + onlineTarget.getAddress());
                            player.sendMessage("Gamemode: " + ChatColor.GREEN + onlineTarget.getGameMode());
                            player.sendMessage("Flying: " + ChatColor.GREEN + onlineTarget.isFlying());
                            player.sendMessage("Health: " + ChatColor.GREEN + onlineTarget.getHealth());
                            player.sendMessage("Level: " + ChatColor.GREEN + onlineTarget.getExpToLevel() + " (Exp: " + ChatColor.RED + onlineTarget.getExp() + ChatColor.GREEN + " )");
                        }
                    }
                } else { //Player is not OP
                    sender.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GOLD + "PI" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " You are not permitted to do this command!");
                }
            }
            return true;
        }
     
    #5 RaringM, Jul 8, 2015
    Last edited: Jul 8, 2015
  6. This should work I added return statements and the correct way to check if the arguments are the ones you are looking for

    Code (Text):
            public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            Player player = (Player) sender;
            if(args.length == 0){
                    player.sendMessage(ChatColor.RED + "Usage: /playerinfo ?");
                    return true;
            }
            if((args.length == 1)&&(args[0] == "?")){
                    if (player.isOp()) {
                      sender.sendMessage(ChatColor.GREEN + "----- " + ChatColor.BOLD + "PlayerInfo Commands" + ChatColor.GREEN + " -----");
                      sender.sendMessage(ChatColor.GREEN + "/playerinfo CMDList");
                      sender.sendMessage(ChatColor.GREEN + "/playerinfo CreateTag <Tag Name>");
                      sender.sendMessage(ChatColor.GREEN + "/playerinfo TagList");
                      sender.sendMessage(ChatColor.GREEN + "/playerinfo EditTag <Tag Number> <New Tag Text>");
                      sender.sendMessage(ChatColor.GREEN + "/playerinfo DeleteTag <Tag Number>");
                      sender.sendMessage(ChatColor.GREEN + "/playerinfo SetTag <Player Name> <Tag Number>");
                      sender.sendMessage(ChatColor.GREEN + "/playerinfo SetNickname <Player Name> <Nickname>");
                      sender.sendMessage(ChatColor.GREEN + "/playerinfo SetChatColor <Player Name> <Chat Color(s)>");
                      sender.sendMessage(ChatColor.GREEN + "/playerinfo SetJoinMSG <Player Name> <Join Message>");
                      sender.sendMessage(ChatColor.GREEN + "/playerinfo SetQuitMSG <Player Name> <Quit Message>");
                      sender.sendMessage(ChatColor.GREEN + "/playerinfo SetDefaultJoinMSG <Join Message>");
                      sender.sendMessage(ChatColor.GREEN + "/playerinfo SetDefaultQuitMSG <Quit Message>");
                      sender.sendMessage(ChatColor.GREEN + "/playerinfo ToggleAdminChat");
                      sender.sendMessage(ChatColor.GREEN + "/playerinfo ClearChat");
                      sender.sendMessage(ChatColor.GREEN + "/playerinfo Broadcast <Message>");
                      return true;
                    }
                    else
                    {
                      sender.sendMessage(this.prefix + ChatColor.RED + " You do not have permission for this command!");
                      return true;
                    }
                    }
         
           if(args.length == 1){
                    Player targetPlayer1 = player.getServer().getPlayer(args[0]);
            if (player.isOp()) {
                    player.sendMessage(ChatColor.DARK_GRAY + "---------------------[" + ChatColor.GOLD + "PlayerInfo" + ChatColor.DARK_GRAY + "]----------------------");
                    player.sendMessage("Username: " + ChatColor.GREEN + targetPlayer1.getName());
                    player.sendMessage("Online: " + ChatColor.GREEN +targetPlayer1.isOnline());
                    player.sendMessage("IP: " + ChatColor.GREEN + targetPlayer1.getAddress());
                    player.sendMessage("Gamemode: " + ChatColor.GREEN + targetPlayer1.getGameMode());
                    player.sendMessage("Flying: " + ChatColor.GREEN + targetPlayer1.isFlying());
                    player.sendMessage("Health: " + ChatColor.GREEN + targetPlayer1.getHealth());
                    player.sendMessage("Level: " + ChatColor.GREEN + targetPlayer1.getLevel() + " (Exp: " + " )");
                    player.sendMessage("Op: " + ChatColor.GREEN + targetPlayer1.isOp());
                    player.sendMessage("Banned: " + ChatColor.GREEN + targetPlayer1.isBanned());
                    return true;
                    }
                    sender.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GOLD + "PI" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " You are not permitted to do this command!");
            return true;
            }
            return false;
            }
    }
     
  7. i sti
    i stil get a error .. when i do the command
    /playerinfo <Username> works but /playerinfo ? not i get a error...
     
    • Like Like x 1
  8. Try the one I gave :p and are you trying to do /playerinfo <username> with an offline player
    My Code:
    PHP:
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            Player player = (Player) sender;
            if (args.length == 0) {
                player.sendMessage(ChatColor.RED + "Usage: /playerinfo ?");
            } else if (args.length == 1) {
                if (player.isOp()) {
                    if(args[0].equalsIgnoreCase("?")) {
                        sender.sendMessage(ChatColor.GREEN + "----- " + ChatColor.BOLD + "PlayerInfo Commands" + ChatColor.GREEN + " -----");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo CMDList");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo CreateTag <Tag Name>");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo TagList");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo EditTag <Tag Number> <New Tag Text>");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo DeleteTag <Tag Number>");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo SetTag <Player Name> <Tag Number>");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo SetNickname <Player Name> <Nickname>");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo SetChatColor <Player Name> <Chat Color(s)>");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo SetJoinMSG <Player Name> <Join Message>");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo SetQuitMSG <Player Name> <Quit Message>");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo SetDefaultJoinMSG <Join Message>");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo SetDefaultQuitMSG <Quit Message>");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo ToggleAdminChat");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo ClearChat");
                        sender.sendMessage(ChatColor.GREEN + "/playerinfo Broadcast <Message>");
                    }
                    else if(!args[0].equalsIgnoreCase("?")) {
                        OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]);
                        player.sendMessage(ChatColor.DARK_GRAY + "---------------------[" + ChatColor.GOLD + "PlayerInfo" + ChatColor.DARK_GRAY + "]----------------------");
                        player.sendMessage("Username: " + ChatColor.GREEN + target.getName());
                        player.sendMessage("Online: " + ChatColor.GREEN + target.isOnline());
                        player.sendMessage("Op: " + ChatColor.GREEN + target.isOp());
                        player.sendMessage("Banned: " + ChatColor.GREEN + target.isBanned());
                        if(target.isOnline()){
                            Player onlineTarget = Bukkit.getPlayer(target.getName());
                            player.sendMessage("IP: " + ChatColor.GREEN + onlineTarget.getAddress());
                            player.sendMessage("Gamemode: " + ChatColor.GREEN + onlineTarget.getGameMode());
                            player.sendMessage("Flying: " + ChatColor.GREEN + onlineTarget.isFlying());
                            player.sendMessage("Health: " + ChatColor.GREEN + onlineTarget.getHealth());
                            player.sendMessage("Level: " + ChatColor.GREEN + onlineTarget.getExpToLevel() + " (Exp: " + ChatColor.RED + onlineTarget.getExp() + ChatColor.GREEN + " )");
                        }
                    }
                } else { //Player is not OP
                    sender.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GOLD + "PI" + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + " You are not permitted to do this command!");
                }
            }
            return true;
        }
     
    • Like Like x 1
  9. Thanks it works !
     
    • Like Like x 1
  10. but now everything behind /playerinfo, the plugin thinks that it is a name...
     
    • Like Like x 1
  11. What, do you mean like /playerinfo njosdgnl it thinks thats a name isn't that what you want
     
  12. How about you learn basic Java and its syntax. @Everyone else, why are you spoon feeding him, he learns nothing from it.
     
  13. no it is just a example. it thinks that it is a name, and yes i want that it is a name but only that he gives info about names that really
    exists.
     
    • Like Like x 1
  14. So you mean only give info about players that are online?
    And I agree with SystemUpdate_ you're code looked like you barely know what you're doing
    Like line 31 and 32 what was the point of does if(args.length == 0) and putting nothing in it and putting multiple checks for args.length equaling zero
    PHP:
            if(args.length == 0){
        }else if(args.length == 1){
     
    #14 RaringM, Jul 8, 2015
    Last edited: Jul 8, 2015