diff options
9 files changed, 41 insertions, 42 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java index 82231cb06..6565a9f57 100644 --- a/Essentials/src/com/earth2me/essentials/Util.java +++ b/Essentials/src/com/earth2me/essentials/Util.java @@ -14,6 +14,7 @@ import java.text.MessageFormat; import java.util.Calendar; import java.util.Enumeration; import java.util.GregorianCalendar; +import java.util.List; import java.util.Locale; import java.util.MissingResourceException; import java.util.ResourceBundle; @@ -469,17 +470,34 @@ public class Util public static String joinList(Object... list) { - final StringBuilder buf = new StringBuilder(); - boolean first = true; + return joinList(", ", list); + } + + public static String joinList(String seperator, Object... list) + { + StringBuilder buf = new StringBuilder(); for (Object each : list) { - if (!first) + if (buf.length() > 0) { - buf.append(", "); - + buf.append(seperator); + } + + if(each instanceof List) + { + buf.append(joinList(seperator, ((List)each).toArray())); + } + else + { + try + { + buf.append(each.toString()); + } + catch (Exception e) + { + buf.append(each.toString()); + } } - first = false; - buf.append(each); } return buf.toString(); } @@ -487,5 +505,5 @@ public class Util public static String capitalCase(String s) { return s.toUpperCase().charAt(0) + s.toLowerCase().substring(1); - } + } } 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/Commandpowertool.java b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java index bc1ccd801..4e85d2aeb 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java @@ -39,7 +39,7 @@ public class Commandpowertool extends EssentialsCommand } else { - user.sendMessage(Util.format("powerToolList", powertools.toString(), itemName)); + user.sendMessage(Util.format("powerToolList", Util.joinList(powertools), itemName)); } return; } @@ -85,7 +85,7 @@ public class Commandpowertool extends EssentialsCommand } powertools.add(command); - user.sendMessage(Util.format("powerToolAttach", powertools.toString(), itemName)); + user.sendMessage(Util.format("powerToolAttach", Util.joinList(powertools), itemName)); } } else 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/Commandspawnmob.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java index 9514bc767..17081e349 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java @@ -82,7 +82,12 @@ public class Commandspawnmob extends EssentialsCommand { 8, 9 }; - Location loc = (new TargetBlock(user, 300, 0.2, ignore)).getTargetBlock().getLocation(); + Block block = (new TargetBlock(user, 300, 0.2, ignore)).getTargetBlock(); + if(block == null) { + user.sendMessage(Util.i18n("unableToSpawnMob")); + return; + } + Location loc = block.getLocation(); Location sloc = Util.getSafeDestination(loc); try { 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) diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index c382a449f..52cefd453 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -147,7 +147,7 @@ kits = \u00a77Kits: {0} lightningSmited = \u00a77You have just been smited lightningUse = \u00a77Smiting {0} loadWarpError = Failed to load warp {0} -loadinfo = Loaded {0} build {1} by {2} +loadinfo = Loaded {0} build {1} by: {2} localFormat = Local: <{0}> {1} mailClear = \u00a7cTo mark your mail as read, type /mail clear mailCleared = \u00a77Mail Cleared! diff --git a/Essentials/src/messages_en.properties b/Essentials/src/messages_en.properties index 288500947..c96c9ecb7 100644 --- a/Essentials/src/messages_en.properties +++ b/Essentials/src/messages_en.properties @@ -147,7 +147,7 @@ kits = \u00a77Kits: {0} lightningSmited = \u00a77You have just been smited lightningUse = \u00a77Smiting {0} loadWarpError = Failed to load warp {0} -loadinfo = Loaded {0} build {1} by {2} +loadinfo = Loaded {0} build {1} by: {2} localFormat = Local: <{0}> {1} mailClear = \u00a7cTo mark your mail as read, type /mail clear mailCleared = \u00a77Mail Cleared! |