Args inside args

Discussion in 'Plugin Development' started by _Stamp_, May 15, 2016.

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

    _Stamp_

    Right so I am giving my plugin a whole revamp, aka new help screen new commands it's more or less going to be a new plugin with the same commands when I am finished, however, I went to add my /ty command into my /sc command so it looks like /sc thank, the problem is that it either doesn't work or seems to think that there is another, extra argument anywho here's the code.
    Just to let you know it's not the plugin.yml or anything as I have done all that so I won't be posting that.

    Code:
         
           
    if (cmd.getName().equalsIgnoreCase("sc") && sender instanceof Player) {
                if (args.length == 0) {
                    sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[" + ChatColor.RED + "" + ChatColor.BOLD
                            + "SC" + ChatColor.GOLD + "" + ChatColor.BOLD + "]" + ChatColor.DARK_RED + "" + ChatColor.BOLD
                            + "Please specify which type of argument you want to use.");
                    sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[" + ChatColor.RED + "" + ChatColor.BOLD
                            + "SC" + ChatColor.GOLD + "" + ChatColor.BOLD + "]" + ChatColor.DARK_RED
                            + "Valid command arguments are");
                    sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[" + ChatColor.RED + "" + ChatColor.BOLD
                            + "SC" + ChatColor.GOLD + "" + ChatColor.BOLD + "]" + ChatColor.RED + "Help");
                    sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[" + ChatColor.RED + "" + ChatColor.BOLD
                            + "SC" + ChatColor.GOLD + "" + ChatColor.BOLD + "]" + ChatColor.RED + "INSERT");
                    sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[" + ChatColor.RED + "" + ChatColor.BOLD
                            + "SC" + ChatColor.GOLD + "" + ChatColor.BOLD + "]" + ChatColor.RED + "INSERT");
                    return true;
    
                }
                if (args.length == 1) {
    
                    if (args[0].equalsIgnoreCase("help")) {
                        sender.sendMessage(ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.GREEN
                                + "[Help]" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE
                                + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-");
                        sender.sendMessage(ChatColor.GREEN + "" + ChatColor.UNDERLINE + "Player Commands");
                        sender.sendMessage(" ");
                        sender.sendMessage(ChatColor.GREEN + "<Command>" + ChatColor.AQUA + "<Desc>");
                        sender.sendMessage(ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-");
                        return true;
                    } else if (args[0].equalsIgnoreCase("wb")) {
                        p.chat("Welcome back!");
                        return true;
                    } else if (args[0].equalsIgnoreCase("thank")) {
                        int length = args.length;
                        if (length == 1) {
                            boolean playerFound = false;
    
                            for (Player playerToThank : Bukkit.getServer().getOnlinePlayers()) {
                                if (playerToThank.getName().equalsIgnoreCase(args[1])) {
    
                                    playerToThank.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[" + ChatColor.RED
                                            + "" + ChatColor.BOLD + "SC" + ChatColor.GOLD + "" + ChatColor.BOLD + "]"
                                            + ChatColor.GOLD + "" + ChatColor.BOLD + "Thanks ~" + ChatColor.YELLOW + ""
                                            + ChatColor.BOLD + sender.getName());
                                    sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[" + ChatColor.RED + ""
                                            + ChatColor.BOLD + "SC" + ChatColor.GOLD + "" + ChatColor.BOLD + "]"
                                            + ChatColor.GOLD + "" + ChatColor.GOLD + "You have successfuly thanked  "
                                            + ChatColor.YELLOW + "" + ChatColor.BOLD + playerToThank.getName()
                                            + ChatColor.GOLD + "" + ChatColor.BOLD + "!");
                                    playerFound = true;
                                    break;
                                }
                            }
    
                            if (playerFound == false) {
                                sender.sendMessage(ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE
                                        + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                        + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                        + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                        + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                        + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                        + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                        + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                        + ChatColor.GREEN + "[Help]" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                        + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                        + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                        + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                        + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                        + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.BLUE + "-"
                                        + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                        + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                        + ChatColor.DARK_BLUE + "-");
                                sender.sendMessage(ChatColor.GREEN + "Something went wrong..");
                                sender.sendMessage(ChatColor.GREEN + "Things that could have went wrong are...");
                                sender.sendMessage(ChatColor.AQUA + "You entered the name wrong.");
                                sender.sendMessage(ChatColor.AQUA + "The player you entered is offline.");
                                sender.sendMessage(ChatColor.GREEN + "The persons name you entered is...");
                                sender.sendMessage(ChatColor.AQUA + args[1]);
                                sender.sendMessage(ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE
                                        + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                        + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                        + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                        + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                        + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                        + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                        + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                        + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                        + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                        + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                        + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                        + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                        + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                        + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                        + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                        + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                        + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-");
    
                            }
    
                        } else
                            sender.sendMessage(ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                    + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                    + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                    + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                    + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                    + ChatColor.GREEN + "[Help]" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                    + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                    + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.BLUE + "-"
                                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                    + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                    + ChatColor.DARK_BLUE + "-");
                        sender.sendMessage(ChatColor.GREEN + "Something went wrong..");
                        sender.sendMessage(ChatColor.GREEN + "Things that could have went wrong are...");
                        sender.sendMessage(ChatColor.AQUA + "You used extra arguments");
                        sender.sendMessage(ChatColor.AQUA + "You didn't input the players name");
                        sender.sendMessage(ChatColor.GREEN + "How the command should look");
                        sender.sendMessage(ChatColor.AQUA + "/sc thank <Name>");
                        sender.sendMessage(ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                                + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"
                                + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-");
                        return true;
    
                    } else if (args[0].equalsIgnoreCase("servername")) {
                        sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[" + ChatColor.RED + "" + ChatColor.BOLD
                                + "SC" + ChatColor.GOLD + "" + ChatColor.BOLD + "] " + ChatColor.AQUA + "The servername is "
                                + Bukkit.getServerName());
                        return true;
    
                    } else {
                        sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[" + ChatColor.RED + "" + ChatColor.BOLD
                                + "SC" + ChatColor.GOLD + "" + ChatColor.BOLD + "]" + ChatColor.RED + ChatColor.DARK_RED
                                + "Error, that is not a command.");
                        sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[" + ChatColor.RED + "" + ChatColor.BOLD
                                + "SC" + ChatColor.GOLD + "" + ChatColor.BOLD + "]" + ChatColor.RED + "Please do /sc help");
    
                    }
    
                }
    
                // start a new sc here
            }
            
    PS: There are no errors in the server log =P
    PPS: Formatted Code
     
    Last edited: May 15, 2016
  2. Offline

    CraftCreeper6

  3. Offline

    _Stamp_

    Done, formatted it (The formatted code is in the original post now)
     
  4. Offline

    CraftCreeper6

    @_Stamp_
    So the command is

    /sc thank [player]?

    Also, make sure that player is not null.
     
  5. Offline

    I Al Istannen

    @_Stamp_
    And maybe consider making this "ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-"......" either a constant somehwere or create a method that generates this automatically (for loop with i as variable, if i % 2 == 0 Blue, else Dark_Blue, maybe make the colors definable in the arguments). You write this piece so often, it just clutters what you want to do. And, if you ever want to change that, have fun changing it in hundreds of places.

    Same is true for the Prefixes "...[SC]...". Just make a constant variable (final String) somwhere to change writing it a hundred times to PREFIX + "Help", PREFIX + "Other Thing". Why? Same arguments as above.
     
  6. Offline

    _Stamp_

    Okay, did what you said, never really thought about that before, it will help me a lot in future of coding!
    here's my new code
    Code:
            Player p = (Player) sender;
            String t = ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.GREEN + "[Help]" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE
                    + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE
                    + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE
                    + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE
                    + "-" + ChatColor.BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-";
            String b = ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-";
            String s = ChatColor.GOLD + "" + ChatColor.BOLD + "[" + ChatColor.RED + "" + ChatColor.BOLD + "SC"
                    + ChatColor.GOLD + "" + ChatColor.BOLD + "]";
            if (cmd.getName().equalsIgnoreCase("sch")) {
                sender.sendMessage(ChatColor.DARK_RED + "" + ChatColor.BOLD + "=================================");
                sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "              Simple Commands            ");
                sender.sendMessage(ChatColor.DARK_RED + "" + ChatColor.BOLD + "=================================");
                sender.sendMessage(
                        ChatColor.AQUA + "" + ChatColor.BOLD + "You can define the server name in your server.properties");
                sender.sendMessage(ChatColor.BLUE + "" + ChatColor.BOLD + "Player commands");
                sender.sendMessage(ChatColor.AQUA + "" + ChatColor.ITALIC + "sch - Displays help for this plugin");
                sender.sendMessage(ChatColor.AQUA + "" + ChatColor.ITALIC + "sn - Displays the servers name");
                sender.sendMessage(
                        ChatColor.AQUA + "" + ChatColor.ITALIC + "welcome - Says a welcome message from your chat");
                sender.sendMessage(ChatColor.AQUA + "" + ChatColor.ITALIC + "wb - Says welcome back");
                sender.sendMessage(ChatColor.AQUA + "" + ChatColor.ITALIC + "ty - Thanks a player (/ty <PlayerName>");
                sender.sendMessage(ChatColor.AQUA + "" + ChatColor.ITALIC + "brb - Says be right back");
                sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Admin Commands");
                sender.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "warn - Warns a player (/warn <PlayerName>");
                sender.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "clearchat - Clears chat");
                sender.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "warnall - Warns all players");
                sender.sendMessage(ChatColor.GREEN + "" + ChatColor.ITALIC + "warnall Option - Spam");
                sender.sendMessage(ChatColor.GREEN + "" + ChatColor.ITALIC + "warnall Option - Caps");
                sender.sendMessage(ChatColor.GREEN + "" + ChatColor.ITALIC + "warnall Option - Swearing");
                return true;
            }
    
            if (cmd.getName().equalsIgnoreCase("sc") && sender instanceof Player) {
                if (args.length == 0) {
                    sender.sendMessage(t);
                    sender.sendMessage(s + ChatColor.DARK_RED + "" + ChatColor.BOLD
                            + "Please specify which type of argument you want to use.");
                    sender.sendMessage(s + ChatColor.DARK_RED + "Valid command arguments are");
                    sender.sendMessage(s + ChatColor.RED + "Help");
                    sender.sendMessage(s + ChatColor.RED + "INSERT");
                    sender.sendMessage(s + ChatColor.RED + "INSERT");
                    sender.sendMessage(b);
                    return true;
    
                }
                if (args.length == 1) {
    
                    if (args[0].equalsIgnoreCase("help")) {
                        sender.sendMessage(t);
                        sender.sendMessage(ChatColor.GREEN + "" + ChatColor.UNDERLINE + "Player Commands");
                        sender.sendMessage(" ");
                        sender.sendMessage(ChatColor.GREEN + "<Command>" + ChatColor.AQUA + "<Desc>");
                        sender.sendMessage(b);
                        return true;
                    } else if (args[0].equalsIgnoreCase("wb")) {
                        p.chat("Welcome back!");
                        return true;
                    } else if (args[0].equalsIgnoreCase("thank")) {
                        int length = args.length;
                        if (length == 1) {
                            boolean playerFound = false;
    
                            for (Player playerToThank : Bukkit.getServer().getOnlinePlayers()) {
                                if (playerToThank.getName().equalsIgnoreCase(args[1])) {
    
                                    playerToThank.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "Thanks ~"
                                            + ChatColor.YELLOW + "" + ChatColor.BOLD + sender.getName());
                                    sender.sendMessage(ChatColor.GOLD + "You have successfuly thanked  " + ChatColor.YELLOW
                                            + "" + ChatColor.BOLD + playerToThank.getName() + ChatColor.GOLD + ""
                                            + ChatColor.BOLD + "!");
                                    playerFound = true;
                                    break;
                                }
                            }
    
                            if (playerFound == false) {
                                sender.sendMessage(t);
                                sender.sendMessage(ChatColor.GREEN + "Something went wrong..");
                                sender.sendMessage(ChatColor.GREEN + "Things that could have went wrong are...");
                                sender.sendMessage(ChatColor.AQUA + "You entered the name wrong.");
                                sender.sendMessage(ChatColor.AQUA + "The player you entered is offline.");
                                sender.sendMessage(ChatColor.GREEN + "The persons name you entered is...");
                                sender.sendMessage(ChatColor.AQUA + args[1]);
                                sender.sendMessage(b);
    
                            }
    
                        } else
                            sender.sendMessage(t);
                        sender.sendMessage(ChatColor.GREEN + "Something went wrong..");
                        sender.sendMessage(ChatColor.GREEN + "Things that could have went wrong are...");
                        sender.sendMessage(ChatColor.AQUA + "You used extra arguments");
                        sender.sendMessage(ChatColor.AQUA + "You didn't input the players name");
                        sender.sendMessage(ChatColor.GREEN + "How the command should look");
                        sender.sendMessage(ChatColor.AQUA + "/sc thank <Name>");
                        sender.sendMessage(b);
                        return true;
    
                    } else if (args[0].equalsIgnoreCase("servername")) {
                        sender.sendMessage(s + ChatColor.AQUA + "The servername is " + Bukkit.getServerName());
                        return true;
    
                    } else {
                        sender.sendMessage(s + ChatColor.RED + ChatColor.DARK_RED + "Error, that is not a command.");
                        sender.sendMessage(s + ChatColor.RED + "Please do /sc help");
    
                    }
    
                }
    
                // start a new sc here
            }
     
  7. Offline

    I Al Istannen

    @_Stamp_
    Better ;)
    You could declare them as field, so that they won't get created every time the command is run, but just once.

    And:
    Maybe it's just me, but I would make a method for generating these Strings. They are really similar from the structure:
    Code:
    public String createColoredMinuses(int amount, ChatColor colorOne, ChatColor colorTwo) {
      StringBuilder builder; // More efficient than using "" + "other" + "other2"
      for(i < amount) // just run it as often, as the argument dictates
        if i % 2 == 0  // Meaning: if you can divide i by 2 and don't have a remainder, this is true (which means, for every even number, return true, for every odd return false) Therefore this switches between true and falsem which creates the blue-dark_blue-blue-... sequence.
          append colorOne and a "-" sign to the builder // Color it with the first color
        else
          append colorTwo and a "-" sign to the builder // Color it with the second color
      endfor
      return generated String // maybe with a ChatColor.RESET at the end, to reset the colors.
    }
    Then use it like "createColoredMinuses(what you want, Blue, Dark_Blue) + " Help +" createColoredMinuses(what you want, Blue, Dark_Blue)". I find it much more readable.
     
  8. Offline

    _Stamp_

    Okay, I think I have did that now!
    Code:
            Player p = (Player) sender;
            String t = ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.GREEN + "[Help]" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE
                    + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE
                    + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE
                    + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE
                    + "-" + ChatColor.BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-";
            String b = ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-" + ChatColor.DARK_BLUE + "-" + ChatColor.BLUE + "-"
                    + ChatColor.DARK_BLUE + "-";
            String s = ChatColor.GOLD + "" + ChatColor.BOLD + "[" + ChatColor.RED + "" + ChatColor.BOLD + "SC"
                    + ChatColor.GOLD + "" + ChatColor.BOLD + "]";
        //    if (cmd.getName().equalsIgnoreCase("sch")) {
        //        sender.sendMessage(ChatColor.DARK_RED + "" + ChatColor.BOLD + "=================================");
            //    sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "              Simple Commands            ");
        //        sender.sendMessage(ChatColor.DARK_RED + "" + ChatColor.BOLD + "=================================");
            //                ChatColor.AQUA + "" + ChatColor.BOLD + "You can define the server name in your server.properties");
        //        sender.sendMessage(ChatColor.BLUE + "" + ChatColor.BOLD + "Player commands");
        //        sender.sendMessage(ChatColor.AQUA + "" + ChatColor.ITALIC + "sch - Displays help for this plugin");
        //        sender.sendMessage(ChatColor.AQUA + "" + ChatColor.ITALIC + "sn - Displays the servers name");
        //        sender.sendMessage(
            //            ChatColor.AQUA + "" + ChatColor.ITALIC + "welcome - Says a welcome message from your chat");
        //        sender.sendMessage(ChatColor.AQUA + "" + ChatColor.ITALIC + "wb - Says welcome back");
            //    sender.sendMessage(ChatColor.AQUA + "" + ChatColor.ITALIC + "ty - Thanks a player (/ty <PlayerName>");
        //        sender.sendMessage(ChatColor.AQUA + "" + ChatColor.ITALIC + "brb - Says be right back");
        //        sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Admin Commands");
        //        sender.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "warn - Warns a player (/warn <PlayerName>");
        //        sender.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "clearchat - Clears chat");
            //    sender.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "warnall - Warns all players");
            //    sender.sendMessage(ChatColor.GREEN + "" + ChatColor.ITALIC + "warnall Option - Spam");
            //    sender.sendMessage(ChatColor.GREEN + "" + ChatColor.ITALIC + "warnall Option - Caps");
            //    sender.sendMessage(ChatColor.GREEN + "" + ChatColor.ITALIC + "warnall Option - Swearing");
        //        return true;
    //        }
    
            if (cmd.getName().equalsIgnoreCase("sc") && sender instanceof Player) {
                if (args.length == 0) {
                    sender.sendMessage(t);
                    sender.sendMessage(s + ChatColor.DARK_RED + "" + ChatColor.BOLD
                            + "Please specify which type of argument you want to use.");
                    sender.sendMessage(s + ChatColor.DARK_RED + "Valid command arguments are");
                    sender.sendMessage(s + ChatColor.RED + "Help");
                    sender.sendMessage(s + ChatColor.RED + "INSERT");
                    sender.sendMessage(s + ChatColor.RED + "INSERT");
                    sender.sendMessage(b);
                    return true;
    
                }
                if (args.length == 1) {
    
                    if (args[0].equalsIgnoreCase("help")) {
                        sender.sendMessage(t);
                        sender.sendMessage(ChatColor.GREEN + "" + ChatColor.UNDERLINE + "Player Commands");
                        sender.sendMessage(" ");
                        sender.sendMessage(ChatColor.GREEN + "<Command>" + ChatColor.AQUA + "<Desc>");
                        sender.sendMessage(b);
                        return true;
                    } else if (args[0].equalsIgnoreCase("wb")) {
                        p.chat("Welcome back!");
                        return true;
                    } else if (args[0].equalsIgnoreCase("thank")) {
                        int length = args.length;
                        if (length == 1) {
                            boolean playerFound = false;
    
                            for (Player playerToThank : Bukkit.getServer().getOnlinePlayers()) {
                                if (playerToThank.getName().equalsIgnoreCase(args[1])) {
                                    if(Bukkit.getServer().getPlayer(args[0]) != null) {
                                    playerToThank.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "Thanks ~"
                                            + ChatColor.YELLOW + "" + ChatColor.BOLD + sender.getName());
                                    sender.sendMessage(ChatColor.GOLD + "You have successfuly thanked  " + ChatColor.YELLOW
                                            + "" + ChatColor.BOLD + playerToThank.getName() + ChatColor.GOLD + ""
                                            + ChatColor.BOLD + "!");
                                    playerFound = true;
                                    break;
                                }else{
                                    sender.sendMessage(t);
                                    sender.sendMessage(s + ChatColor.RED + "That player is offline.");
                                    sender.sendMessage(b);
                                   
                                }
                            }
    
                            if (playerFound == false) {
                                sender.sendMessage(t);
                                sender.sendMessage(ChatColor.GREEN + "Something went wrong..");
                                sender.sendMessage(ChatColor.GREEN + "Things that could have went wrong are...");
                                sender.sendMessage(ChatColor.AQUA + "You entered the name wrong.");
                                sender.sendMessage(ChatColor.AQUA + "The player you entered is offline.");
                                sender.sendMessage(ChatColor.GREEN + "The persons name you entered is...");
                                sender.sendMessage(ChatColor.AQUA + args[1]);
                                sender.sendMessage(b);
    
                            }
    
                        } else
                            sender.sendMessage(t);
                        sender.sendMessage(ChatColor.GREEN + "Something went wrong..");
                        sender.sendMessage(ChatColor.GREEN + "Things that could have went wrong are...");
                        sender.sendMessage(ChatColor.AQUA + "You used extra arguments");
                        sender.sendMessage(ChatColor.AQUA + "You didn't input the players name");
                        sender.sendMessage(ChatColor.GREEN + "How the command should look");
                        sender.sendMessage(ChatColor.AQUA + "/sc thank <Name>");
                        sender.sendMessage(b);
                        return true;
    
                    } else if (args[0].equalsIgnoreCase("servername")) {
                        sender.sendMessage(s + ChatColor.AQUA + "The servername is " + Bukkit.getServerName());
                        return true;
    
                    } else {
                        sender.sendMessage(s + ChatColor.RED + ChatColor.DARK_RED + "Error, that is not a command.");
                        sender.sendMessage(s + ChatColor.RED + "Please do /sc help");
    
                    }
    
                }
    
                // start a new sc here
            }
    I haven't got onto the field part yet however I can't seem to find anywhere that
    Code:
            public String createColoredMinuses(int amount, ChatColor colorOne, ChatColor colorTwo) {
                  StringBuilder builder; // More efficient than using "" + "other" + "other2"
                  for(i < amount) // just run it as often, as the argument dictates
                    if i % 2 == 0  // Meaning: if you can divide i by 2 and don't have a remainder, this is true (which means, for every even number, return true, for every odd return false) Therefore this switches between true and falsem which creates the blue-dark_blue-blue-... sequence.
                      append colorOne and a "-" sign to the builder // Color it with the first color
                    else
                      append colorTwo and a "-" sign to the builder // Color it with the second color
                  endfor
                  return generated String // maybe with a ChatColor.RESET at the end, to reset the colors.
                }
    this would fit in.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 15, 2016
  9. Offline

    I Al Istannen

    @_Stamp_
    It's just a new method you create somewhere in the class. Note, that this is not valid Javacode, but still tells you what to do.
     
  10. Offline

    _Stamp_

    Ahh thank makes a bit more sence!

    @I Al Istannen I can't seem to find how to do it, it's throwing so many errors and I have never really used stringbuilder properly before :eek:

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 15, 2016
    I Al Istannen likes this.
  11. Offline

    I Al Istannen

    @_Stamp_
    The code I gave is called "PseudoCode". It won't compile. It is just used to outline the actions needed. And StringBuilder is quite easy. You create one (StringBuilder builder = new StringBuilder()). Then you just call "builder.append(String or char or int or some other things)". At the end you can use builder.toString() to convert it back to a String. Instead of "String string = "hey" + "this" + "is " + "something";" You use
    "StringBuilder builder = new StringBuilder();
    builder.append("hey");
    builder.append("this");
    builder.append("is");
    builder.append("something");
    String string = builder.toString();"

    Using a StringBuilder is advisable if you combine many Strings, as it is a hundred times (not exaggerating, probably not enough :p) faster.

    For the remaining things, what is causing you trouble?
     
    Last edited: May 15, 2016
  12. Offline

    _Stamp_

    @I Al Istannen Right, now I have done the StringBuilder just I can't seem to find out how to call it because it's in a different method? I have tried putting it in the main commands thing and vice versa but it doesn't work!
     
  13. Offline

    I Al Istannen

    @_Stamp_
    You don't need to call the Stringbuilder from a different method. The method I outlined above returns a String. It should return builder.toString(). Then you can just call the method and use the resulting String. Could you post your updated code?

    And, not trying to be rude, learning Java would also help a great deal ;)
     
    Zombie_Striker likes this.
  14. Offline

    _Stamp_

    @I Al Istannen
    When I first started coding I used youtube tutorials I wish somewhere in the video or even in the comments if someone said/recommended to start with Java, I found out that Java would help me later on when I didn't know about other stuff, anyway, I was thinking about doing it but then its stuff I know so I skip to the part that I don't know and I'm like 'whaaaaa??!? too much writing!'.

    Anywho, as of now I can't post the code because I seem to have lost all my projects in eclipse :eek: I'll edit if anything changes.
     
  15. Offline

    I Al Istannen

    @_Stamp_
    Have you looked in the folder? Are they just not in Eclipse, or is the whole workspace folder gone? over on Spigot, they fanatically want you to install IntelliJ, you might want to give it a try. It's just an alternative to Eclipse, which is said to be more stable and "intelligent".

    Learning a new Language takes some effort :p But yes, there are often just walls of text. Not very pleasing. You might want to buy a good Java book, I have one and found it quite helpful!

    Good luck though! And don't give up!
     
  16. Offline

    _Stamp_

    Thanks for the tips, I might install that one anyway, I have all my projects back this is the annoying part, only the code for the simplecommands plugin (the one I'm working on currently) has been deleted, the plugin.yml is still there just not the code, there is just a long line with a squiggly line under :O
     
  17. Offline

    I Al Istannen

    @_Stamp_
    Wow. What? Sounds quite interesting ;) Mind posting a screenshot? I might be able you. Maybe not. You never know beforehand :p
     
  18. Offline

    _Stamp_

  19. Offline

    I Al Istannen

    @_Stamp_
    Ouch. Looks like the file got corrupted. Had the same with a dying hard drive a few weeks ago. BUT I REALLY don't want to diagnose things like this! I am not qualified for it... :)

    At least you have a good chunk of the code in this thread. But you might want to take the chance and do it different this time :p
     
  20. Offline

    _Stamp_

    Actually now that I think of it, I could open up the exported plugin (Yes I do that everytime I make a change to test it out) then grab the code!

    EDIT - Dang, it only got the part of the pursue code :eek:
    EDIT AGAIN - Well it seems like it could be a while, the decompiler got rid of any excess code which was needed :p
     
    Last edited: May 16, 2016
  21. Offline

    I Al Istannen

    @_Stamp_
    I set my eclipse to export the project and package the source files right with it. Would have helped in this case :p Just write a new post and tahg me, if you have any further questions. I might be off now, but I will check later again. Please don't reply now, but when you have a question, as otherwise your comment will be deleted due to a double post. This means I won't get an alert.

    Good luck with it ;)
     
  22. Offline

    _Stamp_

    Rightio, I have been trying to install IntelliJ the past few days, however, no luck so I have gone back to coding, learned some java and came up with this (I have an issue I will address later so I will give out the full code)

    Code:
    package me.stamp.simplecommands;
    
    import java.util.logging.Logger;
    import org.bukkit.Bukkit;
    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 SimpleCommands extends JavaPlugin
    {
      public final Logger logger = Bukkit.getLogger();
     
      public void onEnable()
      {
        saveDefaultConfig();
      }
     
      public void onDisable() {}
    
          
     
      public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args)
      {
          StringBuilder builder = new StringBuilder();
            for (int i = 0; i < 12; i++) {
                builder.append(ChatColor.BLUE + "-");
                builder.append(ChatColor.DARK_BLUE + "-");
            }
            String result = builder.toString();
    
          Player p = (Player) sender;
          String t = result + ChatColor.GREEN + "[Help]" + result;
    
          String b = result + ChatColor.GREEN + "[+--+]" + result;
          String s = ChatColor.GOLD + "" + ChatColor.BOLD + "[" + ChatColor.RED + "" + ChatColor.BOLD + "SC"
                  + ChatColor.GOLD + "" + ChatColor.BOLD + "]";
      /*    if (cmd.getName().equalsIgnoreCase("sch")) {
              sender.sendMessage(ChatColor.DARK_RED + "" + ChatColor.BOLD + "=================================");
              sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "              Simple Commands            ");
              sender.sendMessage(ChatColor.DARK_RED + "" + ChatColor.BOLD + "=================================");
                          ChatColor.AQUA + "" + ChatColor.BOLD + "You can define the server name in your server.properties");
              sender.sendMessage(ChatColor.BLUE + "" + ChatColor.BOLD + "Player commands");
              sender.sendMessage(ChatColor.AQUA + "" + ChatColor.ITALIC + "sch - Displays help for this plugin");
              sender.sendMessage(ChatColor.AQUA + "" + ChatColor.ITALIC + "sn - Displays the servers name");
              sender.sendMessage(
                      ChatColor.AQUA + "" + ChatColor.ITALIC + "welcome - Says a welcome message from your chat");
              sender.sendMessage(ChatColor.AQUA + "" + ChatColor.ITALIC + "wb - Says welcome back");
              sender.sendMessage(ChatColor.AQUA + "" + ChatColor.ITALIC + "ty - Thanks a player (/ty <PlayerName>");
              sender.sendMessage(ChatColor.AQUA + "" + ChatColor.ITALIC + "brb - Says be right back");
              sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Admin Commands");
              sender.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "warn - Warns a player (/warn <PlayerName>");
              sender.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "clearchat - Clears chat");
             sender.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "warnall - Warns all players");
              sender.sendMessage(ChatColor.GREEN + "" + ChatColor.ITALIC + "warnall Option - Spam");
              sender.sendMessage(ChatColor.GREEN + "" + ChatColor.ITALIC + "warnall Option - Caps");
              sender.sendMessage(ChatColor.GREEN + "" + ChatColor.ITALIC + "warnall Option - Swearing");
              return true;
        }
    */
          if (cmd.getName().equalsIgnoreCase("sc") && sender instanceof Player) {
              if (args.length == 0) {
                  sender.sendMessage(t);
                  sender.sendMessage(s + ChatColor.DARK_RED + "" + ChatColor.BOLD
                          + "Please specify which type of argument you want to use.");
                  sender.sendMessage(s + ChatColor.DARK_RED + "Valid command arguments are");
                  sender.sendMessage(s + ChatColor.RED + "Help");
                  sender.sendMessage(s + ChatColor.RED + "INSERT");
                  sender.sendMessage(s + ChatColor.RED + "INSERT");
                  sender.sendMessage(b);
                  return true;
    
              }
              if (args.length == 1) {
    
                  if (args[0].equalsIgnoreCase("help") && sender instanceof Player) {
                      sender.sendMessage(t);
                      sender.sendMessage(ChatColor.GREEN + "" + ChatColor.UNDERLINE + "Player Commands");
                      sender.sendMessage(" ");
                      sender.sendMessage(ChatColor.GREEN + "<Command>" + ChatColor.AQUA + "<Desc>");
                      sender.sendMessage(b);
                      return true;
                  } else if (args[0].equalsIgnoreCase("wb") && sender instanceof Player) {
                      p.chat("Welcome back!");
                      return true;
                  } else if (args[0].equalsIgnoreCase("thank") && sender instanceof Player) {
                      int length = args.length;
                      if (length == 1) {
                          boolean playerFound = false;
    
                          for (Player playerToThank : Bukkit.getServer().getOnlinePlayers()) {
                              if (playerToThank.getName().equalsIgnoreCase(args[1])) {
                                  if(Bukkit.getServer().getPlayer(args[0]) != null) {
                                  playerToThank.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "Thanks ~"
                                          + ChatColor.YELLOW + "" + ChatColor.BOLD + sender.getName());
                                  sender.sendMessage(ChatColor.GOLD + "You have successfuly thanked  " + ChatColor.YELLOW
                                          + "" + ChatColor.BOLD + playerToThank.getName() + ChatColor.GOLD + ""
                                          + ChatColor.BOLD + "!");
                                  playerFound = true;
                                  break;
                                  }}else{
                                  sender.sendMessage(t);
                                  sender.sendMessage(s + ChatColor.RED + "That player is offline.");
                                  sender.sendMessage(b);
                                
                              }
                          }
    
                          if (playerFound == false) {
                              sender.sendMessage(t);
                              sender.sendMessage(ChatColor.GREEN + "Something went wrong..");
                              sender.sendMessage(ChatColor.GREEN + "Things that could have went wrong are...");
                              sender.sendMessage(ChatColor.AQUA + "You entered the name wrong.");
                              sender.sendMessage(ChatColor.AQUA + "The player you entered is offline.");
                              sender.sendMessage(ChatColor.GREEN + "The persons name you entered is...");
                              sender.sendMessage(ChatColor.AQUA + args[1]);
                              sender.sendMessage(b);
    
                          }
    
                      } else
                          sender.sendMessage(t);
                      sender.sendMessage(ChatColor.GREEN + "Something went wrong..");
                      sender.sendMessage(ChatColor.GREEN + "Things that could have went wrong are...");
                      sender.sendMessage(ChatColor.AQUA + "You used extra arguments");
                      sender.sendMessage(ChatColor.AQUA + "You didn't input the players name");
                      sender.sendMessage(ChatColor.GREEN + "How the command should look");
                      sender.sendMessage(ChatColor.AQUA + "/sc thank <Name>");
                      sender.sendMessage(b);
                      return true;
    
                  } else if (args[0].equalsIgnoreCase("servername") && sender instanceof Player) {
                      sender.sendMessage(s + ChatColor.AQUA + "The servername is " + Bukkit.getServerName());
                      return true;
    
                  } else {
                      sender.sendMessage(s + ChatColor.RED + ChatColor.DARK_RED + "Error, that is not a command.");
                      sender.sendMessage(s + ChatColor.RED + "Please do /sc help");
    
                  }
    
              }
    
              // start a new sc here
          }
    /*   if (cmd.getName().equalsIgnoreCase("sch"))
        {
          sender.sendMessage(ChatColor.DARK_RED + "" + ChatColor.BOLD + "=================================");
          sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "              Simple Commands            ");
          sender.sendMessage(ChatColor.DARK_RED + "" + ChatColor.BOLD + "=================================");
          sender.sendMessage(
            ChatColor.AQUA + "" + ChatColor.BOLD + "You can define the server name in your server.properties");
          sender.sendMessage(ChatColor.BLUE + "" + ChatColor.BOLD  + "Player commands");
          sender.sendMessage(ChatColor.AQUA + "" + "" + ChatColor.ITALIC + "sch - Displays help for this plugin");
          sender.sendMessage(ChatColor.AQUA + "" + "" + ChatColor.ITALIC + "sn - Displays the servers name");
          sender.sendMessage(
            ChatColor.AQUA + "" + "" + ChatColor.ITALIC + "welcome - Says a welcome message from your chat");
          sender.sendMessage(ChatColor.AQUA + "" + "" + ChatColor.ITALIC + "wb - Says welcome back");
          sender.sendMessage(ChatColor.AQUA + "" + "" + ChatColor.ITALIC + "ty - Thanks a player (/ty <PlayerName>");
          sender.sendMessage(ChatColor.AQUA + "" + "" + ChatColor.ITALIC + "brb - Says be right back");
          sender.sendMessage(ChatColor.RED +"" + ChatColor.BOLD + "Admin Commands");
          sender.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "warn - Warns a player (/warn <PlayerName>");
          sender.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "clearchat - Clears chat");
          sender.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "warnall - Warns all players");
          sender.sendMessage(ChatColor.GREEN + "" + ChatColor.ITALIC + "warnall Option - Spam");
          sender.sendMessage(ChatColor.GREEN + "" + ChatColor.ITALIC + "warnall Option - Caps");
          sender.sendMessage(ChatColor.GREEN + "" + ChatColor.ITALIC + "warnall Option - Swearing");
          return true;
        }
        if ((cmd.getName().equalsIgnoreCase("sc")) && ((sender instanceof Player)))
        {
          if (args.length == 0)
          {
            sender.sendMessage(s+ ChatColor.DARK_RED + "" + ChatColor.BOLD + "Please specify which type of argument you want to use.");
            sender.sendMessage(s+ ChatColor.DARK_RED + "Valid command arguments are");
            sender.sendMessage(s + ChatColor.RED + "Help");
            sender.sendMessage(s + ChatColor.RED + "INSERT");
            sender.sendMessage(s + ChatColor.RED + "INSERT");
            return true;
          }
          if (args.length == 1)
          {
            if (args[0].equalsIgnoreCase("help"))
            {
              sender.getServer().broadcastMessage(s + ChatColor.RED + "Please don't spam in chat!");
              return true;
            }
            if (args[0].equalsIgnoreCase("caps"))
            {
              sender.getServer().broadcastMessage(s+ ChatColor.RED + "Please don't overuse caps!");
              return true;
            }
            if (args[0].equalsIgnoreCase("swearing"))
            {
              sender.getServer().broadcastMessage(s + ChatColor.RED + "Please don't swear!");
              return true;
            }      
            sender.sendMessage(s+ ChatColor.DARK_RED + "" + ChatColor.BOLD + "Error, that is an invalid argument.");
            sender.sendMessage(s+ ChatColor.DARK_RED + "Valid command arguments are");
            sender.sendMessage(s + ChatColor.RED + "Help");
            sender.sendMessage(s + ChatColor.RED + "INSERT");
            sender.sendMessage(s + ChatColor.RED + "INSERT");      }
        }
        if (cmd.getName().equalsIgnoreCase("sn"))
        {
          sender.sendMessage(ChatColor.AQUA + "The server name is  " + Bukkit.getServerName());
          return true;
        }
        if ((cmd.getName().equalsIgnoreCase("welcome")) && ((sender instanceof Player)))
        {
          p.chat("Welcome to " + Bukkit.getServerName() + "!");
          return true;
        }
        if ((cmd.getName().equalsIgnoreCase("wb")) && ((sender instanceof Player)))
        {
          p.chat("Welcome back!");
          return true;
        }
        if ((cmd.getName().equalsIgnoreCase("ty")) && ((sender instanceof Player)))
        {
          int length = args.length;
          if (length == 1)
          {
            boolean playerFound = false;
            for (Player playerToThank : Bukkit.getServer().getOnlinePlayers()) {
              if (playerToThank.getName().equalsIgnoreCase(args[0]))
              {
                playerToThank.sendMessage(s + ChatColor.GOLD + ChatColor.BOLD + "Thanks ~" + ChatColor.YELLOW +
                  ChatColor.BOLD + sender.getName());
                sender.sendMessage(s + ChatColor.GOLD + "You have successfuly thanked  " +
                  ChatColor.YELLOW + ChatColor.BOLD + playerToThank.getName() + ChatColor.GOLD +
                  ChatColor.BOLD + "!");
                playerFound = true;
                break;
              }
            }
            if (!playerFound)
            {
              sender.sendMessage(ChatColor.DARK_RED + "" + ChatColor.BOLD + "=================================");
              sender.sendMessage(ChatColor.RED + "" +ChatColor.BOLD + "              ERROR            ");
              sender.sendMessage(ChatColor.DARK_RED + "" + ChatColor.BOLD + "=================================");
              sender.sendMessage(ChatColor.BLUE + "" + ChatColor.ITALIC + "The name you entered is wrong.");
              sender.sendMessage(ChatColor.AQUA + "" + ChatColor.ITALIC + "The player you entered is offline.");
              sender.sendMessage(ChatColor.DARK_RED + "" + ChatColor.BOLD + "=================================");
              sender.sendMessage(ChatColor.DARK_PURPLE + "" + ChatColor.BOLD + "     Command you entered...      ");
              sender.sendMessage(ChatColor.DARK_RED + "" + ChatColor.BOLD + "=================================");
              sender.sendMessage(ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "/ty " + args[0]);
              sender.sendMessage(ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "(Please note that this plugin only shows the variable after the command :D)");
            }
          }
          else
          {
            sender.sendMessage(ChatColor.DARK_RED + "" + ChatColor.BOLD + "You used incorrect arguments!");
          }
          return true;
        }
        if ((cmd.getName().equalsIgnoreCase("brb")) && ((sender instanceof Player)))
        {
          p.chat("Will we right back!");
          return true;
        }
        if ((cmd.getName().equalsIgnoreCase("warn")) && ((sender instanceof Player))) {
          if ((sender.hasPermission("simplecommands.warn")) || (sender.isOp()))
          {
            if (args.length >= 2)
            {
              Player playerFound = Bukkit.getServer().getPlayer(args[0]);
             
              Player target = getServer().getPlayer(args[0]);
              if ((target != null) && (target.isOnline()))
              {
                StringBuilder warner = new StringBuilder();
                for (int i = 0; i < args.length; i++) {
                  warner.append(args[i]).append(" ");
                }
                String message =warner.toString();
                target.sendMessage(s + ChatColor.GOLD + message);
                sender.sendMessage(s + ChatColor.GOLD + "You have sucessfully warned " + target.getName());
              }
              if (playerFound == null)
              {
                sender.sendMessage(
                  ChatColor.DARK_RED + "" + ChatColor.BOLD + "=================================");
                sender.sendMessage(ChatColor.RED +"" + ChatColor.BOLD + "              ERROR            ");
                sender.sendMessage(
                  ChatColor.DARK_RED + "" + ChatColor.BOLD + "=================================");
              }
            }
            else
            {
              sender.sendMessage(ChatColor.DARK_RED + "" + ChatColor.BOLD + "You used incorrect arguments!");
            }
          }
          else
          {
            sender.sendMessage(s + ChatColor.RED + "You do not have permission to use /warn!");
           
            return true;
          }
        }
      */  if ((cmd.getName().equalsIgnoreCase("clearchat")) && ((sender instanceof Player))) {
          if ((sender.hasPermission("simplecommands.clearchat")) || (sender.isOp()))
          {
            for (int i = 0; i < 100; i++) {
              Bukkit.broadcastMessage(" ");
            }
            Bukkit.broadcastMessage(
              s + ChatColor.AQUA + ChatColor.BOLD + "Chat Cleared By " + sender.getName());
          }
          else
          {
            sender.sendMessage(s + ChatColor.RED + "You do not have permission to use /clearchat!");
            return true;
          }
        }
        if ((cmd.getName().equalsIgnoreCase("warnall")) && ((sender instanceof Player)))
        {
          if (args.length == 0)
          {
            sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[" + ChatColor.RED + ChatColor.BOLD + "SC" + ChatColor.GOLD + ChatColor.BOLD + "]" + ChatColor.AQUA + ChatColor.BOLD + "Please specify which type of warnall you want to use.");
            sender.sendMessage(ChatColor.GOLD + "" +ChatColor.BOLD + "[" + ChatColor.RED + ChatColor.BOLD + "SC" + ChatColor.GOLD + ChatColor.BOLD + "]" + ChatColor.RED + ChatColor.BOLD + "Valid warnall arguments are");
            sender.sendMessage(ChatColor.GOLD + "" +ChatColor.BOLD + "[" + ChatColor.RED + ChatColor.BOLD + "SC" + ChatColor.GOLD + ChatColor.BOLD + "]" + ChatColor.RED + "Spam");
            sender.sendMessage(ChatColor.GOLD + "" +ChatColor.BOLD + "[" + ChatColor.RED + ChatColor.BOLD + "SC" + ChatColor.GOLD + ChatColor.BOLD + "]" + ChatColor.RED + "Caps");
            sender.sendMessage(ChatColor.GOLD + "" +ChatColor.BOLD + "[" + ChatColor.RED + ChatColor.BOLD + "SC" + ChatColor.GOLD + ChatColor.BOLD + "]" + ChatColor.RED + "Swearing");
            return true;
          }
          if (args.length == 1) {
            if (args[0].equalsIgnoreCase("spam"))
            {
              if ((sender.hasPermission("simplecommands.warnall.spam")) || (sender.isOp()))
              {
                sender.getServer().broadcastMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[" + ChatColor.RED + ChatColor.BOLD + "SC" + ChatColor.GOLD + ChatColor.BOLD + "]" + ChatColor.RED + "Please don't spam in chat!");
                return true;
              }
              sender.sendMessage(ChatColor.GOLD + "" +ChatColor.BOLD + "[" + ChatColor.RED + ChatColor.BOLD + "SC" + ChatColor.GOLD + ChatColor.BOLD + "]" + ChatColor.RED + "You do not have permission to warn everyone for spam!");
            }
            else
            {
              if (args[0].equalsIgnoreCase("caps"))
              {
                if ((sender.hasPermission("simplecommands.warnall.caps")) || (sender.isOp())) {
                  sender.getServer().broadcastMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[" + ChatColor.RED + ChatColor.BOLD + "SC" + ChatColor.GOLD + ChatColor.BOLD + "]" + ChatColor.RED + "Please don't overuse caps!");
                } else {
                  sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[" + ChatColor.RED + ChatColor.BOLD + "SC" + ChatColor.GOLD + ChatColor.BOLD + "]" + ChatColor.RED + "You do not have permission to warn everyone for caps!");
                }
                return true;
              }
              if (args[0].equalsIgnoreCase("swearing"))
              {
                if ((sender.hasPermission("simplecommands.warnall.swearing")) || (sender.isOp())) {
                  sender.getServer().broadcastMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[" + ChatColor.RED + ChatColor.BOLD + "SC" + ChatColor.GOLD + ChatColor.BOLD + "]" + ChatColor.RED + "Please don't swear!");
                } else {
                  sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[" + ChatColor.RED + ChatColor.BOLD + "SC" + ChatColor.GOLD + ChatColor.BOLD + "]" + ChatColor.RED + "You don't have permission to warn everyone for swearing!");
                }
                return true;
              }
              sender.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "[" + ChatColor.RED + ChatColor.BOLD + "SC" + ChatColor.GOLD + ChatColor.BOLD + "]" + ChatColor.RED + ChatColor.RED + ChatColor.BOLD + "Error, that is a invalid warnall argument!");
              sender.sendMessage(ChatColor.GOLD + "" +ChatColor.BOLD + "[" + ChatColor.RED + ChatColor.BOLD + "SC" + ChatColor.GOLD + ChatColor.BOLD + "]" + ChatColor.RED + ChatColor.BOLD + "Valid warnall arguments are");
              sender.sendMessage(ChatColor.GOLD + "" +ChatColor.BOLD + "[" + ChatColor.RED + ChatColor.BOLD + "SC" + ChatColor.GOLD + ChatColor.BOLD + "]" + ChatColor.RED + "Spam");
              sender.sendMessage(ChatColor.GOLD +"" + ChatColor.BOLD + "[" + ChatColor.RED + ChatColor.BOLD + "SC" + ChatColor.GOLD + ChatColor.BOLD + "]" + ChatColor.RED + "Caps");
              sender.sendMessage(ChatColor.GOLD + "" +ChatColor.BOLD + "[" + ChatColor.RED + ChatColor.BOLD + "SC" + ChatColor.GOLD + ChatColor.BOLD + "]" + ChatColor.RED + "Swearing");
            }
          }
        }
        return true;
      }
    
    
    }
    
    So the issue is this...

    [​IMG]
    Above the red line is '/sc help' run after the server is started/reloaded, under the red line is what happens when you issue the command again or if you do /sc etc... Anything that uses the StringBuilder a seconds time causes this to happen, basically what's happening is the StringBuilder is doubling up doing the [help] or [+--+] then doubling up again for the other coloured minuses, I have no idea what is happening here.
     
  23. Offline

    I Al Istannen

    @_Stamp_
    Hey,

    I was in Berlin for a few days, so I didn't answer earlier.

    I copy pasted your code and it worked perfectly... . Are you sure you have the newest plugin version and everything on the server?

    And a few other things:
    Just use "JavaPlugin#getLogger()". So, as you are in the main class, use getLogger() to get the logger. The one you will get is created specially for your plugin.

    Does nothing, you can leave it out.

    You never checked if the sender is really a player. Try exuting the command from the console. You will get an error message (ClassCastException), as the console is no player. Check that by using "sender instanceof Player" before any casting and send a message and return if the sender is no player.

    These one letter variable names don't say anything. You have NO idea what they are or do. You should always name variables descriptive. You have autcompletion in an IDE, use it! For "t" "helpHeader" would be a much better name. Use one letter variables only in loops ("i") or for things they make sense (e.g. x,y,z for coordinates).

    The thank command won't work. You only check for it if the args length is 1. But the thank command is "/sc thank (0) <name>(1)". So the length is 2. Move it out of that if block. Same with "if (length == 1) {". It must be if length == 2.


    You missed the brackets after the else. The last line in the quote and everything below will be executed everytime, no matter if the if (before the else) is true or false.

    You might want to add a return statement aftert this, so that the next messages (what could have went wrong) won't be send too. You alreay said what was wrong.

    What is the usage of the second if? Only one player has the given name, so the Bukkit#getPlayer() method will return the player every time. You can just use the Bukkit#getPlayer method and leave the loop. If you want to get the player exactly, use the Bukkit#getPlayerExact method.


    You might not want to broadcast the clear chat message, as that will also clear the console. Your choice. Is nothing you must do :)

    Hope you have a nice day and sorry for the late reply.
     
    Last edited: Jun 18, 2016
Thread Status:
Not open for further replies.

Share This Page