diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java index 500aa0713..6565a9f57 100644 --- a/Essentials/src/com/earth2me/essentials/Util.java +++ b/Essentials/src/com/earth2me/essentials/Util.java @@ -11,7 +11,6 @@ import java.net.URL; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.MessageFormat; -import java.util.ArrayList; import java.util.Calendar; import java.util.Enumeration; import java.util.GregorianCalendar; @@ -470,22 +469,34 @@ public class Util } public static String joinList(Object... list) + { + return joinList(", ", list); + } + + public static String joinList(String seperator, Object... list) { StringBuilder buf = new StringBuilder(); for (Object each : list) { if (buf.length() > 0) { - buf.append(", "); + buf.append(seperator); } if(each instanceof List) { - buf.append(joinList(((List)each).toArray())); + buf.append(joinList(seperator, ((List)each).toArray())); } else { - buf.append(each.toString()); + try + { + buf.append(each.toString()); + } + catch (Exception e) + { + buf.append(each.toString()); + } } } return buf.toString(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java index 3e4ee6178..2b285bfe7 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java @@ -55,7 +55,7 @@ public class Commandhome extends EssentialsCommand } else { - user.sendMessage(Util.format("homes", homes.toString())); + user.sendMessage(Util.format("homes", Util.joinList(homes))); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandjails.java b/Essentials/src/com/earth2me/essentials/commands/Commandjails.java index b91a1c985..36eb633fc 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandjails.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandjails.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.Util; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -14,12 +15,6 @@ public class Commandjails extends EssentialsCommand @Override protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception { - StringBuilder jailList = new StringBuilder(); - for (String j : ess.getJail().getJails()) - { - jailList.append(j); - jailList.append(' '); - } - sender.sendMessage("§7" + jailList); + sender.sendMessage("§7" + Util.joinList(" ", ess.getJail().getJails())); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java b/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java index e98deeab7..df0509f94 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java @@ -55,16 +55,6 @@ public class Commandrepair extends EssentialsCommand String armor = repairItems(user.getInventory().getArmorContents()); - if (armor.length() > 0) - { - if (itemList.length() > 0) - { - itemList.append(", "); - } - - itemList.append(armor); - } - if (itemList.length() == 0) { user.sendMessage(Util.format("repairNone")); @@ -72,7 +62,7 @@ public class Commandrepair extends EssentialsCommand else { charge(user); - user.sendMessage(Util.format("repair", itemList.toString())); + user.sendMessage(Util.format("repair", Util.joinList(itemList))); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java index 17d55faee..b93355f5a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java @@ -55,16 +55,7 @@ public class Commandwarp extends EssentialsCommand user.sendMessage(Util.format("warpsCount", warpNameList.size(), page, (int)Math.ceil(warpNameList.size() / (double)WARPS_PER_PAGE))); } final int warpPage = (page - 1) * WARPS_PER_PAGE; - final StringBuilder sb = new StringBuilder(); - for (int i = 0; i < Math.min(warpNameList.size() - warpPage, WARPS_PER_PAGE); i++) - { - if (i > 0) - { - sb.append(", "); - } - sb.append(warpNameList.get(i + warpPage)); - } - user.sendMessage(sb.toString()); + user.sendMessage(Util.joinList(warpNameList.subList(warpPage, warpPage+Math.min(warpNameList.size() - warpPage, WARPS_PER_PAGE)))); return; } if (args.length > 0)