updated to use corrected joinList function.

This commit is contained in:
okamosy 2011-08-23 22:58:19 +01:00 committed by KHobbits
parent 53a73998a2
commit 6946488e0d
5 changed files with 20 additions and 33 deletions

View File

@ -11,7 +11,6 @@ import java.net.URL;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols; import java.text.DecimalFormatSymbols;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
@ -470,23 +469,35 @@ public class Util
} }
public static String joinList(Object... list) public static String joinList(Object... list)
{
return joinList(", ", list);
}
public static String joinList(String seperator, Object... list)
{ {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
for (Object each : list) for (Object each : list)
{ {
if (buf.length() > 0) if (buf.length() > 0)
{ {
buf.append(", "); buf.append(seperator);
} }
if(each instanceof List) if(each instanceof List)
{ {
buf.append(joinList(((List)each).toArray())); buf.append(joinList(seperator, ((List)each).toArray()));
} }
else else
{
try
{ {
buf.append(each.toString()); buf.append(each.toString());
} }
catch (Exception e)
{
buf.append(each.toString());
}
}
} }
return buf.toString(); return buf.toString();
} }

View File

@ -55,7 +55,7 @@ public class Commandhome extends EssentialsCommand
} }
else else
{ {
user.sendMessage(Util.format("homes", homes.toString())); user.sendMessage(Util.format("homes", Util.joinList(homes)));
} }
} }
} }

View File

@ -1,5 +1,6 @@
package com.earth2me.essentials.commands; package com.earth2me.essentials.commands;
import com.earth2me.essentials.Util;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -14,12 +15,6 @@ public class Commandjails extends EssentialsCommand
@Override @Override
protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
{ {
StringBuilder jailList = new StringBuilder(); sender.sendMessage("§7" + Util.joinList(" ", ess.getJail().getJails()));
for (String j : ess.getJail().getJails())
{
jailList.append(j);
jailList.append(' ');
}
sender.sendMessage("§7" + jailList);
} }
} }

View File

@ -55,16 +55,6 @@ public class Commandrepair extends EssentialsCommand
String armor = repairItems(user.getInventory().getArmorContents()); String armor = repairItems(user.getInventory().getArmorContents());
if (armor.length() > 0)
{
if (itemList.length() > 0)
{
itemList.append(", ");
}
itemList.append(armor);
}
if (itemList.length() == 0) if (itemList.length() == 0)
{ {
user.sendMessage(Util.format("repairNone")); user.sendMessage(Util.format("repairNone"));
@ -72,7 +62,7 @@ public class Commandrepair extends EssentialsCommand
else else
{ {
charge(user); charge(user);
user.sendMessage(Util.format("repair", itemList.toString())); user.sendMessage(Util.format("repair", Util.joinList(itemList)));
} }
} }

View File

@ -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))); 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 int warpPage = (page - 1) * WARPS_PER_PAGE;
final StringBuilder sb = new StringBuilder(); user.sendMessage(Util.joinList(warpNameList.subList(warpPage, warpPage+Math.min(warpNameList.size() - warpPage, WARPS_PER_PAGE))));
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());
return; return;
} }
if (args.length > 0) if (args.length > 0)