Solved StringBuilder works from console but not InGame

Discussion in 'Plugin Development' started by viper_monster, Dec 1, 2013.

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

    viper_monster

    Hey after the 1.7.2 update I have experienced a problem with sending some messages. Here is the code:
    Code:
        @Override
        public boolean onCommand(CommandSender s, Command cmd, String cl, String[] args) {
            StringBuilder sb = new StringBuilder();
            File[] files = new File(pl.getDataFolder() + File.separator + "kits").listFiles();
            if (files == null) {
                s.sendMessage(ChatColor.RED + "There are no kits set.");
                return true;
            }
            for (File file : files) {
                if (file.isFile()) {
                    String kit = file.getName().replace(".yml", "");
                    if (sb.length() > 0) {
                        sb.append(", ");
                    }
                    sb.append((s.hasPermission("duckzpvp.kit." + kit) ? ChatColor.GREEN.toString() : ChatColor.RED.toString()) + kit + ChatColor.WHITE.toString()).substring(sb.length() - 2);
                }
            }
            s.sendMessage(ChatColor.GOLD + "To use a kit, type: " + ChatColor.WHITE + "/kit <kitname> " + ChatColor.GOLD + "or" + ChatColor.WHITE + " /<kitname>" + ChatColor.GOLD + ".");
            s.sendMessage(ChatColor.GOLD + "Kits (" + ChatColor.WHITE + files.length + ChatColor.GOLD + "): " + sb.toString().replace(".yml", ""));
            return true;
        }
    
    So when I use /kits from the console it shows this:[​IMG]
    and this from InGame:
    [​IMG]

    Could anyone please help?
     
  2. Offline

    1Rogue

    Put in debug statements. Print each part of the string concatenation and see what doesn't show up.
     
  3. Offline

    viper_monster

    1Rogue, I tried debugging, added some debug messages in the for loop and it showed all the kits. So that works, but when I try to list them using a StringBuilder it doesn't show the kits. Before 1.7.2 update everything was working.

    Any other ideas?
     
  4. Offline

    1Rogue

    Print out the specific concatenations of the final string individually, i.e. not in the loop
     
  5. Offline

    viper_monster

    1Rogue hmmm, weird, with Essentials the same thing happens when you use /list
    [​IMG]
     
Thread Status:
Not open for further replies.

Share This Page