From 09f67c97236e1a5444e5eaf6af4ff2dd5b646af8 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sat, 8 Jun 2013 22:31:19 +0100 Subject: Split util classes. --- .../earth2me/essentials/DescParseTickFormat.java | 298 --------- .../src/com/earth2me/essentials/Enchantments.java | 4 +- .../src/com/earth2me/essentials/Essentials.java | 3 +- .../essentials/EssentialsBlockListener.java | 4 +- .../essentials/EssentialsPlayerListener.java | 12 +- .../com/earth2me/essentials/EssentialsUpgrade.java | 3 +- .../src/com/earth2me/essentials/ITarget.java | 1 - Essentials/src/com/earth2me/essentials/ItemDb.java | 6 +- Essentials/src/com/earth2me/essentials/Kit.java | 6 +- .../src/com/earth2me/essentials/MetaItemStack.java | 21 +- .../src/com/earth2me/essentials/Potions.java | 4 +- .../src/com/earth2me/essentials/Settings.java | 5 +- .../src/com/earth2me/essentials/SpawnMob.java | 11 +- .../src/com/earth2me/essentials/Teleport.java | 8 +- Essentials/src/com/earth2me/essentials/User.java | 23 +- .../src/com/earth2me/essentials/UserData.java | 12 +- .../src/com/earth2me/essentials/UserMap.java | 13 +- Essentials/src/com/earth2me/essentials/Util.java | 736 --------------------- Essentials/src/com/earth2me/essentials/Warps.java | 3 +- .../src/com/earth2me/essentials/api/Economy.java | 9 +- .../essentials/commands/Commandantioch.java | 5 +- .../essentials/commands/Commandbalance.java | 9 +- .../essentials/commands/Commandbalancetop.java | 7 +- .../earth2me/essentials/commands/Commandban.java | 5 +- .../essentials/commands/Commandbigtree.java | 7 +- .../essentials/commands/Commandbroadcast.java | 7 +- .../essentials/commands/Commandclearinventory.java | 7 +- .../earth2me/essentials/commands/Commandeco.java | 13 +- .../essentials/commands/Commandenchant.java | 4 +- .../essentials/commands/Commandessentials.java | 12 +- .../earth2me/essentials/commands/Commandexp.java | 7 +- .../essentials/commands/Commandfirework.java | 5 +- .../earth2me/essentials/commands/Commandgc.java | 8 +- .../earth2me/essentials/commands/Commandgive.java | 7 +- .../earth2me/essentials/commands/Commandhelp.java | 5 +- .../essentials/commands/Commandhelpop.java | 5 +- .../earth2me/essentials/commands/Commandhome.java | 4 +- .../earth2me/essentials/commands/Commandjails.java | 4 +- .../earth2me/essentials/commands/Commandjump.java | 5 +- .../earth2me/essentials/commands/Commandkick.java | 5 +- .../essentials/commands/Commandkickall.java | 5 +- .../earth2me/essentials/commands/Commandkit.java | 6 +- .../earth2me/essentials/commands/Commandlist.java | 12 +- .../earth2me/essentials/commands/Commandmail.java | 7 +- .../earth2me/essentials/commands/Commandme.java | 7 +- .../earth2me/essentials/commands/Commandmsg.java | 7 +- .../earth2me/essentials/commands/Commandmute.java | 9 +- .../earth2me/essentials/commands/Commandnick.java | 7 +- .../earth2me/essentials/commands/Commandping.java | 5 +- .../essentials/commands/Commandpotion.java | 4 +- .../essentials/commands/Commandpowertool.java | 6 +- .../earth2me/essentials/commands/Commandptime.java | 2 +- .../com/earth2me/essentials/commands/Commandr.java | 7 +- .../essentials/commands/Commandrealname.java | 5 +- .../essentials/commands/Commandrecipe.java | 5 +- .../essentials/commands/Commandrepair.java | 3 +- .../earth2me/essentials/commands/Commandseen.java | 16 +- .../earth2me/essentials/commands/Commandsell.java | 11 +- .../essentials/commands/Commandsethome.java | 5 +- .../essentials/commands/Commandsetjail.java | 4 +- .../essentials/commands/Commandsetwarp.java | 7 +- .../essentials/commands/Commandspawner.java | 10 +- .../essentials/commands/Commandspawnmob.java | 4 +- .../essentials/commands/Commandtempban.java | 7 +- .../earth2me/essentials/commands/Commandtime.java | 9 +- .../essentials/commands/Commandtogglejail.java | 11 +- .../earth2me/essentials/commands/Commandtree.java | 7 +- .../essentials/commands/Commandunbanip.java | 5 +- .../earth2me/essentials/commands/Commandwarp.java | 9 +- .../earth2me/essentials/commands/Commandwhois.java | 10 +- .../earth2me/essentials/commands/Commandworth.java | 19 +- .../essentials/commands/EssentialsCommand.java | 3 +- .../essentials/perm/PermissionsHandler.java | 5 +- .../earth2me/essentials/signs/EssentialsSign.java | 3 +- .../com/earth2me/essentials/signs/SignBalance.java | 5 +- .../essentials/signs/SignBlockListener.java | 7 +- .../earth2me/essentials/signs/SignProtection.java | 3 +- .../com/earth2me/essentials/signs/SignTrade.java | 9 +- .../essentials/storage/BukkitConstructor.java | 23 +- .../essentials/textreader/KeywordReplacer.java | 7 +- .../earth2me/essentials/textreader/TextInput.java | 6 +- .../com/earth2me/essentials/utils/DateUtil.java | 176 +++++ .../essentials/utils/DescParseTickFormat.java | 298 +++++++++ .../com/earth2me/essentials/utils/FormatUtil.java | 138 ++++ .../earth2me/essentials/utils/LocationUtil.java | 306 +++++++++ .../com/earth2me/essentials/utils/NumberUtil.java | 56 ++ .../com/earth2me/essentials/utils/StringUtil.java | 66 ++ .../test/com/earth2me/essentials/UtilTest.java | 96 +-- EssentialsAntiBuild/nbproject/build-impl.xml | 17 +- EssentialsAntiBuild/nbproject/genfiles.properties | 4 +- EssentialsChat/nbproject/build-impl.xml | 17 +- EssentialsChat/nbproject/genfiles.properties | 4 +- .../chat/EssentialsChatPlayerListenerLowest.java | 5 +- EssentialsGeoIP/nbproject/build-impl.xml | 17 +- EssentialsGeoIP/nbproject/genfiles.properties | 4 +- EssentialsGroupManager/nbproject/build-impl.xml | 17 +- .../nbproject/genfiles.properties | 4 +- EssentialsProtect/nbproject/build-impl.xml | 17 +- EssentialsProtect/nbproject/genfiles.properties | 4 +- EssentialsSpawn/nbproject/build-impl.xml | 17 +- EssentialsSpawn/nbproject/genfiles.properties | 4 +- EssentialsXMPP/nbproject/build-impl.xml | 17 +- EssentialsXMPP/nbproject/genfiles.properties | 4 +- .../com/earth2me/essentials/xmpp/XMPPManager.java | 7 +- 104 files changed, 1542 insertions(+), 1368 deletions(-) delete mode 100644 Essentials/src/com/earth2me/essentials/DescParseTickFormat.java delete mode 100644 Essentials/src/com/earth2me/essentials/Util.java create mode 100644 Essentials/src/com/earth2me/essentials/utils/DateUtil.java create mode 100644 Essentials/src/com/earth2me/essentials/utils/DescParseTickFormat.java create mode 100644 Essentials/src/com/earth2me/essentials/utils/FormatUtil.java create mode 100644 Essentials/src/com/earth2me/essentials/utils/LocationUtil.java create mode 100644 Essentials/src/com/earth2me/essentials/utils/NumberUtil.java create mode 100644 Essentials/src/com/earth2me/essentials/utils/StringUtil.java diff --git a/Essentials/src/com/earth2me/essentials/DescParseTickFormat.java b/Essentials/src/com/earth2me/essentials/DescParseTickFormat.java deleted file mode 100644 index 91efe3c0a..000000000 --- a/Essentials/src/com/earth2me/essentials/DescParseTickFormat.java +++ /dev/null @@ -1,298 +0,0 @@ -package com.earth2me.essentials; - -import static com.earth2me.essentials.I18n._; -import java.text.SimpleDateFormat; -import java.util.*; - - -/** - * This utility class is used for converting between the ingame time in ticks to ingame time as a friendly string. Note - * that the time is INGAME. - * - * http://www.minecraftwiki.net/wiki/Day/night_cycle - * - * @author Olof Larsson - */ -public final class DescParseTickFormat -{ - // ============================================ - // First some information vars. TODO: Should this be in a config file? - // -------------------------------------------- - public static final Map nameToTicks = new LinkedHashMap(); - public static final Set resetAliases = new HashSet(); - public static final int ticksAtMidnight = 18000; - public static final int ticksPerDay = 24000; - public static final int ticksPerHour = 1000; - public static final double ticksPerMinute = 1000d / 60d; - public static final double ticksPerSecond = 1000d / 60d / 60d; - private static final SimpleDateFormat SDFTwentyFour = new SimpleDateFormat("HH:mm", Locale.ENGLISH); - private static final SimpleDateFormat SDFTwelve = new SimpleDateFormat("h:mmaa", Locale.ENGLISH); - - static - { - SDFTwentyFour.setTimeZone(TimeZone.getTimeZone("GMT")); - SDFTwelve.setTimeZone(TimeZone.getTimeZone("GMT")); - - nameToTicks.put("sunrise", 23000); - nameToTicks.put("dawn", 23000); - - nameToTicks.put("daystart", 0); - nameToTicks.put("day", 0); - - nameToTicks.put("morning", 1000); - - nameToTicks.put("midday", 6000); - nameToTicks.put("noon", 6000); - - nameToTicks.put("afternoon", 9000); - - nameToTicks.put("sunset", 12000); - nameToTicks.put("dusk", 12000); - nameToTicks.put("sundown", 12000); - nameToTicks.put("nightfall", 12000); - - nameToTicks.put("nightstart", 14000); - nameToTicks.put("night", 14000); - - nameToTicks.put("midnight", 18000); - - resetAliases.add("reset"); - resetAliases.add("normal"); - resetAliases.add("default"); - } - - private DescParseTickFormat() - { - } - - // ============================================ - // PARSE. From describing String to int - // -------------------------------------------- - public static long parse(String desc) throws NumberFormatException - { - // Only look at alphanumeric and lowercase and : for 24:00 - desc = desc.toLowerCase(Locale.ENGLISH).replaceAll("[^A-Za-z0-9:]", ""); - - // Detect ticks format - try - { - return parseTicks(desc); - } - catch (Exception e) - { - } - - // Detect 24-hour format - try - { - return parse24(desc); - } - catch (Exception e) - { - } - - // Detect 12-hour format - try - { - return parse12(desc); - } - catch (Exception e) - { - } - - // Detect aliases - try - { - return parseAlias(desc); - } - catch (Exception e) - { - } - - // Well we failed to understand... - throw new NumberFormatException(); - } - - public static long parseTicks(String desc) throws NumberFormatException - { - if (!desc.matches("^[0-9]+ti?c?k?s?$")) - { - throw new NumberFormatException(); - } - - desc = desc.replaceAll("[^0-9]", ""); - - return Long.parseLong(desc) % 24000; - } - - public static long parse24(String desc) throws NumberFormatException - { - if (!desc.matches("^[0-9]{2}[^0-9]?[0-9]{2}$")) - { - throw new NumberFormatException(); - } - - desc = desc.toLowerCase(Locale.ENGLISH).replaceAll("[^0-9]", ""); - - if (desc.length() != 4) - { - throw new NumberFormatException(); - } - - final int hours = Integer.parseInt(desc.substring(0, 2)); - final int minutes = Integer.parseInt(desc.substring(2, 4)); - - return hoursMinutesToTicks(hours, minutes); - } - - public static long parse12(String desc) throws NumberFormatException - { - if (!desc.matches("^[0-9]{1,2}([^0-9]?[0-9]{2})?(pm|am)$")) - { - throw new NumberFormatException(); - } - - int hours = 0; - int minutes = 0; - - desc = desc.toLowerCase(Locale.ENGLISH); - String parsetime = desc.replaceAll("[^0-9]", ""); - - if (parsetime.length() > 4) - { - throw new NumberFormatException(); - } - - if (parsetime.length() == 4) - { - hours += Integer.parseInt(parsetime.substring(0, 2)); - minutes += Integer.parseInt(parsetime.substring(2, 4)); - } - else if (parsetime.length() == 3) - { - hours += Integer.parseInt(parsetime.substring(0, 1)); - minutes += Integer.parseInt(parsetime.substring(1, 3)); - } - else if (parsetime.length() == 2) - { - hours += Integer.parseInt(parsetime.substring(0, 2)); - } - else if (parsetime.length() == 1) - { - hours += Integer.parseInt(parsetime.substring(0, 1)); - } - else - { - throw new NumberFormatException(); - } - - if (desc.endsWith("pm") && hours != 12) - { - hours += 12; - } - - if (desc.endsWith("am") && hours == 12) - { - hours -= 12; - } - - return hoursMinutesToTicks(hours, minutes); - } - - public static long hoursMinutesToTicks(final int hours, final int minutes) - { - long ret = ticksAtMidnight; - ret += (hours) * ticksPerHour; - - ret += (minutes / 60.0) * ticksPerHour; - - ret %= ticksPerDay; - return ret; - } - - public static long parseAlias(final String desc) throws NumberFormatException - { - final Integer ret = nameToTicks.get(desc); - if (ret == null) - { - throw new NumberFormatException(); - } - - return ret; - } - - public static boolean meansReset(final String desc) - { - return resetAliases.contains(desc); - } - - // ============================================ - // FORMAT. From int to describing String - // -------------------------------------------- - public static String format(final long ticks) - { - return _("timeFormat", format24(ticks), format12(ticks), formatTicks(ticks)); - } - - public static String formatTicks(final long ticks) - { - return (ticks % ticksPerDay) + "ticks"; - } - - public static String format24(final long ticks) - { - synchronized (SDFTwentyFour) - { - return formatDateFormat(ticks, SDFTwentyFour); - } - } - - public static String format12(final long ticks) - { - synchronized (SDFTwelve) - { - return formatDateFormat(ticks, SDFTwelve); - } - } - - public static String formatDateFormat(final long ticks, final SimpleDateFormat format) - { - final Date date = ticksToDate(ticks); - return format.format(date); - } - - public static Date ticksToDate(long ticks) - { - // Assume the server time starts at 0. It would start on a day. - // But we will simulate that the server started with 0 at midnight. - ticks = ticks - ticksAtMidnight + ticksPerDay; - - // How many ingame days have passed since the server start? - final long days = ticks / ticksPerDay; - ticks -= days * ticksPerDay; - - // How many hours on the last day? - final long hours = ticks / ticksPerHour; - ticks -= hours * ticksPerHour; - - // How many minutes on the last day? - final long minutes = (long)Math.floor(ticks / ticksPerMinute); - final double dticks = ticks - minutes * ticksPerMinute; - - // How many seconds on the last day? - final long seconds = (long)Math.floor(dticks / ticksPerSecond); - - // Now we create an english GMT calendar (We wan't no daylight savings) - final Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.ENGLISH); - cal.setLenient(true); - - // And we set the time to 0! And append the time that passed! - cal.set(0, Calendar.JANUARY, 1, 0, 0, 0); - cal.add(Calendar.DAY_OF_YEAR, (int)days); - cal.add(Calendar.HOUR_OF_DAY, (int)hours); - cal.add(Calendar.MINUTE, (int)minutes); - cal.add(Calendar.SECOND, (int)seconds + 1); // To solve rounding errors. - - return cal.getTime(); - } -} diff --git a/Essentials/src/com/earth2me/essentials/Enchantments.java b/Essentials/src/com/earth2me/essentials/Enchantments.java index e30bff1c1..870cc6436 100644 --- a/Essentials/src/com/earth2me/essentials/Enchantments.java +++ b/Essentials/src/com/earth2me/essentials/Enchantments.java @@ -1,5 +1,7 @@ package com.earth2me.essentials; +import com.earth2me.essentials.utils.NumberUtil; +import com.earth2me.essentials.utils.StringUtil; import java.util.HashMap; import java.util.Locale; import java.util.Map; @@ -142,7 +144,7 @@ public class Enchantments public static Enchantment getByName(String name) { Enchantment enchantment; - if (Util.isInt(name)) { + if (NumberUtil.isInt(name)) { enchantment = Enchantment.getById(Integer.parseInt(name)); } else { enchantment = Enchantment.getByName(name.toUpperCase(Locale.ENGLISH)); diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index 594a63d83..02c72dda1 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -31,6 +31,7 @@ import com.earth2me.essentials.register.payment.Methods; import com.earth2me.essentials.signs.SignBlockListener; import com.earth2me.essentials.signs.SignEntityListener; import com.earth2me.essentials.signs.SignPlayerListener; +import com.earth2me.essentials.utils.DateUtil; import java.io.File; import java.io.FileReader; import java.io.IOException; @@ -411,7 +412,7 @@ public class Essentials extends JavaPlugin implements IEssentials { if (user.getJailTimeout() > 0) { - user.sendMessage(_("playerJailedFor", user.getName(), Util.formatDateDiff(user.getJailTimeout()))); + user.sendMessage(_("playerJailedFor", user.getName(), DateUtil.formatDateDiff(user.getJailTimeout()))); } else { diff --git a/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java b/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java index c5c35d901..a71bf5c4a 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java @@ -1,5 +1,7 @@ package com.earth2me.essentials; +import com.earth2me.essentials.utils.LocationUtil; +import com.earth2me.essentials.utils.StringUtil; import org.bukkit.GameMode; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -22,7 +24,7 @@ public class EssentialsBlockListener implements Listener { // Do not rely on getItemInHand(); // http://leaky.bukkit.org/issues/663 - final ItemStack is = Util.convertBlockToItem(event.getBlockPlaced()); + final ItemStack is = LocationUtil.convertBlockToItem(event.getBlockPlaced()); if (is == null) { return; diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index e4255572b..631e9ec2b 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -5,6 +5,8 @@ import com.earth2me.essentials.textreader.IText; import com.earth2me.essentials.textreader.KeywordReplacer; import com.earth2me.essentials.textreader.TextInput; import com.earth2me.essentials.textreader.TextPager; +import com.earth2me.essentials.utils.DateUtil; +import com.earth2me.essentials.utils.LocationUtil; import java.io.IOException; import java.util.Iterator; import java.util.List; @@ -117,7 +119,7 @@ public class EssentialsPlayerListener implements Listener to.setZ(from.getZ()); try { - event.setTo(Util.getSafeDestination(to)); + event.setTo(LocationUtil.getSafeDestination(to)); } catch (Exception ex) { @@ -261,7 +263,7 @@ public class EssentialsPlayerListener implements Listener final int x = user.getLocation().getBlockX(); int y = user.getLocation().getBlockY(); final int z = user.getLocation().getBlockZ(); - while (Util.isBlockUnsafe(world, x, y, z) && y > -1) + while (LocationUtil.isBlockUnsafe(world, x, y, z) && y > -1) { y--; } @@ -322,7 +324,7 @@ public class EssentialsPlayerListener implements Listener if (user.getBanTimeout() > 0) { //TODO: TL This - banReason += "\n\n" + "Expires in " + Util.formatDateDiff(user.getBanTimeout()); + banReason += "\n\n" + "Expires in " + DateUtil.formatDateDiff(user.getBanTimeout()); } event.disallow(Result.KICK_BANNED, banReason); return; @@ -491,7 +493,7 @@ public class EssentialsPlayerListener implements Listener { try { - final Location otarget = Util.getTarget(user); + final Location otarget = LocationUtil.getTarget(user); ess.scheduleSyncDelayedTask( new Runnable() @@ -502,7 +504,7 @@ public class EssentialsPlayerListener implements Listener Location loc = user.getLocation(); loc.setX(otarget.getX()); loc.setZ(otarget.getZ()); - while (Util.isBlockDamaging(loc.getWorld(), loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ())) + while (LocationUtil.isBlockDamaging(loc.getWorld(), loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ())) { loc.setY(loc.getY() + 1d); } diff --git a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java index 60b23a8c8..5fabf8c7b 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java @@ -1,5 +1,6 @@ package com.earth2me.essentials; +import com.earth2me.essentials.utils.StringUtil; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.craftbukkit.FakeWorld; import com.earth2me.essentials.settings.Spawns; @@ -580,7 +581,7 @@ public class EssentialsUpgrade { continue; } - final String sanitizedFilename = Util.sanitizeFileName(filename.substring(0, filename.length() - 4)) + ".yml"; + final String sanitizedFilename = StringUtil.sanitizeFileName(filename.substring(0, filename.length() - 4)) + ".yml"; if (sanitizedFilename.equals(filename)) { continue; diff --git a/Essentials/src/com/earth2me/essentials/ITarget.java b/Essentials/src/com/earth2me/essentials/ITarget.java index 4fa833807..87b867c13 100644 --- a/Essentials/src/com/earth2me/essentials/ITarget.java +++ b/Essentials/src/com/earth2me/essentials/ITarget.java @@ -1,7 +1,6 @@ package com.earth2me.essentials; import org.bukkit.Location; -import org.bukkit.Server; public interface ITarget diff --git a/Essentials/src/com/earth2me/essentials/ItemDb.java b/Essentials/src/com/earth2me/essentials/ItemDb.java index a5ba4fe2d..f4e9e43b6 100644 --- a/Essentials/src/com/earth2me/essentials/ItemDb.java +++ b/Essentials/src/com/earth2me/essentials/ItemDb.java @@ -1,7 +1,9 @@ package com.earth2me.essentials; +import com.earth2me.essentials.utils.StringUtil; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IItemDb; +import com.earth2me.essentials.utils.NumberUtil; import java.util.*; import java.util.regex.Pattern; import org.bukkit.Material; @@ -94,7 +96,7 @@ public class ItemDb implements IConf, IItemDb itemid = Integer.parseInt(parts[0]); metaData = Short.parseShort(parts[1]); } - else if (Util.isInt(id)) + else if (NumberUtil.isInt(id)) { itemid = Integer.parseInt(id); } @@ -158,7 +160,7 @@ public class ItemDb implements IConf, IItemDb { nameList = nameList.subList(0, 14); } - return Util.joinList(", ", nameList); + return StringUtil.joinList(", ", nameList); } diff --git a/Essentials/src/com/earth2me/essentials/Kit.java b/Essentials/src/com/earth2me/essentials/Kit.java index b5fd48d5d..39fc0fc66 100644 --- a/Essentials/src/com/earth2me/essentials/Kit.java +++ b/Essentials/src/com/earth2me/essentials/Kit.java @@ -8,6 +8,8 @@ import com.earth2me.essentials.craftbukkit.InventoryWorkaround; import com.earth2me.essentials.textreader.IText; import com.earth2me.essentials.textreader.KeywordReplacer; import com.earth2me.essentials.textreader.SimpleTextInput; +import com.earth2me.essentials.utils.NumberUtil; +import com.earth2me.essentials.utils.DateUtil; import java.math.BigDecimal; import java.util.*; import java.util.logging.Level; @@ -37,7 +39,7 @@ public class Kit BigDecimal costPrice = new Trade("kit-" + kitItem.toLowerCase(Locale.ENGLISH), ess).getCommandCost(user); if (costPrice.signum() > 0) { - cost = _("kitCost", Util.displayCurrency(costPrice, ess)); + cost = _("kitCost", NumberUtil.displayCurrency(costPrice, ess)); } final Map kit = ess.getSettings().getKit(kitItem); @@ -74,7 +76,7 @@ public class Kit } else { - user.sendMessage(_("kitTimed", Util.formatDateDiff(nextUse))); + user.sendMessage(_("kitTimed", DateUtil.formatDateDiff(nextUse))); throw new NoChargeException(); } } diff --git a/Essentials/src/com/earth2me/essentials/MetaItemStack.java b/Essentials/src/com/earth2me/essentials/MetaItemStack.java index f7ea6dbcc..352f85330 100644 --- a/Essentials/src/com/earth2me/essentials/MetaItemStack.java +++ b/Essentials/src/com/earth2me/essentials/MetaItemStack.java @@ -1,9 +1,12 @@ package com.earth2me.essentials; +import com.earth2me.essentials.utils.StringUtil; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.textreader.BookInput; import com.earth2me.essentials.textreader.BookPager; import com.earth2me.essentials.textreader.IText; +import com.earth2me.essentials.utils.FormatUtil; +import com.earth2me.essentials.utils.NumberUtil; import java.util.*; import java.util.regex.Pattern; import org.bukkit.Color; @@ -126,7 +129,7 @@ public class MetaItemStack if (split.length > 1 && split[0].equalsIgnoreCase("name") && hasMetaPermission(sender, "name", false, true, ess)) { - final String displayName = Util.replaceFormat(split[1].replace('_', ' ')); + final String displayName = FormatUtil.replaceFormat(split[1].replace('_', ' ')); final ItemMeta meta = stack.getItemMeta(); meta.setDisplayName(displayName); stack.setItemMeta(meta); @@ -136,7 +139,7 @@ public class MetaItemStack final List lore = new ArrayList(); for (String line : split[1].split("\\|")) { - lore.add(Util.replaceFormat(line.replace('_', ' '))); + lore.add(FormatUtil.replaceFormat(line.replace('_', ' '))); } final ItemMeta meta = stack.getItemMeta(); meta.setLore(lore); @@ -176,14 +179,14 @@ public class MetaItemStack } else if (split.length > 1 && split[0].equalsIgnoreCase("title") && stack.getType() == Material.WRITTEN_BOOK && hasMetaPermission(sender, "title", false, true, ess)) { - final String title = Util.replaceFormat(split[1].replace('_', ' ')); + final String title = FormatUtil.replaceFormat(split[1].replace('_', ' ')); final BookMeta meta = (BookMeta)stack.getItemMeta(); meta.setTitle(title); stack.setItemMeta(meta); } else if (split.length > 1 && split[0].equalsIgnoreCase("power") && stack.getType() == Material.FIREWORK && hasMetaPermission(sender, "firework-power", false, true, ess)) { - final int power = Util.isInt(split[1]) ? Integer.parseInt(split[1]) : 0; + final int power = NumberUtil.isInt(split[1]) ? Integer.parseInt(split[1]) : 0; final FireworkMeta meta = (FireworkMeta)stack.getItemMeta(); meta.setPower(power > 3 ? 4 : power); stack.setItemMeta(meta); @@ -205,9 +208,9 @@ public class MetaItemStack final String[] color = split[1].split("(\\||,)"); if (color.length == 3) { - final int red = Util.isInt(color[0]) ? Integer.parseInt(color[0]) : 0; - final int green = Util.isInt(color[1]) ? Integer.parseInt(color[1]) : 0; - final int blue = Util.isInt(color[2]) ? Integer.parseInt(color[2]) : 0; + final int red = NumberUtil.isInt(color[0]) ? Integer.parseInt(color[0]) : 0; + final int green = NumberUtil.isInt(color[1]) ? Integer.parseInt(color[1]) : 0; + final int blue = NumberUtil.isInt(color[2]) ? Integer.parseInt(color[2]) : 0; final LeatherArmorMeta meta = (LeatherArmorMeta)stack.getItemMeta(); meta.setColor(Color.fromRGB(red, green, blue)); stack.setItemMeta(meta); @@ -360,7 +363,7 @@ public class MetaItemStack } else if (split[0].equalsIgnoreCase("power") || (allowShortName && split[0].equalsIgnoreCase("p"))) { - if (Util.isInt(split[1])) + if (NumberUtil.isInt(split[1])) { validPotionPower = true; power = Integer.parseInt(split[1]); @@ -376,7 +379,7 @@ public class MetaItemStack } else if (split[0].equalsIgnoreCase("duration") || (allowShortName && split[0].equalsIgnoreCase("d"))) { - if (Util.isInt(split[1])) + if (NumberUtil.isInt(split[1])) { validPotionDuration = true; duration = Integer.parseInt(split[1]) * 20; //Duration is in ticks by default, converted to seconds diff --git a/Essentials/src/com/earth2me/essentials/Potions.java b/Essentials/src/com/earth2me/essentials/Potions.java index cba132bda..733a36638 100644 --- a/Essentials/src/com/earth2me/essentials/Potions.java +++ b/Essentials/src/com/earth2me/essentials/Potions.java @@ -1,5 +1,7 @@ package com.earth2me.essentials; +import com.earth2me.essentials.utils.NumberUtil; +import com.earth2me.essentials.utils.StringUtil; import java.util.HashMap; import java.util.Locale; import java.util.Map; @@ -104,7 +106,7 @@ public class Potions public static PotionEffectType getByName(String name) { PotionEffectType peffect; - if (Util.isInt(name)) + if (NumberUtil.isInt(name)) { peffect = PotionEffectType.getById(Integer.parseInt(name)); } diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index 78e661b8e..62a8e9813 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -6,6 +6,7 @@ import com.earth2me.essentials.signs.EssentialsSign; import com.earth2me.essentials.signs.Signs; import com.earth2me.essentials.textreader.IText; import com.earth2me.essentials.textreader.SimpleTextInput; +import com.earth2me.essentials.utils.FormatUtil; import java.io.File; import java.math.BigDecimal; import java.text.MessageFormat; @@ -411,7 +412,7 @@ public class Settings implements ISettings { String format = config.getString("chat.group-formats." + (group == null ? "Default" : group), config.getString("chat.format", "&7[{GROUP}]&r {DISPLAYNAME}&7:&r {MESSAGE}")); - format = Util.replaceFormat(format); + format = FormatUtil.replaceFormat(format); format = format.replace("{DISPLAYNAME}", "%1$s"); format = format.replace("{GROUP}", "{0}"); format = format.replace("{MESSAGE}", "%2$s"); @@ -434,7 +435,7 @@ public class Settings implements ISettings @Override public IText getAnnounceNewPlayerFormat() { - return new SimpleTextInput(Util.replaceFormat(config.getString("newbies.announce-format", "&dWelcome {DISPLAYNAME} to the server!"))); + return new SimpleTextInput(FormatUtil.replaceFormat(config.getString("newbies.announce-format", "&dWelcome {DISPLAYNAME} to the server!"))); } @Override diff --git a/Essentials/src/com/earth2me/essentials/SpawnMob.java b/Essentials/src/com/earth2me/essentials/SpawnMob.java index 8fa7c3ac7..34cfe85cf 100644 --- a/Essentials/src/com/earth2me/essentials/SpawnMob.java +++ b/Essentials/src/com/earth2me/essentials/SpawnMob.java @@ -1,7 +1,10 @@ package com.earth2me.essentials; +import com.earth2me.essentials.utils.StringUtil; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Mob.MobException; +import com.earth2me.essentials.utils.LocationUtil; +import com.earth2me.essentials.utils.NumberUtil; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -38,7 +41,7 @@ public class SpawnMob { availableList.add(_("none")); } - return Util.joinList(availableList); + return StringUtil.joinList(availableList); } public static List mobParts(final String mobString) @@ -80,7 +83,7 @@ public class SpawnMob // This method spawns a mob where the user is looking, owned by user public static void spawnmob(final IEssentials ess, final Server server, final User user, final List parts, final List data, int mobCount) throws Exception { - final Block block = Util.getTarget(user).getBlock(); + final Block block = LocationUtil.getTarget(user).getBlock(); if (block == null) { throw new Exception(_("unableToSpawnMob")); @@ -103,7 +106,7 @@ public class SpawnMob // This method spawns a mob at loc, owned by target public static void spawnmob(final IEssentials ess, final Server server, final CommandSender sender, final User target, final Location loc, final List parts, final List data, int mobCount) throws Exception { - final Location sloc = Util.getSafeDestination(loc); + final Location sloc = LocationUtil.getSafeDestination(loc); for (int i = 0; i < parts.size(); i++) { @@ -393,7 +396,7 @@ public class SpawnMob if (type == EntityType.EXPERIENCE_ORB) { - if (Util.isInt(data)) + if (NumberUtil.isInt(data)) { ((ExperienceOrb)spawned).setExperience(Integer.parseInt(data)); diff --git a/Essentials/src/com/earth2me/essentials/Teleport.java b/Essentials/src/com/earth2me/essentials/Teleport.java index d6d4cf628..2c8ef96e3 100644 --- a/Essentials/src/com/earth2me/essentials/Teleport.java +++ b/Essentials/src/com/earth2me/essentials/Teleport.java @@ -2,6 +2,8 @@ package com.earth2me.essentials; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.ITeleport; +import com.earth2me.essentials.utils.DateUtil; +import com.earth2me.essentials.utils.LocationUtil; import java.util.Calendar; import java.util.GregorianCalendar; import org.bukkit.Location; @@ -50,7 +52,7 @@ public class Teleport implements ITeleport time.setTimeInMillis(lastTime); time.add(Calendar.SECOND, (int)cooldown); time.add(Calendar.MILLISECOND, (int)((cooldown * 1000.0) % 1000.0)); - throw new Exception(_("timeBeforeTeleport", Util.formatDateDiff(time.getTimeInMillis()))); + throw new Exception(_("timeBeforeTeleport", DateUtil.formatDateDiff(time.getTimeInMillis()))); } } // if justCheck is set, don't update lastTeleport; we're just checking @@ -65,7 +67,7 @@ public class Teleport implements ITeleport Calendar c = new GregorianCalendar(); c.add(Calendar.SECOND, (int)delay); c.add(Calendar.MILLISECOND, (int)((delay * 1000.0) % 1000.0)); - user.sendMessage(_("dontMoveMessage", Util.formatDateDiff(c.getTimeInMillis()))); + user.sendMessage(_("dontMoveMessage", DateUtil.formatDateDiff(c.getTimeInMillis()))); } //The now function is used when you want to skip tp delay when teleporting someone to a location or player. @@ -93,7 +95,7 @@ public class Teleport implements ITeleport { cancel(false); teleportee.setLastLocation(); - teleportee.getBase().teleport(Util.getSafeDestination(target.getLocation()), cause); + teleportee.getBase().teleport(LocationUtil.getSafeDestination(target.getLocation()), cause); } //The teleportPlayer function is used when you want to normally teleportPlayer someone to a location or player. diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java index f25ea5f1d..93c4733e7 100644 --- a/Essentials/src/com/earth2me/essentials/User.java +++ b/Essentials/src/com/earth2me/essentials/User.java @@ -3,6 +3,9 @@ package com.earth2me.essentials; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.commands.IEssentialsCommand; import com.earth2me.essentials.register.payment.Method; +import com.earth2me.essentials.utils.NumberUtil; +import com.earth2me.essentials.utils.DateUtil; +import com.earth2me.essentials.utils.FormatUtil; import java.math.BigDecimal; import java.util.Calendar; import java.util.GregorianCalendar; @@ -117,7 +120,7 @@ public class User extends UserData implements Comparable, IReplyTo, IUser cooldownTime.add(Calendar.MILLISECOND, (int)((cooldown * 1000.0) % 1000.0)); if (cooldownTime.after(now) && !isAuthorized("essentials.heal.cooldown.bypass")) { - throw new Exception(_("timeBeforeHeal", Util.formatDateDiff(cooldownTime.getTimeInMillis()))); + throw new Exception(_("timeBeforeHeal", DateUtil.formatDateDiff(cooldownTime.getTimeInMillis()))); } } setLastHealTimestamp(now.getTimeInMillis()); @@ -136,10 +139,10 @@ public class User extends UserData implements Comparable, IReplyTo, IUser return; } setMoney(getMoney().add(value)); - sendMessage(_("addedToAccount", Util.displayCurrency(value, ess))); + sendMessage(_("addedToAccount", NumberUtil.displayCurrency(value, ess))); if (initiator != null) { - initiator.sendMessage(_("addedToOthersAccount", Util.displayCurrency(value, ess), this.getDisplayName(), Util.displayCurrency(getMoney(), ess))); + initiator.sendMessage(_("addedToOthersAccount", NumberUtil.displayCurrency(value, ess), this.getDisplayName(), NumberUtil.displayCurrency(getMoney(), ess))); } } @@ -153,8 +156,8 @@ public class User extends UserData implements Comparable, IReplyTo, IUser { setMoney(getMoney().subtract(value)); reciever.setMoney(reciever.getMoney().add(value)); - sendMessage(_("moneySentTo", Util.displayCurrency(value, ess), reciever.getDisplayName())); - reciever.sendMessage(_("moneyRecievedFrom", Util.displayCurrency(value, ess), getDisplayName())); + sendMessage(_("moneySentTo", NumberUtil.displayCurrency(value, ess), reciever.getDisplayName())); + reciever.sendMessage(_("moneyRecievedFrom", NumberUtil.displayCurrency(value, ess), getDisplayName())); } else { @@ -175,10 +178,10 @@ public class User extends UserData implements Comparable, IReplyTo, IUser return; } setMoney(getMoney().subtract(value)); - sendMessage(_("takenFromAccount", Util.displayCurrency(value, ess))); + sendMessage(_("takenFromAccount", NumberUtil.displayCurrency(value, ess))); if (initiator != null) { - initiator.sendMessage(_("takenFromOthersAccount", Util.displayCurrency(value, ess), this.getDisplayName(), Util.displayCurrency(getMoney(), ess))); + initiator.sendMessage(_("takenFromOthersAccount", NumberUtil.displayCurrency(value, ess), this.getDisplayName(), NumberUtil.displayCurrency(getMoney(), ess))); } } @@ -222,7 +225,7 @@ public class User extends UserData implements Comparable, IReplyTo, IUser @Override public int compareTo(final User other) { - return Util.stripFormat(this.getDisplayName()).compareToIgnoreCase(Util.stripFormat(other.getDisplayName())); + return FormatUtil.stripFormat(this.getDisplayName()).compareToIgnoreCase(FormatUtil.stripFormat(other.getDisplayName())); } @Override @@ -336,11 +339,11 @@ public class User extends UserData implements Comparable, IReplyTo, IUser } if (!longnick && output.length() > 16) { - output = Util.lastCode(strPrefix) + nickname; + output = FormatUtil.lastCode(strPrefix) + nickname; } if (!longnick && output.length() > 16) { - output = Util.lastCode(strPrefix) + nickname.substring(0, 14); + output = FormatUtil.lastCode(strPrefix) + nickname.substring(0, 14); } if (output.charAt(output.length() - 1) == '§') { diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java index 014adb08c..a6474b084 100644 --- a/Essentials/src/com/earth2me/essentials/UserData.java +++ b/Essentials/src/com/earth2me/essentials/UserData.java @@ -1,6 +1,8 @@ package com.earth2me.essentials; +import com.earth2me.essentials.utils.StringUtil; import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.utils.NumberUtil; import java.io.File; import java.math.BigDecimal; import java.util.*; @@ -25,7 +27,7 @@ public abstract class UserData extends PlayerExtension implements IConf { folder.mkdirs(); } - config = new EssentialsConf(new File(folder, Util.sanitizeFileName(base.getName()) + ".yml")); + config = new EssentialsConf(new File(folder, StringUtil.sanitizeFileName(base.getName()) + ".yml")); reloadConfig(); } @@ -124,7 +126,7 @@ public abstract class UserData extends PlayerExtension implements IConf private String getHomeName(String search) { - if (Util.isInt(search)) + if (NumberUtil.isInt(search)) { try { @@ -174,7 +176,7 @@ public abstract class UserData extends PlayerExtension implements IConf public void setHome(String name, Location loc) { //Invalid names will corrupt the yaml - name = Util.safeString(name); + name = StringUtil.safeString(name); homes.put(name, loc); config.setProperty("homes." + name, loc); config.save(); @@ -185,7 +187,7 @@ public abstract class UserData extends PlayerExtension implements IConf String search = getHomeName(name); if (!homes.containsKey(search)) { - search = Util.safeString(search); + search = StringUtil.safeString(search); } if (homes.containsKey(search)) { @@ -634,7 +636,7 @@ public abstract class UserData extends PlayerExtension implements IConf public void setBanReason(String reason) { - config.setProperty("ban.reason", Util.sanitizeString(reason)); + config.setProperty("ban.reason", StringUtil.sanitizeString(reason)); config.save(); } diff --git a/Essentials/src/com/earth2me/essentials/UserMap.java b/Essentials/src/com/earth2me/essentials/UserMap.java index 19cfb98e9..6261b0300 100644 --- a/Essentials/src/com/earth2me/essentials/UserMap.java +++ b/Essentials/src/com/earth2me/essentials/UserMap.java @@ -1,5 +1,6 @@ package com.earth2me.essentials; +import com.earth2me.essentials.utils.StringUtil; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; @@ -46,7 +47,7 @@ public class UserMap extends CacheLoader implements IConf continue; } final String name = string.substring(0, string.length() - 4); - keys.add(Util.sanitizeFileName(name)); + keys.add(StringUtil.sanitizeFileName(name)); } } }); @@ -54,7 +55,7 @@ public class UserMap extends CacheLoader implements IConf public boolean userExists(final String name) { - return keys.contains(Util.sanitizeFileName(name)); + return keys.contains(StringUtil.sanitizeFileName(name)); } public User getUser(final String name) @@ -76,7 +77,7 @@ public class UserMap extends CacheLoader implements IConf @Override public User load(final String name) throws Exception { - String sanitizedName = Util.sanitizeFileName(name); + String sanitizedName = StringUtil.sanitizeFileName(name); if (!sanitizedName.equals(name)) { User user = getUser(sanitizedName); @@ -114,8 +115,8 @@ public class UserMap extends CacheLoader implements IConf public void removeUser(final String name) { - keys.remove(Util.sanitizeFileName(name)); - users.invalidate(Util.sanitizeFileName(name)); + keys.remove(StringUtil.sanitizeFileName(name)); + users.invalidate(StringUtil.sanitizeFileName(name)); users.invalidate(name); } @@ -131,7 +132,7 @@ public class UserMap extends CacheLoader implements IConf public File getUserFile(final String name) { - return getUserFile2(Util.sanitizeFileName(name)); + return getUserFile2(StringUtil.sanitizeFileName(name)); } private File getUserFile2(final String name) diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java deleted file mode 100644 index 3b9b93939..000000000 --- a/Essentials/src/com/earth2me/essentials/Util.java +++ /dev/null @@ -1,736 +0,0 @@ -package com.earth2me.essentials; - -import static com.earth2me.essentials.I18n._; -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; -import java.util.*; -import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.entity.LivingEntity; -import org.bukkit.inventory.ItemStack; - - -public class Util -{ - private Util() - { - } - private final static Logger logger = Logger.getLogger("Minecraft"); - private final static Pattern INVALIDFILECHARS = Pattern.compile("[^a-z0-9]"); - private final static Pattern INVALIDCHARS = Pattern.compile("[^\t\n\r\u0020-\u007E\u0085\u00A0-\uD7FF\uE000-\uFFFC]"); - - //Used to clean file names before saving to disk - public static String sanitizeFileName(final String name) - { - return safeString(name); - } - - //Used to clean strings/names before saving as filenames/permissions - public static String safeString(final String string) - { - return INVALIDFILECHARS.matcher(string.toLowerCase(Locale.ENGLISH)).replaceAll("_"); - } - - //Less restrictive string sanitizing, when not used as perm or filename - public static String sanitizeString(final String string) - { - return INVALIDCHARS.matcher(string).replaceAll(""); - } - - public static String formatDateDiff(long date) - { - Calendar c = new GregorianCalendar(); - c.setTimeInMillis(date); - Calendar now = new GregorianCalendar(); - return Util.formatDateDiff(now, c); - } - - public static String formatDateDiff(Calendar fromDate, Calendar toDate) - { - boolean future = false; - if (toDate.equals(fromDate)) - { - return _("now"); - } - if (toDate.after(fromDate)) - { - future = true; - } - - StringBuilder sb = new StringBuilder(); - int[] types = new int[] - { - Calendar.YEAR, - Calendar.MONTH, - Calendar.DAY_OF_MONTH, - Calendar.HOUR_OF_DAY, - Calendar.MINUTE, - Calendar.SECOND - }; - String[] names = new String[] - { - _("year"), - _("years"), - _("month"), - _("months"), - _("day"), - _("days"), - _("hour"), - _("hours"), - _("minute"), - _("minutes"), - _("second"), - _("seconds") - }; - int accuracy = 0; - for (int i = 0; i < types.length; i++) - { - if (accuracy > 2) - { - break; - } - int diff = dateDiff(types[i], fromDate, toDate, future); - if (diff > 0) - { - accuracy++; - sb.append(" ").append(diff).append(" ").append(names[i * 2 + (diff > 1 ? 1 : 0)]); - } - } - if (sb.length() == 0) - { - return "now"; - } - return sb.toString().trim(); - } - - private static int dateDiff(int type, Calendar fromDate, Calendar toDate, boolean future) - { - int diff = 0; - long savedDate = fromDate.getTimeInMillis(); - while ((future && !fromDate.after(toDate)) || (!future && !fromDate.before(toDate))) - { - savedDate = fromDate.getTimeInMillis(); - fromDate.add(type, future ? 1 : -1); - diff++; - } - diff--; - fromDate.setTimeInMillis(savedDate); - return diff; - } - - public static long parseDateDiff(String time, boolean future) throws Exception - { - Pattern timePattern = Pattern.compile( - "(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?" - + "(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?" - + "(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?" - + "(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?" - + "(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?" - + "(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?" - + "(?:([0-9]+)\\s*(?:s[a-z]*)?)?", Pattern.CASE_INSENSITIVE); - Matcher m = timePattern.matcher(time); - int years = 0; - int months = 0; - int weeks = 0; - int days = 0; - int hours = 0; - int minutes = 0; - int seconds = 0; - boolean found = false; - while (m.find()) - { - if (m.group() == null || m.group().isEmpty()) - { - continue; - } - for (int i = 0; i < m.groupCount(); i++) - { - if (m.group(i) != null && !m.group(i).isEmpty()) - { - found = true; - break; - } - } - if (found) - { - if (m.group(1) != null && !m.group(1).isEmpty()) - { - years = Integer.parseInt(m.group(1)); - } - if (m.group(2) != null && !m.group(2).isEmpty()) - { - months = Integer.parseInt(m.group(2)); - } - if (m.group(3) != null && !m.group(3).isEmpty()) - { - weeks = Integer.parseInt(m.group(3)); - } - if (m.group(4) != null && !m.group(4).isEmpty()) - { - days = Integer.parseInt(m.group(4)); - } - if (m.group(5) != null && !m.group(5).isEmpty()) - { - hours = Integer.parseInt(m.group(5)); - } - if (m.group(6) != null && !m.group(6).isEmpty()) - { - minutes = Integer.parseInt(m.group(6)); - } - if (m.group(7) != null && !m.group(7).isEmpty()) - { - seconds = Integer.parseInt(m.group(7)); - } - break; - } - } - if (!found) - { - throw new Exception(_("illegalDate")); - } - Calendar c = new GregorianCalendar(); - if (years > 0) - { - c.add(Calendar.YEAR, years * (future ? 1 : -1)); - } - if (months > 0) - { - c.add(Calendar.MONTH, months * (future ? 1 : -1)); - } - if (weeks > 0) - { - c.add(Calendar.WEEK_OF_YEAR, weeks * (future ? 1 : -1)); - } - if (days > 0) - { - c.add(Calendar.DAY_OF_MONTH, days * (future ? 1 : -1)); - } - if (hours > 0) - { - c.add(Calendar.HOUR_OF_DAY, hours * (future ? 1 : -1)); - } - if (minutes > 0) - { - c.add(Calendar.MINUTE, minutes * (future ? 1 : -1)); - } - if (seconds > 0) - { - c.add(Calendar.SECOND, seconds * (future ? 1 : -1)); - } - - Calendar max = new GregorianCalendar(); - max.add(Calendar.YEAR, 10); - if (c.after(max)) - { - return max.getTimeInMillis(); - } - return c.getTimeInMillis(); - } - // The player can stand inside these materials - private static final Set HOLLOW_MATERIALS = new HashSet(); - private static final HashSet TRANSPARENT_MATERIALS = new HashSet(); - - static - { - HOLLOW_MATERIALS.add(Material.AIR.getId()); - HOLLOW_MATERIALS.add(Material.SAPLING.getId()); - HOLLOW_MATERIALS.add(Material.POWERED_RAIL.getId()); - HOLLOW_MATERIALS.add(Material.DETECTOR_RAIL.getId()); - HOLLOW_MATERIALS.add(Material.LONG_GRASS.getId()); - HOLLOW_MATERIALS.add(Material.DEAD_BUSH.getId()); - HOLLOW_MATERIALS.add(Material.YELLOW_FLOWER.getId()); - HOLLOW_MATERIALS.add(Material.RED_ROSE.getId()); - HOLLOW_MATERIALS.add(Material.BROWN_MUSHROOM.getId()); - HOLLOW_MATERIALS.add(Material.RED_MUSHROOM.getId()); - HOLLOW_MATERIALS.add(Material.TORCH.getId()); - HOLLOW_MATERIALS.add(Material.REDSTONE_WIRE.getId()); - HOLLOW_MATERIALS.add(Material.SEEDS.getId()); - HOLLOW_MATERIALS.add(Material.SIGN_POST.getId()); - HOLLOW_MATERIALS.add(Material.WOODEN_DOOR.getId()); - HOLLOW_MATERIALS.add(Material.LADDER.getId()); - HOLLOW_MATERIALS.add(Material.RAILS.getId()); - HOLLOW_MATERIALS.add(Material.WALL_SIGN.getId()); - HOLLOW_MATERIALS.add(Material.LEVER.getId()); - HOLLOW_MATERIALS.add(Material.STONE_PLATE.getId()); - HOLLOW_MATERIALS.add(Material.IRON_DOOR_BLOCK.getId()); - HOLLOW_MATERIALS.add(Material.WOOD_PLATE.getId()); - HOLLOW_MATERIALS.add(Material.REDSTONE_TORCH_OFF.getId()); - HOLLOW_MATERIALS.add(Material.REDSTONE_TORCH_ON.getId()); - HOLLOW_MATERIALS.add(Material.STONE_BUTTON.getId()); - HOLLOW_MATERIALS.add(Material.SNOW.getId()); - HOLLOW_MATERIALS.add(Material.SUGAR_CANE_BLOCK.getId()); - HOLLOW_MATERIALS.add(Material.DIODE_BLOCK_OFF.getId()); - HOLLOW_MATERIALS.add(Material.DIODE_BLOCK_ON.getId()); - HOLLOW_MATERIALS.add(Material.PUMPKIN_STEM.getId()); - HOLLOW_MATERIALS.add(Material.MELON_STEM.getId()); - HOLLOW_MATERIALS.add(Material.VINE.getId()); - HOLLOW_MATERIALS.add(Material.FENCE_GATE.getId()); - HOLLOW_MATERIALS.add(Material.WATER_LILY.getId()); - HOLLOW_MATERIALS.add(Material.NETHER_WARTS.getId()); - - for (Integer integer : HOLLOW_MATERIALS) - { - TRANSPARENT_MATERIALS.add(integer.byteValue()); - } - TRANSPARENT_MATERIALS.add((byte)Material.WATER.getId()); - TRANSPARENT_MATERIALS.add((byte)Material.STATIONARY_WATER.getId()); - } - - public static Location getTarget(final LivingEntity entity) throws Exception - { - final Block block = entity.getTargetBlock(TRANSPARENT_MATERIALS, 300); - if (block == null) - { - throw new Exception("Not targeting a block"); - } - return block.getLocation(); - } - public final static int RADIUS = 3; - public final static Vector3D[] VOLUME; - - - public static class Vector3D - { - public Vector3D(int x, int y, int z) - { - this.x = x; - this.y = y; - this.z = z; - } - public int x; - public int y; - public int z; - } - - static - { - List pos = new ArrayList(); - for (int x = -RADIUS; x <= RADIUS; x++) - { - for (int y = -RADIUS; y <= RADIUS; y++) - { - for (int z = -RADIUS; z <= RADIUS; z++) - { - pos.add(new Vector3D(x, y, z)); - } - } - } - Collections.sort(pos, new Comparator() - { - @Override - public int compare(Vector3D a, Vector3D b) - { - return (a.x * a.x + a.y * a.y + a.z * a.z) - (b.x * b.x + b.y * b.y + b.z * b.z); - } - }); - VOLUME = pos.toArray(new Vector3D[0]); - } - - public static Location getSafeDestination(final Location loc) throws Exception - { - if (loc == null || loc.getWorld() == null) - { - throw new Exception(_("destinationNotSet")); - } - final World world = loc.getWorld(); - int x = loc.getBlockX(); - int y = (int)Math.round(loc.getY()); - int z = loc.getBlockZ(); - final int origX = x; - final int origY = y; - final int origZ = z; - - while (isBlockAboveAir(world, x, y, z)) - { - y -= 1; - if (y < 0) - { - y = origY; - break; - } - } - - if (isBlockUnsafe(world, x, y, z)) - { - x = Math.round(loc.getX()) == origX ? x - 1 : x + 1; - z = Math.round(loc.getZ()) == origZ ? z - 1 : z + 1; - } - - int i = 0; - while (isBlockUnsafe(world, x, y, z)) - { - i++; - if (i >= VOLUME.length) - { - x = origX; - y = origY + RADIUS; - z = origZ; - break; - } - x = origX + VOLUME[i].x; - y = origY + VOLUME[i].y; - z = origZ + VOLUME[i].z; - } - - while (isBlockUnsafe(world, x, y, z)) - { - y += 1; - if (y >= world.getMaxHeight()) - { - x += 1; - break; - } - } - - while (isBlockUnsafe(world, x, y, z)) - { - y -= 1; - if (y <= 1) - { - x += 1; - y = world.getHighestBlockYAt(x, z); - if (x - 48 > loc.getBlockX()) - { - throw new Exception(_("holeInFloor")); - } - } - } - return new Location(world, x + 0.5D, y, z + 0.5D, loc.getYaw(), loc.getPitch()); - } - - private static boolean isBlockAboveAir(final World world, final int x, final int y, final int z) - { - return HOLLOW_MATERIALS.contains(world.getBlockAt(x, y - 1, z).getType().getId()); - } - - public static boolean isBlockUnsafe(final World world, final int x, final int y, final int z) - { - if (isBlockDamaging(world, x, y, z)) - { - return true; - } - return isBlockAboveAir(world, x, y, z); - } - - public static boolean isBlockDamaging(final World world, final int x, final int y, final int z) - { - final Block below = world.getBlockAt(x, y - 1, z); - if (below.getType() == Material.LAVA || below.getType() == Material.STATIONARY_LAVA) - { - return true; - } - - if (below.getType() == Material.FIRE) - { - return true; - } - - if (below.getType() == Material.BED_BLOCK) - { - return true; - } - - if ((!HOLLOW_MATERIALS.contains(world.getBlockAt(x, y, z).getType().getId())) - || (!HOLLOW_MATERIALS.contains(world.getBlockAt(x, y + 1, z).getType().getId()))) - { - return true; - } - return false; - } - - public static ItemStack convertBlockToItem(final Block block) - { - final ItemStack is = new ItemStack(block.getType(), 1, (short)0, block.getData()); - switch (is.getType()) - { - case WOODEN_DOOR: - is.setType(Material.WOOD_DOOR); - is.setDurability((short)0); - break; - case IRON_DOOR_BLOCK: - is.setType(Material.IRON_DOOR); - is.setDurability((short)0); - break; - case SIGN_POST: - case WALL_SIGN: - is.setType(Material.SIGN); - is.setDurability((short)0); - break; - case CROPS: - is.setType(Material.SEEDS); - is.setDurability((short)0); - break; - case CAKE_BLOCK: - is.setType(Material.CAKE); - is.setDurability((short)0); - break; - case BED_BLOCK: - is.setType(Material.BED); - is.setDurability((short)0); - break; - case REDSTONE_WIRE: - is.setType(Material.REDSTONE); - is.setDurability((short)0); - break; - case REDSTONE_TORCH_OFF: - case REDSTONE_TORCH_ON: - is.setType(Material.REDSTONE_TORCH_ON); - is.setDurability((short)0); - break; - case DIODE_BLOCK_OFF: - case DIODE_BLOCK_ON: - is.setType(Material.DIODE); - is.setDurability((short)0); - break; - case DOUBLE_STEP: - is.setType(Material.STEP); - break; - case TORCH: - case RAILS: - case LADDER: - case WOOD_STAIRS: - case COBBLESTONE_STAIRS: - case LEVER: - case STONE_BUTTON: - case FURNACE: - case DISPENSER: - case PUMPKIN: - case JACK_O_LANTERN: - case WOOD_PLATE: - case STONE_PLATE: - case PISTON_STICKY_BASE: - case PISTON_BASE: - case IRON_FENCE: - case THIN_GLASS: - case TRAP_DOOR: - case FENCE: - case FENCE_GATE: - case NETHER_FENCE: - is.setDurability((short)0); - break; - case FIRE: - return null; - case PUMPKIN_STEM: - is.setType(Material.PUMPKIN_SEEDS); - break; - case MELON_STEM: - is.setType(Material.MELON_SEEDS); - break; - } - return is; - } - private static DecimalFormat currencyFormat = new DecimalFormat("#0.00", DecimalFormatSymbols.getInstance(Locale.US)); - - public static String formatAsCurrency(final BigDecimal value) - { - currencyFormat.setRoundingMode(RoundingMode.FLOOR); - String str = currencyFormat.format(value); - if (str.endsWith(".00")) - { - str = str.substring(0, str.length() - 3); - } - return str; - } - - public static String displayCurrency(final BigDecimal value, final IEssentials ess) - { - return _("currency", ess.getSettings().getCurrencySymbol(), formatAsCurrency(value)); - } - - public static String shortCurrency(final BigDecimal value, final IEssentials ess) - { - return ess.getSettings().getCurrencySymbol() + formatAsCurrency(value); - } - private static DecimalFormat threeDPlaces = new DecimalFormat("#,###.###"); - - public static String formatDouble(final double value) - { - threeDPlaces.setRoundingMode(RoundingMode.HALF_UP); - return threeDPlaces.format(value); - } - - public static boolean isInt(final String sInt) - { - try - { - Integer.parseInt(sInt); - } - catch (NumberFormatException e) - { - return false; - } - return true; - } - - 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(seperator); - } - - if (each instanceof Collection) - { - buf.append(joinList(seperator, ((Collection)each).toArray())); - } - else - { - try - { - buf.append(each.toString()); - } - catch (Exception e) - { - buf.append(each.toString()); - } - } - } - return buf.toString(); - } - - public static String lastCode(final String input) - { - int pos = input.lastIndexOf("§"); - if (pos == -1 || (pos + 1) == input.length()) - { - return ""; - } - return input.substring(pos, pos + 2); - } - private static transient final Pattern URL_PATTERN = Pattern.compile("((?:(?:https?)://)?[\\w-_\\.]{2,})\\.([a-z]{2,3}(?:/\\S+)?)"); - private static transient final Pattern VANILLA_PATTERN = Pattern.compile("\u00A7+[0-9A-FK-ORa-fk-or]?"); - private static transient final Pattern LOGCOLOR_PATTERN = Pattern.compile("\\x1B\\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]"); - private static transient final Pattern REPLACE_PATTERN = Pattern.compile("&([0-9a-fk-or])"); - private static transient final Pattern VANILLA_COLOR_PATTERN = Pattern.compile("\u00A7+[0-9A-Fa-f]"); - private static transient final Pattern VANILLA_MAGIC_PATTERN = Pattern.compile("\u00A7+[Kk]"); - private static transient final Pattern VANILLA_FORMAT_PATTERN = Pattern.compile("\u00A7+[L-ORl-or]"); - private static transient final Pattern REPLACE_COLOR_PATTERN = Pattern.compile("&([0-9a-f])"); - private static transient final Pattern REPLACE_MAGIC_PATTERN = Pattern.compile("&(k)"); - private static transient final Pattern REPLACE_FORMAT_PATTERN = Pattern.compile("&([l-or])"); - - //This method is used to simply strip the native minecraft colour codes - public static String stripFormat(final String input) - { - if (input == null) - { - return null; - } - return VANILLA_PATTERN.matcher(input).replaceAll(""); - } - - public static String stripLogColorFormat(final String input) - { - if (input == null) - { - return null; - } - return LOGCOLOR_PATTERN.matcher(input).replaceAll(""); - } - - //This method is used to simply replace the ess colour codes with minecraft ones, ie &c - public static String replaceFormat(final String input) - { - if (input == null) - { - return null; - } - return REPLACE_PATTERN.matcher(input).replaceAll("\u00a7$1"); - } - - //This is the general permission sensitive message format function, does not touch urls. - public static String formatString(final IUser user, final String permBase, final String input) - { - if (input == null) - { - return null; - } - String message; - if (user.isAuthorized(permBase + ".color")) - { - message = Util.replaceColor(input, REPLACE_COLOR_PATTERN); - } - else - { - message = Util.stripColor(input, VANILLA_COLOR_PATTERN); - } - if (user.isAuthorized(permBase + ".magic")) - { - message = Util.replaceColor(message, REPLACE_MAGIC_PATTERN); - } - else - { - message = Util.stripColor(message, VANILLA_MAGIC_PATTERN); - } - if (user.isAuthorized(permBase + ".format")) - { - message = Util.replaceColor(message, REPLACE_FORMAT_PATTERN); - } - else - { - message = Util.stripColor(message, VANILLA_FORMAT_PATTERN); - } - return message; - } - - //This is the general permission sensitive message format function, checks for urls. - public static String formatMessage(final IUser user, final String permBase, final String input) - { - if (input == null) - { - return null; - } - String message = formatString(user, permBase, input); - if (!user.isAuthorized(permBase + ".url")) - { - message = Util.blockURL(message); - } - return message; - } - - private static String blockURL(final String input) - { - if (input == null) - { - return null; - } - String text = URL_PATTERN.matcher(input).replaceAll("$1 $2"); - while (URL_PATTERN.matcher(text).find()) - { - text = URL_PATTERN.matcher(text).replaceAll("$1 $2"); - } - return text; - } - - private static String stripColor(final String input, final Pattern pattern) - { - return pattern.matcher(input).replaceAll(""); - } - - private static String replaceColor(final String input, final Pattern pattern) - { - return pattern.matcher(input).replaceAll("\u00a7$1"); - } - private static final Pattern IPPATTERN = Pattern.compile( - "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." - + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"); - - public static boolean validIP(String ipAddress) - { - return IPPATTERN.matcher(ipAddress).matches(); - } -} diff --git a/Essentials/src/com/earth2me/essentials/Warps.java b/Essentials/src/com/earth2me/essentials/Warps.java index 4ee883b06..abe8e8dc1 100644 --- a/Essentials/src/com/earth2me/essentials/Warps.java +++ b/Essentials/src/com/earth2me/essentials/Warps.java @@ -1,5 +1,6 @@ package com.earth2me.essentials; +import com.earth2me.essentials.utils.StringUtil; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IWarps; import com.earth2me.essentials.api.InvalidNameException; @@ -64,7 +65,7 @@ public class Warps implements IConf, IWarps @Override public void setWarp(String name, Location loc) throws Exception { - String filename = Util.sanitizeFileName(name); + String filename = StringUtil.sanitizeFileName(name); EssentialsConf conf = warpPoints.get(new StringIgnoreCase(name)); if (conf == null) { diff --git a/Essentials/src/com/earth2me/essentials/api/Economy.java b/Essentials/src/com/earth2me/essentials/api/Economy.java index 1a71e5b7d..22a895e31 100644 --- a/Essentials/src/com/earth2me/essentials/api/Economy.java +++ b/Essentials/src/com/earth2me/essentials/api/Economy.java @@ -4,7 +4,8 @@ import com.earth2me.essentials.EssentialsConf; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.NumberUtil; import java.io.File; import java.math.BigDecimal; import java.math.MathContext; @@ -40,7 +41,7 @@ public final class Economy { folder.mkdirs(); } - EssentialsConf npcConfig = new EssentialsConf(new File(folder, Util.sanitizeFileName(name) + ".yml")); + EssentialsConf npcConfig = new EssentialsConf(new File(folder, StringUtil.sanitizeFileName(name) + ".yml")); npcConfig.load(); npcConfig.setProperty("npc", true); npcConfig.setProperty("money", ess.getSettings().getStartingBalance()); @@ -54,7 +55,7 @@ public final class Economy { folder.mkdirs(); } - File config = new File(folder, Util.sanitizeFileName(name) + ".yml"); + File config = new File(folder, StringUtil.sanitizeFileName(name) + ".yml"); EssentialsConf npcConfig = new EssentialsConf(config); npcConfig.load(); if (npcConfig.hasProperty("npc") && npcConfig.getBoolean("npc", false)) @@ -375,7 +376,7 @@ public final class Economy { throw new RuntimeException(noCallBeforeLoad); } - return Util.displayCurrency(amount, ess); + return NumberUtil.displayCurrency(amount, ess); } /** diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandantioch.java b/Essentials/src/com/earth2me/essentials/commands/Commandantioch.java index 79ef1f969..a98f448f0 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandantioch.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandantioch.java @@ -1,7 +1,8 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.LocationUtil; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.entity.TNTPrimed; @@ -23,7 +24,7 @@ public class Commandantioch extends EssentialsCommand ess.broadcastMessage(user, "who being naughty in My sight, shall snuff it."); } - final Location loc = Util.getTarget(user); + final Location loc = LocationUtil.getTarget(user); loc.getWorld().spawn(loc, TNTPrimed.class); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java b/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java index 270b497ae..ec82c235d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java @@ -2,7 +2,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.NumberUtil; import java.math.BigDecimal; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -24,7 +25,7 @@ public class Commandbalance extends EssentialsCommand } User target = getPlayer(server, args, 0, true, true); - sender.sendMessage(_("balanceOther", target.getDisplayName(), Util.displayCurrency(target.getMoney(), ess))); + sender.sendMessage(_("balanceOther", target.getDisplayName(), NumberUtil.displayCurrency(target.getMoney(), ess))); } @Override @@ -34,13 +35,13 @@ public class Commandbalance extends EssentialsCommand if (args.length < 1 || !user.isAuthorized("essentials.balance.others")) { final BigDecimal bal = user.getMoney(); - user.sendMessage(_("balance", Util.displayCurrency(bal, ess))); + user.sendMessage(_("balance", NumberUtil.displayCurrency(bal, ess))); } else { final User target = getPlayer(server, args, 0, true, true); final BigDecimal bal = target.getMoney(); - user.sendMessage(_("balanceOther", target.getDisplayName(), Util.displayCurrency(bal, ess))); + user.sendMessage(_("balanceOther", target.getDisplayName(), NumberUtil.displayCurrency(bal, ess))); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java index ddb5a7157..ae7c25a56 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java @@ -2,9 +2,10 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; import com.earth2me.essentials.textreader.SimpleTextInput; import com.earth2me.essentials.textreader.TextPager; +import com.earth2me.essentials.utils.NumberUtil; import java.math.BigDecimal; import java.text.DateFormat; import java.util.*; @@ -132,11 +133,11 @@ public class Commandbalancetop extends EssentialsCommand } }); - cache.getLines().add(_("serverTotal", Util.displayCurrency(totalMoney, ess))); + cache.getLines().add(_("serverTotal", NumberUtil.displayCurrency(totalMoney, ess))); int pos = 1; for (Map.Entry entry : sortedEntries) { - cache.getLines().add(pos + ". " + entry.getKey() + ", " + Util.displayCurrency(entry.getValue(), ess)); + cache.getLines().add(pos + ". " + entry.getKey() + ", " + NumberUtil.displayCurrency(entry.getValue(), ess)); pos++; } cacheage = System.currentTimeMillis(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandban.java b/Essentials/src/com/earth2me/essentials/commands/Commandban.java index d985cada1..d3510f1f7 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandban.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandban.java @@ -4,7 +4,8 @@ import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.OfflinePlayer; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.FormatUtil; import java.util.logging.Level; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -56,7 +57,7 @@ public class Commandban extends EssentialsCommand String banReason; if (args.length > 1) { - banReason = Util.replaceFormat(getFinalArg(args, 1).replace("\\n", "\n").replace("|", "\n")); + banReason = FormatUtil.replaceFormat(getFinalArg(args, 1).replace("\\n", "\n").replace("|", "\n")); } else { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java b/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java index 5dd22503a..405a3e703 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java @@ -2,7 +2,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.LocationUtil; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.TreeType; @@ -36,8 +37,8 @@ public class Commandbigtree extends EssentialsCommand throw new NotEnoughArgumentsException(); } - final Location loc = Util.getTarget(user); - final Location safeLocation = Util.getSafeDestination(loc); + final Location loc = LocationUtil.getTarget(user); + final Location safeLocation = LocationUtil.getSafeDestination(loc); final boolean success = user.getWorld().generateTree(safeLocation, tree); if (success) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java b/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java index 2b588d684..e89ed45bc 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java @@ -2,7 +2,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.FormatUtil; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -22,7 +23,7 @@ public class Commandbroadcast extends EssentialsCommand throw new NotEnoughArgumentsException(); } - ess.broadcastMessage(null, _("broadcast", Util.replaceFormat(getFinalArg(args, 0)), user.getDisplayName())); + ess.broadcastMessage(null, _("broadcast", FormatUtil.replaceFormat(getFinalArg(args, 0)), user.getDisplayName())); } @Override @@ -33,6 +34,6 @@ public class Commandbroadcast extends EssentialsCommand throw new NotEnoughArgumentsException(); } - ess.broadcastMessage(null, _("broadcast", Util.replaceFormat(getFinalArg(args, 0)), sender.getName())); + ess.broadcastMessage(null, _("broadcast", FormatUtil.replaceFormat(getFinalArg(args, 0)), sender.getName())); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java index 5ca434fc6..d3de475eb 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java @@ -2,7 +2,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.NumberUtil; +import com.earth2me.essentials.utils.StringUtil; import java.util.List; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -137,7 +138,7 @@ public class Commandclearinventory extends EssentialsCommand final ItemStack item = ess.getItemDb().get(split[0]); final int type = item.getTypeId(); - if (split.length > 1 && Util.isInt(split[1])) + if (split.length > 1 && NumberUtil.isInt(split[1])) { player.getInventory().clear(type, Integer.parseInt(split[1])); } @@ -147,7 +148,7 @@ public class Commandclearinventory extends EssentialsCommand } else { - if (Util.isInt(split[0])) + if (NumberUtil.isInt(split[0])) { player.getInventory().clear(type, -1); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandeco.java b/Essentials/src/com/earth2me/essentials/commands/Commandeco.java index ffb9ef645..300a1f90a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandeco.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandeco.java @@ -2,7 +2,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.NumberUtil; import java.math.BigDecimal; import java.util.Locale; import org.bukkit.Server; @@ -108,11 +109,11 @@ public class Commandeco extends EssentialsCommand if (broadcast != null) { - server.broadcastMessage(_("resetBal", Util.displayCurrency(broadcast, ess))); + server.broadcastMessage(_("resetBal", NumberUtil.displayCurrency(broadcast, ess))); } if (broadcastAll != null) { - server.broadcastMessage(_("resetBalAll", Util.displayCurrency(broadcastAll, ess))); + server.broadcastMessage(_("resetBalAll", NumberUtil.displayCurrency(broadcastAll, ess))); } } @@ -127,7 +128,7 @@ public class Commandeco extends EssentialsCommand else if (sender == null) { player.setMoney(minBalance); - player.sendMessage(_("takenFromAccount", Util.displayCurrency(player.getMoney(), ess))); + player.sendMessage(_("takenFromAccount", NumberUtil.displayCurrency(player.getMoney(), ess))); } else { @@ -140,10 +141,10 @@ public class Commandeco extends EssentialsCommand BigDecimal minBalance = ess.getSettings().getMinMoney(); boolean underMinimum = (amount.compareTo(minBalance) < 0); player.setMoney(underMinimum ? minBalance : amount); - player.sendMessage(_("setBal", Util.displayCurrency(player.getMoney(), ess))); + player.sendMessage(_("setBal", NumberUtil.displayCurrency(player.getMoney(), ess))); if (sender != null) { - sender.sendMessage(_("setBalOthers", player.getDisplayName(), Util.displayCurrency(player.getMoney(), ess))); + sender.sendMessage(_("setBalOthers", player.getDisplayName(), NumberUtil.displayCurrency(player.getMoney(), ess))); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java b/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java index f95b777a2..6f6bbca78 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java @@ -4,7 +4,7 @@ import com.earth2me.essentials.Enchantments; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.MetaItemStack; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; import java.util.Locale; import java.util.Map; import java.util.Set; @@ -43,7 +43,7 @@ public class Commandenchant extends EssentialsCommand //enchantmentslist.add(enchantmentName); } } - throw new NotEnoughArgumentsException(_("enchantments", Util.joinList(enchantmentslist.toArray()))); + throw new NotEnoughArgumentsException(_("enchantments", StringUtil.joinList(enchantmentslist.toArray()))); } int level = -1; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java index 671a5a2b0..126566e3e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java @@ -3,8 +3,10 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.UserMap; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; import com.earth2me.essentials.metrics.Metrics; +import com.earth2me.essentials.utils.DateUtil; +import com.earth2me.essentials.utils.NumberUtil; import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -218,7 +220,7 @@ public class Commandessentials extends EssentialsCommand private void run_cleanup(final Server server, final CommandSender sender, final String command, final String args[]) throws Exception { - if (args.length < 2 || !Util.isInt(args[1])) + if (args.length < 2 || !NumberUtil.isInt(args[1])) { sender.sendMessage("This sub-command will delete users who havent logged in in the last days."); sender.sendMessage("Optional parameters define the minium amount required to prevent deletion."); @@ -229,8 +231,8 @@ public class Commandessentials extends EssentialsCommand final long daysArg = Long.parseLong(args[1]); final double moneyArg = args.length >= 3 ? Double.parseDouble(args[2].replaceAll("[^0-9\\.]", "")) : 0; - final int homesArg = args.length >= 4 && Util.isInt(args[3]) ? Integer.parseInt(args[3]) : 0; - final int bansArg = args.length >= 5 && Util.isInt(args[4]) ? Integer.parseInt(args[4]) : 0; + final int homesArg = args.length >= 4 && NumberUtil.isInt(args[3]) ? Integer.parseInt(args[3]) : 0; + final int bansArg = args.length >= 5 && NumberUtil.isInt(args[4]) ? Integer.parseInt(args[4]) : 0; final UserMap userMap = ess.getUserMap(); ess.runTaskAsynchronously(new Runnable() @@ -272,7 +274,7 @@ public class Commandessentials extends EssentialsCommand if (ess.getSettings().isDebug()) { - ess.getLogger().info("Deleting user: " + user.getName() + " Money: " + moneyCount + " Homes: " + homeCount + " Last seen: " + Util.formatDateDiff(lastLog)); + ess.getLogger().info("Deleting user: " + user.getName() + " Money: " + moneyCount + " Homes: " + homeCount + " Last seen: " + DateUtil.formatDateDiff(lastLog)); } user.reset(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandexp.java b/Essentials/src/com/earth2me/essentials/commands/Commandexp.java index d309b595b..c2a1dc9ff 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandexp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandexp.java @@ -2,8 +2,9 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; import com.earth2me.essentials.craftbukkit.SetExpFix; +import com.earth2me.essentials.utils.NumberUtil; import java.util.List; import java.util.Locale; import org.bukkit.Server; @@ -61,7 +62,7 @@ public class Commandexp extends EssentialsCommand } else { - if (args.length >= 1 && Util.isInt(args[0].toLowerCase(Locale.ENGLISH).replace("l", "")) && user.isAuthorized("essentials.exp.give")) + if (args.length >= 1 && NumberUtil.isInt(args[0].toLowerCase(Locale.ENGLISH).replace("l", "")) && user.isAuthorized("essentials.exp.give")) { if (args.length >= 2 && user.isAuthorized("essentials.exp.give.others")) { @@ -102,7 +103,7 @@ public class Commandexp extends EssentialsCommand else { String match = args[0].trim(); - if (args.length >= 2 && Util.isInt(args[0].toLowerCase(Locale.ENGLISH).replace("l", ""))) + if (args.length >= 2 && NumberUtil.isInt(args[0].toLowerCase(Locale.ENGLISH).replace("l", ""))) { match = args[1].trim(); expMatch(server, sender, match, args[0], true); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandfirework.java b/Essentials/src/com/earth2me/essentials/commands/Commandfirework.java index 41a844fbd..b07a93595 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandfirework.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandfirework.java @@ -3,7 +3,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.MetaItemStack; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.NumberUtil; +import com.earth2me.essentials.utils.StringUtil; import java.util.regex.Pattern; import org.bukkit.FireworkEffect; import org.bukkit.Material; @@ -75,7 +76,7 @@ public class Commandfirework extends EssentialsCommand boolean direction = false; if (args.length > 1) { - if (Util.isInt(args[1])) + if (NumberUtil.isInt(args[1])) { final int serverLimit = ess.getSettings().getSpawnMobLimit(); amount = Integer.parseInt(args[1]); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgc.java b/Essentials/src/com/earth2me/essentials/commands/Commandgc.java index 1cb0696da..ccfc2e598 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgc.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgc.java @@ -1,7 +1,9 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.NumberUtil; +import com.earth2me.essentials.utils.DateUtil; import java.lang.management.ManagementFactory; import java.util.List; import org.bukkit.ChatColor; @@ -35,8 +37,8 @@ public class Commandgc extends EssentialsCommand color = ChatColor.RED; } - sender.sendMessage(_("uptime", Util.formatDateDiff(ManagementFactory.getRuntimeMXBean().getStartTime()))); - sender.sendMessage(_("tps", "" + color + Util.formatDouble(tps))); + sender.sendMessage(_("uptime", DateUtil.formatDateDiff(ManagementFactory.getRuntimeMXBean().getStartTime()))); + sender.sendMessage(_("tps", "" + color + NumberUtil.formatDouble(tps))); sender.sendMessage(_("gcmax", (Runtime.getRuntime().maxMemory() / 1024 / 1024))); sender.sendMessage(_("gctotal", (Runtime.getRuntime().totalMemory() / 1024 / 1024))); sender.sendMessage(_("gcfree", (Runtime.getRuntime().freeMemory() / 1024 / 1024))); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java index 098499a9e..1d668d2b5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java @@ -3,8 +3,9 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.MetaItemStack; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; import com.earth2me.essentials.craftbukkit.InventoryWorkaround; +import com.earth2me.essentials.utils.NumberUtil; import java.util.Locale; import org.bukkit.Material; import org.bukkit.Server; @@ -46,7 +47,7 @@ public class Commandgive extends EssentialsCommand try { - if (args.length > 3 && Util.isInt(args[2]) && Util.isInt(args[3])) + if (args.length > 3 && NumberUtil.isInt(args[2]) && NumberUtil.isInt(args[3])) { stack.setAmount(Integer.parseInt(args[2])); stack.setDurability(Short.parseShort(args[3])); @@ -78,7 +79,7 @@ public class Commandgive extends EssentialsCommand allowUnsafe = false; } - metaStack.parseStringMeta(sender, allowUnsafe, args, Util.isInt(args[3]) ? 4 : 3, ess); + metaStack.parseStringMeta(sender, allowUnsafe, args, NumberUtil.isInt(args[3]) ? 4 : 3, ess); stack = metaStack.getItemStack(); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java b/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java index 6339359f1..2a650fff1 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java @@ -2,8 +2,9 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; import com.earth2me.essentials.textreader.*; +import com.earth2me.essentials.utils.NumberUtil; import java.util.Locale; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -27,7 +28,7 @@ public class Commandhelp extends EssentialsCommand if (input.getLines().isEmpty()) { - if (Util.isInt(pageStr) || pageStr == null) + if (NumberUtil.isInt(pageStr) || pageStr == null) { output = new HelpInput(user, "", ess); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java b/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java index 3a00c86e3..820efd343 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java @@ -3,7 +3,8 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.FormatUtil; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -35,7 +36,7 @@ public class Commandhelpop extends EssentialsCommand { throw new NotEnoughArgumentsException(); } - final String message = _("helpOp", from, Util.stripFormat(getFinalArg(args, 0))); + final String message = _("helpOp", from, FormatUtil.stripFormat(getFinalArg(args, 0))); CommandSender cs = Console.getCommandSender(server); cs.sendMessage(message); for (Player onlinePlayer : server.getOnlinePlayers()) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java index a13616dc0..903f773d8 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java @@ -3,7 +3,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; import java.util.List; import java.util.Locale; import org.bukkit.Location; @@ -87,7 +87,7 @@ public class Commandhome extends EssentialsCommand homes.add(_("bedNull")); } } - user.sendMessage(_("homes", Util.joinList(homes))); + user.sendMessage(_("homes", StringUtil.joinList(homes))); } } throw new NoChargeException(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandjails.java b/Essentials/src/com/earth2me/essentials/commands/Commandjails.java index 051bcf710..b7eccdba3 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandjails.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandjails.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -15,6 +15,6 @@ public class Commandjails extends EssentialsCommand @Override protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception { - sender.sendMessage("§7" + Util.joinList(" ", ess.getJails().getList())); + sender.sendMessage("§7" + StringUtil.joinList(" ", ess.getJails().getList())); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandjump.java b/Essentials/src/com/earth2me/essentials/commands/Commandjump.java index 073c20dce..edc67e482 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandjump.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandjump.java @@ -3,7 +3,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.LocationUtil; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -39,7 +40,7 @@ public class Commandjump extends EssentialsCommand try { - loc = Util.getTarget(user); + loc = LocationUtil.getTarget(user); loc.setYaw(cloc.getYaw()); loc.setPitch(cloc.getPitch()); loc.setY(loc.getY() + 1); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java index 9df21285d..f50bb4bfb 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java @@ -3,7 +3,8 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.FormatUtil; import java.util.logging.Level; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -41,7 +42,7 @@ public class Commandkick extends EssentialsCommand } String kickReason = args.length > 1 ? getFinalArg(args, 1) : _("kickDefault"); - kickReason = Util.replaceFormat(kickReason.replace("\\n", "\n").replace("|", "\n")); + kickReason = FormatUtil.replaceFormat(kickReason.replace("\\n", "\n").replace("|", "\n")); target.kickPlayer(kickReason); final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java b/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java index 6944823f3..95104fc61 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java @@ -1,7 +1,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.FormatUtil; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -18,7 +19,7 @@ public class Commandkickall extends EssentialsCommand public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception { String kickReason = args.length > 0 ? getFinalArg(args, 0) : _("kickDefault"); - kickReason = Util.replaceFormat(kickReason.replace("\\n", "\n").replace("|", "\n")); + kickReason = FormatUtil.replaceFormat(kickReason.replace("\\n", "\n").replace("|", "\n")); for (Player onlinePlayer : server.getOnlinePlayers()) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java index 0cbab8cb6..c3983b835 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java @@ -4,7 +4,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Kit; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; import java.util.List; import java.util.Locale; import java.util.Map; @@ -31,12 +31,12 @@ public class Commandkit extends EssentialsCommand else if (args.length > 1 && user.isAuthorized("essentials.kit.others")) { final User userTo = getPlayer(server, user, args, 1); - final String kitName = Util.sanitizeString(args[0].toLowerCase(Locale.ENGLISH)).trim(); + final String kitName = StringUtil.sanitizeString(args[0].toLowerCase(Locale.ENGLISH)).trim(); giveKit(userTo, user, kitName); } else { - final String kitName = Util.sanitizeString(args[0].toLowerCase(Locale.ENGLISH)).trim(); + final String kitName = StringUtil.sanitizeString(args[0].toLowerCase(Locale.ENGLISH)).trim(); giveKit(user, user, kitName); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java index 5e0c03387..62acdbb70 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java @@ -2,7 +2,9 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.FormatUtil; +import com.earth2me.essentials.utils.NumberUtil; import java.util.*; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -73,7 +75,7 @@ public class Commandlist extends EssentialsCommand { continue; } - final String group = Util.stripFormat(onlineUser.getGroup().toLowerCase()); + final String group = FormatUtil.stripFormat(onlineUser.getGroup().toLowerCase()); List list = playerList.get(group); if (list == null) { @@ -163,7 +165,7 @@ public class Commandlist extends EssentialsCommand List matchedList = playerList.get(configGroup); // If the group value is an int, then we might need to truncate it - if (Util.isInt(groupValue)) + if (NumberUtil.isInt(groupValue)) { if (matchedList != null && !matchedList.isEmpty()) { @@ -172,7 +174,7 @@ public class Commandlist extends EssentialsCommand int limit = Integer.parseInt(groupValue); if (matchedList.size() > limit) { - sender.sendMessage(outputFormat(oConfigGroup, _("groupNumber", matchedList.size(), commandLabel, Util.stripFormat(configGroup)))); + sender.sendMessage(outputFormat(oConfigGroup, _("groupNumber", matchedList.size(), commandLabel, FormatUtil.stripFormat(configGroup)))); } else { @@ -262,7 +264,7 @@ public class Commandlist extends EssentialsCommand private String outputFormat(String group, String message) { final StringBuilder outputString = new StringBuilder(); - outputString.append(_("listGroupTag", Util.replaceFormat(group))); + outputString.append(_("listGroupTag", FormatUtil.replaceFormat(group))); outputString.append(message); outputString.setCharAt(0, Character.toTitleCase(outputString.charAt(0))); return outputString.toString(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java index e6c4cd8ab..ebf3730f4 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java @@ -2,7 +2,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.FormatUtil; import java.util.List; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -51,7 +52,7 @@ public class Commandmail extends EssentialsCommand } if (!u.isIgnoredPlayer(user)) { - final String mail = user.getName() + ": " + Util.sanitizeString(Util.stripFormat(getFinalArg(args, 2))); + final String mail = user.getName() + ": " + StringUtil.sanitizeString(FormatUtil.stripFormat(getFinalArg(args, 2))); if (mail.length() > 1000) { throw new Exception("Mail message too long. Try to keep it below 1000"); @@ -77,7 +78,7 @@ public class Commandmail extends EssentialsCommand { throw new Exception(_("noPerm", "essentials.mail.sendall")); } - ess.runTaskAsynchronously(new SendAll(user.getName() + ": " + Util.stripFormat(getFinalArg(args, 1)))); + ess.runTaskAsynchronously(new SendAll(user.getName() + ": " + FormatUtil.stripFormat(getFinalArg(args, 1)))); user.sendMessage(_("mailSent")); return; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandme.java b/Essentials/src/com/earth2me/essentials/commands/Commandme.java index 6120caaf2..e1b088e25 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandme.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandme.java @@ -2,7 +2,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.FormatUtil; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -28,7 +29,7 @@ public class Commandme extends EssentialsCommand } String message = getFinalArg(args, 0); - message = Util.formatMessage(user, "essentials.chat", message); + message = FormatUtil.formatMessage(user, "essentials.chat", message); user.setDisplayNick(); ess.broadcastMessage(user, _("action", user.getDisplayName(), message)); @@ -43,7 +44,7 @@ public class Commandme extends EssentialsCommand } String message = getFinalArg(args, 0); - message = Util.replaceFormat(message); + message = FormatUtil.replaceFormat(message); ess.getServer().broadcastMessage(_("action", "@", message)); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java b/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java index 585bb5b29..ca33c33b2 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java @@ -4,7 +4,8 @@ import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.IReplyTo; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.FormatUtil; import java.util.List; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -34,11 +35,11 @@ public class Commandmsg extends EssentialsCommand { throw new Exception(_("voiceSilenced")); } - message = Util.formatMessage(user, "essentials.msg", message); + message = FormatUtil.formatMessage(user, "essentials.msg", message); } else { - message = Util.replaceFormat(message); + message = FormatUtil.replaceFormat(message); } final String translatedMe = _("me"); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java index 4b376b9a7..1a6ab80a2 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java @@ -2,7 +2,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.DateUtil; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -33,7 +34,7 @@ public class Commandmute extends EssentialsCommand if (args.length > 1) { final String time = getFinalArg(args, 1); - muteTimestamp = Util.parseDateDiff(time, true); + muteTimestamp = DateUtil.parseDateDiff(time, true); player.setMuted(true); } else @@ -46,8 +47,8 @@ public class Commandmute extends EssentialsCommand { if (muteTimestamp > 0) { - sender.sendMessage(_("mutedPlayerFor", player.getDisplayName(), Util.formatDateDiff(muteTimestamp))); - player.sendMessage(_("playerMutedFor", Util.formatDateDiff(muteTimestamp))); + sender.sendMessage(_("mutedPlayerFor", player.getDisplayName(), DateUtil.formatDateDiff(muteTimestamp))); + player.sendMessage(_("playerMutedFor", DateUtil.formatDateDiff(muteTimestamp))); } else { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java index b7cf4b32d..d54524ba5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java @@ -2,7 +2,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.FormatUtil; import java.util.Locale; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -66,11 +67,11 @@ public class Commandnick extends EssentialsCommand { if (user == null) { - return Util.replaceFormat(nick); + return FormatUtil.replaceFormat(nick); } else { - return Util.formatString(user, "essentials.nick", nick); + return FormatUtil.formatString(user, "essentials.nick", nick); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandping.java b/Essentials/src/com/earth2me/essentials/commands/Commandping.java index 0b1df5bf5..bd0c25d90 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandping.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandping.java @@ -1,7 +1,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.FormatUtil; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -23,7 +24,7 @@ public class Commandping extends EssentialsCommand } else { - sender.sendMessage(Util.replaceFormat(getFinalArg(args, 0))); + sender.sendMessage(FormatUtil.replaceFormat(getFinalArg(args, 0))); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpotion.java b/Essentials/src/com/earth2me/essentials/commands/Commandpotion.java index 1e0937e6f..f5c760016 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpotion.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpotion.java @@ -4,7 +4,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.MetaItemStack; import com.earth2me.essentials.Potions; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; import java.util.Locale; import java.util.Map; import java.util.Set; @@ -40,7 +40,7 @@ public class Commandpotion extends EssentialsCommand potionslist.add(entry.getKey()); } } - throw new NotEnoughArgumentsException(_("potions", Util.joinList(potionslist.toArray()))); + throw new NotEnoughArgumentsException(_("potions", StringUtil.joinList(potionslist.toArray()))); } if (stack.getType() == Material.POTION) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java index d72744ae3..5aad27e1a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java @@ -2,7 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -68,7 +68,7 @@ public class Commandpowertool extends EssentialsCommand } else { - sender.sendMessage(_("powerToolList", Util.joinList(powertools), itemName)); + sender.sendMessage(_("powerToolList", StringUtil.joinList(powertools), itemName)); } throw new NoChargeException(); } @@ -108,7 +108,7 @@ public class Commandpowertool extends EssentialsCommand } powertools.add(command); - sender.sendMessage(_("powerToolAttach", Util.joinList(powertools), itemName)); + sender.sendMessage(_("powerToolAttach", StringUtil.joinList(powertools), itemName)); } } else diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandptime.java b/Essentials/src/com/earth2me/essentials/commands/Commandptime.java index 46548c57c..44e9bbc64 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandptime.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandptime.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.DescParseTickFormat; +import com.earth2me.essentials.utils.DescParseTickFormat; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import java.util.*; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandr.java b/Essentials/src/com/earth2me/essentials/commands/Commandr.java index d2dfeb78b..e882c0233 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandr.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandr.java @@ -4,7 +4,8 @@ import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.IReplyTo; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.FormatUtil; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -32,13 +33,13 @@ public class Commandr extends EssentialsCommand if (sender instanceof Player) { User user = ess.getUser(sender); - message = Util.formatMessage(user, "essentials.msg", message); + message = FormatUtil.formatMessage(user, "essentials.msg", message); replyTo = user; senderName = user.getDisplayName(); } else { - message = Util.replaceFormat(message); + message = FormatUtil.replaceFormat(message); replyTo = Console.getConsoleReplyTo(); senderName = Console.NAME; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java index dae764160..9cf194798 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java @@ -2,7 +2,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.FormatUtil; import java.util.Locale; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -34,7 +35,7 @@ public class Commandrealname extends EssentialsCommand continue; } u.setDisplayNick(); - final String displayName = Util.stripFormat(u.getDisplayName()).toLowerCase(Locale.ENGLISH); + final String displayName = FormatUtil.stripFormat(u.getDisplayName()).toLowerCase(Locale.ENGLISH); if (displayName.contains(whois)) { foundUser = true; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrecipe.java b/Essentials/src/com/earth2me/essentials/commands/Commandrecipe.java index 7f40a062c..9ccfd21d1 100755 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrecipe.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrecipe.java @@ -2,7 +2,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.NumberUtil; +import com.earth2me.essentials.utils.StringUtil; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -34,7 +35,7 @@ public class Commandrecipe extends EssentialsCommand if (args.length > 1) { - if (Util.isInt(args[1])) + if (NumberUtil.isInt(args[1])) { recipeNo = Integer.parseInt(args[1]) - 1; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java b/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java index a0a0513c2..32b4fd5ee 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.utils.StringUtil; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.*; import java.util.ArrayList; @@ -80,7 +81,7 @@ public class Commandrepair extends EssentialsCommand } else { - user.sendMessage(_("repair", Util.joinList(repaired))); + user.sendMessage(_("repair", StringUtil.joinList(repaired))); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandseen.java b/Essentials/src/com/earth2me/essentials/commands/Commandseen.java index 8c34687ca..655886e83 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandseen.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandseen.java @@ -3,7 +3,9 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.UserMap; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.DateUtil; +import com.earth2me.essentials.utils.FormatUtil; import java.util.ArrayList; import java.util.List; import org.bukkit.Location; @@ -47,7 +49,7 @@ public class Commandseen extends EssentialsCommand User player = ess.getOfflineUser(args[0]); if (player == null) { - if (ipLookup && Util.validIP(args[0])) + if (ipLookup && FormatUtil.validIP(args[0])) { seenIP(server, sender, args[0]); return; @@ -65,7 +67,7 @@ public class Commandseen extends EssentialsCommand { user.setDisplayNick(); - sender.sendMessage(_("seenOnline", user.getDisplayName(), Util.formatDateDiff(user.getLastLogin()))); + sender.sendMessage(_("seenOnline", user.getDisplayName(), DateUtil.formatDateDiff(user.getLastLogin()))); if (user.isAfk()) { sender.sendMessage(_("whoisAFK", _("true"))); @@ -73,13 +75,13 @@ public class Commandseen extends EssentialsCommand if (user.isJailed()) { sender.sendMessage(_("whoisJail", (user.getJailTimeout() > 0 - ? Util.formatDateDiff(user.getJailTimeout()) + ? DateUtil.formatDateDiff(user.getJailTimeout()) : _("true")))); } if (user.isMuted()) { sender.sendMessage(_("whoisMuted", (user.getMuteTimeout() > 0 - ? Util.formatDateDiff(user.getMuteTimeout()) + ? DateUtil.formatDateDiff(user.getMuteTimeout()) : _("true")))); } final String location = user.getGeoLocation(); @@ -98,7 +100,7 @@ public class Commandseen extends EssentialsCommand user.setDisplayNick(); if (user.getLastLogout() > 0) { - sender.sendMessage(_("seenOffline", user.getName(), Util.formatDateDiff(user.getLastLogout()))); + sender.sendMessage(_("seenOffline", user.getName(), DateUtil.formatDateDiff(user.getLastLogout()))); } else { @@ -157,7 +159,7 @@ public class Commandseen extends EssentialsCommand if (matches.size() > 0) { sender.sendMessage(_("matchingIPAddress")); - sender.sendMessage(Util.joinList(matches)); + sender.sendMessage(StringUtil.joinList(matches)); } else { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java index a0a142630..efa37b2eb 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java @@ -3,7 +3,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.NumberUtil; import java.math.BigDecimal; import java.util.Locale; import java.util.logging.Level; @@ -51,7 +52,7 @@ public class Commandsell extends EssentialsCommand } if (totalWorth.signum() > 0) { - user.sendMessage(_("totalWorthAll", type, Util.displayCurrency(totalWorth, ess))); + user.sendMessage(_("totalWorthAll", type, NumberUtil.displayCurrency(totalWorth, ess))); } return; } @@ -73,7 +74,7 @@ public class Commandsell extends EssentialsCommand } if (totalWorth.signum() > 0) { - user.sendMessage(_("totalWorthBlocks", type, Util.displayCurrency(totalWorth, ess))); + user.sendMessage(_("totalWorthBlocks", type, NumberUtil.displayCurrency(totalWorth, ess))); } return; } @@ -163,8 +164,8 @@ public class Commandsell extends EssentialsCommand user.updateInventory(); Trade.log("Command", "Sell", "Item", user.getName(), new Trade(ris, ess), user.getName(), new Trade(result, ess), user.getLocation(), ess); user.giveMoney(result); - user.sendMessage(_("itemSold", Util.displayCurrency(result, ess), amount, is.getType().toString().toLowerCase(Locale.ENGLISH), Util.displayCurrency(worth, ess))); - logger.log(Level.INFO, _("itemSoldConsole", user.getDisplayName(), is.getType().toString().toLowerCase(Locale.ENGLISH), Util.displayCurrency(result, ess), amount, Util.displayCurrency(worth, ess))); + user.sendMessage(_("itemSold", NumberUtil.displayCurrency(result, ess), amount, is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(worth, ess))); + logger.log(Level.INFO, _("itemSoldConsole", user.getDisplayName(), is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(result, ess), amount, NumberUtil.displayCurrency(worth, ess))); return result; } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java b/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java index 1e27e7e3b..67e94acc5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java @@ -2,7 +2,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.NumberUtil; +import com.earth2me.essentials.utils.StringUtil; import java.util.Locale; import org.bukkit.Location; import org.bukkit.Server; @@ -52,7 +53,7 @@ public class Commandsethome extends EssentialsCommand { name = "home"; } - if ("bed".equals(name) || Util.isInt(name)) + if ("bed".equals(name) || NumberUtil.isInt(name)) { throw new NoSuchFieldException(_("invalidHomeName")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java b/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java index 877da4d26..7d590b352 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java @@ -2,7 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; import org.bukkit.Server; @@ -21,7 +21,7 @@ public class Commandsetjail extends EssentialsCommand throw new NotEnoughArgumentsException(); } ess.getJails().setJail(args[0], user.getLocation()); - user.sendMessage(_("jailSet", Util.sanitizeString(args[0]))); + user.sendMessage(_("jailSet", StringUtil.sanitizeString(args[0]))); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java index 279d069aa..6fc79092f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java @@ -2,8 +2,9 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; import com.earth2me.essentials.api.IWarps; +import com.earth2me.essentials.utils.NumberUtil; import org.bukkit.Location; import org.bukkit.Server; @@ -23,7 +24,7 @@ public class Commandsetwarp extends EssentialsCommand throw new NotEnoughArgumentsException(); } - if (Util.isInt(args[0]) || args[0].isEmpty()) + if (NumberUtil.isInt(args[0]) || args[0].isEmpty()) { throw new NoSuchFieldException(_("invalidWarpName")); } @@ -40,7 +41,7 @@ public class Commandsetwarp extends EssentialsCommand { } - if (warpLoc == null || user.isAuthorized("essentials.warp.overwrite." + Util.safeString(args[0]))) + if (warpLoc == null || user.isAuthorized("essentials.warp.overwrite." + StringUtil.safeString(args[0]))) { warps.setWarp(args[0], loc); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java index a01f42f01..a0fb1d9b0 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java @@ -4,7 +4,9 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Mob; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.LocationUtil; +import com.earth2me.essentials.utils.NumberUtil; import java.util.Locale; import org.bukkit.Location; import org.bukkit.Material; @@ -24,10 +26,10 @@ public class Commandspawner extends EssentialsCommand { if (args.length < 1 || args[0].length() < 2) { - throw new NotEnoughArgumentsException(_("mobsAvailable", Util.joinList(Mob.getMobList()))); + throw new NotEnoughArgumentsException(_("mobsAvailable", StringUtil.joinList(Mob.getMobList()))); } - final Location target = Util.getTarget(user); + final Location target = LocationUtil.getTarget(user); if (target == null || target.getBlock().getType() != Material.MOB_SPAWNER) { throw new Exception(_("mobSpawnTarget")); @@ -52,7 +54,7 @@ public class Commandspawner extends EssentialsCommand } if (args.length > 1) { - if (Util.isInt(args[1])) + if (NumberUtil.isInt(args[1])) { delay = Integer.parseInt(args[1]); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java index 706a3f84b..6b1fe596a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java @@ -4,7 +4,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Mob; import com.earth2me.essentials.SpawnMob; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; import java.util.List; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -55,7 +55,7 @@ public class Commandspawnmob extends EssentialsCommand { if (args.length < 3) { - final String mobList = Util.joinList(Mob.getMobList()); + final String mobList = StringUtil.joinList(Mob.getMobList()); throw new NotEnoughArgumentsException(_("mobsAvailable", mobList)); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java b/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java index 016f7f773..689ffdfcc 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java @@ -3,7 +3,8 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.DateUtil; import java.util.GregorianCalendar; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -43,7 +44,7 @@ public class Commandtempban extends EssentialsCommand } } final String time = getFinalArg(args, 1); - final long banTimestamp = Util.parseDateDiff(time, true); + final long banTimestamp = DateUtil.parseDateDiff(time, true); final long maxBanLength = ess.getSettings().getMaxTempban() * 1000; if (maxBanLength > 0 && ((banTimestamp - GregorianCalendar.getInstance().getTimeInMillis()) > maxBanLength) @@ -54,7 +55,7 @@ public class Commandtempban extends EssentialsCommand } final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME; - final String banReason = _("tempBanned", Util.formatDateDiff(banTimestamp), senderName); + final String banReason = _("tempBanned", DateUtil.formatDateDiff(banTimestamp), senderName); user.setBanReason(banReason); user.setBanTimeout(banTimestamp); user.setBanned(true); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtime.java b/Essentials/src/com/earth2me/essentials/commands/Commandtime.java index 92d564391..501d532d4 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtime.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtime.java @@ -1,9 +1,10 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.DescParseTickFormat; +import com.earth2me.essentials.utils.DescParseTickFormat; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.NumberUtil; +import com.earth2me.essentials.utils.StringUtil; import java.util.*; import org.bukkit.Server; import org.bukkit.World; @@ -22,11 +23,11 @@ public class Commandtime extends EssentialsCommand { boolean add = false; final List argList = new ArrayList(Arrays.asList(args)); - if (argList.remove("set") && !argList.isEmpty() && Util.isInt(argList.get(0))) + if (argList.remove("set") && !argList.isEmpty() && NumberUtil.isInt(argList.get(0))) { argList.set(0, argList.get(0) + "t"); } - if (argList.remove("add") && !argList.isEmpty() && Util.isInt(argList.get(0))) + if (argList.remove("add") && !argList.isEmpty() && NumberUtil.isInt(argList.get(0))) { add = true; argList.set(0, argList.get(0) + "t"); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java b/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java index 70a922b7c..d5b4ce9f4 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java @@ -2,7 +2,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.DateUtil; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -61,11 +62,11 @@ public class Commandtogglejail extends EssentialsCommand if (args.length > 2) { final String time = getFinalArg(args, 2); - timeDiff = Util.parseDateDiff(time, true); + timeDiff = DateUtil.parseDateDiff(time, true); player.setJailTimeout(timeDiff); } sender.sendMessage((timeDiff > 0 - ? _("playerJailedFor", player.getName(), Util.formatDateDiff(timeDiff)) + ? _("playerJailedFor", player.getName(), DateUtil.formatDateDiff(timeDiff)) : _("playerJailed", player.getName()))); return; } @@ -79,9 +80,9 @@ public class Commandtogglejail extends EssentialsCommand if (args.length >= 2 && player.isJailed() && args[1].equalsIgnoreCase(player.getJail())) { final String time = getFinalArg(args, 2); - final long timeDiff = Util.parseDateDiff(time, true); + final long timeDiff = DateUtil.parseDateDiff(time, true); player.setJailTimeout(timeDiff); - sender.sendMessage(_("jailSentenceExtended", Util.formatDateDiff(timeDiff))); + sender.sendMessage(_("jailSentenceExtended", DateUtil.formatDateDiff(timeDiff))); return; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtree.java b/Essentials/src/com/earth2me/essentials/commands/Commandtree.java index 6c2c15983..59fe2fb36 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtree.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtree.java @@ -2,7 +2,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.LocationUtil; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.TreeType; @@ -60,8 +61,8 @@ public class Commandtree extends EssentialsCommand throw new NotEnoughArgumentsException(); } - final Location loc = Util.getTarget(user); - final Location safeLocation = Util.getSafeDestination(loc); + final Location loc = LocationUtil.getTarget(user); + final Location safeLocation = LocationUtil.getSafeDestination(loc); final boolean success = user.getWorld().generateTree(safeLocation, tree); if (success) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java b/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java index 9b0cb2fe0..c0711b03a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java @@ -3,7 +3,8 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.FormatUtil; import java.util.logging.Level; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -25,7 +26,7 @@ public class Commandunbanip extends EssentialsCommand throw new NotEnoughArgumentsException(); } String ipAddress; - if (Util.validIP(args[0])) + if (FormatUtil.validIP(args[0])) { ipAddress = args[0]; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java index 5984a29fe..aa44878de 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java @@ -3,8 +3,9 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; import com.earth2me.essentials.api.IWarps; +import com.earth2me.essentials.utils.NumberUtil; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Iterator; @@ -54,7 +55,7 @@ public class Commandwarp extends EssentialsCommand @Override public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception { - if (args.length < 2 || Util.isInt(args[0])) + if (args.length < 2 || NumberUtil.isInt(args[0])) { warpList(sender, args); throw new NoChargeException(); @@ -88,13 +89,13 @@ public class Commandwarp extends EssentialsCommand } } int page = 1; - if (args.length > 0 && Util.isInt(args[0])) + if (args.length > 0 && NumberUtil.isInt(args[0])) { page = Integer.parseInt(args[0]); } final int warpPage = (page - 1) * WARPS_PER_PAGE; - final String warpList = Util.joinList(warpNameList.subList(warpPage, warpPage + Math.min(warpNameList.size() - warpPage, WARPS_PER_PAGE))); + final String warpList = StringUtil.joinList(warpNameList.subList(warpPage, warpPage + Math.min(warpNameList.size() - warpPage, WARPS_PER_PAGE))); if (warpNameList.size() > WARPS_PER_PAGE) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java index ad549cb0a..7e6ed7332 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java @@ -2,8 +2,10 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; import com.earth2me.essentials.craftbukkit.SetExpFix; +import com.earth2me.essentials.utils.NumberUtil; +import com.earth2me.essentials.utils.DateUtil; import java.util.Locale; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -36,7 +38,7 @@ public class Commandwhois extends EssentialsCommand sender.sendMessage(_("whoisLocation", user.getLocation().getWorld().getName(), user.getLocation().getBlockX(), user.getLocation().getBlockY(), user.getLocation().getBlockZ())); if (!ess.getSettings().isEcoDisabled()) { - sender.sendMessage(_("whoisMoney", Util.displayCurrency(user.getMoney(), ess))); + sender.sendMessage(_("whoisMoney", NumberUtil.displayCurrency(user.getMoney(), ess))); } sender.sendMessage(_("whoisIPAddress", user.getAddress().getAddress().toString())); final String location = user.getGeoLocation(); @@ -52,12 +54,12 @@ public class Commandwhois extends EssentialsCommand sender.sendMessage(_("whoisAFK", (user.isAfk() ? _("true") : _("false")))); sender.sendMessage(_("whoisJail", (user.isJailed() ? user.getJailTimeout() > 0 - ? Util.formatDateDiff(user.getJailTimeout()) + ? DateUtil.formatDateDiff(user.getJailTimeout()) : _("true") : _("false")))); sender.sendMessage(_("whoisMuted", (user.isMuted() ? user.getMuteTimeout() > 0 - ? Util.formatDateDiff(user.getMuteTimeout()) + ? DateUtil.formatDateDiff(user.getMuteTimeout()) : _("true") : _("false")))); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java index db1424249..1509e7235 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java @@ -2,7 +2,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.NumberUtil; import java.math.BigDecimal; import java.util.Locale; import org.bukkit.Server; @@ -54,14 +55,14 @@ public class Commandworth extends EssentialsCommand ? _("worthMeta", iStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""), iStack.getDurability(), - Util.displayCurrency(result, ess), + NumberUtil.displayCurrency(result, ess), amount, - Util.displayCurrency(worth, ess)) + NumberUtil.displayCurrency(worth, ess)) : _("worth", iStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""), - Util.displayCurrency(result, ess), + NumberUtil.displayCurrency(result, ess), amount, - Util.displayCurrency(worth, ess))); + NumberUtil.displayCurrency(worth, ess))); } @Override @@ -100,13 +101,13 @@ public class Commandworth extends EssentialsCommand ? _("worthMeta", iStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""), iStack.getDurability(), - Util.displayCurrency(result, ess), + NumberUtil.displayCurrency(result, ess), amount, - Util.displayCurrency(worth, ess)) + NumberUtil.displayCurrency(worth, ess)) : _("worth", iStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""), - Util.displayCurrency(result, ess), + NumberUtil.displayCurrency(result, ess), amount, - Util.displayCurrency(worth, ess))); + NumberUtil.displayCurrency(worth, ess))); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java index 26146f629..86f23f34d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.*; import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.utils.FormatUtil; import java.util.List; import java.util.Locale; import java.util.logging.Logger; @@ -94,7 +95,7 @@ public abstract class EssentialsCommand implements IEssentialsCommand final User userMatch = ess.getUser(onlinePlayer); if (getHidden || !userMatch.isHidden() || userMatch.equals(sourceUser)) { - final String displayName = Util.stripFormat(userMatch.getDisplayName()).toLowerCase(Locale.ENGLISH); + final String displayName = FormatUtil.stripFormat(userMatch.getDisplayName()).toLowerCase(Locale.ENGLISH); if (displayName.contains(matchText)) { return userMatch; diff --git a/Essentials/src/com/earth2me/essentials/perm/PermissionsHandler.java b/Essentials/src/com/earth2me/essentials/perm/PermissionsHandler.java index c5653b0ad..b0e77f761 100644 --- a/Essentials/src/com/earth2me/essentials/perm/PermissionsHandler.java +++ b/Essentials/src/com/earth2me/essentials/perm/PermissionsHandler.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.perm; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.NumberUtil; +import com.earth2me.essentials.utils.StringUtil; import java.util.Collections; import java.util.List; import java.util.logging.Level; @@ -160,7 +161,7 @@ public class PermissionsHandler implements IPermissionsHandler if (bPermPlugin != null && bPermPlugin.isEnabled()) { final String bVer = bPermPlugin.getDescription().getVersion().replace(".", ""); - if (Util.isInt(bVer) && Integer.parseInt(bVer) < 284) + if (NumberUtil.isInt(bVer) && Integer.parseInt(bVer) < 284) { if (!(handler instanceof BPermissionsHandler)) { diff --git a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java index d89ffbed7..a8b9db45b 100644 --- a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java +++ b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.signs; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.*; +import com.earth2me.essentials.utils.NumberUtil; import java.math.BigDecimal; import java.util.HashSet; import java.util.Locale; @@ -289,7 +290,7 @@ public class EssentialsSign final BigDecimal money = trade.getMoney(); if (money != null) { - sign.setLine(index, Util.shortCurrency(money, ess)); + sign.setLine(index, NumberUtil.shortCurrency(money, ess)); } } diff --git a/Essentials/src/com/earth2me/essentials/signs/SignBalance.java b/Essentials/src/com/earth2me/essentials/signs/SignBalance.java index 4949cb645..2cd339c69 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignBalance.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignBalance.java @@ -3,7 +3,8 @@ package com.earth2me.essentials.signs; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.NumberUtil; public class SignBalance extends EssentialsSign @@ -16,7 +17,7 @@ public class SignBalance extends EssentialsSign @Override protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException { - player.sendMessage(_("balance", Util.displayCurrency(player.getMoney(), ess))); + player.sendMessage(_("balance", NumberUtil.displayCurrency(player.getMoney(), ess))); return true; } } diff --git a/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java b/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java index fce49958e..207d0d6e2 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java @@ -2,7 +2,8 @@ package com.earth2me.essentials.signs; import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.FormatUtil; import java.util.logging.Level; import java.util.logging.Logger; import org.bukkit.Material; @@ -90,7 +91,7 @@ public class SignBlockListener implements Listener for (int i = 0; i < 4; i++) { - event.setLine(i, Util.formatString(user, "essentials.signs", event.getLine(i))); + event.setLine(i, FormatUtil.formatString(user, "essentials.signs", event.getLine(i))); } final String topLine = event.getLine(0); @@ -99,7 +100,7 @@ public class SignBlockListener implements Listener final EssentialsSign sign = signs.getSign(); if (topLine.equalsIgnoreCase(sign.getSuccessName())) { - event.setLine(0, Util.stripFormat(topLine)); + event.setLine(0, FormatUtil.stripFormat(topLine)); } } } diff --git a/Essentials/src/com/earth2me/essentials/signs/SignProtection.java b/Essentials/src/com/earth2me/essentials/signs/SignProtection.java index c336ec8c8..9ea3e6e12 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignProtection.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignProtection.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.signs; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.*; import com.earth2me.essentials.Trade.OverflowType; +import com.earth2me.essentials.utils.FormatUtil; import java.util.*; import org.bukkit.Location; import org.bukkit.Material; @@ -145,7 +146,7 @@ public class SignProtection extends EssentialsSign { return SignProtectionState.OWNER; } - if (Util.stripFormat(sign.getLine(3)).equalsIgnoreCase(username)) + if (FormatUtil.stripFormat(sign.getLine(3)).equalsIgnoreCase(username)) { return SignProtectionState.OWNER; } diff --git a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java index eb611e7ea..37501f1aa 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java @@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade.TradeType; import com.earth2me.essentials.*; import com.earth2me.essentials.Trade.OverflowType; +import com.earth2me.essentials.utils.NumberUtil; import java.math.BigDecimal; import java.util.Map; import org.bukkit.inventory.ItemStack; @@ -175,11 +176,11 @@ public class SignTrade extends EssentialsSign final BigDecimal money = getMoney(split[0]); if (money != null) { - if (Util.shortCurrency(money, ess).length() * 2 > 15) + if (NumberUtil.shortCurrency(money, ess).length() * 2 > 15) { throw new SignException("Line can be too long!"); } - sign.setLine(index, Util.shortCurrency(money, ess) + ":0"); + sign.setLine(index, NumberUtil.shortCurrency(money, ess) + ":0"); return; } } @@ -195,7 +196,7 @@ public class SignTrade extends EssentialsSign { throw new SignException(_("moreThanZero")); } - sign.setLine(index, Util.shortCurrency(money, ess) + ":" + Util.shortCurrency(amount, ess).substring(1)); + sign.setLine(index, NumberUtil.shortCurrency(money, ess) + ":" + NumberUtil.shortCurrency(amount, ess).substring(1)); return; } } @@ -384,7 +385,7 @@ public class SignTrade extends EssentialsSign final BigDecimal amount = getBigDecimal(split[1]); if (money != null && amount != null) { - final String newline = Util.shortCurrency(money, ess) + ":" + Util.shortCurrency(value, ess).substring(1); + final String newline = NumberUtil.shortCurrency(money, ess) + ":" + NumberUtil.shortCurrency(value, ess).substring(1); if (newline.length() > 15) { throw new SignException("This sign is full: Line too long!"); diff --git a/Essentials/src/com/earth2me/essentials/storage/BukkitConstructor.java b/Essentials/src/com/earth2me/essentials/storage/BukkitConstructor.java index d313a11b7..674829818 100644 --- a/Essentials/src/com/earth2me/essentials/storage/BukkitConstructor.java +++ b/Essentials/src/com/earth2me/essentials/storage/BukkitConstructor.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.storage; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.NumberUtil; +import com.earth2me.essentials.utils.StringUtil; import java.lang.reflect.Field; import java.util.List; import java.util.Locale; @@ -43,7 +44,7 @@ public class BukkitConstructor extends CustomClassLoaderConstructor { final String val = (String)constructScalar((ScalarNode)node); Material mat; - if (Util.isInt(val)) + if (NumberUtil.isInt(val)) { final int typeId = Integer.parseInt(val); mat = Material.getMaterial(typeId); @@ -67,7 +68,7 @@ public class BukkitConstructor extends CustomClassLoaderConstructor return null; } Material mat; - if (Util.isInt(split[0])) + if (NumberUtil.isInt(split[0])) { final int typeId = Integer.parseInt(split[0]); mat = Material.getMaterial(typeId); @@ -81,7 +82,7 @@ public class BukkitConstructor extends CustomClassLoaderConstructor return null; } byte data = 0; - if (split.length == 2 && Util.isInt(split[1])) + if (split.length == 2 && NumberUtil.isInt(split[1])) { data = Byte.parseByte(split[1]); } @@ -105,7 +106,7 @@ public class BukkitConstructor extends CustomClassLoaderConstructor return null; } Material mat; - if (Util.isInt(split2[0])) + if (NumberUtil.isInt(split2[0])) { final int typeId = Integer.parseInt(split2[0]); mat = Material.getMaterial(typeId); @@ -119,12 +120,12 @@ public class BukkitConstructor extends CustomClassLoaderConstructor return null; } short data = 0; - if (split2.length == 2 && Util.isInt(split2[1])) + if (split2.length == 2 && NumberUtil.isInt(split2[1])) { data = Short.parseShort(split2[1]); } int size = mat.getMaxStackSize(); - if (split1.length > 1 && Util.isInt(split1[1])) + if (split1.length > 1 && NumberUtil.isInt(split1[1])) { size = Integer.parseInt(split1[1]); } @@ -139,7 +140,7 @@ public class BukkitConstructor extends CustomClassLoaderConstructor continue; } Enchantment enchantment; - if (Util.isInt(split3[0])) + if (NumberUtil.isInt(split3[0])) { final int enchantId = Integer.parseInt(split3[0]); enchantment = Enchantment.getById(enchantId); @@ -153,7 +154,7 @@ public class BukkitConstructor extends CustomClassLoaderConstructor continue; } int level = enchantment.getStartLevel(); - if (split3.length == 2 && Util.isInt(split3[1])) + if (split3.length == 2 && NumberUtil.isInt(split3[1])) { level = Integer.parseInt(split3[1]); } @@ -183,7 +184,7 @@ public class BukkitConstructor extends CustomClassLoaderConstructor return null; } Enchantment enchant; - if (Util.isInt(split[0])) + if (NumberUtil.isInt(split[0])) { final int typeId = Integer.parseInt(split[0]); enchant = Enchantment.getById(typeId); @@ -197,7 +198,7 @@ public class BukkitConstructor extends CustomClassLoaderConstructor return null; } int level = enchant.getStartLevel(); - if (split.length == 2 && Util.isInt(split[1])) + if (split.length == 2 && NumberUtil.isInt(split[1])) { level = Integer.parseInt(split[1]); } diff --git a/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java b/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java index 2a95d4d84..a1c71ef39 100644 --- a/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java +++ b/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java @@ -1,9 +1,10 @@ package com.earth2me.essentials.textreader; -import com.earth2me.essentials.DescParseTickFormat; +import com.earth2me.essentials.utils.DescParseTickFormat; import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.NumberUtil; import java.text.DateFormat; import java.util.ArrayList; import java.util.Date; @@ -43,7 +44,7 @@ public class KeywordReplacer implements IText userName = user.getName(); ipAddress = user.getAddress() == null || user.getAddress().getAddress() == null ? "" : user.getAddress().getAddress().toString(); address = user.getAddress() == null ? "" : user.getAddress().toString(); - balance = Util.displayCurrency(user.getMoney(), ess); + balance = NumberUtil.displayCurrency(user.getMoney(), ess); mails = Integer.toString(user.getMails().size()); world = user.getLocation() == null || user.getLocation().getWorld() == null ? "" : user.getLocation().getWorld().getName(); worldTime12 = DescParseTickFormat.format12(user.getWorld() == null ? 0 : user.getWorld().getTime()); diff --git a/Essentials/src/com/earth2me/essentials/textreader/TextInput.java b/Essentials/src/com/earth2me/essentials/textreader/TextInput.java index 6e9256b4c..cd7ee6ec4 100644 --- a/Essentials/src/com/earth2me/essentials/textreader/TextInput.java +++ b/Essentials/src/com/earth2me/essentials/textreader/TextInput.java @@ -2,7 +2,7 @@ package com.earth2me.essentials.textreader; import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; import java.io.*; import java.lang.ref.SoftReference; import java.util.*; @@ -25,10 +25,10 @@ public class TextInput implements IText if (sender instanceof Player) { final User user = ess.getUser(sender); - file = new File(ess.getDataFolder(), filename + "_" + Util.sanitizeFileName(user.getName()) + ".txt"); + file = new File(ess.getDataFolder(), filename + "_" + StringUtil.sanitizeFileName(user.getName()) + ".txt"); if (!file.exists()) { - file = new File(ess.getDataFolder(), filename + "_" + Util.sanitizeFileName(user.getGroup()) + ".txt"); + file = new File(ess.getDataFolder(), filename + "_" + StringUtil.sanitizeFileName(user.getGroup()) + ".txt"); } } if (file == null || !file.exists()) diff --git a/Essentials/src/com/earth2me/essentials/utils/DateUtil.java b/Essentials/src/com/earth2me/essentials/utils/DateUtil.java new file mode 100644 index 000000000..e416fbb0e --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/utils/DateUtil.java @@ -0,0 +1,176 @@ +package com.earth2me.essentials.utils; + +import static com.earth2me.essentials.I18n._; +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + + +public class DateUtil +{ + public static long parseDateDiff(String time, boolean future) throws Exception + { + Pattern timePattern = Pattern.compile("(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*(?:s[a-z]*)?)?", Pattern.CASE_INSENSITIVE); + Matcher m = timePattern.matcher(time); + int years = 0; + int months = 0; + int weeks = 0; + int days = 0; + int hours = 0; + int minutes = 0; + int seconds = 0; + boolean found = false; + while (m.find()) + { + if (m.group() == null || m.group().isEmpty()) + { + continue; + } + for (int i = 0; i < m.groupCount(); i++) + { + if (m.group(i) != null && !m.group(i).isEmpty()) + { + found = true; + break; + } + } + if (found) + { + if (m.group(1) != null && !m.group(1).isEmpty()) + { + years = Integer.parseInt(m.group(1)); + } + if (m.group(2) != null && !m.group(2).isEmpty()) + { + months = Integer.parseInt(m.group(2)); + } + if (m.group(3) != null && !m.group(3).isEmpty()) + { + weeks = Integer.parseInt(m.group(3)); + } + if (m.group(4) != null && !m.group(4).isEmpty()) + { + days = Integer.parseInt(m.group(4)); + } + if (m.group(5) != null && !m.group(5).isEmpty()) + { + hours = Integer.parseInt(m.group(5)); + } + if (m.group(6) != null && !m.group(6).isEmpty()) + { + minutes = Integer.parseInt(m.group(6)); + } + if (m.group(7) != null && !m.group(7).isEmpty()) + { + seconds = Integer.parseInt(m.group(7)); + } + break; + } + } + if (!found) + { + throw new Exception(_("illegalDate")); + } + Calendar c = new GregorianCalendar(); + if (years > 0) + { + c.add(Calendar.YEAR, years * (future ? 1 : -1)); + } + if (months > 0) + { + c.add(Calendar.MONTH, months * (future ? 1 : -1)); + } + if (weeks > 0) + { + c.add(Calendar.WEEK_OF_YEAR, weeks * (future ? 1 : -1)); + } + if (days > 0) + { + c.add(Calendar.DAY_OF_MONTH, days * (future ? 1 : -1)); + } + if (hours > 0) + { + c.add(Calendar.HOUR_OF_DAY, hours * (future ? 1 : -1)); + } + if (minutes > 0) + { + c.add(Calendar.MINUTE, minutes * (future ? 1 : -1)); + } + if (seconds > 0) + { + c.add(Calendar.SECOND, seconds * (future ? 1 : -1)); + } + Calendar max = new GregorianCalendar(); + max.add(Calendar.YEAR, 10); + if (c.after(max)) + { + return max.getTimeInMillis(); + } + return c.getTimeInMillis(); + } + + static int dateDiff(int type, Calendar fromDate, Calendar toDate, boolean future) + { + int diff = 0; + long savedDate = fromDate.getTimeInMillis(); + while ((future && !fromDate.after(toDate)) || (!future && !fromDate.before(toDate))) + { + savedDate = fromDate.getTimeInMillis(); + fromDate.add(type, future ? 1 : -1); + diff++; + } + diff--; + fromDate.setTimeInMillis(savedDate); + return diff; + } + + public static String formatDateDiff(long date) + { + Calendar c = new GregorianCalendar(); + c.setTimeInMillis(date); + Calendar now = new GregorianCalendar(); + return DateUtil.formatDateDiff(now, c); + } + + public static String formatDateDiff(Calendar fromDate, Calendar toDate) + { + boolean future = false; + if (toDate.equals(fromDate)) + { + return _("now"); + } + if (toDate.after(fromDate)) + { + future = true; + } + StringBuilder sb = new StringBuilder(); + int[] types = new int[] + { + Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND + }; + String[] names = new String[] + { + _("year"), _("years"), _("month"), _("months"), _("day"), _("days"), _("hour"), _("hours"), _("minute"), _("minutes"), _("second"), _("seconds") + }; + int accuracy = 0; + for (int i = 0; i < types.length; i++) + { + if (accuracy > 2) + { + break; + } + int diff = dateDiff(types[i], fromDate, toDate, future); + if (diff > 0) + { + accuracy++; + sb.append(" ").append(diff).append(" ").append(names[i * 2 + (diff > 1 ? 1 : 0)]); + } + } + if (sb.length() == 0) + { + return "now"; + } + return sb.toString().trim(); + } +} diff --git a/Essentials/src/com/earth2me/essentials/utils/DescParseTickFormat.java b/Essentials/src/com/earth2me/essentials/utils/DescParseTickFormat.java new file mode 100644 index 000000000..166dd874f --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/utils/DescParseTickFormat.java @@ -0,0 +1,298 @@ +package com.earth2me.essentials.utils; + +import static com.earth2me.essentials.I18n._; +import java.text.SimpleDateFormat; +import java.util.*; + + +/** + * This utility class is used for converting between the ingame time in ticks to ingame time as a friendly string. Note + * that the time is INGAME. + * + * http://www.minecraftwiki.net/wiki/Day/night_cycle + * + * @author Olof Larsson + */ +public final class DescParseTickFormat +{ + // ============================================ + // First some information vars. TODO: Should this be in a config file? + // -------------------------------------------- + public static final Map nameToTicks = new LinkedHashMap(); + public static final Set resetAliases = new HashSet(); + public static final int ticksAtMidnight = 18000; + public static final int ticksPerDay = 24000; + public static final int ticksPerHour = 1000; + public static final double ticksPerMinute = 1000d / 60d; + public static final double ticksPerSecond = 1000d / 60d / 60d; + private static final SimpleDateFormat SDFTwentyFour = new SimpleDateFormat("HH:mm", Locale.ENGLISH); + private static final SimpleDateFormat SDFTwelve = new SimpleDateFormat("h:mmaa", Locale.ENGLISH); + + static + { + SDFTwentyFour.setTimeZone(TimeZone.getTimeZone("GMT")); + SDFTwelve.setTimeZone(TimeZone.getTimeZone("GMT")); + + nameToTicks.put("sunrise", 23000); + nameToTicks.put("dawn", 23000); + + nameToTicks.put("daystart", 0); + nameToTicks.put("day", 0); + + nameToTicks.put("morning", 1000); + + nameToTicks.put("midday", 6000); + nameToTicks.put("noon", 6000); + + nameToTicks.put("afternoon", 9000); + + nameToTicks.put("sunset", 12000); + nameToTicks.put("dusk", 12000); + nameToTicks.put("sundown", 12000); + nameToTicks.put("nightfall", 12000); + + nameToTicks.put("nightstart", 14000); + nameToTicks.put("night", 14000); + + nameToTicks.put("midnight", 18000); + + resetAliases.add("reset"); + resetAliases.add("normal"); + resetAliases.add("default"); + } + + private DescParseTickFormat() + { + } + + // ============================================ + // PARSE. From describing String to int + // -------------------------------------------- + public static long parse(String desc) throws NumberFormatException + { + // Only look at alphanumeric and lowercase and : for 24:00 + desc = desc.toLowerCase(Locale.ENGLISH).replaceAll("[^A-Za-z0-9:]", ""); + + // Detect ticks format + try + { + return parseTicks(desc); + } + catch (Exception e) + { + } + + // Detect 24-hour format + try + { + return parse24(desc); + } + catch (Exception e) + { + } + + // Detect 12-hour format + try + { + return parse12(desc); + } + catch (Exception e) + { + } + + // Detect aliases + try + { + return parseAlias(desc); + } + catch (Exception e) + { + } + + // Well we failed to understand... + throw new NumberFormatException(); + } + + public static long parseTicks(String desc) throws NumberFormatException + { + if (!desc.matches("^[0-9]+ti?c?k?s?$")) + { + throw new NumberFormatException(); + } + + desc = desc.replaceAll("[^0-9]", ""); + + return Long.parseLong(desc) % 24000; + } + + public static long parse24(String desc) throws NumberFormatException + { + if (!desc.matches("^[0-9]{2}[^0-9]?[0-9]{2}$")) + { + throw new NumberFormatException(); + } + + desc = desc.toLowerCase(Locale.ENGLISH).replaceAll("[^0-9]", ""); + + if (desc.length() != 4) + { + throw new NumberFormatException(); + } + + final int hours = Integer.parseInt(desc.substring(0, 2)); + final int minutes = Integer.parseInt(desc.substring(2, 4)); + + return hoursMinutesToTicks(hours, minutes); + } + + public static long parse12(String desc) throws NumberFormatException + { + if (!desc.matches("^[0-9]{1,2}([^0-9]?[0-9]{2})?(pm|am)$")) + { + throw new NumberFormatException(); + } + + int hours = 0; + int minutes = 0; + + desc = desc.toLowerCase(Locale.ENGLISH); + String parsetime = desc.replaceAll("[^0-9]", ""); + + if (parsetime.length() > 4) + { + throw new NumberFormatException(); + } + + if (parsetime.length() == 4) + { + hours += Integer.parseInt(parsetime.substring(0, 2)); + minutes += Integer.parseInt(parsetime.substring(2, 4)); + } + else if (parsetime.length() == 3) + { + hours += Integer.parseInt(parsetime.substring(0, 1)); + minutes += Integer.parseInt(parsetime.substring(1, 3)); + } + else if (parsetime.length() == 2) + { + hours += Integer.parseInt(parsetime.substring(0, 2)); + } + else if (parsetime.length() == 1) + { + hours += Integer.parseInt(parsetime.substring(0, 1)); + } + else + { + throw new NumberFormatException(); + } + + if (desc.endsWith("pm") && hours != 12) + { + hours += 12; + } + + if (desc.endsWith("am") && hours == 12) + { + hours -= 12; + } + + return hoursMinutesToTicks(hours, minutes); + } + + public static long hoursMinutesToTicks(final int hours, final int minutes) + { + long ret = ticksAtMidnight; + ret += (hours) * ticksPerHour; + + ret += (minutes / 60.0) * ticksPerHour; + + ret %= ticksPerDay; + return ret; + } + + public static long parseAlias(final String desc) throws NumberFormatException + { + final Integer ret = nameToTicks.get(desc); + if (ret == null) + { + throw new NumberFormatException(); + } + + return ret; + } + + public static boolean meansReset(final String desc) + { + return resetAliases.contains(desc); + } + + // ============================================ + // FORMAT. From int to describing String + // -------------------------------------------- + public static String format(final long ticks) + { + return _("timeFormat", format24(ticks), format12(ticks), formatTicks(ticks)); + } + + public static String formatTicks(final long ticks) + { + return (ticks % ticksPerDay) + "ticks"; + } + + public static String format24(final long ticks) + { + synchronized (SDFTwentyFour) + { + return formatDateFormat(ticks, SDFTwentyFour); + } + } + + public static String format12(final long ticks) + { + synchronized (SDFTwelve) + { + return formatDateFormat(ticks, SDFTwelve); + } + } + + public static String formatDateFormat(final long ticks, final SimpleDateFormat format) + { + final Date date = ticksToDate(ticks); + return format.format(date); + } + + public static Date ticksToDate(long ticks) + { + // Assume the server time starts at 0. It would start on a day. + // But we will simulate that the server started with 0 at midnight. + ticks = ticks - ticksAtMidnight + ticksPerDay; + + // How many ingame days have passed since the server start? + final long days = ticks / ticksPerDay; + ticks -= days * ticksPerDay; + + // How many hours on the last day? + final long hours = ticks / ticksPerHour; + ticks -= hours * ticksPerHour; + + // How many minutes on the last day? + final long minutes = (long)Math.floor(ticks / ticksPerMinute); + final double dticks = ticks - minutes * ticksPerMinute; + + // How many seconds on the last day? + final long seconds = (long)Math.floor(dticks / ticksPerSecond); + + // Now we create an english GMT calendar (We wan't no daylight savings) + final Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.ENGLISH); + cal.setLenient(true); + + // And we set the time to 0! And append the time that passed! + cal.set(0, Calendar.JANUARY, 1, 0, 0, 0); + cal.add(Calendar.DAY_OF_YEAR, (int)days); + cal.add(Calendar.HOUR_OF_DAY, (int)hours); + cal.add(Calendar.MINUTE, (int)minutes); + cal.add(Calendar.SECOND, (int)seconds + 1); // To solve rounding errors. + + return cal.getTime(); + } +} diff --git a/Essentials/src/com/earth2me/essentials/utils/FormatUtil.java b/Essentials/src/com/earth2me/essentials/utils/FormatUtil.java new file mode 100644 index 000000000..f47ff3296 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/utils/FormatUtil.java @@ -0,0 +1,138 @@ +package com.earth2me.essentials.utils; + +import com.earth2me.essentials.IUser; +import java.util.regex.Pattern; + + +public class FormatUtil +{ + static final transient Pattern REPLACE_COLOR_PATTERN = Pattern.compile("&([0-9a-f])"); + static final transient Pattern VANILLA_MAGIC_PATTERN = Pattern.compile("\u00a7+[Kk]"); + static final transient Pattern VANILLA_FORMAT_PATTERN = Pattern.compile("\u00a7+[L-ORl-or]"); + static final transient Pattern REPLACE_FORMAT_PATTERN = Pattern.compile("&([l-or])"); + static final transient Pattern REPLACE_MAGIC_PATTERN = Pattern.compile("&(k)"); + static final transient Pattern REPLACE_PATTERN = Pattern.compile("&([0-9a-fk-or])"); + static final transient Pattern LOGCOLOR_PATTERN = Pattern.compile("\\x1B\\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]"); + static final transient Pattern VANILLA_PATTERN = Pattern.compile("\u00a7+[0-9A-FK-ORa-fk-or]?"); + static final transient Pattern VANILLA_COLOR_PATTERN = Pattern.compile("\u00a7+[0-9A-Fa-f]"); + static final transient Pattern URL_PATTERN = Pattern.compile("((?:(?:https?)://)?[\\w-_\\.]{2,})\\.([a-z]{2,3}(?:/\\S+)?)"); + public static final Pattern IPPATTERN = Pattern.compile("^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"); + + //This method is used to simply strip the native minecraft colour codes + public static String stripFormat(final String input) + { + if (input == null) + { + return null; + } + return VANILLA_PATTERN.matcher(input).replaceAll(""); + } + + //This is the general permission sensitive message format function, checks for urls. + public static String formatMessage(final IUser user, final String permBase, final String input) + { + if (input == null) + { + return null; + } + String message = formatString(user, permBase, input); + if (!user.isAuthorized(permBase + ".url")) + { + message = FormatUtil.blockURL(message); + } + return message; + } + + //This method is used to simply replace the ess colour codes with minecraft ones, ie &c + public static String replaceFormat(final String input) + { + if (input == null) + { + return null; + } + return REPLACE_PATTERN.matcher(input).replaceAll("\u00a7$1"); + } + + static String replaceColor(final String input, final Pattern pattern) + { + return pattern.matcher(input).replaceAll("\u00a7$1"); + } + + //This is the general permission sensitive message format function, does not touch urls. + public static String formatString(final IUser user, final String permBase, final String input) + { + if (input == null) + { + return null; + } + String message; + if (user.isAuthorized(permBase + ".color")) + { + message = FormatUtil.replaceColor(input, REPLACE_COLOR_PATTERN); + } + else + { + message = FormatUtil.stripColor(input, VANILLA_COLOR_PATTERN); + } + if (user.isAuthorized(permBase + ".magic")) + { + message = FormatUtil.replaceColor(message, REPLACE_MAGIC_PATTERN); + } + else + { + message = FormatUtil.stripColor(message, VANILLA_MAGIC_PATTERN); + } + if (user.isAuthorized(permBase + ".format")) + { + message = FormatUtil.replaceColor(message, REPLACE_FORMAT_PATTERN); + } + else + { + message = FormatUtil.stripColor(message, VANILLA_FORMAT_PATTERN); + } + return message; + } + + public static String stripLogColorFormat(final String input) + { + if (input == null) + { + return null; + } + return LOGCOLOR_PATTERN.matcher(input).replaceAll(""); + } + + static String stripColor(final String input, final Pattern pattern) + { + return pattern.matcher(input).replaceAll(""); + } + + public static String lastCode(final String input) + { + int pos = input.lastIndexOf("\u00a7"); + if (pos == -1 || (pos + 1) == input.length()) + { + return ""; + } + return input.substring(pos, pos + 2); + } + + static String blockURL(final String input) + { + if (input == null) + { + return null; + } + String text = URL_PATTERN.matcher(input).replaceAll("$1 $2"); + while (URL_PATTERN.matcher(text).find()) + { + text = URL_PATTERN.matcher(text).replaceAll("$1 $2"); + } + return text; + } + + public static boolean validIP(String ipAddress) + { + return IPPATTERN.matcher(ipAddress).matches(); + } +} diff --git a/Essentials/src/com/earth2me/essentials/utils/LocationUtil.java b/Essentials/src/com/earth2me/essentials/utils/LocationUtil.java new file mode 100644 index 000000000..f6cee2fde --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/utils/LocationUtil.java @@ -0,0 +1,306 @@ +package com.earth2me.essentials.utils; + +import static com.earth2me.essentials.I18n._; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.entity.LivingEntity; +import org.bukkit.inventory.ItemStack; + + +public class LocationUtil +{ + // The player can stand inside these materials + public static final Set HOLLOW_MATERIALS = new HashSet(); + private static final HashSet TRANSPARENT_MATERIALS = new HashSet(); + + static + { + HOLLOW_MATERIALS.add(Material.AIR.getId()); + HOLLOW_MATERIALS.add(Material.SAPLING.getId()); + HOLLOW_MATERIALS.add(Material.POWERED_RAIL.getId()); + HOLLOW_MATERIALS.add(Material.DETECTOR_RAIL.getId()); + HOLLOW_MATERIALS.add(Material.LONG_GRASS.getId()); + HOLLOW_MATERIALS.add(Material.DEAD_BUSH.getId()); + HOLLOW_MATERIALS.add(Material.YELLOW_FLOWER.getId()); + HOLLOW_MATERIALS.add(Material.RED_ROSE.getId()); + HOLLOW_MATERIALS.add(Material.BROWN_MUSHROOM.getId()); + HOLLOW_MATERIALS.add(Material.RED_MUSHROOM.getId()); + HOLLOW_MATERIALS.add(Material.TORCH.getId()); + HOLLOW_MATERIALS.add(Material.REDSTONE_WIRE.getId()); + HOLLOW_MATERIALS.add(Material.SEEDS.getId()); + HOLLOW_MATERIALS.add(Material.SIGN_POST.getId()); + HOLLOW_MATERIALS.add(Material.WOODEN_DOOR.getId()); + HOLLOW_MATERIALS.add(Material.LADDER.getId()); + HOLLOW_MATERIALS.add(Material.RAILS.getId()); + HOLLOW_MATERIALS.add(Material.WALL_SIGN.getId()); + HOLLOW_MATERIALS.add(Material.LEVER.getId()); + HOLLOW_MATERIALS.add(Material.STONE_PLATE.getId()); + HOLLOW_MATERIALS.add(Material.IRON_DOOR_BLOCK.getId()); + HOLLOW_MATERIALS.add(Material.WOOD_PLATE.getId()); + HOLLOW_MATERIALS.add(Material.REDSTONE_TORCH_OFF.getId()); + HOLLOW_MATERIALS.add(Material.REDSTONE_TORCH_ON.getId()); + HOLLOW_MATERIALS.add(Material.STONE_BUTTON.getId()); + HOLLOW_MATERIALS.add(Material.SNOW.getId()); + HOLLOW_MATERIALS.add(Material.SUGAR_CANE_BLOCK.getId()); + HOLLOW_MATERIALS.add(Material.DIODE_BLOCK_OFF.getId()); + HOLLOW_MATERIALS.add(Material.DIODE_BLOCK_ON.getId()); + HOLLOW_MATERIALS.add(Material.PUMPKIN_STEM.getId()); + HOLLOW_MATERIALS.add(Material.MELON_STEM.getId()); + HOLLOW_MATERIALS.add(Material.VINE.getId()); + HOLLOW_MATERIALS.add(Material.FENCE_GATE.getId()); + HOLLOW_MATERIALS.add(Material.WATER_LILY.getId()); + HOLLOW_MATERIALS.add(Material.NETHER_WARTS.getId()); + + for (Integer integer : HOLLOW_MATERIALS) + { + TRANSPARENT_MATERIALS.add(integer.byteValue()); + } + TRANSPARENT_MATERIALS.add((byte)Material.WATER.getId()); + TRANSPARENT_MATERIALS.add((byte)Material.STATIONARY_WATER.getId()); + } + + public final static int RADIUS = 3; + public final static Vector3D[] VOLUME; + + public static ItemStack convertBlockToItem(final Block block) + { + final ItemStack is = new ItemStack(block.getType(), 1, (short)0, block.getData()); + switch (is.getType()) + { + case WOODEN_DOOR: + is.setType(Material.WOOD_DOOR); + is.setDurability((short)0); + break; + case IRON_DOOR_BLOCK: + is.setType(Material.IRON_DOOR); + is.setDurability((short)0); + break; + case SIGN_POST: + case WALL_SIGN: + is.setType(Material.SIGN); + is.setDurability((short)0); + break; + case CROPS: + is.setType(Material.SEEDS); + is.setDurability((short)0); + break; + case CAKE_BLOCK: + is.setType(Material.CAKE); + is.setDurability((short)0); + break; + case BED_BLOCK: + is.setType(Material.BED); + is.setDurability((short)0); + break; + case REDSTONE_WIRE: + is.setType(Material.REDSTONE); + is.setDurability((short)0); + break; + case REDSTONE_TORCH_OFF: + case REDSTONE_TORCH_ON: + is.setType(Material.REDSTONE_TORCH_ON); + is.setDurability((short)0); + break; + case DIODE_BLOCK_OFF: + case DIODE_BLOCK_ON: + is.setType(Material.DIODE); + is.setDurability((short)0); + break; + case DOUBLE_STEP: + is.setType(Material.STEP); + break; + case TORCH: + case RAILS: + case LADDER: + case WOOD_STAIRS: + case COBBLESTONE_STAIRS: + case LEVER: + case STONE_BUTTON: + case FURNACE: + case DISPENSER: + case PUMPKIN: + case JACK_O_LANTERN: + case WOOD_PLATE: + case STONE_PLATE: + case PISTON_STICKY_BASE: + case PISTON_BASE: + case IRON_FENCE: + case THIN_GLASS: + case TRAP_DOOR: + case FENCE: + case FENCE_GATE: + case NETHER_FENCE: + is.setDurability((short)0); + break; + case FIRE: + return null; + case PUMPKIN_STEM: + is.setType(Material.PUMPKIN_SEEDS); + break; + case MELON_STEM: + is.setType(Material.MELON_SEEDS); + break; + } + return is; + } + + public static class Vector3D + { + public Vector3D(int x, int y, int z) + { + this.x = x; + this.y = y; + this.z = z; + } + public int x; + public int y; + public int z; + } + + static + { + List pos = new ArrayList(); + for (int x = -RADIUS; x <= RADIUS; x++) + { + for (int y = -RADIUS; y <= RADIUS; y++) + { + for (int z = -RADIUS; z <= RADIUS; z++) + { + pos.add(new Vector3D(x, y, z)); + } + } + } + Collections.sort( + pos, new Comparator() + { + @Override + public int compare(Vector3D a, Vector3D b) + { + return (a.x * a.x + a.y * a.y + a.z * a.z) - (b.x * b.x + b.y * b.y + b.z * b.z); + } + }); + VOLUME = pos.toArray(new Vector3D[0]); + } + + + public static Location getTarget(final LivingEntity entity) throws Exception + { + final Block block = entity.getTargetBlock(TRANSPARENT_MATERIALS, 300); + if (block == null) + { + throw new Exception("Not targeting a block"); + } + return block.getLocation(); + } + + static boolean isBlockAboveAir(final World world, final int x, final int y, final int z) + { + return HOLLOW_MATERIALS.contains(world.getBlockAt(x, y - 1, z).getType().getId()); + } + + public static boolean isBlockUnsafe(final World world, final int x, final int y, final int z) + { + if (isBlockDamaging(world, x, y, z)) + { + return true; + } + return isBlockAboveAir(world, x, y, z); + } + + public static boolean isBlockDamaging(final World world, final int x, final int y, final int z) + { + final Block below = world.getBlockAt(x, y - 1, z); + if (below.getType() == Material.LAVA || below.getType() == Material.STATIONARY_LAVA) + { + return true; + } + if (below.getType() == Material.FIRE) + { + return true; + } + if (below.getType() == Material.BED_BLOCK) + { + return true; + } + if ((!HOLLOW_MATERIALS.contains(world.getBlockAt(x, y, z).getType().getId())) || (!HOLLOW_MATERIALS.contains(world.getBlockAt(x, y + 1, z).getType().getId()))) + { + return true; + } + return false; + } + + public static Location getSafeDestination(final Location loc) throws Exception + { + if (loc == null || loc.getWorld() == null) + { + throw new Exception(_("destinationNotSet")); + } + final World world = loc.getWorld(); + int x = loc.getBlockX(); + int y = (int)Math.round(loc.getY()); + int z = loc.getBlockZ(); + final int origX = x; + final int origY = y; + final int origZ = z; + while (isBlockAboveAir(world, x, y, z)) + { + y -= 1; + if (y < 0) + { + y = origY; + break; + } + } + if (isBlockUnsafe(world, x, y, z)) + { + x = Math.round(loc.getX()) == origX ? x - 1 : x + 1; + z = Math.round(loc.getZ()) == origZ ? z - 1 : z + 1; + } + int i = 0; + while (isBlockUnsafe(world, x, y, z)) + { + i++; + if (i >= VOLUME.length) + { + x = origX; + y = origY + RADIUS; + z = origZ; + break; + } + x = origX + VOLUME[i].x; + y = origY + VOLUME[i].y; + z = origZ + VOLUME[i].z; + } + while (isBlockUnsafe(world, x, y, z)) + { + y += 1; + if (y >= world.getMaxHeight()) + { + x += 1; + break; + } + } + while (isBlockUnsafe(world, x, y, z)) + { + y -= 1; + if (y <= 1) + { + x += 1; + y = world.getHighestBlockYAt(x, z); + if (x - 48 > loc.getBlockX()) + { + throw new Exception(_("holeInFloor")); + } + } + } + return new Location(world, x + 0.5, y, z + 0.5, loc.getYaw(), loc.getPitch()); + } +} diff --git a/Essentials/src/com/earth2me/essentials/utils/NumberUtil.java b/Essentials/src/com/earth2me/essentials/utils/NumberUtil.java new file mode 100644 index 000000000..3c6332ea6 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/utils/NumberUtil.java @@ -0,0 +1,56 @@ +package com.earth2me.essentials.utils; + +import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.IEssentials; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.util.Locale; + + +public class NumberUtil +{ + static DecimalFormat threeDPlaces = new DecimalFormat("#,###.###"); + static DecimalFormat currencyFormat = new DecimalFormat("#0.00", DecimalFormatSymbols.getInstance(Locale.US)); + + public static String shortCurrency(final BigDecimal value, final IEssentials ess) + { + return ess.getSettings().getCurrencySymbol() + formatAsCurrency(value); + } + + public static String formatDouble(final double value) + { + threeDPlaces.setRoundingMode(RoundingMode.HALF_UP); + return threeDPlaces.format(value); + } + + public static String formatAsCurrency(final BigDecimal value) + { + currencyFormat.setRoundingMode(RoundingMode.FLOOR); + String str = currencyFormat.format(value); + if (str.endsWith(".00")) + { + str = str.substring(0, str.length() - 3); + } + return str; + } + + public static String displayCurrency(final BigDecimal value, final IEssentials ess) + { + return _("currency", ess.getSettings().getCurrencySymbol(), formatAsCurrency(value)); + } + + public static boolean isInt(final String sInt) + { + try + { + Integer.parseInt(sInt); + } + catch (NumberFormatException e) + { + return false; + } + return true; + } +} diff --git a/Essentials/src/com/earth2me/essentials/utils/StringUtil.java b/Essentials/src/com/earth2me/essentials/utils/StringUtil.java new file mode 100644 index 000000000..10696d78e --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/utils/StringUtil.java @@ -0,0 +1,66 @@ +package com.earth2me.essentials.utils; + +import java.util.*; +import java.util.regex.Pattern; + + +public class StringUtil +{ + private StringUtil() + { + } + private final static Pattern INVALIDFILECHARS = Pattern.compile("[^a-z0-9]"); + private final static Pattern INVALIDCHARS = Pattern.compile("[^\t\n\r\u0020-\u007E\u0085\u00A0-\uD7FF\uE000-\uFFFC]"); + + //Used to clean file names before saving to disk + public static String sanitizeFileName(final String name) + { + return safeString(name); + } + + //Used to clean strings/names before saving as filenames/permissions + public static String safeString(final String string) + { + return INVALIDFILECHARS.matcher(string.toLowerCase(Locale.ENGLISH)).replaceAll("_"); + } + + //Less restrictive string sanitizing, when not used as perm or filename + public static String sanitizeString(final String string) + { + return INVALIDCHARS.matcher(string).replaceAll(""); + } + + 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(seperator); + } + + if (each instanceof Collection) + { + buf.append(joinList(seperator, ((Collection)each).toArray())); + } + else + { + try + { + buf.append(each.toString()); + } + catch (Exception e) + { + buf.append(each.toString()); + } + } + } + return buf.toString(); + } +} diff --git a/Essentials/test/com/earth2me/essentials/UtilTest.java b/Essentials/test/com/earth2me/essentials/UtilTest.java index e1edda95e..53f79d387 100644 --- a/Essentials/test/com/earth2me/essentials/UtilTest.java +++ b/Essentials/test/com/earth2me/essentials/UtilTest.java @@ -1,5 +1,7 @@ package com.earth2me.essentials; +import com.earth2me.essentials.utils.DateUtil; +import com.earth2me.essentials.utils.LocationUtil; import java.io.IOException; import java.util.Calendar; import java.util.GregorianCalendar; @@ -46,25 +48,25 @@ public class UtilTest extends TestCase testSet.add(x + ":" + y + ":" + z); count++; i++; - if (i >= Util.VOLUME.length) + if (i >= LocationUtil.VOLUME.length) { break; } - x = origX + Util.VOLUME[i].x; - y = origY + Util.VOLUME[i].y; - z = origZ + Util.VOLUME[i].z; + x = origX + LocationUtil.VOLUME[i].x; + y = origY + LocationUtil.VOLUME[i].y; + z = origZ + LocationUtil.VOLUME[i].z; } assertTrue(testSet.contains("0:0:0")); assertTrue(testSet.contains("3:3:3")); assertEquals(testSet.size(), count); - int diameter = Util.RADIUS * 2 + 1; + int diameter = LocationUtil.RADIUS * 2 + 1; assertEquals(diameter * diameter * diameter, count); } public void testFDDnow() { Calendar c = new GregorianCalendar(); - String resp = Util.formatDateDiff(c, c); + String resp = DateUtil.formatDateDiff(c, c); assertEquals(resp, "now"); } @@ -73,67 +75,67 @@ public class UtilTest extends TestCase Calendar a, b; a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2010, 1, 1, 10, 0, 1); - assertEquals("1 second", Util.formatDateDiff(a, b)); + assertEquals("1 second", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2010, 1, 1, 10, 0, 2); - assertEquals("2 seconds", Util.formatDateDiff(a, b)); + assertEquals("2 seconds", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2010, 1, 1, 10, 0, 3); - assertEquals("3 seconds", Util.formatDateDiff(a, b)); + assertEquals("3 seconds", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2010, 1, 1, 10, 1, 0); - assertEquals("1 minute", Util.formatDateDiff(a, b)); + assertEquals("1 minute", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2010, 1, 1, 10, 2, 0); - assertEquals("2 minutes", Util.formatDateDiff(a, b)); + assertEquals("2 minutes", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2010, 1, 1, 10, 3, 0); - assertEquals("3 minutes", Util.formatDateDiff(a, b)); + assertEquals("3 minutes", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2010, 1, 1, 11, 0, 0); - assertEquals("1 hour", Util.formatDateDiff(a, b)); + assertEquals("1 hour", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2010, 1, 1, 12, 0, 0); - assertEquals("2 hours", Util.formatDateDiff(a, b)); + assertEquals("2 hours", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2010, 1, 1, 13, 0, 0); - assertEquals("3 hours", Util.formatDateDiff(a, b)); + assertEquals("3 hours", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2010, 1, 2, 10, 0, 0); - assertEquals("1 day", Util.formatDateDiff(a, b)); + assertEquals("1 day", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2010, 1, 3, 10, 0, 0); - assertEquals("2 days", Util.formatDateDiff(a, b)); + assertEquals("2 days", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2010, 1, 4, 10, 0, 0); - assertEquals("3 days", Util.formatDateDiff(a, b)); + assertEquals("3 days", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2010, 2, 1, 10, 0, 0); - assertEquals("1 month", Util.formatDateDiff(a, b)); + assertEquals("1 month", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2010, 3, 1, 10, 0, 0); - assertEquals("2 months", Util.formatDateDiff(a, b)); + assertEquals("2 months", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2010, 4, 1, 10, 0, 0); - assertEquals("3 months", Util.formatDateDiff(a, b)); + assertEquals("3 months", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2011, 1, 1, 10, 0, 0); - assertEquals("1 year", Util.formatDateDiff(a, b)); + assertEquals("1 year", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2012, 1, 1, 10, 0, 0); - assertEquals("2 years", Util.formatDateDiff(a, b)); + assertEquals("2 years", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2013, 1, 1, 10, 0, 0); - assertEquals("3 years", Util.formatDateDiff(a, b)); + assertEquals("3 years", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2011, 4, 5, 23, 38, 12); - assertEquals("1 year 3 months 4 days", Util.formatDateDiff(a, b)); + assertEquals("1 year 3 months 4 days", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 9, 17, 23, 45, 45); b = new GregorianCalendar(2015, 3, 7, 10, 0, 0); - assertEquals("4 years 5 months 20 days", Util.formatDateDiff(a, b)); + assertEquals("4 years 5 months 20 days", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2011, 4, 31, 10, 0, 0); b = new GregorianCalendar(2011, 4, 31, 10, 5, 0); - assertEquals("5 minutes", Util.formatDateDiff(a, b)); + assertEquals("5 minutes", DateUtil.formatDateDiff(a, b)); } public void testFDDpast() @@ -141,63 +143,63 @@ public class UtilTest extends TestCase Calendar a, b; a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2010, 1, 1, 9, 59, 59); - assertEquals("1 second", Util.formatDateDiff(a, b)); + assertEquals("1 second", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2010, 1, 1, 9, 59, 58); - assertEquals("2 seconds", Util.formatDateDiff(a, b)); + assertEquals("2 seconds", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2010, 1, 1, 9, 59, 57); - assertEquals("3 seconds", Util.formatDateDiff(a, b)); + assertEquals("3 seconds", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2010, 1, 1, 9, 59, 0); - assertEquals("1 minute", Util.formatDateDiff(a, b)); + assertEquals("1 minute", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2010, 1, 1, 9, 58, 0); - assertEquals("2 minutes", Util.formatDateDiff(a, b)); + assertEquals("2 minutes", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2010, 1, 1, 9, 57, 0); - assertEquals("3 minutes", Util.formatDateDiff(a, b)); + assertEquals("3 minutes", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2010, 1, 1, 9, 0, 0); - assertEquals("1 hour", Util.formatDateDiff(a, b)); + assertEquals("1 hour", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2010, 1, 1, 8, 0, 0); - assertEquals("2 hours", Util.formatDateDiff(a, b)); + assertEquals("2 hours", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2010, 1, 1, 7, 0, 0); - assertEquals("3 hours", Util.formatDateDiff(a, b)); + assertEquals("3 hours", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 5, 10, 0, 0); b = new GregorianCalendar(2010, 1, 4, 10, 0, 0); - assertEquals("1 day", Util.formatDateDiff(a, b)); + assertEquals("1 day", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 5, 10, 0, 0); b = new GregorianCalendar(2010, 1, 3, 10, 0, 0); - assertEquals("2 days", Util.formatDateDiff(a, b)); + assertEquals("2 days", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 5, 10, 0, 0); b = new GregorianCalendar(2010, 1, 2, 10, 0, 0); - assertEquals("3 days", Util.formatDateDiff(a, b)); + assertEquals("3 days", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 5, 1, 10, 0, 0); b = new GregorianCalendar(2010, 4, 1, 10, 0, 0); - assertEquals("1 month", Util.formatDateDiff(a, b)); + assertEquals("1 month", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 5, 1, 10, 0, 0); b = new GregorianCalendar(2010, 3, 1, 10, 0, 0); - assertEquals("2 months", Util.formatDateDiff(a, b)); + assertEquals("2 months", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 5, 1, 10, 0, 0); b = new GregorianCalendar(2010, 2, 1, 10, 0, 0); - assertEquals("3 months", Util.formatDateDiff(a, b)); + assertEquals("3 months", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2009, 1, 1, 10, 0, 0); - assertEquals("1 year", Util.formatDateDiff(a, b)); + assertEquals("1 year", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2008, 1, 1, 10, 0, 0); - assertEquals("2 years", Util.formatDateDiff(a, b)); + assertEquals("2 years", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2007, 1, 1, 10, 0, 0); - assertEquals("3 years", Util.formatDateDiff(a, b)); + assertEquals("3 years", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); b = new GregorianCalendar(2009, 4, 5, 23, 38, 12); - assertEquals("8 months 26 days 10 hours", Util.formatDateDiff(a, b)); + assertEquals("8 months 26 days 10 hours", DateUtil.formatDateDiff(a, b)); a = new GregorianCalendar(2010, 9, 17, 23, 45, 45); b = new GregorianCalendar(2000, 3, 7, 10, 0, 0); - assertEquals("10 years 6 months 10 days", Util.formatDateDiff(a, b)); + assertEquals("10 years 6 months 10 days", DateUtil.formatDateDiff(a, b)); } } diff --git a/EssentialsAntiBuild/nbproject/build-impl.xml b/EssentialsAntiBuild/nbproject/build-impl.xml index 94e589ef7..72a60d15a 100644 --- a/EssentialsAntiBuild/nbproject/build-impl.xml +++ b/EssentialsAntiBuild/nbproject/build-impl.xml @@ -395,6 +395,11 @@ is divided into following sections: + + + + + @@ -418,7 +423,7 @@ is divided into following sections: - + @@ -432,6 +437,9 @@ is divided into following sections: + + + @@ -559,7 +567,7 @@ is divided into following sections: - + @@ -573,6 +581,9 @@ is divided into following sections: + + + @@ -952,7 +963,7 @@ is divided into following sections: - + diff --git a/EssentialsAntiBuild/nbproject/genfiles.properties b/EssentialsAntiBuild/nbproject/genfiles.properties index ed84f2f67..a00aaef2d 100644 --- a/EssentialsAntiBuild/nbproject/genfiles.properties +++ b/EssentialsAntiBuild/nbproject/genfiles.properties @@ -4,5 +4,5 @@ build.xml.stylesheet.CRC32=28e38971@1.38.3.45 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. nbproject/build-impl.xml.data.CRC32=ddb4519c -nbproject/build-impl.xml.script.CRC32=00e1454b -nbproject/build-impl.xml.stylesheet.CRC32=6ddba6b6@1.53.1.46 +nbproject/build-impl.xml.script.CRC32=1c67208a +nbproject/build-impl.xml.stylesheet.CRC32=c6d2a60f@1.56.1.46 diff --git a/EssentialsChat/nbproject/build-impl.xml b/EssentialsChat/nbproject/build-impl.xml index 2718ae609..7fc117783 100644 --- a/EssentialsChat/nbproject/build-impl.xml +++ b/EssentialsChat/nbproject/build-impl.xml @@ -395,6 +395,11 @@ is divided into following sections: + + + + + @@ -418,7 +423,7 @@ is divided into following sections: - + @@ -432,6 +437,9 @@ is divided into following sections: + + + @@ -559,7 +567,7 @@ is divided into following sections: - + @@ -573,6 +581,9 @@ is divided into following sections: + + + @@ -952,7 +963,7 @@ is divided into following sections: - + diff --git a/EssentialsChat/nbproject/genfiles.properties b/EssentialsChat/nbproject/genfiles.properties index 8f6e6c76c..d624bd5de 100644 --- a/EssentialsChat/nbproject/genfiles.properties +++ b/EssentialsChat/nbproject/genfiles.properties @@ -4,5 +4,5 @@ build.xml.stylesheet.CRC32=28e38971@1.38.2.45 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. nbproject/build-impl.xml.data.CRC32=7c7f517b -nbproject/build-impl.xml.script.CRC32=9ec3d353 -nbproject/build-impl.xml.stylesheet.CRC32=6ddba6b6@1.53.1.46 +nbproject/build-impl.xml.script.CRC32=c6c8dc20 +nbproject/build-impl.xml.stylesheet.CRC32=c6d2a60f@1.56.1.46 diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java index e8fee2fbb..a86dcd14f 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java @@ -2,7 +2,8 @@ package com.earth2me.essentials.chat; import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.FormatUtil; import java.text.MessageFormat; import java.util.Locale; import java.util.Map; @@ -44,7 +45,7 @@ public class EssentialsChatPlayerListenerLowest extends EssentialsChatPlayer /** * This listener should apply the general chat formatting only...then return control back the event handler */ - event.setMessage(Util.formatMessage(user, "essentials.chat", event.getMessage())); + event.setMessage(FormatUtil.formatMessage(user, "essentials.chat", event.getMessage())); String group = user.getGroup(); String world = user.getWorld().getName(); MessageFormat format = ess.getSettings().getChatFormat(group); diff --git a/EssentialsGeoIP/nbproject/build-impl.xml b/EssentialsGeoIP/nbproject/build-impl.xml index 13f9bde1f..156138fed 100644 --- a/EssentialsGeoIP/nbproject/build-impl.xml +++ b/EssentialsGeoIP/nbproject/build-impl.xml @@ -395,6 +395,11 @@ is divided into following sections: + + + + + @@ -418,7 +423,7 @@ is divided into following sections: - + @@ -432,6 +437,9 @@ is divided into following sections: + + + @@ -559,7 +567,7 @@ is divided into following sections: - + @@ -573,6 +581,9 @@ is divided into following sections: + + + @@ -952,7 +963,7 @@ is divided into following sections: - + diff --git a/EssentialsGeoIP/nbproject/genfiles.properties b/EssentialsGeoIP/nbproject/genfiles.properties index 2aab27202..85d5107d3 100644 --- a/EssentialsGeoIP/nbproject/genfiles.properties +++ b/EssentialsGeoIP/nbproject/genfiles.properties @@ -4,5 +4,5 @@ build.xml.stylesheet.CRC32=28e38971@1.44.1.45 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. nbproject/build-impl.xml.data.CRC32=cbf94f59 -nbproject/build-impl.xml.script.CRC32=af872325 -nbproject/build-impl.xml.stylesheet.CRC32=6ddba6b6@1.53.1.46 +nbproject/build-impl.xml.script.CRC32=e3c8394c +nbproject/build-impl.xml.stylesheet.CRC32=c6d2a60f@1.56.1.46 diff --git a/EssentialsGroupManager/nbproject/build-impl.xml b/EssentialsGroupManager/nbproject/build-impl.xml index c0aa4cb1d..df136f2ba 100644 --- a/EssentialsGroupManager/nbproject/build-impl.xml +++ b/EssentialsGroupManager/nbproject/build-impl.xml @@ -370,6 +370,11 @@ is divided into following sections: + + + + + @@ -393,7 +398,7 @@ is divided into following sections: - + @@ -407,6 +412,9 @@ is divided into following sections: + + + @@ -534,7 +542,7 @@ is divided into following sections: - + @@ -548,6 +556,9 @@ is divided into following sections: + + + @@ -920,7 +931,7 @@ is divided into following sections: - + diff --git a/EssentialsGroupManager/nbproject/genfiles.properties b/EssentialsGroupManager/nbproject/genfiles.properties index e05d95a66..3c19c576e 100644 --- a/EssentialsGroupManager/nbproject/genfiles.properties +++ b/EssentialsGroupManager/nbproject/genfiles.properties @@ -4,5 +4,5 @@ build.xml.stylesheet.CRC32=28e38971@1.38.2.45 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. nbproject/build-impl.xml.data.CRC32=a6709b83 -nbproject/build-impl.xml.script.CRC32=3be9db7e -nbproject/build-impl.xml.stylesheet.CRC32=6ddba6b6@1.53.1.46 +nbproject/build-impl.xml.script.CRC32=e5c840ec +nbproject/build-impl.xml.stylesheet.CRC32=c6d2a60f@1.56.1.46 diff --git a/EssentialsProtect/nbproject/build-impl.xml b/EssentialsProtect/nbproject/build-impl.xml index 19108f7b7..8c6e33a7f 100644 --- a/EssentialsProtect/nbproject/build-impl.xml +++ b/EssentialsProtect/nbproject/build-impl.xml @@ -395,6 +395,11 @@ is divided into following sections: + + + + + @@ -418,7 +423,7 @@ is divided into following sections: - + @@ -432,6 +437,9 @@ is divided into following sections: + + + @@ -559,7 +567,7 @@ is divided into following sections: - + @@ -573,6 +581,9 @@ is divided into following sections: + + + @@ -952,7 +963,7 @@ is divided into following sections: - + diff --git a/EssentialsProtect/nbproject/genfiles.properties b/EssentialsProtect/nbproject/genfiles.properties index 94897cd6c..52527c86a 100644 --- a/EssentialsProtect/nbproject/genfiles.properties +++ b/EssentialsProtect/nbproject/genfiles.properties @@ -4,5 +4,5 @@ build.xml.stylesheet.CRC32=28e38971@1.38.3.45 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. nbproject/build-impl.xml.data.CRC32=40644caa -nbproject/build-impl.xml.script.CRC32=eecff97a -nbproject/build-impl.xml.stylesheet.CRC32=6ddba6b6@1.53.1.46 +nbproject/build-impl.xml.script.CRC32=60fc07c9 +nbproject/build-impl.xml.stylesheet.CRC32=c6d2a60f@1.56.1.46 diff --git a/EssentialsSpawn/nbproject/build-impl.xml b/EssentialsSpawn/nbproject/build-impl.xml index 0164b4434..8163b5e31 100644 --- a/EssentialsSpawn/nbproject/build-impl.xml +++ b/EssentialsSpawn/nbproject/build-impl.xml @@ -395,6 +395,11 @@ is divided into following sections: + + + + + @@ -418,7 +423,7 @@ is divided into following sections: - + @@ -432,6 +437,9 @@ is divided into following sections: + + + @@ -559,7 +567,7 @@ is divided into following sections: - + @@ -573,6 +581,9 @@ is divided into following sections: + + + @@ -952,7 +963,7 @@ is divided into following sections: - + diff --git a/EssentialsSpawn/nbproject/genfiles.properties b/EssentialsSpawn/nbproject/genfiles.properties index fea5f8449..fd3a6cd1e 100644 --- a/EssentialsSpawn/nbproject/genfiles.properties +++ b/EssentialsSpawn/nbproject/genfiles.properties @@ -4,5 +4,5 @@ build.xml.stylesheet.CRC32=28e38971@1.38.2.45 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. nbproject/build-impl.xml.data.CRC32=e7b96939 -nbproject/build-impl.xml.script.CRC32=731b5e85 -nbproject/build-impl.xml.stylesheet.CRC32=6ddba6b6@1.53.1.46 +nbproject/build-impl.xml.script.CRC32=1d8d66ff +nbproject/build-impl.xml.stylesheet.CRC32=c6d2a60f@1.56.1.46 diff --git a/EssentialsXMPP/nbproject/build-impl.xml b/EssentialsXMPP/nbproject/build-impl.xml index 7e2958bc2..24de0b0e1 100644 --- a/EssentialsXMPP/nbproject/build-impl.xml +++ b/EssentialsXMPP/nbproject/build-impl.xml @@ -395,6 +395,11 @@ is divided into following sections: + + + + + @@ -418,7 +423,7 @@ is divided into following sections: - + @@ -432,6 +437,9 @@ is divided into following sections: + + + @@ -559,7 +567,7 @@ is divided into following sections: - + @@ -573,6 +581,9 @@ is divided into following sections: + + + @@ -952,7 +963,7 @@ is divided into following sections: - + diff --git a/EssentialsXMPP/nbproject/genfiles.properties b/EssentialsXMPP/nbproject/genfiles.properties index 744ffaed2..61cf684cb 100644 --- a/EssentialsXMPP/nbproject/genfiles.properties +++ b/EssentialsXMPP/nbproject/genfiles.properties @@ -4,5 +4,5 @@ build.xml.stylesheet.CRC32=28e38971@1.42.1.45 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. nbproject/build-impl.xml.data.CRC32=1012a5dd -nbproject/build-impl.xml.script.CRC32=db083724 -nbproject/build-impl.xml.stylesheet.CRC32=6ddba6b6@1.53.1.46 +nbproject/build-impl.xml.script.CRC32=637fa98c +nbproject/build-impl.xml.stylesheet.CRC32=c6d2a60f@1.56.1.46 diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java index ffe651d5b..21798521e 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java @@ -4,7 +4,8 @@ import com.earth2me.essentials.Console; import com.earth2me.essentials.EssentialsConf; import com.earth2me.essentials.IConf; import com.earth2me.essentials.IUser; -import com.earth2me.essentials.Util; +import com.earth2me.essentials.utils.StringUtil; +import com.earth2me.essentials.utils.FormatUtil; import java.io.File; import java.util.*; import java.util.logging.Handler; @@ -64,7 +65,7 @@ public class XMPPManager extends Handler implements MessageListener, ChatManager disconnect(); connect(); } - chat.sendMessage(Util.stripFormat(message)); + chat.sendMessage(FormatUtil.stripFormat(message)); return true; } } @@ -266,7 +267,7 @@ public class XMPPManager extends Handler implements MessageListener, ChatManager for (LogRecord logRecord : copy) { final String message = formatter.format(logRecord); - if (!XMPPManager.this.sendMessage(user, Util.stripLogColorFormat(message))) + if (!XMPPManager.this.sendMessage(user, FormatUtil.stripLogColorFormat(message))) { failedUsers.add(user); break; -- cgit v1.2.3