From 77b4307a2a660b34f4bd984c4ea3dbd9fa985ecf Mon Sep 17 00:00:00 2001 From: Phoenix616 Date: Tue, 23 Apr 2019 16:07:51 +0100 Subject: [PATCH] Implement per player locale --- Essentials/pom.xml | 6 + .../earth2me/essentials/CommandSource.java | 29 +++- .../src/com/earth2me/essentials/Console.java | 10 +- .../com/earth2me/essentials/Essentials.java | 111 ++++++++++++---- .../essentials/EssentialsEntityListener.java | 2 +- .../essentials/EssentialsPlayerListener.java | 42 +++--- .../src/com/earth2me/essentials/I18n.java | 75 ++++++++--- .../com/earth2me/essentials/IEssentials.java | 8 ++ .../com/earth2me/essentials/ISettings.java | 2 + .../src/com/earth2me/essentials/IUser.java | 31 +++-- .../src/com/earth2me/essentials/ItemDb.java | 0 .../src/com/earth2me/essentials/Jails.java | 4 +- .../src/com/earth2me/essentials/Kit.java | 12 +- .../src/com/earth2me/essentials/Kits.java | 6 +- .../earth2me/essentials/MetaItemStack.java | 58 ++++---- .../com/earth2me/essentials/PlayerList.java | 40 ++++-- .../src/com/earth2me/essentials/Settings.java | 11 ++ .../src/com/earth2me/essentials/SpawnMob.java | 22 ++-- .../src/com/earth2me/essentials/Teleport.java | 20 +-- .../earth2me/essentials/TimedTeleport.java | 10 +- .../src/com/earth2me/essentials/Trade.java | 16 +-- .../src/com/earth2me/essentials/User.java | 41 +++++- .../src/com/earth2me/essentials/UserData.java | 19 ++- .../src/com/earth2me/essentials/Warps.java | 14 +- .../src/com/earth2me/essentials/Worth.java | 10 +- .../com/earth2me/essentials/api/II18n.java | 2 +- .../com/earth2me/essentials/api/IWarps.java | 13 ++ .../essentials/commands/Commandafk.java | 14 +- .../essentials/commands/Commandback.java | 10 +- .../essentials/commands/Commandbackup.java | 8 +- .../essentials/commands/Commandbalance.java | 8 +- .../commands/Commandbalancetop.java | 6 +- .../essentials/commands/Commandban.java | 12 +- .../essentials/commands/Commandbanip.java | 9 +- .../essentials/commands/Commandbigtree.java | 6 +- .../essentials/commands/Commandbook.java | 18 ++- .../essentials/commands/Commandbreak.java | 4 +- .../essentials/commands/Commandbroadcast.java | 8 +- .../commands/Commandbroadcastworld.java | 14 +- .../essentials/commands/Commandburn.java | 4 +- .../commands/Commandclearinventory.java | 16 +-- .../Commandclearinventoryconfirmtoggle.java | 6 +- .../essentials/commands/Commandcompass.java | 22 ++-- .../essentials/commands/Commandcondense.java | 6 +- .../essentials/commands/Commandcreatekit.java | 14 +- .../essentials/commands/Commanddelhome.java | 6 +- .../essentials/commands/Commanddeljail.java | 5 +- .../essentials/commands/Commanddelwarp.java | 6 +- .../essentials/commands/Commanddepth.java | 8 +- .../essentials/commands/Commanddisposal.java | 4 +- .../essentials/commands/Commandeco.java | 12 +- .../essentials/commands/Commandenchant.java | 10 +- .../commands/Commandessentials.java | 32 +++-- .../essentials/commands/Commandexp.java | 6 +- .../essentials/commands/Commandext.java | 6 +- .../essentials/commands/Commandfeed.java | 6 +- .../essentials/commands/Commandfirework.java | 18 ++- .../essentials/commands/Commandfly.java | 6 +- .../essentials/commands/Commandgamemode.java | 12 +- .../essentials/commands/Commandgc.java | 14 +- .../essentials/commands/Commandgetpos.java | 16 +-- .../essentials/commands/Commandgive.java | 12 +- .../essentials/commands/Commandgod.java | 6 +- .../essentials/commands/Commandhat.java | 12 +- .../essentials/commands/Commandheal.java | 8 +- .../essentials/commands/Commandhelp.java | 4 +- .../essentials/commands/Commandhelpop.java | 8 +- .../essentials/commands/Commandhome.java | 17 +-- .../essentials/commands/Commandignore.java | 10 +- .../essentials/commands/Commanditem.java | 10 +- .../essentials/commands/Commanditemdb.java | 12 +- .../essentials/commands/Commandjails.java | 8 +- .../essentials/commands/Commandjump.java | 4 +- .../essentials/commands/Commandkick.java | 6 +- .../essentials/commands/Commandkickall.java | 13 +- .../essentials/commands/Commandkill.java | 6 +- .../essentials/commands/Commandkit.java | 18 ++- .../essentials/commands/Commandlightning.java | 6 +- .../essentials/commands/Commandlist.java | 20 ++- .../essentials/commands/Commandlocale.java | 83 ++++++++++++ .../essentials/commands/Commandmail.java | 64 ++++----- .../essentials/commands/Commandme.java | 13 +- .../essentials/commands/Commandmore.java | 8 +- .../essentials/commands/Commandmsg.java | 4 +- .../essentials/commands/Commandmsgtoggle.java | 6 +- .../essentials/commands/Commandmute.java | 43 +++--- .../essentials/commands/Commandnear.java | 11 +- .../essentials/commands/Commandnick.java | 36 +++-- .../essentials/commands/Commandnuke.java | 4 +- .../essentials/commands/Commandpay.java | 12 +- .../commands/Commandpayconfirmtoggle.java | 6 +- .../essentials/commands/Commandpaytoggle.java | 7 +- .../essentials/commands/Commandping.java | 4 +- .../essentials/commands/Commandpotion.java | 10 +- .../essentials/commands/Commandpowertool.java | 24 ++-- .../commands/Commandpowertooltoggle.java | 6 +- .../essentials/commands/Commandptime.java | 18 ++- .../essentials/commands/Commandpweather.java | 16 +-- .../essentials/commands/Commandr.java | 6 +- .../essentials/commands/Commandrealname.java | 4 +- .../essentials/commands/Commandrecipe.java | 38 +++--- .../essentials/commands/Commandremove.java | 8 +- .../essentials/commands/Commandrepair.java | 22 ++-- .../essentials/commands/Commandrtoggle.java | 6 +- .../essentials/commands/Commandseen.java | 56 ++++---- .../essentials/commands/Commandsell.java | 18 ++- .../essentials/commands/Commandsethome.java | 10 +- .../essentials/commands/Commandsetjail.java | 4 +- .../essentials/commands/Commandsetwarp.java | 8 +- .../essentials/commands/Commandsetworth.java | 6 +- .../essentials/commands/Commandshowkit.java | 6 +- .../essentials/commands/Commandskull.java | 12 +- .../essentials/commands/Commandsocialspy.java | 6 +- .../essentials/commands/Commandspawner.java | 16 +-- .../essentials/commands/Commandspawnmob.java | 8 +- .../essentials/commands/Commandspeed.java | 10 +- .../essentials/commands/Commandsudo.java | 8 +- .../essentials/commands/Commandsuicide.java | 6 +- .../essentials/commands/Commandtempban.java | 17 +-- .../essentials/commands/Commandthunder.java | 6 +- .../essentials/commands/Commandtime.java | 12 +- .../commands/Commandtogglejail.java | 18 ++- .../essentials/commands/Commandtop.java | 4 +- .../essentials/commands/Commandtp.java | 42 +++--- .../essentials/commands/Commandtpa.java | 24 ++-- .../essentials/commands/Commandtpaall.java | 12 +- .../essentials/commands/Commandtpacancel.java | 9 +- .../essentials/commands/Commandtpaccept.java | 22 ++-- .../essentials/commands/Commandtpahere.java | 20 ++- .../essentials/commands/Commandtpall.java | 4 +- .../essentials/commands/Commandtpauto.java | 8 +- .../essentials/commands/Commandtpdeny.java | 10 +- .../essentials/commands/Commandtphere.java | 6 +- .../essentials/commands/Commandtpo.java | 10 +- .../essentials/commands/Commandtpohere.java | 4 +- .../essentials/commands/Commandtppos.java | 16 +-- .../essentials/commands/Commandtptoggle.java | 6 +- .../essentials/commands/Commandtree.java | 6 +- .../essentials/commands/Commandunban.java | 8 +- .../essentials/commands/Commandunbanip.java | 2 +- .../essentials/commands/Commandunlimited.java | 12 +- .../essentials/commands/Commandvanish.java | 8 +- .../essentials/commands/Commandwarp.java | 14 +- .../essentials/commands/Commandweather.java | 12 +- .../essentials/commands/Commandwhois.java | 44 +++---- .../essentials/commands/Commandworld.java | 10 +- .../essentials/commands/Commandworth.java | 10 +- .../commands/EssentialsCommand.java | 4 +- .../messaging/IMessageRecipient.java | 9 ++ .../messaging/SimpleMessageRecipient.java | 23 ++-- .../essentials/signs/EssentialsSign.java | 46 +++---- .../essentials/signs/SignBalance.java | 4 +- .../essentials/signs/SignBlockListener.java | 4 +- .../earth2me/essentials/signs/SignBuy.java | 4 +- .../essentials/signs/SignEnchant.java | 22 ++-- .../earth2me/essentials/signs/SignFree.java | 4 +- .../essentials/signs/SignGameMode.java | 25 ++-- .../earth2me/essentials/signs/SignHeal.java | 10 +- .../earth2me/essentials/signs/SignInfo.java | 4 +- .../earth2me/essentials/signs/SignKit.java | 10 +- .../earth2me/essentials/signs/SignMail.java | 6 +- .../essentials/signs/SignProtection.java | 10 +- .../earth2me/essentials/signs/SignRepair.java | 8 +- .../earth2me/essentials/signs/SignSell.java | 4 +- .../essentials/signs/SignSpawnmob.java | 6 +- .../earth2me/essentials/signs/SignTime.java | 10 +- .../earth2me/essentials/signs/SignTrade.java | 124 +++++++++--------- .../earth2me/essentials/signs/SignWarp.java | 17 ++- .../essentials/signs/SignWeather.java | 10 +- .../essentials/textreader/HelpInput.java | 16 +-- .../textreader/KeywordReplacer.java | 14 +- .../essentials/textreader/TextPager.java | 14 +- .../earth2me/essentials/utils/DateUtil.java | 17 ++- Essentials/src/config.yml | 5 +- Essentials/src/messages.properties | 6 + Essentials/src/net/ess3/api/IEssentials.java | 3 + Essentials/src/plugin.yml | 4 + .../EssentialsAntiBuildListener.java | 30 ++--- .../antibuild/EssentialsConnect.java | 2 +- .../EssentialsChatPlayerListenerNormal.java | 8 +- .../geoip/EssentialsGeoIPPlayerListener.java | 2 +- .../essentials/spawn/Commandsetspawn.java | 4 +- .../essentials/spawn/Commandspawn.java | 8 +- nms/LocaleApiProvider/pom.xml | 22 ++++ .../localeapi/ApiPlayerLocaleProvider.java | 26 ++++ .../net/ess3/nms/PlayerLocaleProvider.java | 10 ++ .../nms/refl/ReflPlayerLocaleProvider.java | 50 +++++++ pom.xml | 1 + 188 files changed, 1497 insertions(+), 1264 deletions(-) create mode 100644 Essentials/src/com/earth2me/essentials/ItemDb.java create mode 100644 Essentials/src/com/earth2me/essentials/commands/Commandlocale.java create mode 100644 nms/LocaleApiProvider/pom.xml create mode 100644 nms/LocaleApiProvider/src/net/ess3/nms/localeapi/ApiPlayerLocaleProvider.java create mode 100644 nms/NMSProvider/src/net/ess3/nms/PlayerLocaleProvider.java create mode 100644 nms/ReflectionProvider/src/net/ess3/nms/refl/ReflPlayerLocaleProvider.java diff --git a/Essentials/pom.xml b/Essentials/pom.xml index 6c886407718..fa53dde6e51 100644 --- a/Essentials/pom.xml +++ b/Essentials/pom.xml @@ -114,5 +114,11 @@ 2.16.1 compile + + net.ess3 + LocaleApiProvider + 2.16.1 + compile + diff --git a/Essentials/src/com/earth2me/essentials/CommandSource.java b/Essentials/src/com/earth2me/essentials/CommandSource.java index 8d0305024bb..be1bc1522a5 100644 --- a/Essentials/src/com/earth2me/essentials/CommandSource.java +++ b/Essentials/src/com/earth2me/essentials/CommandSource.java @@ -3,14 +3,22 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import static com.earth2me.essentials.I18n.tl; + public class CommandSource { protected CommandSender sender; + protected User user = null; public CommandSource(final CommandSender base) { this.sender = base; } + public CommandSource(final User user) { + this.sender = user.getBase(); + this.user = user; + } + public final CommandSender getSender() { return sender; } @@ -30,10 +38,29 @@ public final CommandSender setSender(final CommandSender base) { return this.sender = base; } - public void sendMessage(String message) { if (!message.isEmpty()) { sender.sendMessage(message); } } + + public void setUser(User user) { + this.user = user; + } + + public User getUser() { + return user; + } + + public void sendTl(String string, Object... objects) { + sendMessage(tl(string, objects)); + } + + public String tl(String string, Object... objects) { + if (user != null) { + return I18n.tl(user.getApplicableLocale(), string, objects); + } else { + return I18n.tl(string, objects); + } + } } diff --git a/Essentials/src/com/earth2me/essentials/Console.java b/Essentials/src/com/earth2me/essentials/Console.java index 2b442d2c8d3..6173889fe6c 100644 --- a/Essentials/src/com/earth2me/essentials/Console.java +++ b/Essentials/src/com/earth2me/essentials/Console.java @@ -6,6 +6,8 @@ import org.bukkit.Server; import org.bukkit.command.CommandSender; +import java.util.Locale; + public final class Console implements IMessageRecipient { public static final String NAME = "Console"; @@ -54,11 +56,11 @@ public CommandSender getCommandSender() { @Override public boolean isReachable() { return true; } - + + /* ================================ * >> DELEGATE METHODS * ================================ */ - @Override public MessageResponse sendMessage(IMessageRecipient recipient, String message) { return this.messageRecipient.sendMessage(recipient, message); } @@ -74,4 +76,8 @@ public CommandSender getCommandSender() { @Override public void setReplyRecipient(IMessageRecipient recipient) { this.messageRecipient.setReplyRecipient(recipient); } + + @Override public Locale getLocale() { + return this.messageRecipient.getLocale(); + } } diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index 31db97ee3d5..7fe7d40a637 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -38,6 +38,7 @@ import net.ess3.api.*; import net.ess3.api.IEssentials; import net.ess3.api.ISettings; +import net.ess3.nms.PlayerLocaleProvider; import net.ess3.nms.PotionMetaProvider; import net.ess3.nms.SpawnEggProvider; import net.ess3.nms.SpawnerProvider; @@ -45,6 +46,8 @@ import net.ess3.nms.legacy.LegacyPotionMetaProvider; import net.ess3.nms.legacy.LegacySpawnEggProvider; import net.ess3.nms.legacy.LegacySpawnerProvider; +import net.ess3.nms.localeapi.ApiPlayerLocaleProvider; +import net.ess3.nms.refl.ReflPlayerLocaleProvider; import net.ess3.nms.refl.ReflSpawnEggProvider; import net.ess3.nms.updatedmeta.BasePotionDataProvider; import net.ess3.nms.updatedmeta.BlockMetaSpawnerProvider; @@ -110,6 +113,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials { private transient SpawnerProvider spawnerProvider; private transient SpawnEggProvider spawnEggProvider; private transient PotionMetaProvider potionMetaProvider; + private transient PlayerLocaleProvider playerLocaleProvider; private transient Kits kits; public Essentials() { @@ -246,6 +250,12 @@ public void onEnable() { BasePotionDataProvider.class, LegacyPotionMetaProvider.class ), "potion meta").getProvider(); + playerLocaleProvider = new ProviderFactory<>(getLogger(), + Arrays.asList( + ApiPlayerLocaleProvider.class, + ReflPlayerLocaleProvider.class + ) + , "player locale").getProvider(); execTimer.mark("Init(Providers)"); reload(); @@ -343,7 +353,7 @@ public void onDisable() { for (User user : getOnlineUsers()) { if (user.isVanished()) { user.setVanished(false); - user.sendMessage(tl("unvanishedReload")); + user.sendTl("unvanishedReload"); } user.stopTransaction(); } @@ -400,13 +410,15 @@ public List onTabCompleteEssentials(final CommandSender cSender, final C } } - try { - // Note: The tab completer is always a player, even when tab-completing in a command block - User user = null; - if (cSender instanceof Player) { - user = getUser((Player) cSender); - } + // Note: The tab completer is always a player, even when tab-completing in a command block + User user = null; + if (cSender instanceof Player) { + user = getUser((Player) cSender); + } + Locale locale = user != null ? user.getApplicableLocale() : getI18n().getCurrentLocale(); + + try { CommandSource sender = new CommandSource(cSender); // Check for disabled commands @@ -420,8 +432,8 @@ public List onTabCompleteEssentials(final CommandSender cSender, final C cmd.setEssentials(this); cmd.setEssentialsModule(module); } catch (Exception ex) { - sender.sendMessage(tl("commandNotLoaded", commandLabel)); - LOGGER.log(Level.SEVERE, tl("commandNotLoaded", commandLabel), ex); + sender.sendMessage(tl(locale, "commandNotLoaded", commandLabel)); + LOGGER.log(Level.SEVERE, tl(locale, "commandNotLoaded", commandLabel), ex); return Collections.emptyList(); } @@ -444,11 +456,11 @@ public List onTabCompleteEssentials(final CommandSender cSender, final C } catch (Exception ex) { showError(sender, ex, commandLabel); // Tab completion shouldn't fail - LOGGER.log(Level.SEVERE, tl("commandFailed", commandLabel), ex); + LOGGER.log(Level.SEVERE, tl(locale, "commandFailed", commandLabel), ex); return Collections.emptyList(); } } catch (Throwable ex) { - LOGGER.log(Level.SEVERE, tl("commandFailed", commandLabel), ex); + LOGGER.log(Level.SEVERE, tl(locale, "commandFailed", commandLabel), ex); return Collections.emptyList(); } } @@ -476,11 +488,12 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co } try { - - User user = null; Block bSenderBlock = null; + User user = null; + CommandSource sender = new CommandSource(cSender); if (cSender instanceof Player) { user = getUser((Player) cSender); + sender.setUser(user); } else if (cSender instanceof BlockCommandSender) { BlockCommandSender bsender = (BlockCommandSender) cSender; bSenderBlock = bsender.getBlock(); @@ -492,8 +505,6 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co Bukkit.getLogger().log(Level.INFO, "{0} issued server command: /{1} {2}", new Object[]{cSender.getName(), commandLabel, EssentialsCommand.getFinalArg(args, 0)}); } - CommandSource sender = new CommandSource(cSender); - // New mail notification if (user != null && !getSettings().isCommandDisabled("mail") && !command.getName().equals("mail") && user.isAuthorized("essentials.mail")) { user.notifyOfMail(); @@ -516,7 +527,7 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co cmd.setEssentials(this); cmd.setEssentialsModule(module); } catch (Exception ex) { - sender.sendMessage(tl("commandNotLoaded", commandLabel)); + sender.sendTl("commandNotLoaded", commandLabel); LOGGER.log(Level.SEVERE, tl("commandNotLoaded", commandLabel), ex); return true; } @@ -524,15 +535,15 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co // Check authorization if (user != null && !user.isAuthorized(cmd, permissionPrefix)) { LOGGER.log(Level.INFO, tl("deniedAccessCommand", user.getName())); - user.sendMessage(tl("noAccessCommand")); + sender.sendTl("noAccessCommand"); return true; } if (user != null && user.isJailed() && !user.isAuthorized(cmd, "essentials.jail.allow.")) { if (user.getJailTimeout() > 0) { - user.sendMessage(tl("playerJailedFor", user.getName(), DateUtil.formatDateDiff(user.getJailTimeout()))); + sender.sendTl("playerJailedFor", user.getName(), DateUtil.formatDateDiff(sender, user.getJailTimeout())); } else { - user.sendMessage(tl("jailMessage")); + sender.sendTl("jailMessage"); } return true; } @@ -586,7 +597,7 @@ public void cleanupOpenInventories() { @Override public void showError(final CommandSource sender, final Throwable exception, final String commandLabel) { - sender.sendMessage(tl("errorWithMessage", exception.getMessage())); + sender.sendTl("errorWithMessage", exception.getMessage()); if (getSettings().isDebug()) { LOGGER.log(Level.INFO, tl("errorCallingCommand", commandLabel), exception); } @@ -762,23 +773,62 @@ private int broadcastMessage(final IUser sender, final String permission, final IText broadcast = new SimpleTextInput(message); + final Collection players = getOnlinePlayers(); + + for (Player player : players) { + sendBroadcast(sender != null ? sender.getSource() : null, permission, keywords, getUser(player), broadcast); + } + + return players.size(); + } + + @Override + public int broadcastTl(final String string, final Object... objects) { + return broadcastTl(null, null, string, true, objects); + } + + @Override + public int broadcastTl(final IUser sender, final String string, final Object... objects) { + return broadcastTl(sender.getSource(), null, string, false, objects); + } + + @Override + public int broadcastTl(final CommandSource sender, final String string, final Object... objects) { + return broadcastTl(sender, null, string, false, objects); + } + + @Override + public int broadcastTl(final String permission, final String string, final Object... objects) { + return broadcastTl(null, permission, string, false, objects); + } + + private int broadcastTl(final CommandSource sender, final String permission, final String string, final boolean keywords, final Object... objects) { + if (sender != null && sender.getUser() != null && sender.getUser().isHidden()) { + return 0; + } + + final Collection players = getOnlinePlayers(); for (Player player : players) { final User user = getUser(player); - if ((permission == null && (sender == null || !user.isIgnoredPlayer(sender))) || (permission != null && user.isAuthorized(permission))) { - if (keywords) { - broadcast = new KeywordReplacer(broadcast, new CommandSource(player), this, false); - } - for (String messageText : broadcast.getLines()) { - user.sendMessage(messageText); - } - } + sendBroadcast(sender, permission, keywords, user, new SimpleTextInput(user.tl(string, objects))); } return players.size(); } + private void sendBroadcast(final CommandSource sender, final String permission, final boolean keywords, final User user, IText broadcast) { + if ((permission == null && (sender == null || sender.getUser() == null || !user.isIgnoredPlayer(sender.getUser()))) || (permission != null && user.isAuthorized(permission))) { + if (keywords) { + broadcast = new KeywordReplacer(broadcast, user.getSource(), this, false); + } + for (String messageText : broadcast.getLines()) { + user.sendMessage(messageText); + } + } + } + @Override public BukkitTask runTaskAsynchronously(final Runnable run) { return this.getScheduler().runTaskAsynchronously(this, run); @@ -895,6 +945,11 @@ public PotionMetaProvider getPotionMetaProvider() { return potionMetaProvider; } + @Override + public PlayerLocaleProvider getPlayerLocaleProvider() { + return playerLocaleProvider; + } + private static void addDefaultBackPermissionsToWorld(World w) { String permName = "essentials.back.into." + w.getName(); diff --git a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java index 8e2c4dc6909..034bb1ce769 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java @@ -143,7 +143,7 @@ public void onPlayerDeathEvent(final PlayerDeathEvent event) { final User user = ess.getUser(event.getEntity()); if (user.isAuthorized("essentials.back.ondeath") && !ess.getSettings().isCommandDisabled("back")) { user.setLastLocation(); - user.sendMessage(tl("backAfterDeath")); + user.sendMessage(user.tl( "backAfterDeath")); } if (!ess.getSettings().areDeathMessagesEnabled()) { event.setDeathMessage(""); diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index 2a82afa9a98..9099f539e71 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -36,7 +36,7 @@ import java.util.logging.Logger; import java.util.regex.Pattern; -import static com.earth2me.essentials.I18n.tl; +import static com.earth2me.essentials.I18n.capitalCase; public class EssentialsPlayerListener implements Listener { @@ -78,9 +78,9 @@ public void onPlayerChat(final AsyncPlayerChatEvent event) { if (user.isMuted()) { event.setCancelled(true); - user.sendMessage(user.hasMuteReason() ? tl("voiceSilencedReason", user.getMuteReason()) : tl("voiceSilenced")); + user.sendTl(user.hasMuteReason() ? user.tl("voiceSilencedReason", user.getMuteReason()) : user.tl("voiceSilenced")); - LOGGER.info(tl("mutedUserSpeaks", user.getName(), event.getMessage())); + LOGGER.info(user.tl("mutedUserSpeaks", user.getName(), event.getMessage())); } try { final Iterator it = event.getRecipients().iterator(); @@ -283,7 +283,7 @@ public void run() { final List mail = user.getMails(); if (mail.isEmpty()) { if (ess.getSettings().isNotifyNoNewMail()) { - user.sendMessage(tl("noNewMail")); // Only notify if they want us to. + user.sendTl("noNewMail"); // Only notify if they want us to. } } else { user.notifyOfMail(); @@ -296,7 +296,7 @@ public void run() { user.getBase().setAllowFlight(true); user.getBase().setFlying(true); if (ess.getSettings().isSendFlyEnableOnJoin()) { - user.getBase().sendMessage(tl("flyMode", tl("enabled"), user.getDisplayName())); + user.sendTl("flyMode", user.tl( "enabled"), user.getDisplayName()); } } } @@ -379,17 +379,19 @@ public void onPlayerLoginBanned(final PlayerLoginEvent event) { case KICK_BANNED: BanEntry banEntry = ess.getServer().getBanList(BanList.Type.NAME).getBanEntry(event.getPlayer().getName()); if (banEntry != null) { + final User buser = ess.getUser(event.getPlayer()); Date banExpiry = banEntry.getExpiration(); if (banExpiry != null) { String expiry = DateUtil.formatDateDiff(banExpiry.getTime()); - event.setKickMessage(tl("tempbanJoin", expiry, banEntry.getReason())); + event.setKickMessage(buser.tl("tempbanJoin", expiry, banEntry.getReason())); } else { - event.setKickMessage(tl("banJoin", banEntry.getReason())); + event.setKickMessage(buser.tl("banJoin", banEntry.getReason())); } } else { banEntry = ess.getServer().getBanList(BanList.Type.IP).getBanEntry(event.getAddress().getHostAddress()); if (banEntry != null) { - event.setKickMessage(tl("banIpJoin", banEntry.getReason())); + final User buser = ess.getUser(event.getPlayer()); + event.setKickMessage(buser.tl("banIpJoin", banEntry.getReason())); } } break; @@ -407,7 +409,7 @@ public void onPlayerLogin(final PlayerLoginEvent event) { event.allow(); return; } - event.disallow(Result.KICK_FULL, tl("serverFull")); + event.disallow(Result.KICK_FULL, kfuser.tl("serverFull")); break; default: break; @@ -469,9 +471,9 @@ public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) for (User spyer : ess.getOnlineUsers()) { if (spyer.isSocialSpyEnabled() && !player.equals(spyer.getBase())) { if (user.isMuted() && ess.getSettings().getSocialSpyListenMutedPlayers()) { - spyer.sendMessage(tl("socialSpyMutedPrefix") + player.getDisplayName() + ": " + event.getMessage()); + spyer.sendMessage(spyer.tl( "socialSpyMutedPrefix") + player.getDisplayName() + ": " + event.getMessage()); } else { - spyer.sendMessage(tl("socialSpyPrefix") + player.getDisplayName() + ": " + event.getMessage()); + spyer.sendMessage(spyer.tl( "socialSpyPrefix") + player.getDisplayName() + ": " + event.getMessage()); } } } @@ -479,10 +481,11 @@ public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) } } - if (ess.getUser(player).isMuted() && (ess.getSettings().getMuteCommands().contains(cmd) || ess.getSettings().getMuteCommands().contains("*"))) { + final User user = ess.getUser(player); + if (user.isMuted() && (ess.getSettings().getMuteCommands().contains(cmd) || ess.getSettings().getMuteCommands().contains("*"))) { event.setCancelled(true); - player.sendMessage(tl("voiceSilenced")); - LOGGER.info(tl("mutedUserSpeaks", player.getName(), event.getMessage())); + user.sendTl("voiceSilenced"); + LOGGER.info(user.tl("mutedUserSpeaks", player.getName(), event.getMessage())); return; } @@ -498,7 +501,6 @@ public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) broadcast = false; } } - final User user = ess.getUser(player); if (update) { user.updateActivityOnInteract(broadcast); } @@ -523,8 +525,8 @@ public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) } else if (entry.getKey().matcher(fullCommand).matches()) { // User's current cooldown hasn't expired, inform and terminate cooldown code. if (entry.getValue() > System.currentTimeMillis()) { - String commandCooldownTime = DateUtil.formatDateDiff(entry.getValue()); - user.sendMessage(tl("commandCooldown", commandCooldownTime)); + String commandCooldownTime = DateUtil.formatDateDiff(user.getSource(), entry.getValue()); + user.sendTl("commandCooldown", commandCooldownTime); cooldownFound = true; event.setCancelled(true); break; @@ -583,11 +585,11 @@ public void onPlayerChangedWorld(final PlayerChangedWorldEvent event) { if (ess.getSettings().getNoGodWorlds().contains(newWorld) && user.isGodModeEnabledRaw()) { // Player god mode is never disabled in order to retain it when changing worlds once more. // With that said, players will still take damage as per the result of User#isGodModeEnabled() - user.sendMessage(tl("noGodWorldWarning")); + user.sendTl("noGodWorldWarning"); } if (!user.getWorld().getName().equals(newWorld)) { - user.sendMessage(tl("currentWorld", newWorld)); + user.sendTl("currentWorld", newWorld); } if (user.isVanished()) { user.setVanished(user.isAuthorized("essentials.vanish")); @@ -602,7 +604,7 @@ public void onPlayerInteract(final PlayerInteractEvent event) { User player = ess.getUser(event.getPlayer()); if (player.isAuthorized("essentials.sethome.bed") && player.getWorld().getEnvironment().equals(World.Environment.NORMAL)) { player.getBase().setBedSpawnLocation(event.getClickedBlock().getLocation()); - player.sendMessage(tl("bedSet", player.getLocation().getWorld().getName(), player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ())); + player.sendTl("bedSet", player.getLocation().getWorld().getName(), player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()); } } break; diff --git a/Essentials/src/com/earth2me/essentials/I18n.java b/Essentials/src/com/earth2me/essentials/I18n.java index 7d0f8ca2ba0..958a6fa3420 100644 --- a/Essentials/src/com/earth2me/essentials/I18n.java +++ b/Essentials/src/com/earth2me/essentials/I18n.java @@ -20,7 +20,7 @@ public class I18n implements net.ess3.api.II18n { private static final String MESSAGES = "messages"; private final transient Locale defaultLocale = Locale.getDefault(); private transient Locale currentLocale = defaultLocale; - private transient ResourceBundle customBundle; + private transient Map customBundles = new HashMap<>(); private transient ResourceBundle localeBundle; private final transient ResourceBundle defaultBundle; private transient Map messageFormatCache = new HashMap(); @@ -40,7 +40,6 @@ public I18n(final IEssentials ess) { this.ess = ess; defaultBundle = ResourceBundle.getBundle(MESSAGES, Locale.ENGLISH); localeBundle = defaultBundle; - customBundle = NULL_BUNDLE; } public void onEnable() { @@ -56,10 +55,32 @@ public Locale getCurrentLocale() { return currentLocale; } - private String translate(final String string) { + private ResourceBundle getBundle(Locale locale) { + if (customBundles.containsKey(locale)) { + return customBundles.get(locale); + } + + ResourceBundle bundle; + try { + bundle = ResourceBundle.getBundle(MESSAGES, locale, new FileResClassLoader(I18n.class.getClassLoader(), ess)); + } catch (MissingResourceException ex) { + try { + bundle = ResourceBundle.getBundle(MESSAGES, locale); + } catch (MissingResourceException ex2) { + bundle = NULL_BUNDLE; + } + } + customBundles.put(locale, bundle); + return bundle; + } + + private String translate(Locale locale, final String string) { + if (locale == null) { + locale = currentLocale; + } try { try { - return customBundle.getString(string); + return getBundle(locale).getString(string); } catch (MissingResourceException ex) { return localeBundle.getString(string); } @@ -70,18 +91,26 @@ private String translate(final String string) { } public static String tl(final String string, final Object... objects) { + return tl(null, string, objects); + } + + public static String tl(final Locale locale, final String string, final Object... objects) { if (instance == null) { return ""; } if (objects.length == 0) { - return NODOUBLEMARK.matcher(instance.translate(string)).replaceAll("'"); + return NODOUBLEMARK.matcher(instance.translate(locale, string)).replaceAll("'"); } else { - return instance.format(string, objects); + return instance.format(locale, string, objects); } } public String format(final String string, final Object... objects) { - String format = translate(string); + return format(null, string, objects); + } + + public String format(final Locale locale, final String string, final Object... objects) { + String format = translate(locale, string); MessageFormat messageFormat = messageFormatCache.get(format); if (messageFormat == null) { try { @@ -98,16 +127,7 @@ public String format(final String string, final Object... objects) { public void updateLocale(final String loc) { if (loc != null && !loc.isEmpty()) { - final String[] parts = loc.split("[_\\.]"); - if (parts.length == 1) { - currentLocale = new Locale(parts[0]); - } - if (parts.length == 2) { - currentLocale = new Locale(parts[0], parts[1]); - } - if (parts.length == 3) { - currentLocale = new Locale(parts[0], parts[1], parts[2]); - } + currentLocale = getLocale(loc); } ResourceBundle.clearCache(); messageFormatCache = new HashMap(); @@ -119,11 +139,24 @@ public void updateLocale(final String loc) { localeBundle = NULL_BUNDLE; } - try { - customBundle = ResourceBundle.getBundle(MESSAGES, currentLocale, new FileResClassLoader(I18n.class.getClassLoader(), ess)); - } catch (MissingResourceException ex) { - customBundle = NULL_BUNDLE; + customBundles.clear(); + } + + public static Locale getLocale(String loc) { + if (loc == null) { + return instance.currentLocale; + } + final String[] parts = loc.split("[_\\.]"); + if (parts.length == 1) { + return new Locale(parts[0]); + } + if (parts.length == 2) { + return new Locale(parts[0], parts[1]); + } + if (parts.length == 3) { + return new Locale(parts[0], parts[1], parts[2]); } + return instance.currentLocale; } public static String capitalCase(final String input) { diff --git a/Essentials/src/com/earth2me/essentials/IEssentials.java b/Essentials/src/com/earth2me/essentials/IEssentials.java index 216f3ce9427..0da696f6ec4 100644 --- a/Essentials/src/com/earth2me/essentials/IEssentials.java +++ b/Essentials/src/com/earth2me/essentials/IEssentials.java @@ -49,6 +49,14 @@ public interface IEssentials extends Plugin { int broadcastMessage(String permission, String message); + int broadcastTl(String string, Object... objects); + + int broadcastTl(IUser sender, String string, Object... objects); + + int broadcastTl(CommandSource sender, String string, Object... objects); + + int broadcastTl(String permission, String string, Object... objects); + ISettings getSettings(); BukkitScheduler getScheduler(); diff --git a/Essentials/src/com/earth2me/essentials/ISettings.java b/Essentials/src/com/earth2me/essentials/ISettings.java index 22db2fff231..8c08250a61c 100644 --- a/Essentials/src/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/com/earth2me/essentials/ISettings.java @@ -163,6 +163,8 @@ public interface ISettings extends IConf { boolean changeDisplayName(); + boolean changeLocale(); + boolean changePlayerListName(); boolean isPlayerCommand(String string); diff --git a/Essentials/src/com/earth2me/essentials/IUser.java b/Essentials/src/com/earth2me/essentials/IUser.java index f9b0c29545e..5c7c3d3d07b 100644 --- a/Essentials/src/com/earth2me/essentials/IUser.java +++ b/Essentials/src/com/earth2me/essentials/IUser.java @@ -10,6 +10,7 @@ import java.math.BigDecimal; import java.util.Date; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.regex.Pattern; @@ -104,6 +105,10 @@ public interface IUser { void sendMessage(String message); + void sendTl(String string, Object... objects); + + String tl(String string, Object... objects); + /* * UserData */ @@ -148,13 +153,13 @@ public interface IUser { Map getConfigMap(); Map getConfigMap(String node); - + Map getCommandCooldowns(); Date getCommandCooldownExpiry(String label); - + void addCommandCooldown(Pattern pattern, Date expiresAt, boolean save); - + boolean clearCommandCooldown(Pattern pattern); /* @@ -169,19 +174,19 @@ public interface IUser { String getAfkMessage(); void setAfkMessage(final String message); - + long getAfkSince(); - + boolean isAcceptingPay(); - + void setAcceptingPay(boolean acceptingPay); - + boolean isPromptingPayConfirm(); - + void setPromptingPayConfirm(boolean prompt); - + boolean isPromptingClearConfirm(); - + void setPromptingClearConfirm(boolean prompt); boolean isLastMessageReplyRecipient(); @@ -189,4 +194,10 @@ public interface IUser { void setLastMessageReplyRecipient(boolean enabled); Map getConfirmingPayments(); + + Locale getApplicableLocale(); + + Locale getLocale(); + + void setLocale(Locale locale); } diff --git a/Essentials/src/com/earth2me/essentials/ItemDb.java b/Essentials/src/com/earth2me/essentials/ItemDb.java new file mode 100644 index 00000000000..e69de29bb2d diff --git a/Essentials/src/com/earth2me/essentials/Jails.java b/Essentials/src/com/earth2me/essentials/Jails.java index 3e5860acb5b..b501d4bf384 100644 --- a/Essentials/src/com/earth2me/essentials/Jails.java +++ b/Essentials/src/com/earth2me/essentials/Jails.java @@ -237,7 +237,7 @@ public void onJailPlayerTeleport(final PlayerTeleportEvent event) { LOGGER.log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); } } - user.sendMessage(tl("jailMessage")); + user.sendTl("jailMessage"); } @EventHandler(priority = EventPriority.HIGHEST) @@ -258,7 +258,7 @@ public void onJailPlayerJoin(final PlayerJoinEvent event) { LOGGER.log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); } } - user.sendMessage(tl("jailMessage")); + user.sendTl("jailMessage"); } } } diff --git a/Essentials/src/com/earth2me/essentials/Kit.java b/Essentials/src/com/earth2me/essentials/Kit.java index 4d5a71493a8..15b8c02e3ce 100644 --- a/Essentials/src/com/earth2me/essentials/Kit.java +++ b/Essentials/src/com/earth2me/essentials/Kit.java @@ -42,7 +42,7 @@ public String getName() { public void checkPerms(final User user) throws Exception { if (!user.isAuthorized("essentials.kits." + kitName)) { - throw new Exception(tl("noKitPermission", "essentials.kits." + kitName)); + throw new Exception(user.tl( "noKitPermission", "essentials.kits." + kitName)); } } @@ -52,10 +52,10 @@ public void checkDelay(final User user) throws Exception { if (nextUse == 0L) { return; } else if (nextUse < 0L) { - user.sendMessage(tl("kitOnce")); + user.sendTl("kitOnce"); throw new NoChargeException(); } else { - user.sendMessage(tl("kitTimed", DateUtil.formatDateDiff(nextUse))); + user.sendTl("kitTimed", DateUtil.formatDateDiff(user.getSource(), nextUse)); throw new NoChargeException(); } } @@ -85,7 +85,7 @@ public long getNextUse(final User user) throws Exception { // Make sure delay is valid delay = kit.containsKey("delay") ? ((Number) kit.get("delay")).doubleValue() : 0.0d; } catch (Exception e) { - throw new Exception(tl("kitError2")); + throw new Exception(user.tl( "kitError2")); } // When was the last kit used? @@ -203,12 +203,12 @@ public void expandItems(final User user, final List items) throws Except } user.getBase().updateInventory(); if (spew) { - user.sendMessage(tl("kitInvFull")); + user.sendTl("kitInvFull"); } } catch (Exception e) { user.getBase().updateInventory(); ess.getLogger().log(Level.WARNING, e.getMessage()); - throw new Exception(tl("kitError2"), e); + throw new Exception(user.tl( "kitError2"), e); } } } diff --git a/Essentials/src/com/earth2me/essentials/Kits.java b/Essentials/src/com/earth2me/essentials/Kits.java index 92b3f70e57d..0f94cc22ab3 100644 --- a/Essentials/src/com/earth2me/essentials/Kits.java +++ b/Essentials/src/com/earth2me/essentials/Kits.java @@ -91,7 +91,7 @@ public String listKits(final net.ess3.api.IEssentials ess, final User user) thro String name = capitalCase(kitItem); BigDecimal costPrice = new Trade("kit-" + kitItem.toLowerCase(Locale.ENGLISH), ess).getCommandCost(user); if (costPrice.signum() > 0) { - cost = tl("kitCost", NumberUtil.displayCurrency(costPrice, ess)); + cost = user.tl( "kitCost", NumberUtil.displayCurrency(costPrice, ess)); } Kit kit = new Kit(kitItem, ess); @@ -99,7 +99,7 @@ public String listKits(final net.ess3.api.IEssentials ess, final User user) thro if (nextUse == -1 && ess.getSettings().isSkippingUsedOneTimeKitsFromKitList()) { continue; } else if (nextUse != 0) { - name = tl("kitDelay", name); + name = user.tl( "kitDelay", name); } list.append(" ").append(name).append(cost); @@ -107,7 +107,7 @@ public String listKits(final net.ess3.api.IEssentials ess, final User user) thro } return list.toString().trim(); } catch (Exception ex) { - throw new Exception(tl("kitError"), ex); + throw new Exception(user.tl( "kitError"), ex); } } diff --git a/Essentials/src/com/earth2me/essentials/MetaItemStack.java b/Essentials/src/com/earth2me/essentials/MetaItemStack.java index e9c4683ffee..64ce5826f1d 100644 --- a/Essentials/src/com/earth2me/essentials/MetaItemStack.java +++ b/Essentials/src/com/earth2me/essentials/MetaItemStack.java @@ -11,7 +11,7 @@ import net.ess3.api.IEssentials; import net.ess3.nms.refl.ReflUtil; -import org.apache.commons.lang.ArrayUtils; +import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.DyeColor; import org.bukkit.FireworkEffect; @@ -127,7 +127,7 @@ public void parseStringMeta(final CommandSource sender, final boolean allowUnsaf ess.getLogger().log(Level.INFO, "Itemstack is invalid", npe); } } catch (NoSuchMethodError nsme) { - throw new Exception(tl("noMetaJson"), nsme); + throw new Exception(sender.tl("noMetaJson"), nsme); } catch (Throwable throwable) { throw new Exception(throwable.getMessage(), throwable); } @@ -137,13 +137,13 @@ public void parseStringMeta(final CommandSource sender, final boolean allowUnsaf } if (validFirework) { if (!hasMetaPermission(sender, "firework", true, true, ess)) { - throw new Exception(tl("noMetaFirework")); + throw new Exception(sender.tl("noMetaFirework")); } FireworkEffect effect = builder.build(); FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta(); fmeta.addEffect(effect); if (fmeta.getEffects().size() > 1 && !hasMetaPermission(sender, "firework-multiple", true, true, ess)) { - throw new Exception(tl("multipleCharges")); + throw new Exception(sender.tl("multipleCharges")); } stack.setItemMeta(fmeta); } @@ -181,7 +181,7 @@ public void addStringMeta(final CommandSource sender, final boolean allowUnsafe, meta.setOwningPlayer(ess.getServer().getOfflinePlayer(owner)); stack.setItemMeta(meta); } else { - throw new Exception(tl("onlyPlayerSkulls")); + throw new Exception(sender.tl("onlyPlayerSkulls")); } } else if (split.length > 1 && split[0].equalsIgnoreCase("book") && stack.getType() == WRITTEN_BOOK && (hasMetaPermission(sender, "book", true, true, ess) || hasMetaPermission(sender, "chapter-" + split[1].toLowerCase(Locale.ENGLISH), true, true, ess))) { final BookMeta meta = (BookMeta) stack.getItemMeta(); @@ -207,7 +207,7 @@ public void addStringMeta(final CommandSource sender, final boolean allowUnsafe, meta.setPower(power > 3 ? 4 : power); stack.setItemMeta(meta); } else if (split.length > 1 && split[0].equalsIgnoreCase("itemflags") && hasMetaPermission(sender, "itemflags", false, true, ess)) { - addItemFlags(string); + addItemFlags(sender, string); } else if (MaterialUtil.isFirework(stack.getType())) {//WARNING - Meta for fireworks will be ignored after this point. addFireworkMeta(sender, false, string, ess); } else if (MaterialUtil.isPotion(stack.getType())) { //WARNING - Meta for potions will be ignored after this point. @@ -238,17 +238,25 @@ public void addStringMeta(final CommandSource sender, final boolean allowUnsafe, meta.setColor(Color.fromRGB(red, green, blue)); stack.setItemMeta(meta); } else { - throw new Exception(tl("leatherSyntax")); + throw new Exception(sender.tl("leatherSyntax")); } } else { parseEnchantmentStrings(sender, allowUnsafe, split, ess); } } + /** + * @deprecated Use {@link #addItemFlags(CommandSource, String)} + */ + @Deprecated public void addItemFlags(final String string) throws Exception { + addItemFlags(new CommandSource(Bukkit.getConsoleSender()), string); + } + + public void addItemFlags(CommandSource sender, final String string) throws Exception { String[] separate = splitPattern.split(string, 2); if (separate.length != 2) { - throw new Exception(tl("invalidItemFlagMeta", string)); + throw new Exception(sender.tl("invalidItemFlagMeta", string)); } String[] split = separate[1].split(","); @@ -263,7 +271,7 @@ public void addItemFlags(final String string) throws Exception { } if (meta.getItemFlags().isEmpty()) { - throw new Exception(tl("invalidItemFlagMeta", string)); + throw new Exception(sender.tl("invalidItemFlagMeta", string)); } stack.setItemMeta(meta); @@ -279,13 +287,13 @@ public void addFireworkMeta(final CommandSource sender, final boolean allowShort if (split[0].equalsIgnoreCase("color") || split[0].equalsIgnoreCase("colour") || (allowShortName && split[0].equalsIgnoreCase("c"))) { if (validFirework) { if (!hasMetaPermission(sender, "firework", true, true, ess)) { - throw new Exception(tl("noMetaFirework")); + throw new Exception(sender.tl("noMetaFirework")); } FireworkEffect effect = builder.build(); FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta(); fmeta.addEffect(effect); if (fmeta.getEffects().size() > 1 && !hasMetaPermission(sender, "firework-multiple", true, true, ess)) { - throw new Exception(tl("multipleCharges")); + throw new Exception(sender.tl("multipleCharges")); } stack.setItemMeta(fmeta); builder = FireworkEffect.builder(); @@ -298,7 +306,7 @@ public void addFireworkMeta(final CommandSource sender, final boolean allowShort validFirework = true; primaryColors.add(colorMap.get(color.toUpperCase()).getFireworkColor()); } else { - throw new Exception(tl("invalidFireworkFormat", split[1], split[0])); + throw new Exception(sender.tl("invalidFireworkFormat", split[1], split[0])); } } builder.withColor(primaryColors); @@ -308,7 +316,7 @@ public void addFireworkMeta(final CommandSource sender, final boolean allowShort if (fireworkShape.containsKey(split[1].toUpperCase())) { finalEffect = fireworkShape.get(split[1].toUpperCase()); } else { - throw new Exception(tl("invalidFireworkFormat", split[1], split[0])); + throw new Exception(sender.tl("invalidFireworkFormat", split[1], split[0])); } if (finalEffect != null) { builder.with(finalEffect); @@ -320,7 +328,7 @@ public void addFireworkMeta(final CommandSource sender, final boolean allowShort if (colorMap.containsKey(color.toUpperCase())) { fadeColors.add(colorMap.get(color.toUpperCase()).getFireworkColor()); } else { - throw new Exception(tl("invalidFireworkFormat", split[1], split[0])); + throw new Exception(sender.tl("invalidFireworkFormat", split[1], split[0])); } } if (!fadeColors.isEmpty()) { @@ -334,7 +342,7 @@ public void addFireworkMeta(final CommandSource sender, final boolean allowShort } else if (effect.equalsIgnoreCase("trail")) { builder.trail(true); } else { - throw new Exception(tl("invalidFireworkFormat", split[1], split[0])); + throw new Exception(sender.tl("invalidFireworkFormat", split[1], split[0])); } } } @@ -355,10 +363,10 @@ public void addPotionMeta(final CommandSource sender, final boolean allowShortNa if (hasMetaPermission(sender, "potions." + pEffectType.getName().toLowerCase(Locale.ENGLISH), true, false, ess)) { validPotionEffect = true; } else { - throw new Exception(tl("noPotionEffectPerm", pEffectType.getName().toLowerCase(Locale.ENGLISH))); + throw new Exception(sender.tl("noPotionEffectPerm", pEffectType.getName().toLowerCase(Locale.ENGLISH))); } } else { - throw new Exception(tl("invalidPotionMeta", split[1])); + throw new Exception(sender.tl("invalidPotionMeta", split[1])); } } else if (split[0].equalsIgnoreCase("power") || (allowShortName && split[0].equalsIgnoreCase("p"))) { if (NumberUtil.isInt(split[1])) { @@ -368,14 +376,14 @@ public void addPotionMeta(final CommandSource sender, final boolean allowShortNa power -= 1; } } else { - throw new Exception(tl("invalidPotionMeta", split[1])); + throw new Exception(sender.tl("invalidPotionMeta", split[1])); } } else if (split[0].equalsIgnoreCase("duration") || (allowShortName && split[0].equalsIgnoreCase("d"))) { if (NumberUtil.isInt(split[1])) { validPotionDuration = true; duration = Integer.parseInt(split[1]) * 20; //Duration is in ticks by default, converted to seconds } else { - throw new Exception(tl("invalidPotionMeta", split[1])); + throw new Exception(sender.tl("invalidPotionMeta", split[1])); } } else if (split[0].equalsIgnoreCase("splash") || (allowShortName && split[0].equalsIgnoreCase("s"))) { isSplashPotion = Boolean.valueOf(split[1]); @@ -385,7 +393,7 @@ public void addPotionMeta(final CommandSource sender, final boolean allowShortNa PotionMeta pmeta = (PotionMeta) stack.getItemMeta(); pEffect = pEffectType.createEffect(duration, power); if (pmeta.getCustomEffects().size() > 1 && !hasMetaPermission(sender, "potions.multiple", true, false, ess)) { - throw new Exception(tl("multiplePotionEffects")); + throw new Exception(sender.tl("multiplePotionEffects")); } pmeta.addCustomEffect(pEffect, true); stack.setItemMeta(pmeta); @@ -428,7 +436,7 @@ private void parseEnchantmentStrings(final CommandSource sender, final boolean a public void addEnchantment(final CommandSource sender, final boolean allowUnsafe, final Enchantment enchantment, final int level) throws Exception { if (enchantment == null) { - throw new Exception(tl("enchantmentNotFound")); + throw new Exception(sender.tl("enchantmentNotFound")); } try { if (stack.getType().equals(Material.ENCHANTED_BOOK)) { @@ -465,7 +473,7 @@ public Enchantment getEnchantment(final User user, final String name) throws Exc final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH); if (!hasMetaPermission(user, "enchantments." + enchantmentName, true, false)) { - throw new Exception(tl("enchantmentPerm", enchantmentName)); + throw new Exception(user.tl( "enchantmentPerm", enchantmentName)); } return enchantment; } @@ -475,7 +483,7 @@ public void addBannerMeta(final CommandSource sender, final boolean allowShortNa final String[] split = splitPattern.split(string, 2); if (split.length < 2) { - throw new Exception(tl("invalidBanner", split[1])); + throw new Exception(sender.tl("invalidBanner", split[1])); } PatternType patternType = null; @@ -499,7 +507,7 @@ public void addBannerMeta(final CommandSource sender, final boolean allowShortNa final String[] split = splitPattern.split(string, 2); if (split.length < 2) { - throw new Exception(tl("invalidBanner", split[1])); + throw new Exception(sender.tl("invalidBanner", split[1])); } PatternType patternType = null; @@ -539,7 +547,7 @@ private boolean hasMetaPermission(final User user, final String metaPerm, final if (graceful) { return false; } else { - throw new Exception(tl("noMetaPerm", metaPerm)); + throw new Exception(user.tl( "noMetaPerm", metaPerm)); } } diff --git a/Essentials/src/com/earth2me/essentials/PlayerList.java b/Essentials/src/com/earth2me/essentials/PlayerList.java index 9bf6c1aaf1e..8f48e82558f 100644 --- a/Essentials/src/com/earth2me/essentials/PlayerList.java +++ b/Essentials/src/com/earth2me/essentials/PlayerList.java @@ -1,6 +1,7 @@ package com.earth2me.essentials; import com.earth2me.essentials.utils.FormatUtil; +import org.bukkit.Bukkit; import org.bukkit.Server; import java.util.*; @@ -10,7 +11,12 @@ public class PlayerList { // Cosmetic list formatting + @Deprecated public static String listUsers(final IEssentials ess, final List users, final String seperator) { + return listUsers(ess, new CommandSource(Bukkit.getConsoleSender()), users, seperator); + } + + public static String listUsers(final IEssentials ess, final CommandSource sender, final List users, final String seperator) { final StringBuilder groupString = new StringBuilder(); Collections.sort(users); boolean needComma = false; @@ -20,10 +26,10 @@ public static String listUsers(final IEssentials ess, final List users, fi } needComma = true; if (user.isAfk()) { - groupString.append(tl("listAfkTag")); + groupString.append(sender.tl("listAfkTag")); } if (user.isHidden()) { - groupString.append(tl("listHiddenTag")); + groupString.append(sender.tl("listHiddenTag")); } user.setDisplayNick(); groupString.append(user.getDisplayName()); @@ -32,24 +38,28 @@ public static String listUsers(final IEssentials ess, final List users, fi return groupString.toString(); } - // Produce a user summary: There are 5 out of maximum 10 players online. + @Deprecated public static String listSummary(final IEssentials ess, final User user, final boolean showHidden) { + return listSummary(ess, new CommandSource(user), showHidden); + } + + public static String listSummary(final IEssentials ess, final CommandSource sender, final boolean showHidden) { Server server = ess.getServer(); int playerHidden = 0; int hiddenCount = 0; for (User onlinePlayer : ess.getOnlineUsers()) { - if (onlinePlayer.isHidden() || (user != null && !user.getBase().canSee(onlinePlayer.getBase()))) { + if (onlinePlayer.isHidden() || (sender.getUser() != null && !sender.getUser().getBase().canSee(onlinePlayer.getBase()))) { playerHidden++; - if (showHidden || user.getBase().canSee(onlinePlayer.getBase())) { + if (showHidden || sender.getUser().getBase().canSee(onlinePlayer.getBase())) { hiddenCount++; } } } String online; if (hiddenCount > 0) { - online = tl("listAmountHidden", ess.getOnlinePlayers().size() - playerHidden, hiddenCount, server.getMaxPlayers()); + online = sender.tl("listAmountHidden", ess.getOnlinePlayers().size() - playerHidden, hiddenCount, server.getMaxPlayers()); } else { - online = tl("listAmount", ess.getOnlinePlayers().size() - playerHidden, server.getMaxPlayers()); + online = sender.tl("listAmount", ess.getOnlinePlayers().size() - playerHidden, server.getMaxPlayers()); } return online; } @@ -98,25 +108,35 @@ public static List getMergedList(final IEssentials ess, final Map + @Deprecated public static String listGroupUsers(final IEssentials ess, final Map> playerList, final String groupName) throws Exception { + return listGroupUsers(ess, new CommandSource(Bukkit.getConsoleSender()), playerList, groupName); + } + + public static String listGroupUsers(final IEssentials ess, final CommandSource sender, final Map> playerList, final String groupName) throws Exception { final List users = getMergedList(ess, playerList, groupName); final List groupUsers = playerList.get(groupName); if (groupUsers != null && !groupUsers.isEmpty()) { users.addAll(groupUsers); } if (users == null || users.isEmpty()) { - throw new Exception(tl("groupDoesNotExist")); + throw new Exception(sender.tl("groupDoesNotExist")); } final StringBuilder displayGroupName = new StringBuilder(); displayGroupName.append(Character.toTitleCase(groupName.charAt(0))); displayGroupName.append(groupName.substring(1)); - return outputFormat(displayGroupName.toString(), listUsers(ess, users, ", ")); + return outputFormat(sender, displayGroupName.toString(), listUsers(ess, users, ", ")); } // Build the output string + @Deprecated public static String outputFormat(final String group, final String message) { + return outputFormat(new CommandSource(Bukkit.getConsoleSender()), group, message); + } + + public static String outputFormat(final CommandSource sender, final String group, final String message) { final StringBuilder outputString = new StringBuilder(); - outputString.append(tl("listGroupTag", FormatUtil.replaceFormat(group))); + outputString.append(sender.tl("listGroupTag", FormatUtil.replaceFormat(group))); outputString.append(message); return outputString.toString(); } diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index a19accb45f3..6753a3138e2 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -790,6 +790,17 @@ public boolean changeDisplayName() { return changeDisplayName; } + private boolean changeLocale = true; + + private boolean _changeLocale() { + return config.getBoolean("change-locale", true); + } + + @Override + public boolean changeLocale() { + return changeLocale; + } + private boolean changePlayerListName = false; private boolean _changePlayerListName() { diff --git a/Essentials/src/com/earth2me/essentials/SpawnMob.java b/Essentials/src/com/earth2me/essentials/SpawnMob.java index cb66fa1693c..863b1fbea55 100644 --- a/Essentials/src/com/earth2me/essentials/SpawnMob.java +++ b/Essentials/src/com/earth2me/essentials/SpawnMob.java @@ -36,7 +36,7 @@ public static String mobList(final User user) { } } if (availableList.isEmpty()) { - availableList.add(tl("none")); + availableList.add(user.tl( "none")); } return StringUtil.joinList(availableList); } @@ -78,7 +78,7 @@ public static List mobData(final String mobString) { 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 = LocationUtil.getTarget(user.getBase()).getBlock(); if (block == null) { - throw new Exception(tl("unableToSpawnMob")); + throw new Exception(user.tl( "unableToSpawnMob")); } spawnmob(ess, server, user.getSource(), user, block.getLocation(), parts, data, mobCount); } @@ -109,7 +109,7 @@ public static void spawnmob(final IEssentials ess, final Server server, final Co if (mobCount > effectiveLimit) { mobCount = effectiveLimit; - sender.sendMessage(tl("mobSpawnLimit")); + sender.sendTl("mobSpawnLimit"); } Mob mob = Mob.fromName(parts.get(0)); // Get the first mob @@ -117,13 +117,13 @@ public static void spawnmob(final IEssentials ess, final Server server, final Co for (int i = 0; i < mobCount; i++) { spawnMob(ess, server, sender, target, sloc, parts, data); } - sender.sendMessage(mobCount * parts.size() + " " + mob.name.toLowerCase(Locale.ENGLISH) + mob.suffix + " " + tl("spawned")); + sender.sendMessage(mobCount * parts.size() + " " + mob.name.toLowerCase(Locale.ENGLISH) + mob.suffix + " " + sender.tl("spawned")); } catch (MobException e1) { - throw new Exception(tl("unableToSpawnMob"), e1); + throw new Exception(sender.tl("unableToSpawnMob"), e1); } catch (NumberFormatException e2) { - throw new Exception(tl("numberRequired"), e2); + throw new Exception(sender.tl("numberRequired"), e2); } catch (NullPointerException np) { - throw new Exception(tl("soloMob"), np); + throw new Exception(sender.tl("soloMob"), np); } } @@ -163,15 +163,15 @@ private static void spawnMob(final IEssentials ess, final Server server, final C private static void checkSpawnable(IEssentials ess, CommandSource sender, Mob mob) throws Exception { if (mob == null || mob.getType() == null) { - throw new Exception(tl("invalidMob")); + throw new Exception(sender.tl("invalidMob")); } if (ess.getSettings().getProtectPreventSpawn(mob.getType().toString().toLowerCase(Locale.ENGLISH))) { - throw new Exception(tl("disabledToSpawnMob")); + throw new Exception(sender.tl("disabledToSpawnMob")); } if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.spawnmob." + mob.name.toLowerCase(Locale.ENGLISH))) { - throw new Exception(tl("noPermToSpawnMob")); + throw new Exception(sender.tl("noPermToSpawnMob")); } } @@ -179,7 +179,7 @@ private static void changeMobData(final CommandSource sender, final EntityType t String data = inputData; if (data.isEmpty()) { - sender.sendMessage(tl("mobDataList", StringUtil.joinList(MobData.getValidHelp(spawned)))); + sender.sendTl("mobDataList", StringUtil.joinList(MobData.getValidHelp(spawned))); } if (spawned instanceof Zombie) { diff --git a/Essentials/src/com/earth2me/essentials/Teleport.java b/Essentials/src/com/earth2me/essentials/Teleport.java index e5bd413053d..158b5db6f4c 100644 --- a/Essentials/src/com/earth2me/essentials/Teleport.java +++ b/Essentials/src/com/earth2me/essentials/Teleport.java @@ -63,7 +63,7 @@ && cooldownApplies()) { time.setTimeInMillis(lastTime); time.add(Calendar.SECOND, (int) cooldown); time.add(Calendar.MILLISECOND, (int) ((cooldown * 1000.0) % 1000.0)); - throw new Exception(tl("timeBeforeTeleport", DateUtil.formatDateDiff(time.getTimeInMillis()))); + throw new Exception(teleportOwner.tl( "timeBeforeTeleport", DateUtil.formatDateDiff(teleportOwner.getSource(), time.getTimeInMillis()))); } } // if justCheck is set, don't update lastTeleport; we're just checking @@ -95,7 +95,7 @@ private void warnUser(final IUser user, final double delay) { Calendar c = new GregorianCalendar(); c.add(Calendar.SECOND, (int) delay); c.add(Calendar.MILLISECOND, (int) ((delay * 1000.0) % 1000.0)); - user.sendMessage(tl("dontMoveMessage", DateUtil.formatDateDiff(c.getTimeInMillis()))); + user.sendTl("dontMoveMessage", DateUtil.formatDateDiff(user.getSource(), c.getTimeInMillis())); } //The now function is used when you want to skip tp delay when teleporting someone to a location or player. @@ -115,7 +115,7 @@ public void now(Player entity, boolean cooldown, TeleportCause cause) throws Exc } final ITarget target = new PlayerTarget(entity); now(teleportOwner, target, cause); - teleportOwner.sendMessage(tl("teleporting", target.getLocation().getWorld().getName(), target.getLocation().getBlockX(), target.getLocation().getBlockY(), target.getLocation().getBlockZ())); + teleportOwner.sendTl("teleporting", target.getLocation().getWorld().getName(), target.getLocation().getBlockX(), target.getLocation().getBlockY(), target.getLocation().getBlockZ()); } protected void now(IUser teleportee, ITarget target, TeleportCause cause) throws Exception { @@ -131,7 +131,7 @@ protected void now(IUser teleportee, ITarget target, TeleportCause cause) throws PaperLib.teleportAsync(teleportee.getBase(), LocationUtil.getSafeDestination(ess, teleportee, loc), cause); } } else { - throw new Exception(tl("unsafeTeleportDestination", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); + throw new Exception(teleportee.tl( "unsafeTeleportDestination", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); } } else { if (ess.getSettings().isForceDisableTeleportSafety()) { @@ -162,7 +162,7 @@ public void teleport(Location loc, Trade chargeFor, TeleportCause cause) throws @Override public void teleport(Player entity, Trade chargeFor, TeleportCause cause) throws Exception { ITarget target = new PlayerTarget(entity); - teleportOwner.sendMessage(tl("teleportToPlayer", entity.getDisplayName())); + teleportOwner.sendTl("teleportToPlayer", entity.getDisplayName()); teleport(teleportOwner, target, chargeFor, cause); } @@ -177,8 +177,8 @@ public void teleportPlayer(IUser teleportee, Location loc, Trade chargeFor, Tele public void teleportPlayer(IUser teleportee, Player entity, Trade chargeFor, TeleportCause cause) throws Exception { ITarget target = new PlayerTarget(entity); teleport(teleportee, target, chargeFor, cause); - teleportee.sendMessage(tl("teleporting", target.getLocation().getWorld().getName(), target.getLocation().getBlockX(), target.getLocation().getBlockY(), target.getLocation().getBlockZ())); - teleportOwner.sendMessage(tl("teleporting", target.getLocation().getWorld().getName(), target.getLocation().getBlockX(), target.getLocation().getBlockY(), target.getLocation().getBlockZ())); + teleportee.sendTl("teleporting", target.getLocation().getWorld().getName(), target.getLocation().getBlockX(), target.getLocation().getBlockY(), target.getLocation().getBlockZ()); + teleportOwner.sendTl("teleporting", target.getLocation().getWorld().getName(), target.getLocation().getBlockX(), target.getLocation().getBlockY(), target.getLocation().getBlockZ()); } private void teleport(IUser teleportee, ITarget target, Trade chargeFor, TeleportCause cause) throws Exception { @@ -292,9 +292,9 @@ public void warp(IUser teleportee, String warp, Trade chargeFor, TeleportCause c } warp = event.getWarp(); Location loc = ess.getWarps().getWarp(warp); - teleportee.sendMessage(tl("warpingTo", warp, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); + teleportee.sendTl("warpingTo", warp, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); if (!teleportee.equals(teleportOwner)) { - teleportOwner.sendMessage(tl("warpingTo", warp, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); + teleportOwner.sendTl("warpingTo", warp, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); } teleport(teleportee, new LocationTarget(loc), chargeFor, cause); } @@ -310,7 +310,7 @@ public void back(Trade chargeFor) throws Exception { public void back(IUser teleporter, Trade chargeFor) throws Exception { tpType = TeleportType.BACK; final Location loc = teleportOwner.getLastLocation(); - teleportOwner.sendMessage(tl("backUsageMsg", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); + teleportOwner.sendTl("backUsageMsg", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); teleportOther(teleporter, teleportOwner, new LocationTarget(loc), chargeFor, TeleportCause.COMMAND); } diff --git a/Essentials/src/com/earth2me/essentials/TimedTeleport.java b/Essentials/src/com/earth2me/essentials/TimedTeleport.java index c3e959f5821..4f71ec977be 100644 --- a/Essentials/src/com/earth2me/essentials/TimedTeleport.java +++ b/Essentials/src/com/earth2me/essentials/TimedTeleport.java @@ -89,14 +89,14 @@ public void run() { try { teleport.cooldown(false); } catch (Exception ex) { - teleportOwner.sendMessage(tl("cooldownWithMessage", ex.getMessage())); + teleportOwner.sendTl("cooldownWithMessage", ex.getMessage()); if (teleportOwner != teleportUser) { - teleportUser.sendMessage(tl("cooldownWithMessage", ex.getMessage())); + teleportUser.sendTl("cooldownWithMessage", ex.getMessage()); } } try { cancelTimer(false); - teleportUser.sendMessage(tl("teleportationCommencing")); + teleportUser.sendTl("teleportationCommencing"); try { if (timer_chargeFor != null) { @@ -129,9 +129,9 @@ void cancelTimer(boolean notifyUser) { try { ess.getServer().getScheduler().cancelTask(timer_task); if (notifyUser) { - teleportOwner.sendMessage(tl("pendingTeleportCancelled")); + teleportOwner.sendTl("pendingTeleportCancelled"); if (timer_teleportee != null && !timer_teleportee.equals(teleportOwner.getBase().getUniqueId())) { - ess.getUser(timer_teleportee).sendMessage(tl("pendingTeleportCancelled")); + ess.getUser(timer_teleportee).sendTl("pendingTeleportCancelled"); } } } finally { diff --git a/Essentials/src/com/earth2me/essentials/Trade.java b/Essentials/src/com/earth2me/essentials/Trade.java index e003dccacf2..a8034ffab03 100644 --- a/Essentials/src/com/earth2me/essentials/Trade.java +++ b/Essentials/src/com/earth2me/essentials/Trade.java @@ -87,20 +87,20 @@ public void isAffordableFor(final IUser user) throws ChargeException { } if (getMoney() != null && getMoney().signum() > 0 && !user.canAfford(getMoney())) { - throw new ChargeException(tl("notEnoughMoney", NumberUtil.displayCurrency(getMoney(), ess))); + throw new ChargeException(user.tl("notEnoughMoney", NumberUtil.displayCurrency(getMoney(), ess))); } if (getItemStack() != null && !user.getBase().getInventory().containsAtLeast(itemStack, itemStack.getAmount())) { - throw new ChargeException(tl("missingItems", getItemStack().getAmount(), ess.getItemDb().name(getItemStack()))); + throw new ChargeException(user.tl("missingItems", getItemStack().getAmount(), ess.getItemDb().name(getItemStack()))); } BigDecimal money; if (command != null && !command.isEmpty() && (money = getCommandCost(user)).signum() > 0 && !user.canAfford(money)) { - throw new ChargeException(tl("notEnoughMoney", NumberUtil.displayCurrency(money, ess))); + throw new ChargeException(user.tl("notEnoughMoney", NumberUtil.displayCurrency(money, ess))); } if (exp != null && exp > 0 && SetExpFix.getTotalExperience(user.getBase()) < exp) { - throw new ChargeException(tl("notEnoughExperience")); + throw new ChargeException(user.tl("notEnoughExperience")); } } @@ -183,7 +183,7 @@ public void charge(final IUser user) throws ChargeException { ess.getLogger().log(Level.INFO, "charging user " + user.getName() + " money " + getMoney().toPlainString()); } if (!user.canAfford(getMoney()) && getMoney().signum() > 0) { - throw new ChargeException(tl("notEnoughMoney", NumberUtil.displayCurrency(getMoney(), ess))); + throw new ChargeException(user.tl("notEnoughMoney", NumberUtil.displayCurrency(getMoney(), ess))); } user.takeMoney(getMoney()); } @@ -192,7 +192,7 @@ public void charge(final IUser user) throws ChargeException { ess.getLogger().log(Level.INFO, "charging user " + user.getName() + " itemstack " + getItemStack().toString()); } if (!user.getBase().getInventory().containsAtLeast(getItemStack(), getItemStack().getAmount())) { - throw new ChargeException(tl("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " "))); + throw new ChargeException(user.tl("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " "))); } user.getBase().getInventory().removeItem(getItemStack()); user.getBase().updateInventory(); @@ -200,7 +200,7 @@ public void charge(final IUser user) throws ChargeException { if (command != null) { final BigDecimal cost = getCommandCost(user); if (!user.canAfford(cost) && cost.signum() > 0) { - throw new ChargeException(tl("notEnoughMoney", NumberUtil.displayCurrency(cost, ess))); + throw new ChargeException(user.tl("notEnoughMoney", NumberUtil.displayCurrency(cost, ess))); } user.takeMoney(cost); } @@ -210,7 +210,7 @@ public void charge(final IUser user) throws ChargeException { } final int experience = SetExpFix.getTotalExperience(user.getBase()); if (experience < getExperience() && getExperience() > 0) { - throw new ChargeException(tl("notEnoughExperience")); + throw new ChargeException(user.tl("notEnoughExperience")); } SetExpFix.setTotalExperience(user.getBase(), experience - getExperience()); } diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java index e9ac59ed5ec..d8862da02d8 100644 --- a/Essentials/src/com/earth2me/essentials/User.java +++ b/Essentials/src/com/earth2me/essentials/User.java @@ -126,7 +126,7 @@ public void healCooldown() throws Exception { cooldownTime.add(Calendar.SECOND, (int) cooldown); cooldownTime.add(Calendar.MILLISECOND, (int) ((cooldown * 1000.0) % 1000.0)); if (cooldownTime.after(now) && !isAuthorized("essentials.heal.cooldown.bypass")) { - throw new Exception(tl("timeBeforeHeal", DateUtil.formatDateDiff(cooldownTime.getTimeInMillis()))); + throw new Exception(tl("timeBeforeHeal", DateUtil.formatDateDiff(getSource(), cooldownTime.getTimeInMillis()))); } } setLastHealTimestamp(now.getTimeInMillis()); @@ -145,7 +145,7 @@ public void giveMoney(final BigDecimal value, final CommandSource initiator) thr setMoney(getMoney().add(value)); sendMessage(tl("addedToAccount", NumberUtil.displayCurrency(value, ess))); if (initiator != null) { - initiator.sendMessage(tl("addedToOthersAccount", NumberUtil.displayCurrency(value, ess), this.getDisplayName(), NumberUtil.displayCurrency(getMoney(), ess))); + initiator.sendTl("addedToOthersAccount", NumberUtil.displayCurrency(value, ess), this.getDisplayName(), NumberUtil.displayCurrency(getMoney(), ess)); } } @@ -159,7 +159,7 @@ public void payUser(final User reciever, final BigDecimal value) throws Exceptio setMoney(getMoney().subtract(value)); reciever.setMoney(reciever.getMoney().add(value)); sendMessage(tl("moneySentTo", NumberUtil.displayCurrency(value, ess), reciever.getDisplayName())); - reciever.sendMessage(tl("moneyRecievedFrom", NumberUtil.displayCurrency(value, ess), getDisplayName())); + reciever.sendTl("moneyRecievedFrom", NumberUtil.displayCurrency(value, ess), getDisplayName()); } else { throw new ChargeException(tl("notEnoughMoney", NumberUtil.displayCurrency(value, ess))); } @@ -182,7 +182,7 @@ public void takeMoney(final BigDecimal value, final CommandSource initiator) { } sendMessage(tl("takenFromAccount", NumberUtil.displayCurrency(value, ess))); if (initiator != null) { - initiator.sendMessage(tl("takenFromOthersAccount", NumberUtil.displayCurrency(value, ess), this.getDisplayName(), NumberUtil.displayCurrency(getMoney(), ess))); + initiator.sendTl("takenFromOthersAccount", NumberUtil.displayCurrency(value, ess), this.getDisplayName(), NumberUtil.displayCurrency(getMoney(), ess)); } } @@ -599,7 +599,7 @@ public void checkActivity() { for (User user : ess.getOnlineUsers()) { if (user.isAuthorized("essentials.kick.notify")) { - user.sendMessage(tl("playerKicked", Console.NAME, getName(), kickReason)); + user.sendTl("playerKicked", Console.NAME, getName(), kickReason); } } } @@ -799,6 +799,16 @@ public void sendMessage(String message) { } } + @Override + public void sendTl(String string, Object... objects) { + sendMessage(tl(string, objects)); + } + + @Override + public String tl(String string, Object... objects) { + return I18n.tl(getApplicableLocale(), string, objects); + } + @Override public int compareTo(final User other) { return FormatUtil.stripFormat(getDisplayName()).compareToIgnoreCase(FormatUtil.stripFormat(other.getDisplayName())); @@ -820,7 +830,7 @@ public int hashCode() { @Override public CommandSource getSource() { - return new CommandSource(getBase()); + return new CommandSource(this); } @Override @@ -870,6 +880,25 @@ public Map getConfirmingPayments() { return confirmingPayments; } + @Override + public Locale getApplicableLocale() { + if (!ess.getSettings().changeLocale()) { + return ess.getI18n().getCurrentLocale(); + } + + Locale locale = super.getLocale(); + if (locale == null) { + if (getBase() != null) { + String clientLocale = ess.getPlayerLocaleProvider().getLocale(getBase()); + if (clientLocale != null) { + return I18n.getLocale(clientLocale); + } + } + return ess.getI18n().getCurrentLocale(); + } + return locale; + } + public String getConfirmingClearCommand() { return confirmingClearCommand; } diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java index b1bc072c88a..e735850aa15 100644 --- a/Essentials/src/com/earth2me/essentials/UserData.java +++ b/Essentials/src/com/earth2me/essentials/UserData.java @@ -95,6 +95,7 @@ public final void reloadConfig() { confirmPay = _getConfirmPay(); confirmClear = _getConfirmClear(); lastMessageReplyRecipient = _getLastMessageReplyRecipient(); + locale = _getLocale(); } private BigDecimal money; @@ -210,7 +211,7 @@ public void delHome(String name) throws Exception { config.removeProperty("homes." + search); config.save(); } else { - throw new Exception(tl("invalidHome", search)); + throw new Exception(((User) this).tl("invalidHome", search)); } } @@ -999,6 +1000,22 @@ public void setLastMessageReplyRecipient(boolean enabled) { save(); } + private Locale locale = null; + + private Locale _getLocale() { + return I18n.getLocale(config.getString("locale", null)); + } + + public Locale getLocale() { + return locale; + } + + public void setLocale(Locale locale) { + this.locale = locale; + config.setProperty("locale", locale != null ? locale.toString() : null); + save(); + } + public UUID getConfigUUID() { return config.uuid; } diff --git a/Essentials/src/com/earth2me/essentials/Warps.java b/Essentials/src/com/earth2me/essentials/Warps.java index f66fce9d598..2d92a19c23e 100644 --- a/Essentials/src/com/earth2me/essentials/Warps.java +++ b/Essentials/src/com/earth2me/essentials/Warps.java @@ -4,6 +4,7 @@ import com.earth2me.essentials.utils.StringUtil; import net.ess3.api.InvalidNameException; import net.ess3.api.InvalidWorldException; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Server; import java.io.File; @@ -65,7 +66,7 @@ public void setWarp(IUser user, String name, Location loc) throws Exception { if (conf == null) { File confFile = new File(warpsFolder, filename + ".yml"); if (confFile.exists()) { - throw new Exception(tl("similarWarpExist")); + throw new Exception(user.tl("similarWarpExist")); } conf = new EssentialsConf(confFile); warpPoints.put(new StringIgnoreCase(name), conf); @@ -76,7 +77,7 @@ public void setWarp(IUser user, String name, Location loc) throws Exception { try { conf.saveWithError(); } catch (IOException ex) { - throw new IOException(tl("invalidWarpName")); + throw new IOException(user.tl("invalidWarpName")); } } @@ -96,12 +97,17 @@ public UUID getLastOwner(String warp) throws WarpNotFoundException { @Override public void removeWarp(String name) throws Exception { + removeWarp(new CommandSource(Bukkit.getConsoleSender()), name); + } + + @Override + public void removeWarp(CommandSource sender, String name) throws Exception { EssentialsConf conf = warpPoints.get(new StringIgnoreCase(name)); if (conf == null) { - throw new Exception(tl("warpNotExist")); + throw new Exception(sender.tl("warpNotExist")); } if (!conf.getFile().delete()) { - throw new Exception(tl("warpDeleteError")); + throw new Exception(sender.tl("warpDeleteError")); } warpPoints.remove(new StringIgnoreCase(name)); } diff --git a/Essentials/src/com/earth2me/essentials/Worth.java b/Essentials/src/com/earth2me/essentials/Worth.java index 804797dd393..f3664000446 100644 --- a/Essentials/src/com/earth2me/essentials/Worth.java +++ b/Essentials/src/com/earth2me/essentials/Worth.java @@ -75,7 +75,7 @@ public BigDecimal getPrice(IEssentials ess, ItemStack itemStack) { */ public int getAmount(IEssentials ess, User user, ItemStack is, String[] args, boolean isBulkSell) throws Exception { if (is == null || is.getType() == Material.AIR) { - throw new Exception(tl("itemSellAir")); + throw new Exception(user.tl("itemSellAir")); } int amount = 0; @@ -95,7 +95,7 @@ public int getAmount(IEssentials ess, User user, ItemStack is, String[] args, bo boolean requireStack = ess.getSettings().isTradeInStacks(is.getType()); if (requireStack && !stack) { - throw new Exception(tl("itemMustBeStacked")); + throw new Exception(user.tl("itemMustBeStacked")); } int max = 0; @@ -118,9 +118,9 @@ public int getAmount(IEssentials ess, User user, ItemStack is, String[] args, bo } if (amount > max || amount < 1) { if (!isBulkSell) { - user.sendMessage(tl("itemNotEnough2")); - user.sendMessage(tl("itemNotEnough3")); - throw new Exception(tl("itemNotEnough1")); + user.sendTl("itemNotEnough2"); + user.sendTl("itemNotEnough3"); + throw new Exception(user.tl("itemNotEnough1")); } else { return amount; } diff --git a/Essentials/src/com/earth2me/essentials/api/II18n.java b/Essentials/src/com/earth2me/essentials/api/II18n.java index 4adb9a95835..84a255b7786 100644 --- a/Essentials/src/com/earth2me/essentials/api/II18n.java +++ b/Essentials/src/com/earth2me/essentials/api/II18n.java @@ -5,7 +5,7 @@ public interface II18n { /** - * Gets the current locale setting + * Gets the current default locale setting * * @return the current locale, if not set it will return the default locale */ diff --git a/Essentials/src/com/earth2me/essentials/api/IWarps.java b/Essentials/src/com/earth2me/essentials/api/IWarps.java index 3a5dcb7f1a2..32a2d1aca0f 100644 --- a/Essentials/src/com/earth2me/essentials/api/IWarps.java +++ b/Essentials/src/com/earth2me/essentials/api/IWarps.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.api; +import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.IConf; import com.earth2me.essentials.IUser; import com.earth2me.essentials.commands.WarpNotFoundException; @@ -43,9 +44,21 @@ public interface IWarps extends IConf { * @param name - Name of warp * * @throws Exception + * @deprecated Use {@link #removeWarp(CommandSource, String)} */ + @Deprecated void removeWarp(String name) throws Exception; + /** + * Delete a warp from the warp DB + * + * @param sender - The one who wants to remove the warp + * @param name - Name of warp + * + * @throws Exception + */ + void removeWarp(CommandSource sender, String name) throws Exception; + /** * Set a warp * diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandafk.java b/Essentials/src/com/earth2me/essentials/commands/Commandafk.java index 09f56bba765..401ab9d558f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandafk.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandafk.java @@ -7,8 +7,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandafk extends EssentialsCommand { public Commandafk() { @@ -51,10 +49,10 @@ public void run(Server server, CommandSource sender, String commandLabel, String private void toggleAfk(User sender, User user, String message) throws Exception { if (message != null && sender != null) { if (sender.isMuted()) { - throw new Exception(sender.hasMuteReason() ? tl("voiceSilencedReason", sender.getMuteReason()) : tl("voiceSilenced")); + throw new Exception(sender.hasMuteReason() ? sender.tl("voiceSilencedReason", sender.getMuteReason()) : sender.tl("voiceSilenced")); } if (!sender.isAuthorized("essentials.afk.message")) { - throw new Exception(tl("noPermToAFKMessage")); + throw new Exception(sender.tl("noPermToAFKMessage")); } } user.setDisplayNick(); @@ -62,22 +60,22 @@ private void toggleAfk(User sender, User user, String message) throws Exception if (!user.toggleAfk()) { //user.sendMessage(_("markedAsNotAway")); if (!user.isHidden()) { - msg = tl("userIsNotAway", user.getDisplayName()); + msg = "userIsNotAway"; } user.updateActivity(false); } else { //user.sendMessage(_("markedAsAway")); if (!user.isHidden()) { if (message != null) { - msg = tl("userIsAwayWithMessage", user.getDisplayName(), message); + msg = "userIsAwayWithMessage"; } else { - msg = tl("userIsAway", user.getDisplayName()); + msg = "userIsAway"; } } user.setAfkMessage(message); } if (!msg.isEmpty()) { - ess.broadcastMessage(user, msg); + ess.broadcastTl(user, msg, user.getDisplayName(), message); } user.setDisplayNick(); // Set this again after toggling } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandback.java b/Essentials/src/com/earth2me/essentials/commands/Commandback.java index e8171359bba..30761247163 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandback.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandback.java @@ -11,8 +11,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandback extends EssentialsCommand { public Commandback() { @@ -51,14 +49,14 @@ private void parseCommand(Server server, CommandSource sender, String[] args, bo } for (Player player : players) { - sender.sendMessage(tl("backOther", player.getName())); + sender.sendTl("backOther", player.getName()); teleportBack(sender, ess.getUser(player)); } } private void teleportBack(CommandSource sender, User user) throws Exception { if (user.getLastLocation() == null) { - throw new Exception(tl("noLocationFound")); + throw new Exception(sender.tl("noLocationFound")); } String lastWorldName = user.getLastLocation().getWorld().getName(); @@ -68,11 +66,11 @@ private void teleportBack(CommandSource sender, User user) throws Exception { requester = ess.getUser(sender.getPlayer()); if (user.getWorld() != user.getLastLocation().getWorld() && this.ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + lastWorldName)) { - throw new Exception(tl("noPerm", "essentials.worlds." + lastWorldName)); + throw new Exception(sender.tl("noPerm", "essentials.worlds." + lastWorldName)); } if (!requester.isAuthorized("essentials.back.into." + lastWorldName)) { - throw new Exception(tl("noPerm", "essentials.back.into." + lastWorldName)); + throw new Exception(sender.tl("noPerm", "essentials.back.into." + lastWorldName)); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java b/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java index 801794625fd..e3281151548 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java @@ -4,8 +4,6 @@ import com.earth2me.essentials.CommandSource; import org.bukkit.Server; -import static com.earth2me.essentials.I18n.tl; - public class Commandbackup extends EssentialsCommand { public Commandbackup() { @@ -16,13 +14,13 @@ public Commandbackup() { protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { final Backup backup = ess.getBackup(); if (backup == null) { - throw new Exception(tl("backupDisabled")); + throw new Exception(sender.tl("backupDisabled")); } final String command = ess.getSettings().getBackupCommand(); if (command == null || "".equals(command) || "save-all".equalsIgnoreCase(command)) { - throw new Exception(tl("backupDisabled")); + throw new Exception(sender.tl("backupDisabled")); } backup.run(); - sender.sendMessage(tl("backupStarted")); + sender.sendTl("backupStarted"); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java b/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java index cc3fafc97c1..7548fa41633 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java @@ -9,8 +9,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandbalance extends EssentialsCommand { public Commandbalance() { @@ -24,7 +22,7 @@ protected void run(final Server server, final CommandSource sender, final String } User target = getPlayer(server, args, 0, true, true); - sender.sendMessage(tl("balanceOther", target.isHidden() ? target.getName() : target.getDisplayName(), NumberUtil.displayCurrency(target.getMoney(), ess))); + sender.sendTl("balanceOther", target.isHidden() ? target.getName() : target.getDisplayName(), NumberUtil.displayCurrency(target.getMoney(), ess)); } @Override @@ -32,10 +30,10 @@ public void run(final Server server, final User user, final String commandLabel, if (args.length == 1 && user.isAuthorized("essentials.balance.others")) { final User target = getPlayer(server, args, 0, true, true); final BigDecimal bal = target.getMoney(); - user.sendMessage(tl("balanceOther", target.isHidden() ? target.getName() : target.getDisplayName(), NumberUtil.displayCurrency(bal, ess))); + user.sendTl("balanceOther", target.isHidden() ? target.getName() : target.getDisplayName(), NumberUtil.displayCurrency(bal, ess)); } else if (args.length < 2) { final BigDecimal bal = user.getMoney(); - user.sendMessage(tl("balance", NumberUtil.displayCurrency(bal, ess))); + user.sendTl("balance", NumberUtil.displayCurrency(bal, ess)); } else { throw new NotEnoughArgumentsException(); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java index b21d4408cf3..970b7888d2f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java @@ -49,7 +49,7 @@ protected void run(final Server server, final CommandSource sender, final String return; } if (ess.getUserMap().getUniqueUsers() > MINUSERS) { - sender.sendMessage(tl("orderBalances", ess.getUserMap().getUniqueUsers())); + sender.sendTl("orderBalances", ess.getUserMap().getUniqueUsers()); } } finally { lock.readLock().unlock(); @@ -57,7 +57,7 @@ protected void run(final Server server, final CommandSource sender, final String ess.runTaskAsynchronously(new Viewer(sender, commandLabel, page, force)); } else { if (ess.getUserMap().getUniqueUsers() > MINUSERS) { - sender.sendMessage(tl("orderBalances", ess.getUserMap().getUniqueUsers())); + sender.sendTl("orderBalances", ess.getUserMap().getUniqueUsers()); } ess.runTaskAsynchronously(new Viewer(sender, commandLabel, page, force)); } @@ -68,7 +68,7 @@ private static void outputCache(final CommandSource sender, String command, int final Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(cacheage); final DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); - sender.sendMessage(tl("balanceTop", format.format(cal.getTime()))); + sender.sendTl("balanceTop", format.format(cal.getTime())); new TextPager(cache).showPage(Integer.toString(page), null, "balancetop", sender); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandban.java b/Essentials/src/com/earth2me/essentials/commands/Commandban.java index e7ff69964db..20c848d1a1d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandban.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandban.java @@ -35,11 +35,11 @@ public void run(final Server server, final CommandSource sender, final String co } if (!user.getBase().isOnline()) { if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.ban.offline")) { - throw new Exception(tl("banExemptOffline")); + throw new Exception(user.tl("banExemptOffline")); } } else { if (user.isAuthorized("essentials.ban.exempt") && sender.isPlayer()) { - throw new Exception(tl("banExempt")); + throw new Exception(user.tl("banExempt")); } } @@ -48,21 +48,21 @@ public void run(final Server server, final CommandSource sender, final String co if (args.length > 1) { banReason = FormatUtil.replaceFormat(getFinalArg(args, 1).replace("\\n", "\n").replace("|", "\n")); } else { - banReason = tl("defaultBanReason"); + banReason = user.tl("defaultBanReason"); } ess.getServer().getBanList(BanList.Type.NAME).addBan(user.getName(), banReason, null, senderName); - String banDisplay = tl("banFormat", banReason, senderName); + String banDisplay = user.tl("banFormat", banReason, senderName); user.getBase().kickPlayer(banDisplay); server.getLogger().log(Level.INFO, tl("playerBanned", senderName, user.getName(), banDisplay)); if (nomatch) { - sender.sendMessage(tl("userUnknown", user.getName())); + sender.sendTl("userUnknown", user.getName()); } - ess.broadcastMessage("essentials.ban.notify", tl("playerBanned", senderName, user.getName(), banReason)); + ess.broadcastTl("essentials.ban.notify", "playerBanned", senderName, user.getName(), banReason); } @Override diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java b/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java index 1ba6bb56ee6..ca46faf2998 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java @@ -48,21 +48,20 @@ public void run(final Server server, final CommandSource sender, final String co if (args.length > 1) { banReason = FormatUtil.replaceFormat(getFinalArg(args, 1).replace("\\n", "\n").replace("|", "\n")); } else { - banReason = tl("defaultBanReason"); + banReason = sender.tl("defaultBanReason"); } - String banDisplay = tl("banFormat", banReason, senderName); - ess.getServer().getBanList(BanList.Type.IP).addBan(ipAddress, banReason, null, senderName); server.getLogger().log(Level.INFO, tl("playerBanIpAddress", senderName, ipAddress, banReason)); for (Player player : ess.getServer().getOnlinePlayers()) { if (player.getAddress().getAddress().getHostAddress().equalsIgnoreCase(ipAddress)) { - player.kickPlayer(banDisplay); + final User buser = ess.getUser(player); + player.kickPlayer(buser.tl("banFormat", banReason, senderName)); } } - ess.broadcastMessage("essentials.banip.notify", tl("playerBanIpAddress", senderName, ipAddress, banReason)); + ess.broadcastTl("essentials.banip.notify", "playerBanIpAddress", senderName, ipAddress, banReason); } @Override diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java b/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java index 19b217ba541..852fbecdffb 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java @@ -10,8 +10,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandbigtree extends EssentialsCommand { public Commandbigtree() { @@ -37,9 +35,9 @@ public void run(final Server server, final User user, final String commandLabel, final Location safeLocation = LocationUtil.getSafeDestination(loc); final boolean success = user.getWorld().generateTree(safeLocation, tree); if (success) { - user.sendMessage(tl("bigTreeSuccess")); + user.sendTl("bigTreeSuccess"); } else { - throw new Exception(tl("bigTreeFailure")); + throw new Exception(user.tl("bigTreeFailure")); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbook.java b/Essentials/src/com/earth2me/essentials/commands/Commandbook.java index ea2934716b5..9884c119784 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbook.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbook.java @@ -12,8 +12,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandbook extends EssentialsCommand { @@ -34,26 +32,26 @@ public void run(final Server server, final User user, final String commandLabel, if (user.isAuthorized("essentials.book.author") && (isAuthor(bmeta, player) || user.isAuthorized("essentials.book.others"))) { bmeta.setAuthor(args[1]); item.setItemMeta(bmeta); - user.sendMessage(tl("bookAuthorSet", getFinalArg(args, 1))); + user.sendTl("bookAuthorSet", getFinalArg(args, 1)); } else { - throw new Exception(tl("denyChangeAuthor")); + throw new Exception(user.tl("denyChangeAuthor")); } } else if (args.length > 1 && args[0].equalsIgnoreCase("title")) { if (user.isAuthorized("essentials.book.title") && (isAuthor(bmeta, player) || user.isAuthorized("essentials.book.others"))) { bmeta.setTitle(args[1]); item.setItemMeta(bmeta); - user.sendMessage(tl("bookTitleSet", getFinalArg(args, 1))); + user.sendTl("bookTitleSet", getFinalArg(args, 1)); } else { - throw new Exception(tl("denyChangeTitle")); + throw new Exception(user.tl("denyChangeTitle")); } } else { if (isAuthor(bmeta, player) || user.isAuthorized("essentials.book.others")) { ItemStack newItem = new ItemStack(WRITABLE_BOOK, item.getAmount()); newItem.setItemMeta(bmeta); InventoryWorkaround.setItemInMainHand(user.getBase(), newItem); - user.sendMessage(tl("editBookContents")); + user.sendTl("editBookContents"); } else { - throw new Exception(tl("denyBookEdit")); + throw new Exception(user.tl("denyBookEdit")); } } } else if (item.getType() == WRITABLE_BOOK) { @@ -64,9 +62,9 @@ public void run(final Server server, final User user, final String commandLabel, ItemStack newItem = new ItemStack(Material.WRITTEN_BOOK, item.getAmount()); newItem.setItemMeta(bmeta); InventoryWorkaround.setItemInMainHand(user.getBase(), newItem); - user.sendMessage(tl("bookLocked")); + user.sendTl("bookLocked"); } else { - throw new Exception(tl("holdBook")); + throw new Exception(user.tl("holdBook")); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbreak.java b/Essentials/src/com/earth2me/essentials/commands/Commandbreak.java index 118a614a1ab..a5df15dc8c6 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbreak.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbreak.java @@ -8,8 +8,6 @@ import java.util.Set; -import static com.earth2me.essentials.I18n.tl; - public class Commandbreak extends EssentialsCommand { public Commandbreak() { @@ -27,7 +25,7 @@ public void run(final Server server, final User user, final String commandLabel, throw new NoChargeException(); } if (block.getType() == Material.BEDROCK && !user.isAuthorized("essentials.break.bedrock")) { - throw new Exception(tl("noBreakBedrock")); + throw new Exception(user.tl("noBreakBedrock")); } //final List list = (List)block.getDrops(); //final BlockBreakEvent event = new BlockBreakEvent(block, user.getBase(), list); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java b/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java index dfd165f59b1..88061d1f1e9 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java @@ -15,19 +15,19 @@ public Commandbroadcast() { @Override public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - sendBroadcast(user.getDisplayName(), args); + sendBroadcast(user.getSource(), user.getDisplayName(), args); } @Override public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { - sendBroadcast(sender.getSender().getName(), args); + sendBroadcast(sender, sender.getSender().getName(), args); } - private void sendBroadcast(final String name, final String[] args) throws NotEnoughArgumentsException { + private void sendBroadcast(final CommandSource sender, final String name, final String[] args) throws NotEnoughArgumentsException { if (args.length < 1) { throw new NotEnoughArgumentsException(); } - ess.broadcastMessage(tl("broadcast", FormatUtil.replaceFormat(getFinalArg(args, 0)).replace("\\n", "\n"), name)); + ess.broadcastTl(sender, "broadcast", FormatUtil.replaceFormat(getFinalArg(args, 0)).replace("\\n", "\n"), name); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbroadcastworld.java b/Essentials/src/com/earth2me/essentials/commands/Commandbroadcastworld.java index 109f4efe1bb..e77341af392 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbroadcastworld.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbroadcastworld.java @@ -45,7 +45,7 @@ public void run(final Server server, final User user, final String commandLabel, message = getFinalArg(args, 0); } - sendBroadcast(world.getName(), user.getDisplayName(), message); + sendBroadcast(user.getSource(), world.getName(), user.getDisplayName(), message); } @Override @@ -53,27 +53,27 @@ public void run(final Server server, final CommandSource sender, final String co if (args.length < 2) { throw new NotEnoughArgumentsException("world"); } - sendBroadcast(args[0], sender.getSender().getName(), getFinalArg(args, 1)); + sendBroadcast(sender, args[0], sender.getSender().getName(), getFinalArg(args, 1)); } - private void sendBroadcast(final String worldName, final String name, final String message) throws Exception { + private void sendBroadcast(final CommandSource sender, final String worldName, final String name, final String message) throws Exception { World world = ess.getWorld(worldName); if (world == null) { - throw new Exception(tl("invalidWorld")); + throw new Exception(sender.tl("invalidWorld")); } if (message.isEmpty()) { throw new NotEnoughArgumentsException(); } - sendToWorld(world, tl("broadcast", FormatUtil.replaceFormat(message).replace("\\n", "\n"), name)); + sendToWorld(world, "broadcast", FormatUtil.replaceFormat(message).replace("\\n", "\n"), name); } - private void sendToWorld(World world, String message) { - IText broadcast = new SimpleTextInput(message); + private void sendToWorld(World world, String string, Object... objects) { final Collection players = ess.getOnlinePlayers(); for (Player player : players) { if (player.getWorld().equals(world)) { final User user = ess.getUser(player); + IText broadcast = new SimpleTextInput(user.tl(string, objects)); broadcast = new KeywordReplacer(broadcast, new CommandSource(player), ess, false); for (String messageText : broadcast.getLines()) { user.sendMessage(messageText); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandburn.java b/Essentials/src/com/earth2me/essentials/commands/Commandburn.java index b9d2b4484c3..52905c57977 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandburn.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandburn.java @@ -7,8 +7,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandburn extends EssentialsCommand { public Commandburn() { @@ -27,7 +25,7 @@ protected void run(final Server server, final CommandSource sender, final String User user = getPlayer(server, sender, args, 0); user.getBase().setFireTicks(Integer.parseInt(args[1]) * 20); - sender.sendMessage(tl("burnMsg", user.getDisplayName(), Integer.parseInt(args[1]))); + sender.sendTl("burnMsg", user.getDisplayName(), Integer.parseInt(args[1])); } @Override diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java index 338d780c419..34c401623cf 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java @@ -1,7 +1,5 @@ package com.earth2me.essentials.commands; -import static com.earth2me.essentials.I18n.tl; - import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.User; import com.earth2me.essentials.craftbukkit.InventoryWorkaround; @@ -52,7 +50,7 @@ private void parseCommand(Server server, CommandSource sender, String commandLab } if (allowAll && args.length > 0 && args[0].contentEquals("*")) { - sender.sendMessage(tl("inventoryClearingFromAll")); + sender.sendTl("inventoryClearingFromAll"); offset = 1; players = ess.getOnlinePlayers(); } else if (allowOthers && args.length > 0 && args[0].trim().length() > 2) { @@ -70,7 +68,7 @@ private void parseCommand(Server server, CommandSource sender, String commandLab if (senderUser != null && senderUser.isPromptingClearConfirm()) { if (!formattedCommand.equals(previousClearCommand)) { senderUser.setConfirmingClearCommand(formattedCommand); - senderUser.sendMessage(tl("confirmClear", formattedCommand)); + senderUser.sendTl("confirmClear", formattedCommand); return; } } @@ -108,14 +106,14 @@ protected void clearHandler(CommandSource sender, Player player, String[] args, if (type == -1) // type -1 represents wildcard or all items { if (showExtended) { - sender.sendMessage(tl("inventoryClearingAllItems", player.getDisplayName())); + sender.sendTl("inventoryClearingAllItems", player.getDisplayName()); } InventoryWorkaround.clearInventoryNoArmor(player.getInventory()); InventoryWorkaround.setItemInOffHand(player, null); } else if (type == -2) // type -2 represents double wildcard or all items and armor { if (showExtended) { - sender.sendMessage(tl("inventoryClearingAllArmor", player.getDisplayName())); + sender.sendTl("inventoryClearingAllArmor", player.getDisplayName()); } InventoryWorkaround.clearInventoryNoArmor(player.getInventory()); InventoryWorkaround.setItemInOffHand(player, null); @@ -128,7 +126,7 @@ protected void clearHandler(CommandSource sender, Player player, String[] args, ItemStack removedStack = player.getInventory().removeItem(stack).get(0); final int removedAmount = (BASE_AMOUNT - removedStack.getAmount()); if (removedAmount > 0 || showExtended) { - sender.sendMessage(tl("inventoryClearingStack", removedAmount, stack.getType().toString().toLowerCase(Locale.ENGLISH), player.getDisplayName())); + sender.sendTl("inventoryClearingStack", removedAmount, stack.getType().toString().toLowerCase(Locale.ENGLISH), player.getDisplayName()); } } else { if (amount < 0) { @@ -136,11 +134,11 @@ protected void clearHandler(CommandSource sender, Player player, String[] args, } ItemStack stack = new ItemStack(mat, amount); if (player.getInventory().containsAtLeast(stack, amount)) { - sender.sendMessage(tl("inventoryClearingStack", amount, stack.getType().toString().toLowerCase(Locale.ENGLISH), player.getDisplayName())); + sender.sendTl("inventoryClearingStack", amount, stack.getType().toString().toLowerCase(Locale.ENGLISH), player.getDisplayName()); player.getInventory().removeItem(stack); } else { if (showExtended) { - sender.sendMessage(tl("inventoryClearFail", player.getDisplayName(), amount, stack.getType().toString().toLowerCase(Locale.ENGLISH))); + sender.sendTl("inventoryClearFail", player.getDisplayName(), amount, stack.getType().toString().toLowerCase(Locale.ENGLISH)); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventoryconfirmtoggle.java b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventoryconfirmtoggle.java index e7b3e90721d..09eb2785a86 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventoryconfirmtoggle.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventoryconfirmtoggle.java @@ -1,7 +1,5 @@ package com.earth2me.essentials.commands; -import static com.earth2me.essentials.I18n.tl; - import com.earth2me.essentials.User; import org.bukkit.Server; @@ -22,9 +20,9 @@ public void run(Server server, User user, String commandLabel, String[] args) th } user.setPromptingClearConfirm(confirmingClear); if (confirmingClear) { - user.sendMessage(tl("clearInventoryConfirmToggleOn")); + user.sendTl("clearInventoryConfirmToggleOn"); } else { - user.sendMessage(tl("clearInventoryConfirmToggleOff")); + user.sendTl("clearInventoryConfirmToggleOff"); } user.setConfirmingClearCommand(null); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandcompass.java b/Essentials/src/com/earth2me/essentials/commands/Commandcompass.java index 65525d18ad7..087f5434a35 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandcompass.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandcompass.java @@ -3,8 +3,6 @@ import com.earth2me.essentials.User; import org.bukkit.Server; -import static com.earth2me.essentials.I18n.tl; - public class Commandcompass extends EssentialsCommand { public Commandcompass() { @@ -16,24 +14,24 @@ public void run(final Server server, final User user, final String commandLabel, final int bearing = (int) (user.getLocation().getYaw() + 180 + 360) % 360; String dir; if (bearing < 23) { - dir = tl("north"); + dir = user.tl("north"); } else if (bearing < 68) { - dir = tl("northEast"); + dir = user.tl("northEast"); } else if (bearing < 113) { - dir = tl("east"); + dir = user.tl("east"); } else if (bearing < 158) { - dir = tl("southEast"); + dir = user.tl("southEast"); } else if (bearing < 203) { - dir = tl("south"); + dir = user.tl("south"); } else if (bearing < 248) { - dir = tl("southWest"); + dir = user.tl("southWest"); } else if (bearing < 293) { - dir = tl("west"); + dir = user.tl("west"); } else if (bearing < 338) { - dir = tl("northWest"); + dir = user.tl("northWest"); } else { - dir = tl("north"); + dir = user.tl("north"); } - user.sendMessage(tl("compassBearing", dir, bearing)); + user.sendTl("compassBearing", dir, bearing); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandcondense.java b/Essentials/src/com/earth2me/essentials/commands/Commandcondense.java index f5c4905fe4f..f80c3146eaf 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandcondense.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandcondense.java @@ -14,8 +14,6 @@ import java.util.*; -import static com.earth2me.essentials.I18n.tl; - public class Commandcondense extends EssentialsCommand { public Commandcondense() { @@ -50,9 +48,9 @@ public void run(final Server server, final User user, final String commandLabel, user.getBase().updateInventory(); if (didConvert) { - user.sendMessage(tl("itemsConverted")); + user.sendTl("itemsConverted"); } else { - user.sendMessage(tl("itemsNotConverted")); + user.sendTl("itemsNotConverted"); throw new NoChargeException(); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandcreatekit.java b/Essentials/src/com/earth2me/essentials/commands/Commandcreatekit.java index 5d6459087ce..231295f8d9d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandcreatekit.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandcreatekit.java @@ -30,8 +30,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import static com.earth2me.essentials.I18n.tl; - public class Commandcreatekit extends EssentialsCommand { private static final String PASTE_URL = "https://hastebin.com/"; @@ -70,7 +68,7 @@ public void run(final Server server, final User user, final String commandLabel, // Some users might want to directly write to config knowing the consequences. *shrug* if (!ess.getSettings().isPastebinCreateKit()) { ess.getKits().addKit(kitname, list, delay); - user.sendMessage(tl("createdKit", kitname, list.size(), delay)); + user.sendTl("createdKit", kitname, list.size(), delay); } else { ConfigurationSection config = new MemoryConfiguration(); config.set("kits." + kitname + ".delay", delay); @@ -99,7 +97,7 @@ public void run() { } // Error if (connection.getResponseCode() >= 400) { - sender.sendMessage(tl("createKitFailed", kitName)); + sender.sendTl("createKitFailed", kitName); String message = CharStreams.toString(new InputStreamReader(connection.getErrorStream(), Charsets.UTF_8)); ess.getLogger().severe("Error creating kit: " + message); return; @@ -110,19 +108,19 @@ public void run() { String pasteUrl = PASTE_URL + object.get("key").getAsString(); connection.disconnect(); - String separator = tl("createKitSeparator"); + String separator = sender.tl("createKitSeparator"); String delayFormat = "0"; if (delay > 0) { - delayFormat = DateUtil.formatDateDiff(System.currentTimeMillis() + (delay * 1000)); + delayFormat = DateUtil.formatDateDiff(sender, System.currentTimeMillis() + (delay * 1000)); } sender.sendMessage(separator); - sender.sendMessage(tl("createKitSuccess", kitName, delayFormat, pasteUrl)); + sender.sendTl("createKitSuccess", kitName, delayFormat, pasteUrl); sender.sendMessage(separator); if (ess.getSettings().isDebug()) { ess.getLogger().info(sender.getSender().getName() + " created a kit: " + pasteUrl); } } catch (Exception e) { - sender.sendMessage(tl("createKitFailed", kitName)); + sender.sendTl("createKitFailed", kitName); e.printStackTrace(); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java b/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java index 5aee512439f..112a48233bc 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java @@ -4,12 +4,10 @@ import com.earth2me.essentials.User; import org.bukkit.Server; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Locale; -import static com.earth2me.essentials.I18n.tl; public class Commanddelhome extends EssentialsCommand { @@ -45,11 +43,11 @@ public void run(final Server server, final CommandSource sender, final String co } if (name.equalsIgnoreCase("bed")) { - throw new Exception(tl("invalidHomeName")); + throw new Exception(user.tl("invalidHomeName")); } user.delHome(name.toLowerCase(Locale.ENGLISH)); - sender.sendMessage(tl("deleteHome", name)); + sender.sendTl("deleteHome", name); } @Override diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanddeljail.java b/Essentials/src/com/earth2me/essentials/commands/Commanddeljail.java index 01643e81db3..7ff7a5c2f10 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanddeljail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanddeljail.java @@ -5,7 +5,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; public class Commanddeljail extends EssentialsCommand { @@ -20,11 +19,11 @@ protected void run(final Server server, final CommandSource sender, final String } if (ess.getJails().getJail(args[0]) == null) { - throw new Exception(tl("jailNotExist")); + throw new Exception(sender.tl("jailNotExist")); } ess.getJails().removeJail(args[0]); - sender.sendMessage(tl("deleteJail", args[0])); + sender.sendTl("deleteJail", args[0]); } @Override diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java index 0ea9669fdf4..1d8ae74c939 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java @@ -7,8 +7,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commanddelwarp extends EssentialsCommand { public Commanddelwarp() { @@ -21,8 +19,8 @@ public void run(final Server server, final CommandSource sender, final String co throw new NotEnoughArgumentsException(); } - ess.getWarps().removeWarp(args[0]); - sender.sendMessage(tl("deleteWarp", args[0])); + ess.getWarps().removeWarp(sender, args[0]); + sender.sendTl("deleteWarp", args[0]); } @Override diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanddepth.java b/Essentials/src/com/earth2me/essentials/commands/Commanddepth.java index 34aa53526c3..61a0723429b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanddepth.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanddepth.java @@ -3,8 +3,6 @@ import com.earth2me.essentials.User; import org.bukkit.Server; -import static com.earth2me.essentials.I18n.tl; - public class Commanddepth extends EssentialsCommand { public Commanddepth() { @@ -15,11 +13,11 @@ public Commanddepth() { public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { final int depth = user.getLocation().getBlockY() - 63; if (depth > 0) { - user.sendMessage(tl("depthAboveSea", depth)); + user.sendTl("depthAboveSea", depth); } else if (depth < 0) { - user.sendMessage(tl("depthBelowSea", (-depth))); + user.sendTl("depthBelowSea", (-depth)); } else { - user.sendMessage(tl("depth")); + user.sendTl("depth"); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanddisposal.java b/Essentials/src/com/earth2me/essentials/commands/Commanddisposal.java index f4751e0440a..71e6e0dff0c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanddisposal.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanddisposal.java @@ -3,8 +3,6 @@ import com.earth2me.essentials.User; import org.bukkit.Server; -import static com.earth2me.essentials.I18n.tl; - public class Commanddisposal extends EssentialsCommand { public Commanddisposal() { @@ -13,7 +11,7 @@ public Commanddisposal() { @Override protected void run(Server server, User user, String commandLabel, String[] args) throws Exception { - user.sendMessage(tl("openingDisposal")); + user.sendTl("openingDisposal"); user.getBase().openInventory(ess.getServer().createInventory(user.getBase(), 36, "Disposal")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandeco.java b/Essentials/src/com/earth2me/essentials/commands/Commandeco.java index ef8c1eaee37..a3424db5c1b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandeco.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandeco.java @@ -43,9 +43,9 @@ public void run(final Server server, final CommandSource sender, final String co if (cmd == Commandeco.EcoCommands.RESET || cmd == Commandeco.EcoCommands.SET) { if (args[1].contentEquals("**")) { - server.broadcastMessage(tl("resetBalAll", NumberUtil.displayCurrency(amount, ess))); + ess.broadcastTl("resetBalAll", NumberUtil.displayCurrency(amount, ess)); } else if (args[1].contentEquals("*")) { - server.broadcastMessage(tl("resetBal", NumberUtil.displayCurrency(amount, ess))); + ess.broadcastTl("resetBal", NumberUtil.displayCurrency(amount, ess)); } } } @@ -79,9 +79,9 @@ private void take(BigDecimal amount, final User player, final CommandSource send } catch (MaxMoneyException ex) { // Take shouldn't be able to throw a max money exception } - player.sendMessage(tl("takenFromAccount", NumberUtil.displayCurrency(player.getMoney(), ess))); + player.sendTl("takenFromAccount", NumberUtil.displayCurrency(player.getMoney(), ess)); } else { - throw new ChargeException(tl("insufficientFunds")); + throw new ChargeException(player.tl("insufficientFunds")); } } @@ -91,9 +91,9 @@ private void set(BigDecimal amount, final User player, final CommandSource sende boolean underMinimum = (amount.compareTo(minBalance) < 0); boolean aboveMax = (amount.compareTo(maxBalance) > 0); player.setMoney(underMinimum ? minBalance : aboveMax ? maxBalance : amount); - player.sendMessage(tl("setBal", NumberUtil.displayCurrency(player.getMoney(), ess))); + player.sendTl("setBal", NumberUtil.displayCurrency(player.getMoney(), ess)); if (sender != null) { - sender.sendMessage(tl("setBalOthers", player.getDisplayName(), NumberUtil.displayCurrency(player.getMoney(), ess))); + sender.sendTl("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 b3945e400ef..58fdcc5d608 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandenchant.java @@ -19,8 +19,6 @@ import java.util.Set; import java.util.TreeSet; -import static com.earth2me.essentials.I18n.tl; - public class Commandenchant extends EssentialsCommand { public Commandenchant() { @@ -32,7 +30,7 @@ public Commandenchant() { protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { final ItemStack stack = user.getItemInHand(); if (stack == null || stack.getType() == Material.AIR) { - throw new Exception(tl("nothingInHand")); + throw new Exception(user.tl("nothingInHand")); } if (args.length == 0) { final Set enchantmentslist = new TreeSet<>(); @@ -43,7 +41,7 @@ protected void run(final Server server, final User user, final String commandLab //enchantmentslist.add(enchantmentName); } } - throw new NotEnoughArgumentsException(tl("enchantments", StringUtil.joinList(enchantmentslist.toArray()))); + throw new NotEnoughArgumentsException(user.tl("enchantments", StringUtil.joinList(enchantmentslist.toArray()))); } int level = 1; @@ -65,9 +63,9 @@ protected void run(final Server server, final User user, final String commandLab user.getBase().updateInventory(); final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH); if (level == 0) { - user.sendMessage(tl("enchantmentRemoved", enchantmentName.replace('_', ' '))); + user.sendTl("enchantmentRemoved", enchantmentName.replace('_', ' ')); } else { - user.sendMessage(tl("enchantmentApplied", enchantmentName.replace('_', ' '))); + user.sendTl("enchantmentApplied", enchantmentName.replace('_', ' ')); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java index 329a31abae7..53d51e77054 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java @@ -18,8 +18,6 @@ import java.util.*; -import static com.earth2me.essentials.I18n.tl; - // This command has 4 undocumented behaviours #EasterEgg public class Commandessentials extends EssentialsCommand { @@ -90,7 +88,7 @@ private void run_disabled(final Server server, final CommandSource sender, final disabledCommands.append(entry.getKey()).append(" => ").append(entry.getValue()); } if (disabledCommands.length() > 0) { - sender.sendMessage(tl("blockList")); + sender.sendTl("blockList"); sender.sendMessage(disabledCommands.toString()); } } @@ -111,7 +109,7 @@ private void run_debug(final Server server, final CommandSource sender, final St private void run_reload(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { ess.reload(); - sender.sendMessage(tl("essentialsReload", ess.getDescription().getVersion())); + sender.sendTl("essentialsReload", ess.getDescription().getVersion()); } private void run_nya(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { @@ -206,7 +204,7 @@ private void run_cleanup(final Server server, final CommandSource sender, final sender.sendMessage("Unless you define larger default values, this command wil ignore people who have more than 0 money/homes."); throw new Exception("/ cleanup [money] [homes]"); } - sender.sendMessage(tl("cleaning")); + sender.sendTl("cleaning"); final long daysArg = Long.parseLong(args[1]); final double moneyArg = args.length >= 3 ? FloatUtil.parseDouble(args[2].replaceAll("[^0-9\\.]", "")) : 0; @@ -250,7 +248,7 @@ public void run() { user.reset(); } - sender.sendMessage(tl("cleaned")); + sender.sendTl("cleaned"); } }); @@ -312,8 +310,8 @@ private void run_version(final Server server, final CommandSource sender, final final PluginManager pm = server.getPluginManager(); final String essVer = pm.getPlugin("Essentials").getDescription().getVersion(); - sender.sendMessage(tl(isServerSupported ? "versionOutputFine" : "versionOutputWarn", "Server", server.getBukkitVersion() + " " + server.getVersion())); - sender.sendMessage(tl("versionOutputFine", "EssentialsX", essVer)); + sender.sendTl(isServerSupported ? "versionOutputFine" : "versionOutputWarn", "Server", server.getBukkitVersion() + " " + server.getVersion()); + sender.sendTl("versionOutputFine", "EssentialsX", essVer); for (Plugin plugin : pm.getPlugins()) { final PluginDescriptionFile desc = plugin.getDescription(); @@ -326,22 +324,22 @@ private void run_version(final Server server, final CommandSource sender, final if (!version.equalsIgnoreCase(essVer)) { isMismatched = true; - sender.sendMessage(tl("versionOutputWarn", name, version)); + sender.sendTl("versionOutputWarn", name, version); } else { - sender.sendMessage(tl("versionOutputFine", name, version)); + sender.sendTl("versionOutputFine", name, version); } } else { - sender.sendMessage(tl("versionOutputUnsupported", name, version)); + sender.sendTl("versionOutputUnsupported", name, version); isUnsupported = true; } } if (versionPlugins.contains(name)) { if (warnPlugins.contains(name)) { - sender.sendMessage(tl("versionOutputUnsupported", name, version)); + sender.sendTl("versionOutputUnsupported", name, version); isUnsupported = true; } else { - sender.sendMessage(tl("versionOutputFine", name, version)); + sender.sendTl("versionOutputFine", name, version); } } @@ -349,19 +347,19 @@ private void run_version(final Server server, final CommandSource sender, final } if (isMismatched) { - sender.sendMessage(tl("versionMismatchAll")); + sender.sendTl("versionMismatchAll"); } if (!isVaultInstalled) { - sender.sendMessage(tl("versionOutputVaultMissing")); + sender.sendTl("versionOutputVaultMissing"); } if (isUnsupported) { - sender.sendMessage(tl("versionOutputUnsupportedPlugins")); + sender.sendTl("versionOutputUnsupportedPlugins"); } if (!VersionUtil.isServerSupported()) { - sender.sendMessage(tl("serverUnsupported")); + sender.sendTl("serverUnsupported"); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandexp.java b/Essentials/src/com/earth2me/essentials/commands/Commandexp.java index aeb631d4052..d5eb20a49d1 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandexp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandexp.java @@ -12,8 +12,6 @@ import java.util.List; import java.util.Locale; -import static com.earth2me.essentials.I18n.tl; - public class Commandexp extends EssentialsCommand { public Commandexp() { @@ -126,7 +124,7 @@ private void expMatch(final Server server, final CommandSource sender, final Str } private void showExp(final CommandSource sender, final User target) { - sender.sendMessage(tl("exp", target.getDisplayName(), SetExpFix.getTotalExperience(target.getBase()), target.getBase().getLevel(), SetExpFix.getExpUntilNextLevel(target.getBase()))); + sender.sendTl("exp", target.getDisplayName(), SetExpFix.getTotalExperience(target.getBase()), target.getBase().getLevel(), SetExpFix.getExpUntilNextLevel(target.getBase())); } //TODO: Limit who can give negative exp? @@ -158,7 +156,7 @@ private void setExp(final CommandSource sender, final User target, String strAmo amount = 0l; } SetExpFix.setTotalExperience(target.getBase(), (int) amount); - sender.sendMessage(tl("expSet", target.getDisplayName(), amount)); + sender.sendTl("expSet", target.getDisplayName(), amount); } @Override diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandext.java b/Essentials/src/com/earth2me/essentials/commands/Commandext.java index b751b1e4c4d..3937d62e0dd 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandext.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandext.java @@ -8,8 +8,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandext extends EssentialsLoopCommand { public Commandext() { @@ -29,7 +27,7 @@ protected void run(final Server server, final CommandSource sender, final String public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { extPlayer(user.getBase()); - user.sendMessage(tl("extinguish")); + user.sendTl("extinguish"); return; } @@ -39,7 +37,7 @@ public void run(final Server server, final User user, final String commandLabel, @Override protected void updatePlayer(final Server server, final CommandSource sender, final User player, final String[] args) { extPlayer(player.getBase()); - sender.sendMessage(tl("extinguishOthers", player.getDisplayName())); + sender.sendTl("extinguishOthers", player.getDisplayName()); } private void extPlayer(final Player player) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java b/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java index b0a4e3df73d..5415e4ee618 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java @@ -9,8 +9,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandfeed extends EssentialsLoopCommand { public Commandfeed() { @@ -29,7 +27,7 @@ protected void run(final Server server, final User user, final String commandLab } feedPlayer(user.getBase()); - user.sendMessage(tl("feed")); + user.sendTl("feed"); } @Override @@ -45,7 +43,7 @@ protected void run(final Server server, final CommandSource sender, final String protected void updatePlayer(final Server server, final CommandSource sender, final User player, final String[] args) throws PlayerExemptException { try { feedPlayer(player.getBase()); - sender.sendMessage(tl("feedOther", player.getDisplayName())); + sender.sendTl("feedOther", player.getDisplayName()); } catch (QuietAbortException e) { //Handle Quietly } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandfirework.java b/Essentials/src/com/earth2me/essentials/commands/Commandfirework.java index 65dfabed95c..867391f0cdd 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandfirework.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandfirework.java @@ -18,8 +18,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - //This command has quite a complicated syntax, in theory it has 4 seperate syntaxes which are all variable: // //1: /firework clear - This clears all of the effects on a firework stack @@ -51,14 +49,14 @@ protected void run(final Server server, final User user, final String commandLab FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta(); fmeta.clearEffects(); stack.setItemMeta(fmeta); - user.sendMessage(tl("fireworkEffectsCleared")); + user.sendTl("fireworkEffectsCleared"); } else if (args.length > 1 && (args[0].equalsIgnoreCase("power") || (args[0].equalsIgnoreCase("p")))) { FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta(); try { int power = Integer.parseInt(args[1]); fmeta.setPower(power > 3 ? 4 : power); } catch (NumberFormatException e) { - throw new Exception(tl("invalidFireworkFormat", args[1], args[0])); + throw new Exception(user.tl("invalidFireworkFormat", args[1], args[0])); } stack.setItemMeta(fmeta); } else if ((args[0].equalsIgnoreCase("fire") || (args[0].equalsIgnoreCase("f"))) && user.isAuthorized("essentials.firework.fire")) { @@ -70,7 +68,7 @@ protected void run(final Server server, final User user, final String commandLab amount = Integer.parseInt(args[1]); if (amount > serverLimit) { amount = serverLimit; - user.sendMessage(tl("mobSpawnLimit")); + user.sendTl("mobSpawnLimit"); } } else { direction = true; @@ -94,7 +92,7 @@ protected void run(final Server server, final User user, final String commandLab try { mStack.addFireworkMeta(user.getSource(), true, arg, ess); } catch (Exception e) { - user.sendMessage(tl("fireworkSyntax")); + user.sendTl("fireworkSyntax"); throw e; } } @@ -103,20 +101,20 @@ protected void run(final Server server, final User user, final String commandLab FireworkMeta fmeta = (FireworkMeta) mStack.getItemStack().getItemMeta(); FireworkEffect effect = mStack.getFireworkBuilder().build(); if (fmeta.getEffects().size() > 0 && !user.isAuthorized("essentials.firework.multiple")) { - throw new Exception(tl("multipleCharges")); + throw new Exception(user.tl("multipleCharges")); } fmeta.addEffect(effect); stack.setItemMeta(fmeta); } else { - user.sendMessage(tl("fireworkSyntax")); - throw new Exception(tl("fireworkColor")); + user.sendTl("fireworkSyntax"); + throw new Exception(user.tl("fireworkColor")); } } } else { throw new NotEnoughArgumentsException(); } } else { - throw new Exception(tl("holdFirework")); + throw new Exception(user.tl("holdFirework")); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandfly.java b/Essentials/src/com/earth2me/essentials/commands/Commandfly.java index afc27b4c7fa..7ba9de2f059 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandfly.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandfly.java @@ -5,8 +5,6 @@ import org.bukkit.Server; import net.ess3.api.events.FlyStatusChangeEvent; -import static com.earth2me.essentials.I18n.tl; - public class Commandfly extends EssentialsToggleCommand { public Commandfly() { super("fly", "essentials.fly.others"); @@ -40,9 +38,9 @@ void togglePlayer(CommandSource sender, User user, Boolean enabled) { user.getBase().setFlying(false); } - user.sendMessage(tl("flyMode", tl(enabled ? "enabled" : "disabled"), user.getDisplayName())); + user.sendTl("flyMode", user.tl(enabled ? "enabled" : "disabled"), user.getDisplayName()); if (!sender.isPlayer() || !sender.getPlayer().equals(user.getBase())) { - sender.sendMessage(tl("flyMode", tl(enabled ? "enabled" : "disabled"), user.getDisplayName())); + sender.sendTl("flyMode", sender.tl(enabled ? "enabled" : "disabled"), user.getDisplayName()); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java b/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java index c16a1a381b3..9f22f9ba396 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java @@ -11,8 +11,6 @@ import java.util.List; import java.util.Locale; -import static com.earth2me.essentials.I18n.tl; - public class Commandgamemode extends EssentialsCommand { public Commandgamemode() { @@ -61,21 +59,21 @@ protected void run(final Server server, final User user, final String commandLab } if (!canChangeToMode(user, gameMode)) { - user.sendMessage(tl("cantGamemode", gameMode.name())); + user.sendTl("cantGamemode", gameMode.name()); return; } user.getBase().setGameMode(gameMode); - user.sendMessage(tl("gameMode", tl(user.getBase().getGameMode().toString().toLowerCase(Locale.ENGLISH)), user.getDisplayName())); + user.sendTl("gameMode", user.tl(user.getBase().getGameMode().toString().toLowerCase(Locale.ENGLISH)), user.getDisplayName()); } private void gamemodeOtherPlayers(final Server server, final CommandSource sender, final GameMode gameMode, final String name) throws NotEnoughArgumentsException, PlayerNotFoundException { if (name.trim().length() < 2 || gameMode == null) { - throw new NotEnoughArgumentsException(tl("gameModeInvalid")); + throw new NotEnoughArgumentsException(sender.tl("gameModeInvalid")); } if (sender.isPlayer() && !canChangeToMode(ess.getUser(sender.getPlayer()), gameMode)) { - sender.sendMessage(tl("cantGamemode", gameMode.name())); + sender.sendTl("cantGamemode", gameMode.name()); return; } @@ -89,7 +87,7 @@ private void gamemodeOtherPlayers(final Server server, final CommandSource sende } foundUser = true; player.getBase().setGameMode(gameMode); - sender.sendMessage(tl("gameMode", tl(player.getBase().getGameMode().toString().toLowerCase(Locale.ENGLISH)), player.getDisplayName())); + sender.sendTl("gameMode", sender.tl(player.getBase().getGameMode().toString().toLowerCase(Locale.ENGLISH)), player.getDisplayName()); } if (!foundUser) { throw new PlayerNotFoundException(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgc.java b/Essentials/src/com/earth2me/essentials/commands/Commandgc.java index 1d79213d1b9..86d9c5c996e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgc.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgc.java @@ -9,8 +9,6 @@ import java.util.List; import java.util.logging.Level; -import static com.earth2me.essentials.I18n.tl; - public class Commandgc extends EssentialsCommand { public Commandgc() { @@ -29,11 +27,11 @@ protected void run(final Server server, final CommandSource sender, final String color = ChatColor.RED; } - sender.sendMessage(tl("uptime", DateUtil.formatDateDiff(ManagementFactory.getRuntimeMXBean().getStartTime()))); - sender.sendMessage(tl("tps", "" + color + NumberUtil.formatDouble(tps))); - sender.sendMessage(tl("gcmax", (Runtime.getRuntime().maxMemory() / 1024 / 1024))); - sender.sendMessage(tl("gctotal", (Runtime.getRuntime().totalMemory() / 1024 / 1024))); - sender.sendMessage(tl("gcfree", (Runtime.getRuntime().freeMemory() / 1024 / 1024))); + sender.sendTl("uptime", DateUtil.formatDateDiff(sender, ManagementFactory.getRuntimeMXBean().getStartTime())); + sender.sendTl("tps", "" + color + NumberUtil.formatDouble(tps)); + sender.sendTl("gcmax", (Runtime.getRuntime().maxMemory() / 1024 / 1024)); + sender.sendTl("gctotal", (Runtime.getRuntime().totalMemory() / 1024 / 1024)); + sender.sendTl("gcfree", (Runtime.getRuntime().freeMemory() / 1024 / 1024)); List worlds = server.getWorlds(); for (World w : worlds) { @@ -57,7 +55,7 @@ protected void run(final Server server, final CommandSource sender, final String Bukkit.getLogger().log(Level.SEVERE, "Corrupted chunk data on world " + w, ex); } - sender.sendMessage(tl("gcWorld", worldType, w.getName(), w.getLoadedChunks().length, w.getEntities().size(), tileEntities)); + sender.sendTl("gcWorld", worldType, w.getName(), w.getLoadedChunks().length, w.getEntities().size(), tileEntities); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java b/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java index c6ba0c4842b..ee605b4f456 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java @@ -8,8 +8,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandgetpos extends EssentialsCommand { public Commandgetpos() { @@ -36,14 +34,14 @@ protected void run(final Server server, final CommandSource sender, final String } private void outputPosition(final CommandSource sender, final Location coords, final Location distance) { - sender.sendMessage(tl("currentWorld", coords.getWorld().getName())); - sender.sendMessage(tl("posX", coords.getBlockX())); - sender.sendMessage(tl("posY", coords.getBlockY())); - sender.sendMessage(tl("posZ", coords.getBlockZ())); - sender.sendMessage(tl("posYaw", (coords.getYaw() + 360) % 360)); - sender.sendMessage(tl("posPitch", coords.getPitch())); + sender.sendTl("currentWorld", coords.getWorld().getName()); + sender.sendTl("posX", coords.getBlockX()); + sender.sendTl("posY", coords.getBlockY()); + sender.sendTl("posZ", coords.getBlockZ()); + sender.sendTl("posYaw", (coords.getYaw() + 360) % 360); + sender.sendTl("posPitch", coords.getPitch()); if (distance != null && coords.getWorld().equals(distance.getWorld())) { - sender.sendMessage(tl("distance", coords.distance(distance))); + sender.sendTl("distance", coords.distance(distance)); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java index b43d0d1b09c..44a3b2aa2d4 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java @@ -16,8 +16,6 @@ import java.util.Locale; import java.util.Map; -import static com.earth2me.essentials.I18n.tl; - public class Commandgive extends EssentialsCommand { public Commandgive() { @@ -34,7 +32,7 @@ public void run(final Server server, final CommandSource sender, final String co final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""); if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).canSpawnItem(stack.getType())) { - throw new Exception(tl("cantSpawnItem", itemname)); + throw new Exception(sender.tl("cantSpawnItem", itemname)); } final User giveTo = getPlayer(server, sender, args, 0); @@ -56,7 +54,7 @@ public void run(final Server server, final CommandSource sender, final String co MetaItemStack metaStack = new MetaItemStack(stack); if (!metaStack.canSpawn(ess)) { - throw new Exception(tl("unableToSpawnItem", itemname)); + throw new Exception(sender.tl("unableToSpawnItem", itemname)); } if (args.length > 3) { @@ -75,11 +73,11 @@ public void run(final Server server, final CommandSource sender, final String co } if (stack.getType() == Material.AIR) { - throw new Exception(tl("cantSpawnItem", "Air")); + throw new Exception(sender.tl("cantSpawnItem", "Air")); } final String itemName = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' '); - sender.sendMessage(tl("giveSpawn", stack.getAmount(), itemName, giveTo.getDisplayName())); + sender.sendTl("giveSpawn", stack.getAmount(), itemName, giveTo.getDisplayName()); Map leftovers; @@ -96,7 +94,7 @@ public void run(final Server server, final CommandSource sender, final String co World w = giveTo.getWorld(); w.dropItemNaturally(giveTo.getLocation(), item); } else { - sender.sendMessage(tl("giveSpawnFailure", item.getAmount(), itemName, giveTo.getDisplayName())); + sender.sendTl("giveSpawnFailure", item.getAmount(), itemName, giveTo.getDisplayName()); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgod.java b/Essentials/src/com/earth2me/essentials/commands/Commandgod.java index 4df72fa5c93..1646e10a2bd 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgod.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgod.java @@ -5,8 +5,6 @@ import net.ess3.api.events.GodStatusChangeEvent; import org.bukkit.Server; -import static com.earth2me.essentials.I18n.tl; - public class Commandgod extends EssentialsToggleCommand { public Commandgod() { @@ -40,9 +38,9 @@ void togglePlayer(CommandSource sender, User user, Boolean enabled) { user.getBase().setFoodLevel(20); } - user.sendMessage(tl("godMode", enabled ? tl("enabled") : tl("disabled"))); + user.sendTl("godMode", enabled ? user.tl("enabled") : user.tl("disabled")); if (!sender.isPlayer() || !sender.getPlayer().equals(user.getBase())) { - sender.sendMessage(tl("godMode", tl(enabled ? "godEnabledFor" : "godDisabledFor", user.getDisplayName()))); + sender.sendTl("godMode", sender.tl(enabled ? "godEnabledFor" : "godDisabledFor", user.getDisplayName())); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhat.java b/Essentials/src/com/earth2me/essentials/commands/Commandhat.java index 4ba9189450c..05e17ac6636 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhat.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhat.java @@ -11,8 +11,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandhat extends EssentialsCommand { public Commandhat() { @@ -25,12 +23,12 @@ protected void run(final Server server, final User user, final String commandLab final PlayerInventory inv = user.getBase().getInventory(); final ItemStack head = inv.getHelmet(); if (head == null || head.getType() == Material.AIR) { - user.sendMessage(tl("hatEmpty")); + user.sendTl("hatEmpty"); } else { final ItemStack air = new ItemStack(Material.AIR); inv.setHelmet(air); InventoryWorkaround.addItems(user.getBase().getInventory(), head); - user.sendMessage(tl("hatRemoved")); + user.sendTl("hatRemoved"); } } else { final ItemStack hand = user.getItemInHand(); @@ -40,12 +38,12 @@ protected void run(final Server server, final User user, final String commandLab final ItemStack head = inv.getHelmet(); inv.setHelmet(hand); inv.setItemInHand(head); - user.sendMessage(tl("hatPlaced")); + user.sendTl("hatPlaced"); } else { - user.sendMessage(tl("hatArmor")); + user.sendTl("hatArmor"); } } else { - user.sendMessage(tl("hatFail")); + user.sendTl("hatFail"); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandheal.java b/Essentials/src/com/earth2me/essentials/commands/Commandheal.java index 688a923d212..06dcef075d8 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandheal.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandheal.java @@ -11,8 +11,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandheal extends EssentialsLoopCommand { public Commandheal() { @@ -46,7 +44,7 @@ public void run(final Server server, final CommandSource sender, final String co protected void updatePlayer(final Server server, final CommandSource sender, final User player, final String[] args) throws PlayerExemptException { try { healPlayer(player); - sender.sendMessage(tl("healOther", player.getDisplayName())); + sender.sendTl("healOther", player.getDisplayName()); } catch (QuietAbortException e) { //Handle Quietly } @@ -56,7 +54,7 @@ private void healPlayer(final User user) throws PlayerExemptException, QuietAbor final Player player = user.getBase(); if (player.getHealth() == 0) { - throw new PlayerExemptException(tl("healDead")); + throw new PlayerExemptException(user.tl("healDead")); } final double amount = player.getMaxHealth() - player.getHealth(); @@ -74,7 +72,7 @@ private void healPlayer(final User user) throws PlayerExemptException, QuietAbor player.setHealth(newAmount); player.setFoodLevel(20); player.setFireTicks(0); - user.sendMessage(tl("heal")); + user.sendTl("heal"); for (PotionEffect effect : player.getActivePotionEffects()) { player.removePotionEffect(effect.getType()); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java b/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java index bdfbaeb929b..b6c98dace3b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java @@ -10,8 +10,6 @@ import java.util.List; import java.util.Locale; -import static com.earth2me.essentials.I18n.tl; - public class Commandhelp extends EssentialsCommand { public Commandhelp() { @@ -48,7 +46,7 @@ protected void run(final Server server, final User user, final String commandLab @Override protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { - sender.sendMessage(tl("helpConsole")); + sender.sendTl("helpConsole"); } @Override diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java b/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java index 51b1d666152..794d03a8337 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java @@ -35,10 +35,10 @@ private String sendMessage(final Server server, final CommandSource sender, fina if (args.length < 1) { throw new NotEnoughArgumentsException(); } - final String message = tl("helpOp", from, FormatUtil.stripFormat(getFinalArg(args, 0))); - server.getLogger().log(Level.INFO, message); - ess.broadcastMessage("essentials.helpop.receive", message); - return message; + final String message = FormatUtil.stripFormat(getFinalArg(args, 0)); + ess.broadcastTl("essentials.helpop.receive", "helpOp", from, message); + server.getLogger().log(Level.INFO, tl("helpOp", from, message)); + return sender.tl("helpOp", from, message); } @Override diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java index 6885dbdfdb7..31bf6786cf3 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java @@ -7,13 +7,10 @@ import org.bukkit.Server; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Locale; -import static com.earth2me.essentials.I18n.tl; - public class Commandhome extends EssentialsCommand { public Commandhome() { @@ -45,7 +42,7 @@ public void run(final Server server, final User user, final String commandLabel, user.getTeleport().teleport(bed, charge, TeleportCause.COMMAND); throw new NoChargeException(); } else { - throw new Exception(tl("bedMissing")); + throw new Exception(user.tl("bedMissing")); } } goHome(user, player, homeName.toLowerCase(Locale.ENGLISH), charge); @@ -55,19 +52,19 @@ public void run(final Server server, final User user, final String commandLabel, if (homes.isEmpty() && player.equals(user)) { user.getTeleport().respawn(charge, TeleportCause.COMMAND); } else if (homes.isEmpty()) { - throw new Exception(tl("noHomeSetPlayer")); + throw new Exception(user.tl("noHomeSetPlayer")); } else if (homes.size() == 1 && player.equals(user)) { goHome(user, player, homes.get(0), charge); } else { final int count = homes.size(); if (user.isAuthorized("essentials.home.bed")) { if (bed != null) { - homes.add(tl("bed")); + homes.add(user.tl("bed")); } else { - homes.add(tl("bedNull")); + homes.add(user.tl("bedNull")); } } - user.sendMessage(tl("homes", StringUtil.joinList(homes), count, getHomeLimit(player))); + user.sendTl("homes", StringUtil.joinList(homes), count, getHomeLimit(player)); } } throw new NoChargeException(); @@ -92,10 +89,10 @@ private void goHome(final User user, final User player, final String home, final throw new NotEnoughArgumentsException(); } if (user.getWorld() != loc.getWorld() && ess.getSettings().isWorldHomePermissions() && !user.isAuthorized("essentials.worlds." + loc.getWorld().getName())) { - throw new Exception(tl("noPerm", "essentials.worlds." + loc.getWorld().getName())); + throw new Exception(user.tl("noPerm", "essentials.worlds." + loc.getWorld().getName())); } user.getTeleport().teleport(loc, charge, TeleportCause.COMMAND); - user.sendMessage(tl("teleportHome", home)); + user.sendTl("teleportHome", home); } @Override diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandignore.java b/Essentials/src/com/earth2me/essentials/commands/Commandignore.java index a065a3450be..36857152ce6 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandignore.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandignore.java @@ -6,8 +6,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandignore extends EssentialsCommand { public Commandignore() { @@ -22,7 +20,7 @@ protected void run(final Server server, final User user, final String commandLab sb.append(s).append(" "); } String ignoredList = sb.toString().trim(); - user.sendMessage(ignoredList.length() > 0 ? tl("ignoredList", ignoredList) : tl("noIgnored")); + user.sendMessage(ignoredList.length() > 0 ? user.tl("ignoredList", ignoredList) : user.tl("noIgnored")); } else { User player; try { @@ -34,13 +32,13 @@ protected void run(final Server server, final User user, final String commandLab throw new PlayerNotFoundException(); } if (player.isIgnoreExempt()) { - user.sendMessage(tl("ignoreExempt")); + user.sendTl("ignoreExempt"); } else if (user.isIgnoredPlayer(player)) { user.setIgnoredPlayer(player, false); - user.sendMessage(tl("unignorePlayer", player.getName())); + user.sendTl("unignorePlayer", player.getName()); } else { user.setIgnoredPlayer(player, true); - user.sendMessage(tl("ignorePlayer", player.getName())); + user.sendTl("ignorePlayer", player.getName()); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java index 00c1b39eabf..d9dc3ab27ba 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java @@ -12,8 +12,6 @@ import java.util.List; import java.util.Locale; -import static com.earth2me.essentials.I18n.tl; - public class Commanditem extends EssentialsCommand { public Commanditem() { @@ -30,7 +28,7 @@ public void run(final Server server, final User user, final String commandLabel, final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""); if (!user.canSpawnItem(stack.getType())) { - throw new Exception(tl("cantSpawnItem", itemname)); + throw new Exception(user.tl("cantSpawnItem", itemname)); } try { @@ -47,7 +45,7 @@ public void run(final Server server, final User user, final String commandLabel, MetaItemStack metaStack = new MetaItemStack(stack); if (!metaStack.canSpawn(ess)) { - throw new Exception(tl("unableToSpawnItem", itemname)); + throw new Exception(user.tl("unableToSpawnItem", itemname)); } if (args.length > 2) { @@ -60,11 +58,11 @@ public void run(final Server server, final User user, final String commandLabel, if (stack.getType() == Material.AIR) { - throw new Exception(tl("cantSpawnItem", "Air")); + throw new Exception(user.tl("cantSpawnItem", "Air")); } final String displayName = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' '); - user.sendMessage(tl("itemSpawn", stack.getAmount(), displayName)); + user.sendTl("itemSpawn", stack.getAmount(), displayName); if (user.isAuthorized("essentials.oversizedstacks")) { InventoryWorkaround.addOversizedItems(user.getBase().getInventory(), ess.getSettings().getOversizedStackSize(), stack); } else { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanditemdb.java b/Essentials/src/com/earth2me/essentials/commands/Commanditemdb.java index 6a105754d6d..8e8078aa617 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanditemdb.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanditemdb.java @@ -9,8 +9,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commanditemdb extends EssentialsCommand { public Commanditemdb() { @@ -39,23 +37,23 @@ protected void run(Server server, CommandSource sender, String commandLabel, Str itemId = itemStack.getType().getId() + ":" + itemStack.getDurability(); } - sender.sendMessage(tl("itemType", itemStack.getType().toString(), itemId)); + sender.sendTl("itemType", itemStack.getType().toString(), itemId); // Don't send IDs twice - if (!tl("itemType").contains("{1}") && !itemId.equals("none")) { - sender.sendMessage(tl("itemId", itemId)); + if (!sender.tl("itemType").contains("{1}") && !itemId.equals("none")) { + sender.sendTl("itemId", itemId); } if (itemHeld && itemStack.getType() != Material.AIR) { int maxuses = itemStack.getType().getMaxDurability(); int durability = ((maxuses + 1) - itemStack.getDurability()); if (maxuses != 0) { - sender.sendMessage(tl("durability", Integer.toString(durability))); + sender.sendTl("durability", Integer.toString(durability)); } } final String itemNameList = ess.getItemDb().names(itemStack); if (itemNameList != null) { - sender.sendMessage(tl("itemNames", ess.getItemDb().names(itemStack))); + sender.sendTl("itemNames", ess.getItemDb().names(itemStack)); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandjails.java b/Essentials/src/com/earth2me/essentials/commands/Commandjails.java index e48bf2153dc..e334450fb63 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandjails.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandjails.java @@ -4,10 +4,6 @@ import com.earth2me.essentials.utils.StringUtil; import org.bukkit.Server; -import java.util.Collection; - -import static com.earth2me.essentials.I18n.tl; - public class Commandjails extends EssentialsCommand { public Commandjails() { @@ -17,9 +13,9 @@ public Commandjails() { @Override protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (ess.getJails().getCount() < 1) { - sender.sendMessage(tl("noJailsDefined")); + sender.sendTl("noJailsDefined"); } else { - sender.sendMessage(tl("jailList", StringUtil.joinList(" ", ess.getJails().getList()))); + sender.sendTl("jailList", 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 046fd61a864..69cf299255b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandjump.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandjump.java @@ -11,8 +11,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - // This method contains an undocumented sub command #EasterEgg public class Commandjump extends EssentialsCommand { public Commandjump() { @@ -41,7 +39,7 @@ public void run(final Server server, final User user, final String commandLabel, loc.setPitch(cloc.getPitch()); loc.setY(loc.getY() + 1); } catch (NullPointerException ex) { - throw new Exception(tl("jumpError"), ex); + throw new Exception(user.tl("jumpError"), ex); } final Trade charge = new Trade(this.getName(), ess); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java index 8d45893fb43..d53d0a423a4 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java @@ -32,18 +32,18 @@ public void run(final Server server, final CommandSource sender, final String co } if (target.isAuthorized("essentials.kick.exempt")) { - throw new Exception(tl("kickExempt")); + throw new Exception(user.tl("kickExempt")); } } - String kickReason = args.length > 1 ? getFinalArg(args, 1) : tl("kickDefault"); + String kickReason = args.length > 1 ? getFinalArg(args, 1) : target.tl("kickDefault"); kickReason = FormatUtil.replaceFormat(kickReason.replace("\\n", "\n").replace("|", "\n")); target.getBase().kickPlayer(kickReason); final String senderName = sender.isPlayer() ? sender.getPlayer().getDisplayName() : Console.NAME; server.getLogger().log(Level.INFO, tl("playerKicked", senderName, target.getName(), kickReason)); - ess.broadcastMessage("essentials.kick.notify", tl("playerKicked", senderName, target.getName(), kickReason)); + ess.broadcastTl("essentials.kick.notify", "playerKicked", senderName, target.getName(), kickReason); } @Override diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java b/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java index 303adfc5dff..296f6e052ab 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java @@ -1,12 +1,11 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.CommandSource; +import com.earth2me.essentials.User; import com.earth2me.essentials.utils.FormatUtil; import org.bukkit.Server; import org.bukkit.entity.Player; -import static com.earth2me.essentials.I18n.tl; - public class Commandkickall extends EssentialsCommand { public Commandkickall() { @@ -15,16 +14,16 @@ public Commandkickall() { @Override public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { - String kickReason = args.length > 0 ? getFinalArg(args, 0) : tl("kickDefault"); - kickReason = FormatUtil.replaceFormat(kickReason.replace("\\n", "\n").replace("|", "\n")); - for (Player onlinePlayer : ess.getOnlinePlayers()) { if (!sender.isPlayer() || !onlinePlayer.getName().equalsIgnoreCase(sender.getPlayer().getName())) { - if (!ess.getUser(onlinePlayer).isAuthorized("essentials.kickall.exempt")) { + final User kuser = ess.getUser(onlinePlayer); + if (!kuser.isAuthorized("essentials.kickall.exempt")) { + String kickReason = args.length > 0 ? getFinalArg(args, 0) : kuser.tl("kickDefault"); + kickReason = FormatUtil.replaceFormat(kickReason.replace("\\n", "\n").replace("|", "\n")); onlinePlayer.kickPlayer(kickReason); } } } - sender.sendMessage(tl("kickedAll")); + sender.sendTl("kickedAll"); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkill.java b/Essentials/src/com/earth2me/essentials/commands/Commandkill.java index d53861d92d6..f6bf500fc6c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkill.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkill.java @@ -9,8 +9,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandkill extends EssentialsLoopCommand { public Commandkill() { @@ -30,7 +28,7 @@ public void run(final Server server, final CommandSource sender, final String co protected void updatePlayer(final Server server, final CommandSource sender, final User user, final String[] args) throws PlayerExemptException { final Player matchPlayer = user.getBase(); if (sender.isPlayer() && user.isAuthorized("essentials.kill.exempt") && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.kill.force")) { - throw new PlayerExemptException(tl("killExempt", matchPlayer.getDisplayName())); + throw new PlayerExemptException(user.tl("killExempt", matchPlayer.getDisplayName())); } final EntityDamageEvent ede = new EntityDamageEvent(matchPlayer, sender.isPlayer() && sender.getPlayer().getName().equals(matchPlayer.getName()) ? EntityDamageEvent.DamageCause.SUICIDE : EntityDamageEvent.DamageCause.CUSTOM, Short.MAX_VALUE); server.getPluginManager().callEvent(ede); @@ -44,7 +42,7 @@ protected void updatePlayer(final Server server, final CommandSource sender, fin matchPlayer.setHealth(0); } - sender.sendMessage(tl("kill", matchPlayer.getDisplayName())); + sender.sendTl("kill", matchPlayer.getDisplayName()); } @Override diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java index 5779deff750..332363e459c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java @@ -12,8 +12,6 @@ import java.util.Locale; import java.util.logging.Level; -import static com.earth2me.essentials.I18n.tl; - public class Commandkit extends EssentialsCommand { public Commandkit() { @@ -24,7 +22,7 @@ public Commandkit() { public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { final String kitList = ess.getKits().listKits(ess, user); - user.sendMessage(kitList.length() > 0 ? tl("kits", kitList) : tl("noKits")); + user.sendMessage(kitList.length() > 0 ? user.tl("kits", kitList) : user.tl("noKits")); throw new NoChargeException(); } else if (args.length > 1 && user.isAuthorized("essentials.kit.others")) { final User userTo = getPlayer(server, user, args, 1); @@ -40,7 +38,7 @@ public void run(final Server server, final User user, final String commandLabel, public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { final String kitList = ess.getKits().listKits(ess, null); - sender.sendMessage(kitList.length() > 0 ? tl("kits", kitList) : tl("noKits")); + sender.sendMessage(kitList.length() > 0 ? sender.tl("kits", kitList) : sender.tl("noKits")); throw new NoChargeException(); } else { final User userTo = getPlayer(server, args, 1, true, false); @@ -50,15 +48,15 @@ public void run(final Server server, final CommandSource sender, final String co final Kit kit = new Kit(kitName, ess); kit.expandItems(userTo); - sender.sendMessage(tl("kitGiveTo", kitName, userTo.getDisplayName())); - userTo.sendMessage(tl("kitReceive", kitName)); + sender.sendTl("kitGiveTo", kitName, userTo.getDisplayName()); + userTo.sendTl("kitReceive", kitName); } } } private void giveKits(final User userTo, final User userFrom, final String kitNames) throws Exception { if (kitNames.isEmpty()) { - throw new Exception(tl("kitNotFound")); + throw new Exception(userFrom.tl("kitNotFound")); } String[] kitList = kitNames.split(","); @@ -66,7 +64,7 @@ private void giveKits(final User userTo, final User userFrom, final String kitNa for (final String kitName : kitList) { if (kitName.isEmpty()) { - throw new Exception(tl("kitNotFound")); + throw new Exception(userFrom.tl("kitNotFound")); } Kit kit = new Kit(kitName, ess); @@ -86,10 +84,10 @@ private void giveKits(final User userTo, final User userFrom, final String kitNa kit.chargeUser(userTo); if (!userFrom.equals(userTo)) { - userFrom.sendMessage(tl("kitGiveTo", kit.getName(), userTo.getDisplayName())); + userFrom.sendTl("kitGiveTo", kit.getName(), userTo.getDisplayName()); } - userTo.sendMessage(tl("kitReceive", kit.getName())); + userTo.sendTl("kitReceive", kit.getName()); } catch (NoChargeException ex) { if (ess.getSettings().isDebug()) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java b/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java index 1b479d0fc1f..9afa88ce150 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java @@ -12,8 +12,6 @@ import java.util.List; import java.util.Set; -import static com.earth2me.essentials.I18n.tl; - public class Commandlightning extends EssentialsLoopCommand { int power = 5; @@ -44,14 +42,14 @@ public void run(final Server server, final CommandSource sender, final String co @Override protected void updatePlayer(final Server server, final CommandSource sender, final User matchUser, final String[] args) { - sender.sendMessage(tl("lightningUse", matchUser.getDisplayName())); + sender.sendTl("lightningUse", matchUser.getDisplayName()); final LightningStrike strike = matchUser.getBase().getWorld().strikeLightningEffect(matchUser.getBase().getLocation()); if (!matchUser.isGodModeEnabled()) { matchUser.getBase().damage(power, strike); } if (ess.getSettings().warnOnSmite()) { - matchUser.sendMessage(tl("lightningSmited")); + matchUser.sendTl("lightningSmited"); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java index 41a0adad8bd..b6136164224 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java @@ -9,8 +9,6 @@ import java.util.*; -import static com.earth2me.essentials.I18n.tl; - public class Commandlist extends EssentialsCommand { public Commandlist() { @@ -21,15 +19,15 @@ public Commandlist() { public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { boolean showHidden = true; User user = null; - if (sender.isPlayer()) { - user = ess.getUser(sender.getPlayer()); + if (sender.getUser() != null) { + user = sender.getUser(); showHidden = user.isAuthorized("essentials.list.hidden") || user.canInteractVanished(); } - sender.sendMessage(PlayerList.listSummary(ess, user, showHidden)); + sender.sendMessage(PlayerList.listSummary(ess, sender, showHidden)); final Map> playerList = PlayerList.getPlayerLists(ess, user, showHidden); if (args.length > 0) { - sender.sendMessage(PlayerList.listGroupUsers(ess, playerList, args[0].toLowerCase())); + sender.sendMessage(PlayerList.listGroupUsers(ess, sender, playerList, args[0].toLowerCase())); } else { sendGroupedList(sender, commandLabel, playerList); } @@ -67,9 +65,9 @@ private void sendGroupedList(CommandSource sender, String commandLabel, Map limit) { - sender.sendMessage(PlayerList.outputFormat(oConfigGroup, tl("groupNumber", matchedList.size(), commandLabel, FormatUtil.stripFormat(configGroup)))); + sender.sendMessage(PlayerList.outputFormat(sender, oConfigGroup, sender.tl("groupNumber", matchedList.size(), commandLabel, FormatUtil.stripFormat(configGroup)))); } else { - sender.sendMessage(PlayerList.outputFormat(oConfigGroup, PlayerList.listUsers(ess, outputUserList, ", "))); + sender.sendMessage(PlayerList.outputFormat(sender, oConfigGroup, PlayerList.listUsers(ess, sender, outputUserList, ", "))); } continue; } @@ -82,7 +80,7 @@ private void sendGroupedList(CommandSource sender, String commandLabel, Map var = playerList.keySet(); @@ -107,13 +105,13 @@ private void sendGroupedList(CommandSource sender, String commandLabel, Map 1 && user.isAuthorized("essentials.locale.others")) { + loopOfflinePlayers(server, user.getSource(), false, true, args[0], new String[]{args[1]}); + user.sendTl("localeChanged"); + } else { + updatePlayer(server, user.getSource(), user, args); + } + } + + @Override + public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { + if (!ess.getSettings().changeLocale()) { + throw new Exception(sender.tl("localeChange")); + } + if (args.length < 1) { + throw new NotEnoughArgumentsException(); + } + loopOfflinePlayers(server, sender, false, true, args[0], new String[]{args[1]}); + sender.sendTl("localeChanged"); + } + + @Override + protected void updatePlayer(final Server server, final CommandSource sender, final User target, final String[] args) throws NotEnoughArgumentsException { + if ("none".equalsIgnoreCase(args[0]) || "default".equalsIgnoreCase(args[0])) { + target.setLocale(null); + target.sendTl("localeNoMore"); + return; + } + + final Locale locale = I18n.getLocale(args[0]); + if (locale == null) { + throw new NotEnoughArgumentsException(sender.tl("localeUnknown", args[0])); + } else if (locale.equals(target.getLocale())) { + sender.sendTl("localeInUse", target.getLocale().getDisplayName()); + } else { + target.setLocale(locale); + target.sendTl("localeSet", locale.getDisplayName()); + } + } + + @Override + protected List getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) { + if (args.length == 1 && user.isAuthorized("essentials.locale.others")) { + return getPlayers(server, user); + } else { + return Collections.emptyList(); + } + } + + @Override + protected List getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) { + if (args.length == 1) { + return getPlayers(server, sender); + } else { + return Collections.emptyList(); + } + } +} diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java index b5e30f4aa68..1aba9647e3f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java @@ -14,8 +14,6 @@ import java.util.List; import java.util.UUID; -import static com.earth2me.essentials.I18n.tl; - public class Commandmail extends EssentialsCommand { private static int mailsPerMinute = 0; @@ -31,7 +29,7 @@ public void run(final Server server, final User user, final String commandLabel, if (args.length >= 1 && "read".equalsIgnoreCase(args[0])) { final List mail = user.getMails(); if (mail.isEmpty()) { - user.sendMessage(tl("noMail")); + user.sendTl("noMail"); throw new NoChargeException(); } @@ -39,26 +37,26 @@ public void run(final Server server, final User user, final String commandLabel, final TextPager pager = new TextPager(input); pager.showPage(args.length > 1 ? args[1] : null, null, commandLabel + " " + args[0], user.getSource()); - user.sendMessage(tl("mailClear")); + user.sendTl("mailClear"); return; } if (args.length >= 3 && "send".equalsIgnoreCase(args[0])) { if (!user.isAuthorized("essentials.mail.send")) { - throw new Exception(tl("noPerm", "essentials.mail.send")); + throw new Exception(user.tl("noPerm", "essentials.mail.send")); } if (user.isMuted()) { - throw new Exception(user.hasMuteReason() ? tl("voiceSilencedReason", user.getMuteReason()) : tl("voiceSilenced")); + throw new Exception(user.hasMuteReason() ? user.tl("voiceSilencedReason", user.getMuteReason()) : user.tl("voiceSilenced")); } User u = getPlayer(server, args[1], true, true); if (u == null) { - throw new Exception(tl("playerNeverOnServer", args[1])); + throw new Exception(user.tl("playerNeverOnServer", args[1])); } - String mail = tl("mailFormat", user.getName(), FormatUtil.formatMessage(user, "essentials.mail", StringUtil.sanitizeString(FormatUtil.stripFormat(getFinalArg(args, 2))))); + String mail = user.tl("mailFormat", user.getName(), FormatUtil.formatMessage(user, "essentials.mail", StringUtil.sanitizeString(FormatUtil.stripFormat(getFinalArg(args, 2))))); if (mail.length() > 1000) { - throw new Exception(tl("mailTooLong")); + throw new Exception(user.tl("mailTooLong")); } if (!u.isIgnoredPlayer(user)) { @@ -68,32 +66,32 @@ public void run(final Server server, final User user, final String commandLabel, } mailsPerMinute++; if (mailsPerMinute > ess.getSettings().getMailsPerMinute()) { - throw new Exception(tl("mailDelay", ess.getSettings().getMailsPerMinute())); + throw new Exception(user.tl("mailDelay", ess.getSettings().getMailsPerMinute())); } - u.addMail(tl("mailMessage", mail)); + u.addMail(u.tl("mailMessage", mail)); } - user.sendMessage(tl("mailSentTo", u.getDisplayName(), u.getName())); + user.sendTl("mailSentTo", u.getDisplayName(), u.getName()); user.sendMessage(mail); return; } if (args.length > 1 && "sendall".equalsIgnoreCase(args[0])) { if (!user.isAuthorized("essentials.mail.sendall")) { - throw new Exception(tl("noPerm", "essentials.mail.sendall")); + throw new Exception(user.tl("noPerm", "essentials.mail.sendall")); } - ess.runTaskAsynchronously(new SendAll(tl("mailFormat", user.getName(), - FormatUtil.formatMessage(user, "essentials.mail", StringUtil.sanitizeString(FormatUtil.stripFormat(getFinalArg(args, 1))))))); - user.sendMessage(tl("mailSent")); + ess.runTaskAsynchronously(new SendAll("mailFormat", user.getName(), + FormatUtil.formatMessage(user, "essentials.mail", StringUtil.sanitizeString(FormatUtil.stripFormat(getFinalArg(args, 1)))))); + user.sendTl("mailSent"); return; } if (args.length >= 1 && "clear".equalsIgnoreCase(args[0])) { if (user.getMails() == null || user.getMails().isEmpty()) { - user.sendMessage(tl("noMail")); + user.sendTl("noMail"); throw new NoChargeException(); } user.setMails(null); - user.sendMessage(tl("mailCleared")); + user.sendTl("mailCleared"); return; } throw new NotEnoughArgumentsException(); @@ -102,29 +100,29 @@ public void run(final Server server, final User user, final String commandLabel, @Override protected void run(Server server, CommandSource sender, String commandLabel, String[] args) throws Exception { if (args.length >= 1 && "read".equalsIgnoreCase(args[0])) { - throw new Exception(tl("onlyPlayers", commandLabel + " read")); + throw new Exception(sender.tl("onlyPlayers", commandLabel + " read")); } else if (args.length >= 1 && "clear".equalsIgnoreCase(args[0])) { - throw new Exception(tl("onlyPlayers", commandLabel + " clear")); + throw new Exception(sender.tl("onlyPlayers", commandLabel + " clear")); } else if (args.length >= 3 && "send".equalsIgnoreCase(args[0])) { User u = getPlayer(server, args[1], true, true); if (u == null) { - throw new Exception(tl("playerNeverOnServer", args[1])); + throw new Exception(sender.tl("playerNeverOnServer", args[1])); } - u.addMail(tl("mailFormat", "Server", FormatUtil.replaceFormat(getFinalArg(args, 2)))); - sender.sendMessage(tl("mailSent")); + u.addMail(u.tl("mailFormat", "Server", FormatUtil.replaceFormat(getFinalArg(args, 2)))); + sender.sendTl("mailSent"); return; } else if (args.length >= 2 && "sendall".equalsIgnoreCase(args[0])) { - ess.runTaskAsynchronously(new SendAll(tl("mailFormat", "Server", FormatUtil.replaceFormat(getFinalArg(args, 1))))); - sender.sendMessage(tl("mailSent")); + ess.runTaskAsynchronously(new SendAll("mailFormat", "Server", FormatUtil.replaceFormat(getFinalArg(args, 1)))); + sender.sendTl("mailSent"); return; } else if (args.length >= 2) { //allow sending from console without "send" argument, since it's the only thing the console can do User u = getPlayer(server, args[0], true, true); if (u == null) { - throw new Exception(tl("playerNeverOnServer", args[0])); + throw new Exception(sender.tl("playerNeverOnServer", args[0])); } - u.addMail(tl("mailFormat", "Server", FormatUtil.replaceFormat(getFinalArg(args, 1)))); - sender.sendMessage(tl("mailSent")); + u.addMail(u.tl("mailFormat", "Server", FormatUtil.replaceFormat(getFinalArg(args, 1)))); + sender.sendTl("mailSent"); return; } throw new NotEnoughArgumentsException(); @@ -132,10 +130,12 @@ protected void run(Server server, CommandSource sender, String commandLabel, Str private class SendAll implements Runnable { - String message; + String string; + Object objects; - public SendAll(String message) { - this.message = message; + public SendAll(String string, Object... objects) { + this.string = string; + this.objects = objects; } @Override @@ -143,7 +143,7 @@ public void run() { for (UUID userid : ess.getUserMap().getAllUniqueUsers()) { User user = ess.getUserMap().getUser(userid); if (user != null) { - user.addMail(message); + user.addMail(user.tl(string, objects)); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandme.java b/Essentials/src/com/earth2me/essentials/commands/Commandme.java index 09840610334..a42df00e586 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandme.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandme.java @@ -13,8 +13,6 @@ import java.util.List; import java.util.Set; -import static com.earth2me.essentials.I18n.tl; - public class Commandme extends EssentialsCommand { public Commandme() { @@ -24,7 +22,7 @@ public Commandme() { @Override public void run(Server server, User user, String commandLabel, String[] args) throws Exception { if (user.isMuted()) { - throw new Exception(user.hasMuteReason() ? tl("voiceSilencedReason", user.getMuteReason()) : tl("voiceSilenced")); + throw new Exception(user.hasMuteReason() ? user.tl("voiceSilencedReason", user.getMuteReason()) : user.tl("voiceSilenced")); } if (args.length < 1) { @@ -36,9 +34,8 @@ public void run(Server server, User user, String commandLabel, String[] args) th user.setDisplayNick(); int radius = ess.getSettings().getChatRadius(); - String toSend = tl("action", user.getDisplayName(), message); if (radius < 1) { - ess.broadcastMessage(user, toSend); + ess.broadcastTl(user, "action", user.getDisplayName(), message); return; } @@ -74,11 +71,11 @@ public void run(Server server, User user, String commandLabel, String[] args) th } if (outList.size() < 2) { - user.sendMessage(tl("localNoOne")); + user.sendTl("localNoOne"); } for (Player onlinePlayer : outList) { - onlinePlayer.sendMessage(toSend); + ess.getUser(onlinePlayer).sendTl("action", user.getDisplayName(), message); } } @@ -91,7 +88,7 @@ public void run(Server server, CommandSource sender, String commandLabel, String String message = getFinalArg(args, 0); message = FormatUtil.replaceFormat(message); - ess.getServer().broadcastMessage(tl("action", "@", message)); + ess.broadcastTl(sender, "action", "@", message); } @Override diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmore.java b/Essentials/src/com/earth2me/essentials/commands/Commandmore.java index 2109d176b58..441fe31dc8a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmore.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmore.java @@ -6,8 +6,6 @@ import java.util.Locale; -import static com.earth2me.essentials.I18n.tl; - public class Commandmore extends EssentialsCommand { public Commandmore() { @@ -18,15 +16,15 @@ public Commandmore() { public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { final ItemStack stack = user.getItemInHand(); if (stack == null) { - throw new Exception(tl("cantSpawnItem", "Air")); + throw new Exception(user.tl("cantSpawnItem", "Air")); } if (stack.getAmount() >= ((user.isAuthorized("essentials.oversizedstacks")) ? ess.getSettings().getOversizedStackSize() : stack.getMaxStackSize())) { - throw new Exception(tl("fullStack")); + throw new Exception(user.tl("fullStack")); } final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""); if (!user.canSpawnItem(stack.getType())) { - throw new Exception(tl("cantSpawnItem", itemname)); + throw new Exception(user.tl("cantSpawnItem", itemname)); } if (user.isAuthorized("essentials.oversizedstacks")) { stack.setAmount(ess.getSettings().getOversizedStackSize()); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java b/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java index f2fdfcc3385..ae1ee3419df 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java @@ -1,7 +1,5 @@ package com.earth2me.essentials.commands; -import static com.earth2me.essentials.I18n.tl; - import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.Console; import com.earth2me.essentials.User; @@ -29,7 +27,7 @@ public void run(Server server, CommandSource sender, String commandLabel, String if (sender.isPlayer()) { User user = ess.getUser(sender.getPlayer()); if (user.isMuted()) { - throw new Exception(user.hasMuteReason() ? tl("voiceSilencedReason", user.getMuteReason()) : tl("voiceSilenced")); + throw new Exception(user.hasMuteReason() ? user.tl("voiceSilencedReason", user.getMuteReason()) : user.tl("voiceSilenced")); } message = FormatUtil.formatMessage(user, "essentials.msg", message); canWildcard = user.isAuthorized("essentials.msg.multiple"); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmsgtoggle.java b/Essentials/src/com/earth2me/essentials/commands/Commandmsgtoggle.java index be9bcd0227d..2e14a446ed4 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmsgtoggle.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmsgtoggle.java @@ -4,8 +4,6 @@ import com.earth2me.essentials.User; import org.bukkit.Server; -import static com.earth2me.essentials.I18n.tl; - public class Commandmsgtoggle extends EssentialsToggleCommand { public Commandmsgtoggle() { @@ -30,9 +28,9 @@ void togglePlayer(CommandSource sender, User user, Boolean enabled) { user.setIgnoreMsg(enabled); - user.sendMessage(!enabled ? tl("msgEnabled") : tl("msgDisabled")); + user.sendMessage(!enabled ? user.tl("msgEnabled") : user.tl("msgDisabled")); if (!sender.isPlayer() || !user.getBase().equals(sender.getPlayer())) { - sender.sendMessage(!enabled ? tl("msgEnabledFor", user.getDisplayName()) : tl("msgDisabledFor", user.getDisplayName())); + sender.sendMessage(!enabled ? user.tl("msgEnabledFor", user.getDisplayName()) : user.tl("msgDisabledFor", user.getDisplayName())); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java index 2fac8ce924e..999d721823c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java @@ -33,11 +33,11 @@ public void run(final Server server, final CommandSource sender, final String co } if (!user.getBase().isOnline()) { if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.mute.offline")) { - throw new Exception(tl("muteExemptOffline")); + throw new Exception(sender.tl("muteExemptOffline")); } } else { if (user.isAuthorized("essentials.mute.exempt") && sender.isPlayer()) { - throw new Exception(tl("muteExempt")); + throw new Exception(sender.tl("muteExempt")); } } @@ -69,49 +69,50 @@ public void run(final Server server, final CommandSource sender, final String co } user.setMuteTimeout(muteTimestamp); final boolean muted = user.getMuted(); - String muteTime = DateUtil.formatDateDiff(muteTimestamp); + String muteTime = DateUtil.formatDateDiff(sender, muteTimestamp); if (nomatch) { - sender.sendMessage(tl("userUnknown", user.getName())); + sender.sendTl("userUnknown", user.getName()); } if (muted) { if (muteTimestamp > 0) { if (!user.hasMuteReason()) { - sender.sendMessage(tl("mutedPlayerFor", user.getDisplayName(), muteTime)); - user.sendMessage(tl("playerMutedFor", muteTime)); + sender.sendTl("mutedPlayerFor", user.getDisplayName(), muteTime); + user.sendTl("playerMutedFor", muteTime); } else { - sender.sendMessage(tl("mutedPlayerForReason", user.getDisplayName(), muteTime, user.getMuteReason())); - user.sendMessage(tl("playerMutedForReason", muteTime, user.getMuteReason())); + sender.sendTl("mutedPlayerForReason", user.getDisplayName(), muteTime, user.getMuteReason()); + user.sendTl("playerMutedForReason", muteTime, user.getMuteReason()); } } else { if (!user.hasMuteReason()) { - sender.sendMessage(tl("mutedPlayer", user.getDisplayName())); - user.sendMessage(tl("playerMuted")); + sender.sendTl("mutedPlayer", user.getDisplayName()); + user.sendTl("playerMuted"); } else { - sender.sendMessage(tl("mutedPlayerReason", user.getDisplayName(), user.getMuteReason())); - user.sendMessage(tl("playerMutedReason", user.getMuteReason())); + sender.sendTl("mutedPlayerReason", user.getDisplayName(), user.getMuteReason()); + user.sendTl("playerMutedReason", user.getMuteReason()); } } - final String message; if (muteTimestamp > 0) { if (!user.hasMuteReason()) { - message = tl("muteNotifyFor", sender.getSender().getName(), user.getName(), muteTime); + server.getLogger().log(Level.INFO, tl("muteNotifyFor", sender.getSender().getName(), user.getName(), muteTime)); + ess.broadcastTl("essentials.mute.notify", "muteNotifyFor", sender.getSender().getName(), user.getName(), muteTime); } else { - message = tl("muteNotifyForReason", sender.getSender().getName(), user.getName(), muteTime, user.getMuteReason()); + server.getLogger().log(Level.INFO, tl("muteNotifyForReason", sender.getSender().getName(), user.getName(), muteTime, user.getMuteReason())); + ess.broadcastTl("essentials.mute.notify", "muteNotifyForReason", sender.getSender().getName(), user.getName(), muteTime, user.getMuteReason()); } } else { if (!user.hasMuteReason()) { - message = tl("muteNotify", sender.getSender().getName(), user.getName()); + server.getLogger().log(Level.INFO, tl("muteNotify", sender.getSender().getName(), user.getName())); + ess.broadcastTl("essentials.mute.notify", "muteNotify", sender.getSender().getName(), user.getName()); } else { - message = tl("muteNotifyReason", sender.getSender().getName(), user.getName(), user.getMuteReason()); + server.getLogger().log(Level.INFO, tl("muteNotifyReason", sender.getSender().getName(), user.getName(), user.getMuteReason())); + ess.broadcastTl("essentials.mute.notify", "muteNotifyReason", sender.getSender().getName(), user.getName(), user.getMuteReason()); } } - server.getLogger().log(Level.INFO, message); - ess.broadcastMessage("essentials.mute.notify", message); } else { - sender.sendMessage(tl("unmutedPlayer", user.getDisplayName())); - user.sendMessage(tl("playerUnmuted")); + sender.sendTl("unmutedPlayer", user.getDisplayName()); + user.sendTl("playerUnmuted"); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnear.java b/Essentials/src/com/earth2me/essentials/commands/Commandnear.java index cb93f7736a0..33321688871 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandnear.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandnear.java @@ -12,8 +12,6 @@ import java.util.PriorityQueue; import java.util.Queue; -import static com.earth2me.essentials.I18n.tl; - public class Commandnear extends EssentialsCommand { public Commandnear() { @@ -52,14 +50,14 @@ protected void run(final Server server, final User user, final String commandLab radius = Math.abs(radius); if (radius > maxRadius && !user.isAuthorized("essentials.near.maxexempt")) { - user.sendMessage(tl("radiusTooBig", maxRadius)); + user.sendTl("radiusTooBig", maxRadius); radius = maxRadius; } if (otherUser == null || !user.isAuthorized("essentials.near.others")) { otherUser = user; } - user.sendMessage(tl("nearbyPlayers", getLocal(server, otherUser, radius))); + user.sendTl("nearbyPlayers", getLocal(server, otherUser, radius)); } @Override @@ -75,7 +73,7 @@ protected void run(final Server server, final CommandSource sender, final String } catch (NumberFormatException e) { } } - sender.sendMessage(tl("nearbyPlayers", getLocal(server, otherUser, radius))); + sender.sendTl("nearbyPlayers", getLocal(server, otherUser, radius)); } private String getLocal(final Server server, final User user, final long radius) { @@ -108,8 +106,7 @@ private String getLocal(final Server server, final User user, final long radius) User nearbyPlayer = nearbyPlayers.poll(); output.append(nearbyPlayer.getDisplayName()).append("§f(§4").append((long) nearbyPlayer.getLocation().distance(loc)).append("m§f)"); } - - return output.length() > 1 ? output.toString() : tl("none"); + return output.length() > 1 ? output.toString() : user.tl("none"); } @Override diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java index 93e13002d77..448d56a7e0d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java @@ -12,8 +12,6 @@ import java.util.List; import java.util.Locale; -import static com.earth2me.essentials.I18n.tl; - public class Commandnick extends EssentialsLoopCommand { public Commandnick() { @@ -26,15 +24,15 @@ public void run(final Server server, final User user, final String commandLabel, throw new NotEnoughArgumentsException(); } if (!ess.getSettings().changeDisplayName()) { - throw new Exception(tl("nickDisplayName")); + throw new Exception(user.tl("nickDisplayName")); } if (args.length > 1 && user.isAuthorized("essentials.nick.others")) { - final String[] nickname = formatNickname(user, args[1]).split(" "); + final String[] nickname = formatNickname(user.getSource(), user, args[1]).split(" "); loopOfflinePlayers(server, user.getSource(), false, true, args[0], nickname); - user.sendMessage(tl("nickChanged")); + user.sendTl("nickChanged"); } else { - final String[] nickname = formatNickname(user, args[0]).split(" "); + final String[] nickname = formatNickname(user.getSource(), user, args[0]).split(" "); updatePlayer(server, user.getSource(), user, nickname); } } @@ -45,11 +43,11 @@ public void run(final Server server, final CommandSource sender, final String co throw new NotEnoughArgumentsException(); } if (!ess.getSettings().changeDisplayName()) { - throw new Exception(tl("nickDisplayName")); + throw new Exception(sender.tl("nickDisplayName")); } - final String[] nickname = formatNickname(null, args[1]).split(" "); + final String[] nickname = formatNickname(sender, null, args[1]).split(" "); loopOfflinePlayers(server, sender, false, true, args[0], nickname); - sender.sendMessage(tl("nickChanged")); + sender.sendTl("nickChanged"); } @Override @@ -57,32 +55,32 @@ protected void updatePlayer(final Server server, final CommandSource sender, fin final String nick = args[0]; if ("off".equalsIgnoreCase(nick)) { setNickname(server, sender, target, null); - target.sendMessage(tl("nickNoMore")); + target.sendTl("nickNoMore"); } else if (target.getName().equalsIgnoreCase(nick)) { String oldName = target.getDisplayName(); setNickname(server, sender, target, nick); if (!target.getDisplayName().equalsIgnoreCase(oldName)) { - target.sendMessage(tl("nickNoMore")); + target.sendTl("nickNoMore"); } - target.sendMessage(tl("nickSet", target.getDisplayName())); + target.sendTl("nickSet", target.getDisplayName()); } else if (nickInUse(server, target, nick)) { - throw new NotEnoughArgumentsException(tl("nickInUse")); + throw new NotEnoughArgumentsException(sender.tl("nickInUse")); } else { setNickname(server, sender, target, nick); - target.sendMessage(tl("nickSet", target.getDisplayName())); + target.sendTl("nickSet", target.getDisplayName()); } } - private String formatNickname(final User user, final String nick) throws Exception { + private String formatNickname(CommandSource sender, final User user, final String nick) throws Exception { String newNick = user == null ? FormatUtil.replaceFormat(nick) : FormatUtil.formatString(user, "essentials.nick", nick); if (!newNick.matches("^[a-zA-Z_0-9\u00a7]+$") && user != null && !user.isAuthorized("essentials.nick.allowunsafe")) { - throw new Exception(tl("nickNamesAlpha")); + throw new Exception(sender.tl("nickNamesAlpha")); } else if (getNickLength(newNick) > ess.getSettings().getMaxNickLength()) { - throw new Exception(tl("nickTooLong")); + throw new Exception(sender.tl("nickTooLong")); } else if (FormatUtil.stripFormat(newNick).length() < 1) { - throw new Exception(tl("nickNamesAlpha")); + throw new Exception(sender.tl("nickNamesAlpha")); } else if (user != null && (user.isAuthorized("essentials.nick.changecolors") && !user.isAuthorized("essentials.nick.changecolors.bypass")) && !FormatUtil.stripFormat(newNick).equals(user.getName())) { - throw new Exception(tl("nickNamesOnlyColorChanges")); + throw new Exception(sender.tl("nickNamesOnlyColorChanges")); } return newNick; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnuke.java b/Essentials/src/com/earth2me/essentials/commands/Commandnuke.java index cb3c2a218fa..1f3d4c58ec1 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandnuke.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandnuke.java @@ -12,8 +12,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandnuke extends EssentialsCommand { public Commandnuke() { @@ -38,7 +36,7 @@ protected void run(final Server server, final CommandSource sender, final String if (player == null) { continue; } - player.sendMessage(tl("nuke")); + ess.getUser(player).sendTl("nuke"); final Location loc = player.getLocation(); final World world = loc.getWorld(); for (int x = -10; x <= 10; x += 5) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpay.java b/Essentials/src/com/earth2me/essentials/commands/Commandpay.java index 9e412cb1bb6..6d8033d5017 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpay.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpay.java @@ -15,8 +15,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandpay extends EssentialsLoopCommand { BigDecimal amount; @@ -34,7 +32,7 @@ public void run(final Server server, final User user, final String commandLabel, } if (args[1].contains("-")) { - throw new Exception(tl("payMustBePositive")); + throw new Exception(user.tl("payMustBePositive")); } String stringAmount = args[1].replaceAll("[^0-9\\.]", ""); @@ -45,12 +43,12 @@ public void run(final Server server, final User user, final String commandLabel, amount = new BigDecimal(stringAmount); if (amount.compareTo(ess.getSettings().getMinimumPayAmount()) < 0) { // Check if amount is less than minimum-pay-amount - throw new Exception(tl("minimumPayAmount", NumberUtil.displayCurrencyExactly(ess.getSettings().getMinimumPayAmount(), ess))); + throw new Exception(user.tl("minimumPayAmount", NumberUtil.displayCurrencyExactly(ess.getSettings().getMinimumPayAmount(), ess))); } loopOnlinePlayers(server, user.getSource(), false, user.isAuthorized("essentials.pay.multiple"), args[0], args); if (informToConfirm) { String cmd = "/" + commandLabel + " " + StringUtil.joinList(" ", (Object[]) args); - user.sendMessage(tl("confirmPayment", NumberUtil.displayCurrency(amount, ess), cmd)); + user.sendTl("confirmPayment", NumberUtil.displayCurrency(amount, ess), cmd); } } @@ -59,7 +57,7 @@ protected void updatePlayer(final Server server, final CommandSource sender, fin User user = ess.getUser(sender.getPlayer()); try { if (!player.isAcceptingPay()) { - sender.sendMessage(tl("notAcceptingPay", player.getDisplayName())); + sender.sendTl("notAcceptingPay", player.getDisplayName()); return; } if (user.isPromptingPayConfirm() && !amount.equals(user.getConfirmingPayments().get(player))) { // checks if exists and if command needs to be repeated. @@ -77,7 +75,7 @@ protected void updatePlayer(final Server server, final CommandSource sender, fin user.getConfirmingPayments().remove(player); Trade.log("Command", "Pay", "Player", user.getName(), new Trade(amount, ess), player.getName(), new Trade(amount, ess), user.getLocation(), ess); } catch (MaxMoneyException ex) { - sender.sendMessage(tl("maxMoney")); + sender.sendTl("maxMoney"); try { user.setMoney(user.getMoney().add(amount)); } catch (MaxMoneyException ignored) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpayconfirmtoggle.java b/Essentials/src/com/earth2me/essentials/commands/Commandpayconfirmtoggle.java index 3da30ccccbc..75851c747da 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpayconfirmtoggle.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpayconfirmtoggle.java @@ -1,7 +1,5 @@ package com.earth2me.essentials.commands; -import static com.earth2me.essentials.I18n.tl; - import com.earth2me.essentials.User; import org.bukkit.Server; @@ -22,9 +20,9 @@ public void run(Server server, User user, String commandLabel, String[] args) th } user.setPromptingPayConfirm(confirmingPay); if (confirmingPay) { - user.sendMessage(tl("payConfirmToggleOn")); + user.sendTl("payConfirmToggleOn"); } else { - user.sendMessage(tl("payConfirmToggleOff")); + user.sendTl("payConfirmToggleOff"); } user.getConfirmingPayments().clear(); // Clear any outstanding confirmations. } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpaytoggle.java b/Essentials/src/com/earth2me/essentials/commands/Commandpaytoggle.java index 426af8eade9..efdf48cc958 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpaytoggle.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpaytoggle.java @@ -1,8 +1,5 @@ package com.earth2me.essentials.commands; -import static com.earth2me.essentials.I18n.tl; - -import com.earth2me.essentials.I18n; import com.earth2me.essentials.User; import org.bukkit.Server; @@ -23,9 +20,9 @@ public void run(Server server, User user, String commandLabel, String[] args) th } user.setAcceptingPay(acceptingPay); if (acceptingPay) { - user.sendMessage(tl("payToggleOn")); + user.sendTl("payToggleOn"); } else { - user.sendMessage(tl("payToggleOff")); + user.sendTl("payToggleOff"); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandping.java b/Essentials/src/com/earth2me/essentials/commands/Commandping.java index dba0ff32780..5aca828327e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandping.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandping.java @@ -4,8 +4,6 @@ import com.earth2me.essentials.utils.FormatUtil; import org.bukkit.Server; -import static com.earth2me.essentials.I18n.tl; - // This command can be used to echo messages to the users screen, mostly useless but also an #EasterEgg public class Commandping extends EssentialsCommand { public Commandping() { @@ -16,7 +14,7 @@ public Commandping() { public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { - sender.sendMessage(tl("pong")); + sender.sendTl("pong"); } else { 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 61466aadc39..3eea2d53f94 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpotion.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpotion.java @@ -1,6 +1,5 @@ package com.earth2me.essentials.commands; -import org.bukkit.DyeColor; import com.google.common.collect.Lists; import com.earth2me.essentials.MetaItemStack; @@ -11,7 +10,6 @@ import org.bukkit.Server; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; @@ -22,8 +20,6 @@ import java.util.Set; import java.util.TreeSet; -import static com.earth2me.essentials.I18n.tl; - import net.ess3.nms.refl.ReflUtil; @@ -44,7 +40,7 @@ protected void run(final Server server, final User user, final String commandLab potionslist.add(entry.getKey()); } } - throw new NotEnoughArgumentsException(tl("potions", StringUtil.joinList(potionslist.toArray()))); + throw new NotEnoughArgumentsException(user.tl("potions", StringUtil.joinList(potionslist.toArray()))); } boolean holdingPotion = stack.getType() == Material.POTION; @@ -72,14 +68,14 @@ protected void run(final Server server, final User user, final String commandLab pmeta = (PotionMeta) mStack.getItemStack().getItemMeta(); stack.setItemMeta(pmeta); } else { - user.sendMessage(tl("invalidPotion")); + user.sendTl("invalidPotion"); throw new NotEnoughArgumentsException(); } } } } else { - throw new Exception(tl("holdPotion")); + throw new Exception(user.tl("holdPotion")); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java index 556ab8be672..f8f8497ad72 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java @@ -13,8 +13,6 @@ import java.util.List; import java.util.Locale; -import static com.earth2me.essentials.I18n.tl; - public class Commandpowertool extends EssentialsCommand { public Commandpowertool() { @@ -45,12 +43,12 @@ protected void powertool(final Server server, final CommandSource sender, final // check to see if this is a clear all command if (command != null && command.equalsIgnoreCase("d:")) { user.clearAllPowertools(); - sender.sendMessage(tl("powerToolClearAll")); + sender.sendTl("powerToolClearAll"); return; } if (itemStack == null || itemStack.getType() == Material.AIR) { - throw new Exception(tl("powerToolAir")); + throw new Exception(user.tl("powerToolAir")); } final String itemName = itemStack.getType().toString().toLowerCase(Locale.ENGLISH).replaceAll("_", " "); @@ -58,28 +56,28 @@ protected void powertool(final Server server, final CommandSource sender, final if (command != null && !command.isEmpty()) { if (command.equalsIgnoreCase("l:")) { if (powertools == null || powertools.isEmpty()) { - throw new Exception(tl("powerToolListEmpty", itemName)); + throw new Exception(user.tl("powerToolListEmpty", itemName)); } else { - sender.sendMessage(tl("powerToolList", StringUtil.joinList(powertools), itemName)); + sender.sendTl("powerToolList", StringUtil.joinList(powertools), itemName); } throw new NoChargeException(); } if (command.startsWith("r:")) { command = command.substring(2); if (!powertools.contains(command)) { - throw new Exception(tl("powerToolNoSuchCommandAssigned", command, itemName)); + throw new Exception(user.tl("powerToolNoSuchCommandAssigned", command, itemName)); } powertools.remove(command); - sender.sendMessage(tl("powerToolRemove", command, itemName)); + sender.sendTl("powerToolRemove", command, itemName); } else { if (command.startsWith("a:")) { if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.powertool.append")) { - throw new Exception(tl("noPerm", "essentials.powertool.append")); + throw new Exception(user.tl("noPerm", "essentials.powertool.append")); } command = command.substring(2); if (powertools.contains(command)) { - throw new Exception(tl("powerToolAlreadySet", command, itemName)); + throw new Exception(user.tl("powerToolAlreadySet", command, itemName)); } } else if (powertools != null && !powertools.isEmpty()) { // Replace all commands with this one @@ -89,18 +87,18 @@ protected void powertool(final Server server, final CommandSource sender, final } powertools.add(command); - sender.sendMessage(tl("powerToolAttach", StringUtil.joinList(powertools), itemName)); + sender.sendTl("powerToolAttach", StringUtil.joinList(powertools), itemName); } } else { if (powertools != null) { powertools.clear(); } - sender.sendMessage(tl("powerToolRemoveAll", itemName)); + sender.sendTl("powerToolRemoveAll", itemName); } if (!user.arePowerToolsEnabled()) { user.setPowerToolsEnabled(true); - user.sendMessage(tl("powerToolsEnabled")); + user.sendTl("powerToolsEnabled"); } user.setPowertool(itemStack, powertools); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpowertooltoggle.java b/Essentials/src/com/earth2me/essentials/commands/Commandpowertooltoggle.java index fadf3fa473c..2532cc6b5a2 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpowertooltoggle.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpowertooltoggle.java @@ -3,8 +3,6 @@ import com.earth2me.essentials.User; import org.bukkit.Server; -import static com.earth2me.essentials.I18n.tl; - public class Commandpowertooltoggle extends EssentialsCommand { public Commandpowertooltoggle() { @@ -14,9 +12,9 @@ public Commandpowertooltoggle() { @Override protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { if (!user.hasPowerTools()) { - user.sendMessage(tl("noPowerTools")); + user.sendTl("noPowerTools"); return; } - user.sendMessage(user.togglePowerToolsEnabled() ? tl("powerToolsEnabled") : tl("powerToolsDisabled")); + user.sendMessage(user.togglePowerToolsEnabled() ? user.tl("powerToolsEnabled") : user.tl("powerToolsDisabled")); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandptime.java b/Essentials/src/com/earth2me/essentials/commands/Commandptime.java index 54ffda63e3f..a90421fc043 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandptime.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandptime.java @@ -11,8 +11,6 @@ import java.util.*; -import static com.earth2me.essentials.I18n.tl; - public class Commandptime extends EssentialsCommand { private static final Set getAliases = new HashSet<>(); @@ -46,7 +44,7 @@ public void run(final Server server, final CommandSource sender, final String co if (sender.isPlayer()) { User user = ess.getUser(sender.getPlayer()); if (user != null && (!users.contains(user) || users.size() > 1) && !user.isAuthorized("essentials.ptime.others")) { - user.sendMessage(tl("pTimeOthersPermission")); + user.sendTl("pTimeOthersPermission"); return; } } @@ -81,18 +79,18 @@ public void run(final Server server, final CommandSource sender, final String co */ private void getUsersTime(final CommandSource sender, final Collection users) { if (users.size() > 1) { - sender.sendMessage(tl("pTimePlayers")); + sender.sendTl("pTimePlayers"); } for (User user : users) { if (user.getBase().getPlayerTimeOffset() == 0) { - sender.sendMessage(tl("pTimeNormal", user.getName())); + sender.sendTl("pTimeNormal", user.getName()); } else { String time = DescParseTickFormat.format(user.getBase().getPlayerTime()); if (!user.getBase().isPlayerTimeRelative()) { - sender.sendMessage(tl("pTimeCurrentFixed", user.getName(), time)); + sender.sendTl("pTimeCurrentFixed", user.getName(), time); } else { - sender.sendMessage(tl("pTimeCurrent", user.getName(), time)); + sender.sendTl("pTimeCurrent", user.getName(), time); } } } @@ -133,13 +131,13 @@ private void setUsersTime(final CommandSource sender, final Collection use // Inform the sender of the change if (ticks == null) { - sender.sendMessage(tl("pTimeReset", msg.toString())); + sender.sendTl("pTimeReset", msg.toString()); } else { String time = DescParseTickFormat.format(ticks); if (!relative) { - sender.sendMessage(tl("pTimeSetFixed", time, msg.toString())); + sender.sendTl("pTimeSetFixed", time, msg.toString()); } else { - sender.sendMessage(tl("pTimeSet", time, msg.toString())); + sender.sendTl("pTimeSet", time, msg.toString()); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpweather.java b/Essentials/src/com/earth2me/essentials/commands/Commandpweather.java index 57702a66e3f..7ef3b85b982 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpweather.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpweather.java @@ -10,8 +10,6 @@ import java.util.*; -import static com.earth2me.essentials.I18n.tl; - public class Commandpweather extends EssentialsCommand { public static final Set getAliases = new HashSet<>(); @@ -54,7 +52,7 @@ public void run(final Server server, final CommandSource sender, final String co if (sender.isPlayer()) { User user = ess.getUser(sender.getPlayer()); if (user != null && (!users.contains(user) || users.size() > 1) && !user.isAuthorized("essentials.pweather.others")) { - user.sendMessage(tl("pWeatherOthersPermission")); + user.sendTl("pWeatherOthersPermission"); return; } } @@ -67,14 +65,14 @@ public void run(final Server server, final CommandSource sender, final String co */ private void getUsersWeather(final CommandSource sender, final Collection users) { if (users.size() > 1) { - sender.sendMessage(tl("pWeatherPlayers")); + sender.sendTl("pWeatherPlayers"); } for (User user : users) { if (user.getBase().getPlayerWeather() == null) { - sender.sendMessage(tl("pWeatherNormal", user.getName())); + sender.sendTl("pWeatherNormal", user.getName()); } else { - sender.sendMessage(tl("pWeatherCurrent", user.getName(), user.getBase().getPlayerWeather().toString().toLowerCase(Locale.ENGLISH))); + sender.sendTl("pWeatherCurrent", user.getName(), user.getBase().getPlayerWeather().toString().toLowerCase(Locale.ENGLISH)); } } } @@ -98,16 +96,16 @@ private void setUsersWeather(final CommandSource sender, final Collection user.getBase().resetPlayerWeather(); } - sender.sendMessage(tl("pWeatherReset", msg)); + sender.sendTl("pWeatherReset", msg); } else { if (!weatherAliases.containsKey(weatherType)) { - throw new NotEnoughArgumentsException(tl("pWeatherInvalidAlias")); + throw new NotEnoughArgumentsException(sender.tl("pWeatherInvalidAlias")); } for (User user : users) { user.getBase().setPlayerWeather(weatherAliases.get(weatherType)); } - sender.sendMessage(tl("pWeatherSet", weatherType, msg.toString())); + sender.sendTl("pWeatherSet", weatherType, msg.toString()); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandr.java b/Essentials/src/com/earth2me/essentials/commands/Commandr.java index 67a2d1dec5f..dec4df88fb7 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandr.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandr.java @@ -7,8 +7,6 @@ import com.earth2me.essentials.utils.FormatUtil; import org.bukkit.Server; -import static com.earth2me.essentials.I18n.tl; - public class Commandr extends EssentialsCommand { public Commandr() { @@ -28,7 +26,7 @@ public void run(final Server server, final CommandSource sender, final String co User user = ess.getUser(sender.getPlayer()); if (user.isMuted()) { - throw new Exception(user.hasMuteReason() ? tl("voiceSilencedReason", user.getMuteReason()) : tl("voiceSilenced")); + throw new Exception(user.hasMuteReason() ? user.tl("voiceSilencedReason", user.getMuteReason()) : user.tl("voiceSilenced")); } message = FormatUtil.formatMessage(user, "essentials.msg", message); @@ -41,7 +39,7 @@ public void run(final Server server, final CommandSource sender, final String co final IMessageRecipient target = messageSender.getReplyRecipient(); // Check to make sure the sender does have a quick-reply recipient if (target == null) { - throw new Exception(tl("foreverAlone")); + throw new Exception(sender.tl("foreverAlone")); } messageSender.sendMessage(target, message); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java index fc97fb2980e..cfaf0006e91 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java @@ -7,8 +7,6 @@ import java.util.Locale; -import static com.earth2me.essentials.I18n.tl; - public class Commandrealname extends EssentialsCommand { public Commandrealname() { @@ -31,7 +29,7 @@ protected void run(final Server server, final CommandSource sender, final String final String displayName = FormatUtil.stripFormat(u.getDisplayName()).toLowerCase(Locale.ENGLISH); if (displayName.contains(whois)) { foundUser = true; - sender.sendMessage(tl("realName", u.getDisplayName(), u.getName())); + sender.sendTl("realName", u.getDisplayName(), u.getName()); } } if (!foundUser) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrecipe.java b/Essentials/src/com/earth2me/essentials/commands/Commandrecipe.java index f0d4ec805bb..b4bb35e733b 100755 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrecipe.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrecipe.java @@ -15,8 +15,6 @@ import java.util.Locale; import java.util.Map; -import static com.earth2me.essentials.I18n.tl; - import net.ess3.nms.refl.ReflUtil; @@ -52,21 +50,21 @@ public void run(final Server server, final CommandSource sender, final String co if (NumberUtil.isInt(args[1])) { recipeNo = Integer.parseInt(args[1]) - 1; } else { - throw new Exception(tl("invalidNumber")); + throw new Exception(sender.tl("invalidNumber")); } } final List recipesOfType = ess.getServer().getRecipesFor(itemType); if (recipesOfType.size() < 1) { - throw new Exception(tl("recipeNone", getMaterialName(itemType))); + throw new Exception(sender.tl("recipeNone", getMaterialName(sender, itemType))); } if (recipeNo < 0 || recipeNo >= recipesOfType.size()) { - throw new Exception(tl("recipeBadIndex")); + throw new Exception(sender.tl("recipeBadIndex")); } final Recipe selectedRecipe = recipesOfType.get(recipeNo); - sender.sendMessage(tl("recipe", getMaterialName(itemType), recipeNo + 1, recipesOfType.size())); + sender.sendTl("recipe", getMaterialName(sender, itemType), recipeNo + 1, recipesOfType.size()); if (selectedRecipe instanceof FurnaceRecipe) { furnaceRecipe(sender, (FurnaceRecipe) selectedRecipe); @@ -85,12 +83,12 @@ public void run(final Server server, final CommandSource sender, final String co } if (recipesOfType.size() > 1 && args.length == 1) { - sender.sendMessage(tl("recipeMore", commandLabel, args[0], getMaterialName(itemType))); + sender.sendTl("recipeMore", commandLabel, args[0], getMaterialName(sender, itemType)); } } public void furnaceRecipe(final CommandSource sender, final FurnaceRecipe recipe) { - sender.sendMessage(tl("recipeFurnace", getMaterialName(recipe.getInput()))); + sender.sendTl("recipeFurnace", getMaterialName(sender, recipe.getInput())); } public void shapedRecipe(final CommandSource sender, final ShapedRecipe recipe, final boolean showWindow) { @@ -131,15 +129,15 @@ public void shapedRecipe(final CommandSource sender, final ShapedRecipe recipe, materials[j][k] = item == null ? null : item.getType(); } } - sender.sendMessage(tl("recipeGrid", colorMap.get(materials[0][0]), colorMap.get(materials[0][1]), colorMap.get(materials[0][2]))); - sender.sendMessage(tl("recipeGrid", colorMap.get(materials[1][0]), colorMap.get(materials[1][1]), colorMap.get(materials[1][2]))); - sender.sendMessage(tl("recipeGrid", colorMap.get(materials[2][0]), colorMap.get(materials[2][1]), colorMap.get(materials[2][2]))); + sender.sendTl("recipeGrid", colorMap.get(materials[0][0]), colorMap.get(materials[0][1]), colorMap.get(materials[0][2])); + sender.sendTl("recipeGrid", colorMap.get(materials[1][0]), colorMap.get(materials[1][1]), colorMap.get(materials[1][2])); + sender.sendTl("recipeGrid", colorMap.get(materials[2][0]), colorMap.get(materials[2][1]), colorMap.get(materials[2][2])); StringBuilder s = new StringBuilder(); for (Material items : colorMap.keySet().toArray(new Material[colorMap.size()])) { - s.append(tl("recipeGridItem", colorMap.get(items), getMaterialName(items))); + s.append(sender.tl("recipeGridItem", colorMap.get(items), getMaterialName(sender, items))); } - sender.sendMessage(tl("recipeWhere", s.toString())); + sender.sendTl("recipeWhere", s.toString()); } } @@ -160,26 +158,26 @@ public void shapelessRecipe(final CommandSource sender, final ShapelessRecipe re } else { StringBuilder s = new StringBuilder(); for (int i = 0; i < ingredients.size(); i++) { - s.append(getMaterialName(ingredients.get(i))); + s.append(getMaterialName(sender, ingredients.get(i))); if (i != ingredients.size() - 1) { s.append(","); } s.append(" "); } - sender.sendMessage(tl("recipeShapeless", s.toString())); + sender.sendTl("recipeShapeless", s.toString()); } } - public String getMaterialName(final ItemStack stack) { + public String getMaterialName(final CommandSource sender, final ItemStack stack) { if (stack == null) { - return tl("recipeNothing"); + return sender.tl("recipeNothing"); } - return getMaterialName(stack.getType()); + return getMaterialName(sender, stack.getType()); } - public String getMaterialName(final Material type) { + public String getMaterialName(final CommandSource sender, final Material type) { if (type == null) { - return tl("recipeNothing"); + return sender.tl("recipeNothing"); } return type.toString().replace("_", " ").toLowerCase(Locale.ENGLISH); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandremove.java b/Essentials/src/com/earth2me/essentials/commands/Commandremove.java index 282ddc03749..b76c4a5ca7b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandremove.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandremove.java @@ -15,8 +15,6 @@ import java.util.List; import java.util.Locale; -import static com.earth2me.essentials.I18n.tl; - // This could be rewritten in a simpler form if we made a mapping of all Entity names to their types (which would also provide possible mod support) public class Commandremove extends EssentialsCommand { @@ -61,7 +59,7 @@ private void parseCommand(Server server, CommandSource sender, String[] args, Wo List customTypes = new ArrayList<>(); if (world == null) { - throw new Exception(tl("invalidWorld")); + throw new Exception(sender.tl("invalidWorld")); } if (args[0].contentEquals("*") || args[0].contentEquals("all")) { @@ -110,7 +108,7 @@ private void removeHandler(CommandSource sender, List types, List types, List history = ess.getUserMap().getUserHistory(user.getBase().getUniqueId()); if (history != null && history.size() > 1) { - sender.sendMessage(tl("seenAccounts", StringUtil.joinListSkip(", ", user.getName(), history))); + sender.sendTl("seenAccounts", StringUtil.joinListSkip(", ", user.getName(), history)); } if (user.isAfk()) { - sender.sendMessage(tl("whoisAFK", tl("true"))); + sender.sendTl("whoisAFK", sender.tl("true")); } if (user.isJailed()) { - sender.sendMessage(tl("whoisJail", (user.getJailTimeout() > 0 ? DateUtil.formatDateDiff(user.getJailTimeout()) : tl("true")))); + sender.sendTl("whoisJail", (user.getJailTimeout() > 0 ? DateUtil.formatDateDiff(sender, user.getJailTimeout()) : sender.tl("true"))); } if (user.isMuted()) { long muteTimeout = user.getMuteTimeout(); if (!user.hasMuteReason()) { - sender.sendMessage(tl("whoisMuted", (muteTimeout > 0 ? DateUtil.formatDateDiff(muteTimeout) : tl("true")))); + sender.sendTl("whoisMuted", (muteTimeout > 0 ? DateUtil.formatDateDiff(sender, muteTimeout) : sender.tl("true"))); } else { - sender.sendMessage(tl("whoisMutedReason", (muteTimeout > 0 ? DateUtil.formatDateDiff(muteTimeout) : tl("true")), user.getMuteReason())); + sender.sendTl("whoisMutedReason", (muteTimeout > 0 ? DateUtil.formatDateDiff(sender, muteTimeout) : sender.tl("true")), user.getMuteReason()); } } final String location = user.getGeoLocation(); if (location != null && (!(sender.isPlayer()) || ess.getUser(sender.getPlayer()).isAuthorized("essentials.geoip.show"))) { - sender.sendMessage(tl("whoisGeoLocation", location)); + sender.sendTl("whoisGeoLocation", location); } if (showIp) { - sender.sendMessage(tl("whoisIPAddress", user.getBase().getAddress().getAddress().toString())); + sender.sendTl("whoisIPAddress", user.getBase().getAddress().getAddress().toString()); } } private void seenOffline(final Server server, final CommandSource sender, User user, final boolean showBan, final boolean showIp, final boolean showLocation) throws Exception { user.setDisplayNick(); if (user.getLastLogout() > 0) { - sender.sendMessage(tl("seenOffline", user.getName(), DateUtil.formatDateDiff(user.getLastLogout()))); + sender.sendTl("seenOffline", user.getName(), DateUtil.formatDateDiff(sender, user.getLastLogout())); } else { - sender.sendMessage(tl("userUnknown", user.getName())); + sender.sendTl("userUnknown", user.getName()); } if (ess.getSettings().isDebug()) { @@ -147,45 +145,45 @@ private void seenOffline(final Server server, final CommandSource sender, User u List history = ess.getUserMap().getUserHistory(user.getBase().getUniqueId()); if (history != null && history.size() > 1) { - sender.sendMessage(tl("seenAccounts", StringUtil.joinListSkip(", ", user.getName(), history))); + sender.sendTl("seenAccounts", StringUtil.joinListSkip(", ", user.getName(), history)); } if (BanLookup.isBanned(ess, user)) { final BanEntry banEntry = BanLookup.getBanEntry(ess, user.getName()); - final String reason = showBan ? banEntry.getReason() : tl("true"); - sender.sendMessage(tl("whoisBanned", reason)); + final String reason = showBan ? banEntry.getReason() : sender.tl("true"); + sender.sendTl("whoisBanned", reason); if (banEntry.getExpiration() != null) { Date expiry = banEntry.getExpiration(); - String expireString = tl("now"); + String expireString = user.tl("now"); if (expiry.after(new Date())) { - expireString = DateUtil.formatDateDiff(expiry.getTime()); + expireString = DateUtil.formatDateDiff(sender, expiry.getTime()); } - sender.sendMessage(tl("whoisTempBanned", expireString)); + sender.sendTl("whoisTempBanned", expireString); } } if (user.isMuted()) { long muteTimeout = user.getMuteTimeout(); if (!user.hasMuteReason()) { - sender.sendMessage(tl("whoisMuted", (muteTimeout > 0 ? DateUtil.formatDateDiff(muteTimeout) : tl("true")))); + sender.sendTl("whoisMuted", (muteTimeout > 0 ? DateUtil.formatDateDiff(sender, muteTimeout) : sender.tl("true"))); } else { - sender.sendMessage(tl("whoisMutedReason", (muteTimeout > 0 ? DateUtil.formatDateDiff(muteTimeout) : tl("true")), user.getMuteReason())); + sender.sendTl("whoisMutedReason", (muteTimeout > 0 ? DateUtil.formatDateDiff(sender, muteTimeout) : sender.tl("true")), user.getMuteReason()); } } final String location = user.getGeoLocation(); if (location != null && (!(sender.isPlayer()) || ess.getUser(sender.getPlayer()).isAuthorized("essentials.geoip.show"))) { - sender.sendMessage(tl("whoisGeoLocation", location)); + sender.sendTl("whoisGeoLocation", location); } if (showIp) { if (!user.getLastLoginAddress().isEmpty()) { - sender.sendMessage(tl("whoisIPAddress", user.getLastLoginAddress())); + sender.sendTl("whoisIPAddress", user.getLastLoginAddress()); } } if (showLocation) { final Location loc = user.getLogoutLocation(); if (loc != null) { - sender.sendMessage(tl("whoisLocation", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); + sender.sendTl("whoisLocation", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); } } } @@ -194,10 +192,10 @@ private void seenIP(final Server server, final CommandSource sender, final Strin final UserMap userMap = ess.getUserMap(); if (ess.getServer().getBanList(BanList.Type.IP).isBanned(ipAddress)) { - sender.sendMessage(tl("isIpBanned", ipAddress)); + sender.sendTl("isIpBanned", ipAddress); } - sender.sendMessage(tl("runningPlayerMatch", ipAddress)); + sender.sendTl("runningPlayerMatch", ipAddress); ess.runTaskAsynchronously(new Runnable() { @Override @@ -217,10 +215,10 @@ public void run() { } if (matches.size() > 0) { - sender.sendMessage(tl("matchingIPAddress")); + sender.sendTl("matchingIPAddress"); sender.sendMessage(StringUtil.joinList(matches)); } else { - sender.sendMessage(tl("noMatchingPlayers")); + sender.sendTl("noMatchingPlayers"); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java index e6c41a98b4f..c8798a0b035 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java @@ -13,8 +13,6 @@ import java.util.Locale; import java.util.logging.Level; -import static com.earth2me.essentials.I18n.tl; - public class Commandsell extends EssentialsCommand { public Commandsell() { @@ -30,9 +28,9 @@ public void run(final Server server, final User user, final String commandLabel, } if (args[0].equalsIgnoreCase("hand") && !user.isAuthorized("essentials.sell.hand")) { - throw new Exception(tl("sellHandPermission")); + throw new Exception(user.tl("sellHandPermission")); } else if ((args[0].equalsIgnoreCase("inventory") || args[0].equalsIgnoreCase("invent") || args[0].equalsIgnoreCase("all")) && !user.isAuthorized("essentials.sell.bulk")) { - throw new Exception(tl("sellBulkPermission")); + throw new Exception(user.tl("sellBulkPermission")); } List is = ess.getItemDb().getMatching(user, args); @@ -60,9 +58,9 @@ public void run(final Server server, final User user, final String commandLabel, } if (count != 1) { if (args[0].equalsIgnoreCase("blocks")) { - user.sendMessage(tl("totalWorthBlocks", type, NumberUtil.displayCurrency(totalWorth, ess))); + user.sendTl("totalWorthBlocks", type, NumberUtil.displayCurrency(totalWorth, ess)); } else { - user.sendMessage(tl("totalWorthAll", type, NumberUtil.displayCurrency(totalWorth, ess))); + user.sendTl("totalWorthAll", type, NumberUtil.displayCurrency(totalWorth, ess)); } } } @@ -72,12 +70,12 @@ private BigDecimal sellItem(User user, ItemStack is, String[] args, boolean isBu BigDecimal worth = ess.getWorth().getPrice(ess, is); if (worth == null) { - throw new Exception(tl("itemCannotBeSold")); + throw new Exception(user.tl("itemCannotBeSold")); } if (amount <= 0) { if (!isBulkSell) { - user.sendMessage(tl("itemSold", NumberUtil.displayCurrency(BigDecimal.ZERO, ess), BigDecimal.ZERO, is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(worth, ess))); + user.sendTl("itemSold", NumberUtil.displayCurrency(BigDecimal.ZERO, ess), BigDecimal.ZERO, is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(worth, ess)); } return BigDecimal.ZERO; } @@ -95,8 +93,8 @@ private BigDecimal sellItem(User user, ItemStack is, String[] args, boolean isBu user.getBase().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(tl("itemSold", NumberUtil.displayCurrency(result, ess), amount, is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(worth, ess))); - logger.log(Level.INFO, tl("itemSoldConsole", user.getDisplayName(), is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(result, ess), amount, NumberUtil.displayCurrency(worth, ess))); + user.sendTl("itemSold", NumberUtil.displayCurrency(result, ess), amount, is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(worth, ess)); + logger.log(Level.INFO, user.tl("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 dd91bf61244..530c73295ba 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java @@ -8,8 +8,6 @@ import java.util.Locale; -import static com.earth2me.essentials.I18n.tl; - public class Commandsethome extends EssentialsCommand { public Commandsethome() { @@ -45,15 +43,15 @@ public void run(final Server server, final User user, final String commandLabel, name = "home"; } if ("bed".equals(name) || NumberUtil.isInt(name)) { - throw new NoSuchFieldException(tl("invalidHomeName")); + throw new NoSuchFieldException(user.tl("invalidHomeName")); } if (!ess.getSettings().isTeleportSafetyEnabled() && LocationUtil.isBlockUnsafeForUser(usersHome, location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ())) { - throw new Exception(tl("unsafeTeleportDestination", location.getWorld().getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ())); + throw new Exception(user.tl("unsafeTeleportDestination", location.getWorld().getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ())); } usersHome.setHome(name, location); - user.sendMessage(tl("homeSet", user.getLocation().getWorld().getName(), user.getLocation().getBlockX(), user.getLocation().getBlockY(), user.getLocation().getBlockZ(), name)); + user.sendTl("homeSet", user.getLocation().getWorld().getName(), user.getLocation().getBlockX(), user.getLocation().getBlockY(), user.getLocation().getBlockZ(), name); } @@ -64,7 +62,7 @@ private boolean checkHomeLimit(final User user, final User usersHome, String nam return false; } if (usersHome.getHomes().size() >= limit) { - throw new Exception(tl("maxHomes", ess.getSettings().getHomeLimit(user))); + throw new Exception(user.tl("maxHomes", ess.getSettings().getHomeLimit(user))); } if (limit == 1) { return true; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java b/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java index dbf3059e54b..8efe36df1da 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java @@ -4,8 +4,6 @@ import com.earth2me.essentials.utils.StringUtil; import org.bukkit.Server; -import static com.earth2me.essentials.I18n.tl; - public class Commandsetjail extends EssentialsCommand { public Commandsetjail() { @@ -18,7 +16,7 @@ public void run(final Server server, final User user, final String commandLabel, throw new NotEnoughArgumentsException(); } ess.getJails().setJail(args[0], user.getLocation()); - user.sendMessage(tl("jailSet", StringUtil.sanitizeString(args[0]))); + user.sendTl("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 a6cf878f661..23998f1dd34 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java @@ -8,8 +8,6 @@ import org.bukkit.Location; import org.bukkit.Server; -import static com.earth2me.essentials.I18n.tl; - public class Commandsetwarp extends EssentialsCommand { public Commandsetwarp() { @@ -23,7 +21,7 @@ public void run(final Server server, final User user, final String commandLabel, } if (NumberUtil.isInt(args[0]) || args[0].isEmpty()) { - throw new NoSuchFieldException(tl("invalidWarpName")); + throw new NoSuchFieldException(user.tl("invalidWarpName")); } final Location loc = user.getLocation(); @@ -38,8 +36,8 @@ public void run(final Server server, final User user, final String commandLabel, if (warpLoc == null || user.isAuthorized("essentials.warp.overwrite." + StringUtil.safeString(args[0]))) { warps.setWarp(user, args[0], loc); } else { - throw new Exception(tl("warpOverwrite")); + throw new Exception(user.tl("warpOverwrite")); } - user.sendMessage(tl("warpSet", args[0])); + user.sendTl("warpSet", args[0]); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java b/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java index d3e61c5283b..c3ed4e475e9 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java @@ -6,8 +6,6 @@ import org.bukkit.Server; import org.bukkit.inventory.ItemStack; -import static com.earth2me.essentials.I18n.tl; - public class Commandsetworth extends EssentialsCommand { public Commandsetworth() { @@ -32,7 +30,7 @@ public void run(final Server server, final User user, final String commandLabel, } ess.getWorth().setPrice(ess, stack, FloatUtil.parseDouble(price)); - user.sendMessage(tl("worthSet")); + user.sendTl("worthSet"); } @Override @@ -43,6 +41,6 @@ public void run(final Server server, final CommandSource sender, final String co ItemStack stack = ess.getItemDb().get(args[0]); ess.getWorth().setPrice(ess, stack, FloatUtil.parseDouble(args[1])); - sender.sendMessage(tl("worthSet")); + sender.sendTl("worthSet"); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandshowkit.java b/Essentials/src/com/earth2me/essentials/commands/Commandshowkit.java index b280b02df29..773ab051913 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandshowkit.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandshowkit.java @@ -9,8 +9,6 @@ import java.util.List; import java.util.Locale; -import static com.earth2me.essentials.I18n.tl; - public class Commandshowkit extends EssentialsCommand { public Commandshowkit() { @@ -26,9 +24,9 @@ public void run(final Server server, final User user, final String commandLabel, final String[] kits = args[0].toLowerCase(Locale.ENGLISH).split(","); for (final String kitName : kits) { Kit kit = new Kit(kitName, ess); - user.sendMessage(tl("kitContains", kitName)); + user.sendTl("kitContains", kitName); for (String s : kit.getItems()) { - user.sendMessage(tl("kitItem", s)); + user.sendTl("kitItem", s); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandskull.java b/Essentials/src/com/earth2me/essentials/commands/Commandskull.java index 5cb06a865f9..7603cde02ab 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandskull.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandskull.java @@ -13,8 +13,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandskull extends EssentialsCommand { private static final Material SKULL_ITEM = EnumUtil.getMaterial("PLAYER_HEAD", "SKULL_ITEM"); @@ -29,7 +27,7 @@ protected void run(final Server server, final User user, final String commandLab if (args.length > 0 && user.isAuthorized("essentials.skull.others")) { if (!args[0].matches("^[A-Za-z0-9_]+$")) { - throw new IllegalArgumentException(tl("alphaNames")); + throw new IllegalArgumentException(user.tl("alphaNames")); } owner = args[0]; } else { @@ -47,11 +45,11 @@ protected void run(final Server server, final User user, final String commandLab metaSkull = (SkullMeta) itemSkull.getItemMeta(); spawn = true; } else { - throw new Exception(tl("invalidSkull")); + throw new Exception(user.tl("invalidSkull")); } if (metaSkull.hasOwner() && !user.isAuthorized("essentials.skull.modify")) { - throw new Exception(tl("noPermissionSkull")); + throw new Exception(user.tl("noPermissionSkull")); } metaSkull.setDisplayName("§fSkull of " + owner); @@ -61,9 +59,9 @@ protected void run(final Server server, final User user, final String commandLab if (spawn) { InventoryWorkaround.addItems(user.getBase().getInventory(), itemSkull); - user.sendMessage(tl("givenSkull", owner)); + user.sendTl("givenSkull", owner); } else { - user.sendMessage(tl("skullChanged", owner)); + user.sendTl("skullChanged", owner); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsocialspy.java b/Essentials/src/com/earth2me/essentials/commands/Commandsocialspy.java index 76ce77ac509..ab113f7f00a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsocialspy.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsocialspy.java @@ -4,8 +4,6 @@ import com.earth2me.essentials.User; import org.bukkit.Server; -import static com.earth2me.essentials.I18n.tl; - public class Commandsocialspy extends EssentialsToggleCommand { public Commandsocialspy() { @@ -31,9 +29,9 @@ void togglePlayer(CommandSource sender, User user, Boolean enabled) throws NotEn user.setSocialSpyEnabled(enabled); - user.sendMessage(tl("socialSpy", user.getDisplayName(), enabled ? tl("enabled") : tl("disabled"))); + user.sendTl("socialSpy", user.getDisplayName(), enabled ? user.tl("enabled") : user.tl("disabled")); if (!sender.isPlayer() || !sender.getPlayer().equals(user.getBase())) { - sender.sendMessage(tl("socialSpy", user.getDisplayName(), enabled ? tl("enabled") : tl("disabled"))); + sender.sendTl("socialSpy", user.getDisplayName(), enabled ? user.tl("enabled") : user.tl("disabled")); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java index ee079d6789d..2b992c7c518 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java @@ -14,8 +14,6 @@ import java.util.Locale; -import static com.earth2me.essentials.I18n.tl; - public class Commandspawner extends EssentialsCommand { public Commandspawner() { @@ -25,14 +23,14 @@ public Commandspawner() { @Override protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { if (args.length < 1 || args[0].length() < 2) { - throw new NotEnoughArgumentsException(tl("mobsAvailable", StringUtil.joinList(Mob.getMobList()))); + throw new NotEnoughArgumentsException(user.tl("mobsAvailable", StringUtil.joinList(Mob.getMobList()))); } final Location target = LocationUtil.getTarget(user.getBase()); Material MOB_SPAWNER = EnumUtil.getMaterial("SPAWNER", "MOB_SPAWNER"); if (target == null || target.getBlock().getType() != MOB_SPAWNER) { - throw new Exception(tl("mobSpawnTarget")); + throw new Exception(user.tl("mobSpawnTarget")); } String name = args[0]; @@ -41,13 +39,13 @@ protected void run(final Server server, final User user, final String commandLab Mob mob = null; mob = Mob.fromName(name); if (mob == null) { - throw new Exception(tl("invalidMob")); + throw new Exception(user.tl("invalidMob")); } if (ess.getSettings().getProtectPreventSpawn(mob.getType().toString().toLowerCase(Locale.ENGLISH))) { - throw new Exception(tl("disabledToSpawnMob")); + throw new Exception(user.tl("disabledToSpawnMob")); } if (!user.isAuthorized("essentials.spawner." + mob.name.toLowerCase(Locale.ENGLISH))) { - throw new Exception(tl("noPermToSpawnMob")); + throw new Exception(user.tl("noPermToSpawnMob")); } if (args.length > 1) { if (NumberUtil.isInt(args[1])) { @@ -62,10 +60,10 @@ protected void run(final Server server, final User user, final String commandLab spawner.setDelay(delay); spawner.update(); } catch (Throwable ex) { - throw new Exception(tl("mobSpawnError"), ex); + throw new Exception(user.tl("mobSpawnError"), ex); } charge.charge(user); - user.sendMessage(tl("setSpawner", mob.name)); + user.sendTl("setSpawner", mob.name); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java index b8f3c400239..9fff97bdbd5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java @@ -9,8 +9,6 @@ import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandspawnmob extends EssentialsCommand { public Commandspawnmob() { @@ -21,7 +19,7 @@ public Commandspawnmob() { public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { final String mobList = SpawnMob.mobList(user); - throw new NotEnoughArgumentsException(tl("mobsAvailable", mobList)); + throw new NotEnoughArgumentsException(user.tl("mobsAvailable", mobList)); } List mobParts = SpawnMob.mobParts(args[0]); @@ -33,7 +31,7 @@ public void run(final Server server, final User user, final String commandLabel, } if (mobParts.size() > 1 && !user.isAuthorized("essentials.spawnmob.stack")) { - throw new Exception(tl("cannotStackMob")); + throw new Exception(user.tl("cannotStackMob")); } if (args.length >= 3) { @@ -49,7 +47,7 @@ public void run(final Server server, final User user, final String commandLabel, public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 3) { final String mobList = StringUtil.joinList(Mob.getMobList()); - throw new NotEnoughArgumentsException(tl("mobsAvailable", mobList)); + throw new NotEnoughArgumentsException(sender.tl("mobsAvailable", mobList)); } List mobParts = SpawnMob.mobParts(args[0]); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspeed.java b/Essentials/src/com/earth2me/essentials/commands/Commandspeed.java index 13061b23d43..e84d67fa4df 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspeed.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspeed.java @@ -9,8 +9,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandspeed extends EssentialsCommand { public Commandspeed() { @@ -53,10 +51,10 @@ protected void run(final Server server, final User user, final String commandLab if (isFly) { user.getBase().setFlySpeed(getRealMoveSpeed(speed, isFly, isBypass)); - user.sendMessage(tl("moveSpeed", tl("flying"), speed, user.getDisplayName())); + user.sendTl("moveSpeed", user.tl("flying"), speed, user.getDisplayName()); } else { user.getBase().setWalkSpeed(getRealMoveSpeed(speed, isFly, isBypass)); - user.sendMessage(tl("moveSpeed", tl("walking"), speed, user.getDisplayName())); + user.sendTl("moveSpeed", user.tl("walking"), speed, user.getDisplayName()); } } @@ -72,10 +70,10 @@ private void speedOtherPlayers(final Server server, final CommandSource sender, foundUser = true; if (isFly) { matchPlayer.setFlySpeed(getRealMoveSpeed(speed, isFly, isBypass)); - sender.sendMessage(tl("moveSpeed", tl("flying"), speed, matchPlayer.getDisplayName())); + sender.sendTl("moveSpeed", sender.tl("flying"), speed, matchPlayer.getDisplayName()); } else { matchPlayer.setWalkSpeed(getRealMoveSpeed(speed, isFly, isBypass)); - sender.sendMessage(tl("moveSpeed", tl("walking"), speed, matchPlayer.getDisplayName())); + sender.sendTl("moveSpeed", sender.tl("walking"), speed, matchPlayer.getDisplayName()); } } if (!foundUser) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsudo.java b/Essentials/src/com/earth2me/essentials/commands/Commandsudo.java index 7a92e360c14..9ac95fdb4f7 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsudo.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsudo.java @@ -8,8 +8,6 @@ import java.util.Locale; -import static com.earth2me.essentials.I18n.tl; - public class Commandsudo extends EssentialsLoopCommand { public Commandsudo() { @@ -30,7 +28,7 @@ public void run(final Server server, final CommandSource sender, final String co final String command = getFinalArg(arguments, 0); boolean multiple = !sender.isPlayer() ? true : ess.getUser(sender.getPlayer()).isAuthorized("essentials.sudo.multiple"); - sender.sendMessage(tl("sudoRun", args[0], command, "")); + sender.sendTl("sudoRun", args[0], command, ""); loopOnlinePlayers(server, sender, multiple, multiple, args[0], new String[]{command}); } @@ -41,7 +39,7 @@ protected void updatePlayer(final Server server, final CommandSource sender, fin } if (user.isAuthorized("essentials.sudo.exempt") && sender.isPlayer()) { - sender.sendMessage(tl("sudoExempt", user.getName())); + sender.sendTl("sudoExempt", user.getName()); return; } @@ -58,7 +56,7 @@ public void run() { try { user.getBase().chat("/" + command); } catch (Exception e) { - sender.sendMessage(tl("errorCallingCommand", command)); + sender.sendTl("errorCallingCommand", command); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java b/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java index e9b13849d08..25a0c15228f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java @@ -4,8 +4,6 @@ import org.bukkit.Server; import org.bukkit.event.entity.EntityDamageEvent; -import static com.earth2me.essentials.I18n.tl; - public class Commandsuicide extends EssentialsCommand { public Commandsuicide() { @@ -21,8 +19,8 @@ public void run(final Server server, final User user, final String commandLabel, if (user.getBase().getHealth() > 0) { user.getBase().setHealth(0); } - user.sendMessage(tl("suicideMessage")); + user.sendTl("suicideMessage"); user.setDisplayNick(); - ess.broadcastMessage(user, tl("suicideSuccess", user.getDisplayName())); + ess.broadcastMessage(user, user.tl("suicideSuccess", user.getDisplayName())); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java b/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java index b0f03db29bf..d5741ddf8ce 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java @@ -7,14 +7,11 @@ import org.bukkit.BanList; import org.bukkit.Server; -import java.util.Collections; import java.util.Date; import java.util.GregorianCalendar; import java.util.List; import java.util.logging.Level; -import static com.earth2me.essentials.I18n.tl; - public class Commandtempban extends EssentialsCommand { public Commandtempban() { @@ -29,12 +26,12 @@ public void run(final Server server, final CommandSource sender, final String co final User user = getPlayer(server, args, 0, true, true); if (!user.getBase().isOnline()) { if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.tempban.offline")) { - sender.sendMessage(tl("tempbanExemptOffline")); + sender.sendTl("tempbanExemptOffline"); return; } } else { if (user.isAuthorized("essentials.tempban.exempt") && sender.isPlayer()) { - sender.sendMessage(tl("tempbanExempt")); + sender.sendTl("tempbanExempt"); return; } } @@ -44,22 +41,22 @@ public void run(final Server server, final CommandSource sender, final String co final long maxBanLength = ess.getSettings().getMaxTempban() * 1000; if (maxBanLength > 0 && ((banTimestamp - GregorianCalendar.getInstance().getTimeInMillis()) > maxBanLength) && sender.isPlayer() && !(ess.getUser(sender.getPlayer()).isAuthorized("essentials.tempban.unlimited"))) { - sender.sendMessage(tl("oversizedTempban")); + sender.sendTl("oversizedTempban"); throw new NoChargeException(); } if (banReason.length() < 2) { - banReason = tl("defaultBanReason"); + banReason = user.tl("defaultBanReason"); } final String senderName = sender.isPlayer() ? sender.getPlayer().getDisplayName() : Console.NAME; ess.getServer().getBanList(BanList.Type.NAME).addBan(user.getName(), banReason, new Date(banTimestamp), senderName); - final String expiry = DateUtil.formatDateDiff(banTimestamp); + final String expiry = DateUtil.formatDateDiff(sender, banTimestamp); - final String banDisplay = tl("tempBanned", expiry, senderName, banReason); + final String banDisplay = user.tl("tempBanned", expiry, senderName, banReason); user.getBase().kickPlayer(banDisplay); - final String message = tl("playerTempBanned", senderName, user.getName(), expiry, banReason); + final String message = user.tl("playerTempBanned", senderName, user.getName(), expiry, banReason); server.getLogger().log(Level.INFO, message); ess.broadcastMessage("essentials.ban.notify", message); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandthunder.java b/Essentials/src/com/earth2me/essentials/commands/Commandthunder.java index 48dfc272786..1d56356ff33 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandthunder.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandthunder.java @@ -8,8 +8,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandthunder extends EssentialsCommand { public Commandthunder() { @@ -28,11 +26,11 @@ public void run(final Server server, final User user, final String commandLabel, world.setThundering(setThunder); world.setThunderDuration(Integer.parseInt(args[1]) * 20); - user.sendMessage(tl("thunderDuration", (setThunder ? tl("enabled") : tl("disabled")), Integer.parseInt(args[1]))); + user.sendTl("thunderDuration", (setThunder ? user.tl("enabled") : user.tl("disabled")), Integer.parseInt(args[1])); } else { world.setThundering(setThunder); - user.sendMessage(tl("thunder", setThunder ? tl("enabled") : tl("disabled"))); + user.sendTl("thunder", setThunder ? user.tl("enabled") : user.tl("disabled")); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtime.java b/Essentials/src/com/earth2me/essentials/commands/Commandtime.java index de6510fb26a..394ff7e3176 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtime.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtime.java @@ -10,8 +10,6 @@ import java.util.*; -import static com.earth2me.essentials.I18n.tl; - public class Commandtime extends EssentialsCommand { public Commandtime() { @@ -55,7 +53,7 @@ public void run(final Server server, final CommandSource sender, final String co final User user = ess.getUser(sender.getPlayer()); if (user != null && !user.isAuthorized("essentials.time.set")) { - throw new Exception(tl("timeSetPermission")); + throw new Exception(sender.tl("timeSetPermission")); } // Parse the target time int ticks from args[0] @@ -80,7 +78,7 @@ private void getWorldsTime(final CommandSource sender, final Collection w } for (World world : worlds) { - sender.sendMessage(tl("timeWorldCurrent", world.getName(), DescParseTickFormat.format(world.getTime()))); + sender.sendTl("timeWorldCurrent", world.getName(), DescParseTickFormat.format(world.getTime())); } } @@ -91,7 +89,7 @@ private void setWorldsTime(final CommandSource sender, final Collection w User user = ess.getUser(sender.getPlayer()); for (World world : worlds) { if (!canUpdateWorld(user, world)) { - throw new Exception(tl("timeSetWorldPermission", user.getWorld().getName())); + throw new Exception(user.tl("timeSetWorldPermission", user.getWorld().getName())); } } @@ -113,7 +111,7 @@ private void setWorldsTime(final CommandSource sender, final Collection w output.append(world.getName()); } - sender.sendMessage(tl("timeWorldSet", DescParseTickFormat.format(ticks), output.toString())); + sender.sendTl("timeWorldSet", DescParseTickFormat.format(ticks), output.toString()); } /** @@ -145,7 +143,7 @@ else if (selector.equalsIgnoreCase("*") || selector.equalsIgnoreCase("all")) { } // We failed to understand the world target... else { - throw new Exception(tl("invalidWorld")); + throw new Exception(sender.tl("invalidWorld")); } return worlds; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java b/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java index 080f665925f..d2d7a5b4467 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java @@ -10,8 +10,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandtogglejail extends EssentialsCommand { public Commandtogglejail() { @@ -29,12 +27,12 @@ public void run(final Server server, final CommandSource sender, final String co if (args.length >= 2 && !player.isJailed()) { if (!player.getBase().isOnline()) { if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.togglejail.offline")) { - sender.sendMessage(tl("mayNotJailOffline")); + sender.sendTl("mayNotJailOffline"); return; } } else { if (player.isAuthorized("essentials.jail.exempt")) { - sender.sendMessage(tl("mayNotJail")); + sender.sendTl("mayNotJail"); return; } } @@ -50,7 +48,7 @@ public void run(final Server server, final CommandSource sender, final String co ess.getJails().getJail(args[1]); } player.setJailed(true); - player.sendMessage(tl("userJailed")); + player.sendTl("userJailed"); player.setJail(null); player.setJail(args[1]); long timeDiff = 0; @@ -59,13 +57,13 @@ public void run(final Server server, final CommandSource sender, final String co timeDiff = DateUtil.parseDateDiff(time, true); player.setJailTimeout(timeDiff); } - sender.sendMessage((timeDiff > 0 ? tl("playerJailedFor", player.getName(), DateUtil.formatDateDiff(timeDiff)) : tl("playerJailed", player.getName()))); + sender.sendMessage((timeDiff > 0 ? sender.tl("playerJailedFor", player.getName(), DateUtil.formatDateDiff(sender, timeDiff)) : sender.tl("playerJailed", player.getName()))); } return; } if (args.length >= 2 && player.isJailed() && !args[1].equalsIgnoreCase(player.getJail())) { - sender.sendMessage(tl("jailAlreadyIncarcerated", player.getJail())); + sender.sendTl("jailAlreadyIncarcerated", player.getJail()); return; } @@ -73,7 +71,7 @@ public void run(final Server server, final CommandSource sender, final String co final String time = getFinalArg(args, 2); final long timeDiff = DateUtil.parseDateDiff(time, true); player.setJailTimeout(timeDiff); - sender.sendMessage(tl("jailSentenceExtended", DateUtil.formatDateDiff(timeDiff))); + sender.sendTl("jailSentenceExtended", DateUtil.formatDateDiff(sender, timeDiff)); return; } @@ -88,12 +86,12 @@ public void run(final Server server, final CommandSource sender, final String co if (!event.isCancelled()) { player.setJailed(false); player.setJailTimeout(0); - player.sendMessage(tl("jailReleasedPlayerNotify")); + player.sendTl("jailReleasedPlayerNotify"); player.setJail(null); if (player.getBase().isOnline()) { player.getTeleport().back(); } - sender.sendMessage(tl("jailReleased", player.getName())); + sender.sendTl("jailReleased", player.getName()); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtop.java b/Essentials/src/com/earth2me/essentials/commands/Commandtop.java index 6b60d2de647..4a81b622d74 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtop.java @@ -7,8 +7,6 @@ import org.bukkit.Server; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import static com.earth2me.essentials.I18n.tl; - public class Commandtop extends EssentialsCommand { public Commandtop() { @@ -23,7 +21,7 @@ public void run(final Server server, final User user, final String commandLabel, final float yaw = user.getLocation().getYaw(); final Location loc = LocationUtil.getSafeDestination(new Location(user.getWorld(), topX, user.getWorld().getMaxHeight(), topZ, yaw, pitch)); user.getTeleport().teleport(loc, new Trade(this.getName(), ess), TeleportCause.COMMAND); - user.sendMessage(tl("teleportTop", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); + user.sendTl("teleportTop", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtp.java b/Essentials/src/com/earth2me/essentials/commands/Commandtp.java index 535ae1d9e60..f17f3eb9f57 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtp.java @@ -11,8 +11,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandtp extends EssentialsCommand { public Commandtp() { @@ -28,10 +26,10 @@ public void run(final Server server, final User user, final String commandLabel, case 1: final User player = getPlayer(server, user, args, 0); if (!player.isTeleportEnabled()) { - throw new Exception(tl("teleportDisabled", player.getDisplayName())); + throw new Exception(user.tl("teleportDisabled", player.getDisplayName())); } if (user.getWorld() != player.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + player.getWorld().getName())) { - throw new Exception(tl("noPerm", "essentials.worlds." + player.getWorld().getName())); + throw new Exception(user.tl("noPerm", "essentials.worlds." + player.getWorld().getName())); } final Trade charge = new Trade(this.getName(), ess); charge.isAffordableFor(user); @@ -39,57 +37,57 @@ public void run(final Server server, final User user, final String commandLabel, throw new NoChargeException(); case 3: if (!user.isAuthorized("essentials.tp.position")) { - throw new Exception(tl("noPerm", "essentials.tp.position")); + throw new Exception(user.tl("noPerm", "essentials.tp.position")); } final double x2 = args[0].startsWith("~") ? user.getLocation().getX() + (args[0].length() > 1 ? Double.parseDouble(args[0].substring(1)) : 0) : Double.parseDouble(args[0]); final double y2 = args[1].startsWith("~") ? user.getLocation().getY() + (args[1].length() > 1 ? Double.parseDouble(args[1].substring(1)) : 0) : Double.parseDouble(args[1]); final double z2 = args[2].startsWith("~") ? user.getLocation().getZ() + (args[2].length() > 1 ? Double.parseDouble(args[2].substring(1)) : 0) : Double.parseDouble(args[2]); if (x2 > 30000000 || y2 > 30000000 || z2 > 30000000 || x2 < -30000000 || y2 < -30000000 || z2 < -30000000) { - throw new NotEnoughArgumentsException(tl("teleportInvalidLocation")); + throw new NotEnoughArgumentsException(user.tl("teleportInvalidLocation")); } final Location locpos = new Location(user.getWorld(), x2, y2, z2, user.getLocation().getYaw(), user.getLocation().getPitch()); user.getTeleport().now(locpos, false, TeleportCause.COMMAND); - user.sendMessage(tl("teleporting", locpos.getWorld().getName(), locpos.getBlockX(), locpos.getBlockY(), locpos.getBlockZ())); + user.sendTl("teleporting", locpos.getWorld().getName(), locpos.getBlockX(), locpos.getBlockY(), locpos.getBlockZ()); break; case 4: if (!user.isAuthorized("essentials.tp.others")) { - throw new Exception(tl("noPerm", "essentials.tp.others")); + throw new Exception(user.tl("noPerm", "essentials.tp.others")); } if (!user.isAuthorized("essentials.tp.position")) { - throw new Exception(tl("noPerm", "essentials.tp.position")); + throw new Exception(user.tl("noPerm", "essentials.tp.position")); } final User target2 = getPlayer(server, user, args, 0); final double x = args[1].startsWith("~") ? target2.getLocation().getX() + (args[1].length() > 1 ? Double.parseDouble(args[1].substring(1)) : 0) : Double.parseDouble(args[1]); final double y = args[2].startsWith("~") ? target2.getLocation().getY() + (args[2].length() > 1 ? Double.parseDouble(args[2].substring(1)) : 0) : Double.parseDouble(args[2]); final double z = args[3].startsWith("~") ? target2.getLocation().getZ() + (args[3].length() > 1 ? Double.parseDouble(args[3].substring(1)) : 0) : Double.parseDouble(args[3]); if (x > 30000000 || y > 30000000 || z > 30000000 || x < -30000000 || y < -30000000 || z < -30000000) { - throw new NotEnoughArgumentsException(tl("teleportInvalidLocation")); + throw new NotEnoughArgumentsException(user.tl("teleportInvalidLocation")); } final Location locposother = new Location(target2.getWorld(), x, y, z, target2.getLocation().getYaw(), target2.getLocation().getPitch()); if (!target2.isTeleportEnabled()) { - throw new Exception(tl("teleportDisabled", target2.getDisplayName())); + throw new Exception(user.tl("teleportDisabled", target2.getDisplayName())); } - user.sendMessage(tl("teleporting", locposother.getWorld().getName(), locposother.getBlockX(), locposother.getBlockY(), locposother.getBlockZ())); + user.sendTl("teleporting", locposother.getWorld().getName(), locposother.getBlockX(), locposother.getBlockY(), locposother.getBlockZ()); target2.getTeleport().now(locposother, false, TeleportCause.COMMAND); - target2.sendMessage(tl("teleporting", locposother.getWorld().getName(), locposother.getBlockX(), locposother.getBlockY(), locposother.getBlockZ())); + target2.sendTl("teleporting", locposother.getWorld().getName(), locposother.getBlockX(), locposother.getBlockY(), locposother.getBlockZ()); break; case 2: default: if (!user.isAuthorized("essentials.tp.others")) { - throw new Exception(tl("noPerm", "essentials.tp.others")); + throw new Exception(user.tl("noPerm", "essentials.tp.others")); } final User target = getPlayer(server, user, args, 0); final User toPlayer = getPlayer(server, user, args, 1); if (!target.isTeleportEnabled()) { - throw new Exception(tl("teleportDisabled", target.getDisplayName())); + throw new Exception(user.tl("teleportDisabled", target.getDisplayName())); } if (!toPlayer.isTeleportEnabled()) { - throw new Exception(tl("teleportDisabled", toPlayer.getDisplayName())); + throw new Exception(user.tl("teleportDisabled", toPlayer.getDisplayName())); } if (target.getWorld() != toPlayer.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + toPlayer.getWorld().getName())) { - throw new Exception(tl("noPerm", "essentials.worlds." + toPlayer.getWorld().getName())); + throw new Exception(user.tl("noPerm", "essentials.worlds." + toPlayer.getWorld().getName())); } - target.sendMessage(tl("teleportAtoB", user.getDisplayName(), toPlayer.getDisplayName())); + target.sendTl("teleportAtoB", user.getDisplayName(), toPlayer.getDisplayName()); target.getTeleport().now(toPlayer.getBase(), false, TeleportCause.COMMAND); break; } @@ -104,19 +102,19 @@ public void run(final Server server, final CommandSource sender, final String co final User target = getPlayer(server, args, 0, true, false); if (args.length == 2) { final User toPlayer = getPlayer(server, args, 1, true, false); - target.sendMessage(tl("teleportAtoB", Console.NAME, toPlayer.getDisplayName())); + target.sendTl("teleportAtoB", Console.NAME, toPlayer.getDisplayName()); target.getTeleport().now(toPlayer.getBase(), false, TeleportCause.COMMAND); } else if (args.length > 3) { final double x = args[1].startsWith("~") ? target.getLocation().getX() + (args[1].length() > 1 ? Double.parseDouble(args[1].substring(1)) : 0) : Double.parseDouble(args[1]); final double y = args[2].startsWith("~") ? target.getLocation().getY() + (args[2].length() > 1 ? Double.parseDouble(args[2].substring(1)) : 0) : Double.parseDouble(args[2]); final double z = args[3].startsWith("~") ? target.getLocation().getZ() + (args[3].length() > 1 ? Double.parseDouble(args[3].substring(1)) : 0) : Double.parseDouble(args[3]); if (x > 30000000 || y > 30000000 || z > 30000000 || x < -30000000 || y < -30000000 || z < -30000000) { - throw new NotEnoughArgumentsException(tl("teleportInvalidLocation")); + throw new NotEnoughArgumentsException(sender.tl("teleportInvalidLocation")); } final Location loc = new Location(target.getWorld(), x, y, z, target.getLocation().getYaw(), target.getLocation().getPitch()); - sender.sendMessage(tl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); + sender.sendTl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); target.getTeleport().now(loc, false, TeleportCause.COMMAND); - target.sendMessage(tl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); + target.sendTl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); } else { throw new NotEnoughArgumentsException(); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java index ece18ded35c..2417b30e93d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java @@ -9,8 +9,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandtpa extends EssentialsCommand { public Commandtpa() { @@ -28,38 +26,38 @@ public void run(Server server, User user, String commandLabel, String[] args) th throw new NotEnoughArgumentsException(); } if (!player.isTeleportEnabled()) { - throw new Exception(tl("teleportDisabled", player.getDisplayName())); + throw new Exception(user.tl("teleportDisabled", player.getDisplayName())); } if (user.getWorld() != player.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + player.getWorld().getName())) { - throw new Exception(tl("noPerm", "essentials.worlds." + player.getWorld().getName())); + throw new Exception(user.tl("noPerm", "essentials.worlds." + player.getWorld().getName())); } // Don't let sender request teleport twice to the same player. if (user.getConfigUUID().equals(player.getTeleportRequest()) && player.hasOutstandingTeleportRequest() // Check timeout && player.isTpRequestHere() == false) { // Make sure the last teleport request was actually tpa and not tpahere - throw new Exception(tl("requestSentAlready", player.getDisplayName())); + throw new Exception(user.tl("requestSentAlready", player.getDisplayName())); } if (player.isAutoTeleportEnabled() && !player.isIgnoredPlayer(user)) { final Trade charge = new Trade(this.getName(), ess); Teleport teleport = user.getTeleport(); teleport.setTpType(Teleport.TeleportType.TPA); teleport.teleport(player.getBase(), charge, PlayerTeleportEvent.TeleportCause.COMMAND); - player.sendMessage(tl("requestAcceptedAuto", user.getDisplayName())); - user.sendMessage(tl("requestAcceptedFromAuto", player.getDisplayName())); + player.sendTl("requestAcceptedAuto", user.getDisplayName()); + user.sendTl("requestAcceptedFromAuto", player.getDisplayName()); return; } if (!player.isIgnoredPlayer(user)) { player.requestTeleport(user, false); - player.sendMessage(tl("teleportRequest", user.getDisplayName())); - player.sendMessage(tl("typeTpaccept")); - player.sendMessage(tl("typeTpdeny")); + player.sendTl("teleportRequest", user.getDisplayName()); + player.sendTl("typeTpaccept"); + player.sendTl("typeTpdeny"); if (ess.getSettings().getTpaAcceptCancellation() != 0) { - player.sendMessage(tl("teleportRequestTimeoutInfo", ess.getSettings().getTpaAcceptCancellation())); + player.sendTl("teleportRequestTimeoutInfo", ess.getSettings().getTpaAcceptCancellation()); } } - user.sendMessage(tl("requestSent", player.getDisplayName())); + user.sendTl("requestSent", player.getDisplayName()); if (user.isAuthorized("essentials.tpacancel")) { - user.sendMessage(tl("typeTpacancel")); + user.sendTl("typeTpacancel"); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java index 0d3adb6b9c3..9a3152b716a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java @@ -7,8 +7,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandtpaall extends EssentialsCommand { public Commandtpaall() { @@ -30,7 +28,7 @@ public void run(final Server server, final CommandSource sender, final String co } private void teleportAAllPlayers(final Server server, final CommandSource sender, final User target) { - sender.sendMessage(tl("teleportAAll")); + sender.sendTl("teleportAAll"); for (User player : ess.getOnlineUsers()) { if (target == player) { continue; @@ -38,15 +36,15 @@ private void teleportAAllPlayers(final Server server, final CommandSource sender if (!player.isTeleportEnabled()) { continue; } - if (sender.equals(target.getBase()) && target.getWorld() != player.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !target.isAuthorized("essentials.worlds." + target.getWorld().getName())) { + if (sender.getSender().equals(target.getBase()) && target.getWorld() != player.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !target.isAuthorized("essentials.worlds." + target.getWorld().getName())) { continue; } try { player.requestTeleport(target, true); - player.sendMessage(tl("teleportHereRequest", target.getDisplayName())); - player.sendMessage(tl("typeTpaccept")); + player.sendTl("teleportHereRequest", target.getDisplayName()); + player.sendTl("typeTpaccept"); if (ess.getSettings().getTpaAcceptCancellation() != 0) { - player.sendMessage(tl("teleportRequestTimeoutInfo", ess.getSettings().getTpaAcceptCancellation())); + player.sendTl("teleportRequestTimeoutInfo", ess.getSettings().getTpaAcceptCancellation()); } } catch (Exception ex) { ess.showError(sender, ex, getName()); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpacancel.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpacancel.java index 9c949445eb2..759427653db 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpacancel.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpacancel.java @@ -1,8 +1,5 @@ package com.earth2me.essentials.commands; -import static com.earth2me.essentials.I18n.tl; - -import com.earth2me.essentials.I18n; import com.earth2me.essentials.User; import net.ess3.api.IEssentials; @@ -45,14 +42,14 @@ public void run(final Server server, final User user, final String commandLabel, } } if (cancellations > 0) { - user.sendMessage(tl("teleportRequestAllCancelled", cancellations)); + user.sendTl("teleportRequestAllCancelled", cancellations); } else { - throw new Exception(tl("noPendingRequest")); + throw new Exception(user.tl("noPendingRequest")); } } else { User targetPlayer = getPlayer(server, user, args, 0); if (cancelTeleportRequest(ess, targetPlayer, user)) { - user.sendMessage(tl("teleportRequestSpecificCancelled", targetPlayer.getName())); + user.sendTl("teleportRequestSpecificCancelled", targetPlayer.getName()); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java index ab7a6127066..2f54082350e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java @@ -7,8 +7,6 @@ import org.bukkit.Server; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import static com.earth2me.essentials.I18n.tl; - public class Commandtpaccept extends EssentialsCommand { public Commandtpaccept() { @@ -21,33 +19,33 @@ public void run(final Server server, final User user, final String commandLabel, try { requester = ess.getUser(user.getTeleportRequest()); } catch (Exception ex) { - throw new Exception(tl("noPendingRequest")); + throw new Exception(user.tl("noPendingRequest")); } if (!requester.getBase().isOnline()) { - throw new Exception(tl("noPendingRequest")); + throw new Exception(user.tl("noPendingRequest")); } if (user.isTpRequestHere() && ((!requester.isAuthorized("essentials.tpahere") && !requester.isAuthorized("essentials.tpaall")) || (user.getWorld() != requester.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + user.getWorld().getName())))) { - throw new Exception(tl("noPendingRequest")); + throw new Exception(user.tl("noPendingRequest")); } if (!user.isTpRequestHere() && (!requester.isAuthorized("essentials.tpa") || (user.getWorld() != requester.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + requester.getWorld().getName())))) { - throw new Exception(tl("noPendingRequest")); + throw new Exception(user.tl("noPendingRequest")); } if (args.length > 0 && !requester.getName().contains(args[0])) { - throw new Exception(tl("noPendingRequest")); + throw new Exception(user.tl("noPendingRequest")); } if (!user.hasOutstandingTeleportRequest()) { user.requestTeleport(null, false); - throw new Exception(tl("requestTimedOut")); + throw new Exception(user.tl("requestTimedOut")); } final Trade charge = new Trade(this.getName(), ess); - user.sendMessage(tl("requestAccepted")); - requester.sendMessage(tl("requestAcceptedFrom", user.getDisplayName())); + user.sendTl("requestAccepted"); + requester.sendTl("requestAcceptedFrom", user.getDisplayName()); try { if (user.isTpRequestHere()) { @@ -55,14 +53,14 @@ public void run(final Server server, final User user, final String commandLabel, Teleport teleport = requester.getTeleport(); teleport.setTpType(Teleport.TeleportType.TPA); teleport.teleportPlayer(user, user.getTpRequestLocation(), charge, TeleportCause.COMMAND); - requester.sendMessage(tl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); + requester.sendTl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); } else { Teleport teleport = requester.getTeleport(); teleport.setTpType(Teleport.TeleportType.TPA); teleport.teleport(user.getBase(), charge, TeleportCause.COMMAND); } } catch (Exception ex) { - user.sendMessage(tl("pendingTeleportCancelled")); + user.sendTl("pendingTeleportCancelled"); ess.showError(requester.getSource(), ex, commandLabel); } user.requestTeleport(null, false); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java index 4878c20da63..49d7866f9a8 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java @@ -6,8 +6,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandtpahere extends EssentialsCommand { public Commandtpahere() { @@ -25,27 +23,27 @@ public void run(final Server server, final User user, final String commandLabel, throw new NotEnoughArgumentsException(); } if (!player.isTeleportEnabled()) { - throw new Exception(tl("teleportDisabled", player.getDisplayName())); + throw new Exception(user.tl("teleportDisabled", player.getDisplayName())); } if (user.getWorld() != player.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + user.getWorld().getName())) { - throw new Exception(tl("noPerm", "essentials.worlds." + user.getWorld().getName())); + throw new Exception(user.tl("noPerm", "essentials.worlds." + user.getWorld().getName())); } // Don't let sender request teleport twice to the same player. if (user.getConfigUUID().equals(player.getTeleportRequest()) && player.hasOutstandingTeleportRequest() // Check timeout && player.isTpRequestHere() == true) { // Make sure the last teleport request was actually tpahere and not tpa - throw new Exception(tl("requestSentAlready", player.getDisplayName())); + throw new Exception(user.tl("requestSentAlready", player.getDisplayName())); } if (!player.isIgnoredPlayer(user)) { player.requestTeleport(user, true); - player.sendMessage(tl("teleportHereRequest", user.getDisplayName())); - player.sendMessage(tl("typeTpaccept")); - player.sendMessage(tl("typeTpdeny")); + player.sendTl("teleportHereRequest", user.getDisplayName()); + player.sendTl("typeTpaccept"); + player.sendTl("typeTpdeny"); if (ess.getSettings().getTpaAcceptCancellation() != 0) { - player.sendMessage(tl("teleportRequestTimeoutInfo", ess.getSettings().getTpaAcceptCancellation())); + player.sendTl("teleportRequestTimeoutInfo", ess.getSettings().getTpaAcceptCancellation()); } } - user.sendMessage(tl("requestSent", player.getDisplayName())); - user.sendMessage(tl("typeTpacancel")); + user.sendTl("requestSent", player.getDisplayName()); + user.sendTl("typeTpacancel"); } @Override diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java index aa3ee8e7ed3..85feb42d381 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java @@ -9,8 +9,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandtpall extends EssentialsCommand { public Commandtpall() { @@ -32,7 +30,7 @@ public void run(final Server server, final CommandSource sender, final String co } private void teleportAllPlayers(Server server, CommandSource sender, User target) { - sender.sendMessage(tl("teleportAll")); + sender.sendTl("teleportAll"); final Location loc = target.getLocation(); for (User player : ess.getOnlineUsers()) { if (target == player) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpauto.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpauto.java index e2bc526ac5e..1f70d3aff84 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpauto.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpauto.java @@ -4,8 +4,6 @@ import com.earth2me.essentials.User; import org.bukkit.Server; -import static com.earth2me.essentials.I18n.tl; - public class Commandtpauto extends EssentialsToggleCommand { public Commandtpauto() { @@ -30,12 +28,12 @@ void togglePlayer(CommandSource sender, User user, Boolean enabled) { user.setAutoTeleportEnabled(enabled); - user.sendMessage(enabled ? tl("autoTeleportEnabled") : tl("autoTeleportDisabled")); + user.sendTl(enabled ? "autoTeleportEnabled" : "autoTeleportDisabled"); if (enabled && !user.isTeleportEnabled()) { - user.sendMessage(tl("teleportationDisabledWarning")); + user.sendTl("teleportationDisabledWarning"); } if (!sender.isPlayer() || !user.getBase().equals(sender.getPlayer())) { - sender.sendMessage(enabled ? tl("autoTeleportEnabledFor", user.getDisplayName()) : tl("autoTeleportDisabledFor", user.getDisplayName())); + sender.sendTl(enabled ? "autoTeleportEnabledFor" : "autoTeleportDisabledFor", user.getDisplayName()); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpdeny.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpdeny.java index 352f6621cee..702bcd18bf3 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpdeny.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpdeny.java @@ -3,8 +3,6 @@ import com.earth2me.essentials.User; import org.bukkit.Server; -import static com.earth2me.essentials.I18n.tl; - public class Commandtpdeny extends EssentialsCommand { public Commandtpdeny() { @@ -14,15 +12,15 @@ public Commandtpdeny() { @Override public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { if (user.getTeleportRequest() == null) { - throw new Exception(tl("noPendingRequest")); + throw new Exception(user.tl("noPendingRequest")); } final User player = ess.getUser(user.getTeleportRequest()); if (player == null) { - throw new Exception(tl("noPendingRequest")); + throw new Exception(user.tl("noPendingRequest")); } - user.sendMessage(tl("requestDenied")); - player.sendMessage(tl("requestDeniedFrom", user.getDisplayName())); + user.sendTl("requestDenied"); + player.sendTl("requestDeniedFrom", user.getDisplayName()); user.requestTeleport(null, false); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java b/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java index c8177c246d9..50717243575 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java @@ -8,8 +8,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandtphere extends EssentialsCommand { public Commandtphere() { @@ -20,10 +18,10 @@ public Commandtphere() { public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { final User player = getPlayer(server, user, args, 0); if (!player.isTeleportEnabled()) { - throw new Exception(tl("teleportDisabled", player.getDisplayName())); + throw new Exception(user.tl("teleportDisabled", player.getDisplayName())); } if (user.getWorld() != player.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + user.getWorld().getName())) { - throw new Exception(tl("noPerm", "essentials.worlds." + user.getWorld().getName())); + throw new Exception(user.tl("noPerm", "essentials.worlds." + user.getWorld().getName())); } user.getTeleport().teleportPlayer(player, user.getBase(), new Trade(this.getName(), ess), TeleportCause.COMMAND); throw new NoChargeException(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpo.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpo.java index 0ce0132caed..0aa3fdbbe0e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpo.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpo.java @@ -7,8 +7,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandtpo extends EssentialsCommand { public Commandtpo() { @@ -24,24 +22,24 @@ public void run(final Server server, final User user, final String commandLabel, case 1: final User player = getPlayer(server, user, args, 0); if (user.getWorld() != player.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + player.getWorld().getName())) { - throw new Exception(tl("noPerm", "essentials.worlds." + player.getWorld().getName())); + throw new Exception(user.tl("noPerm", "essentials.worlds." + player.getWorld().getName())); } user.getTeleport().now(player.getBase(), false, TeleportCause.COMMAND); break; default: if (!user.isAuthorized("essentials.tp.others")) { - throw new Exception(tl("noPerm", "essentials.tp.others")); + throw new Exception(user.tl("noPerm", "essentials.tp.others")); } final User target = getPlayer(server, user, args, 0); final User toPlayer = getPlayer(server, user, args, 1); if (target.getWorld() != toPlayer.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + toPlayer.getWorld().getName())) { - throw new Exception(tl("noPerm", "essentials.worlds." + toPlayer.getWorld().getName())); + throw new Exception(user.tl("noPerm", "essentials.worlds." + toPlayer.getWorld().getName())); } target.getTeleport().now(toPlayer.getBase(), false, TeleportCause.COMMAND); - target.sendMessage(tl("teleportAtoB", user.getDisplayName(), toPlayer.getDisplayName())); + target.sendTl("teleportAtoB", user.getDisplayName(), toPlayer.getDisplayName()); break; } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java index 39016cb10ef..54a5b9961b3 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java @@ -7,8 +7,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandtpohere extends EssentialsCommand { public Commandtpohere() { @@ -25,7 +23,7 @@ public void run(final Server server, final User user, final String commandLabel, final User player = getPlayer(server, user, args, 0); if (user.getWorld() != player.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + user.getWorld().getName())) { - throw new Exception(tl("noPerm", "essentials.worlds." + user.getWorld().getName())); + throw new Exception(user.tl("noPerm", "essentials.worlds." + user.getWorld().getName())); } // Verify permission diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java b/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java index 763e5cec855..6fd4a206fb6 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java @@ -13,8 +13,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandtppos extends EssentialsCommand { public Commandtppos() { @@ -34,7 +32,7 @@ public void run(final Server server, final User user, final String commandLabel, if (args.length == 4) { World w = ess.getWorld(args[3]); if (user.getWorld() != w && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + w.getName())) { - throw new Exception(tl("noPerm", "essentials.worlds." + w.getName())); + throw new Exception(user.tl("noPerm", "essentials.worlds." + w.getName())); } loc.setWorld(w); } @@ -45,16 +43,16 @@ public void run(final Server server, final User user, final String commandLabel, if (args.length > 5) { World w = ess.getWorld(args[5]); if (user.getWorld() != w && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + w.getName())) { - throw new Exception(tl("noPerm", "essentials.worlds." + w.getName())); + throw new Exception(user.tl("noPerm", "essentials.worlds." + w.getName())); } loc.setWorld(w); } if (x > 30000000 || y > 30000000 || z > 30000000 || x < -30000000 || y < -30000000 || z < -30000000) { - throw new NotEnoughArgumentsException(tl("teleportInvalidLocation")); + throw new NotEnoughArgumentsException(user.tl("teleportInvalidLocation")); } final Trade charge = new Trade(this.getName(), ess); charge.isAffordableFor(user); - user.sendMessage(tl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); + user.sendTl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); user.getTeleport().teleport(loc, charge, TeleportCause.COMMAND); throw new NoChargeException(); } @@ -81,10 +79,10 @@ public void run(final Server server, final CommandSource sender, final String co loc.setWorld(ess.getWorld(args[6])); } if (x > 30000000 || y > 30000000 || z > 30000000 || x < -30000000 || y < -30000000 || z < -30000000) { - throw new NotEnoughArgumentsException(tl("teleportInvalidLocation")); + throw new NotEnoughArgumentsException(user.tl("teleportInvalidLocation")); } - sender.sendMessage(tl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); - user.sendMessage(tl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); + sender.sendTl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); + user.sendTl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); user.getTeleport().teleport(loc, null, TeleportCause.COMMAND); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java b/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java index 122e37218fd..507f65020ec 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java @@ -4,8 +4,6 @@ import com.earth2me.essentials.User; import org.bukkit.Server; -import static com.earth2me.essentials.I18n.tl; - public class Commandtptoggle extends EssentialsToggleCommand { public Commandtptoggle() { @@ -30,9 +28,9 @@ void togglePlayer(CommandSource sender, User user, Boolean enabled) { user.setTeleportEnabled(enabled); - user.sendMessage(enabled ? tl("teleportationEnabled") : tl("teleportationDisabled")); + user.sendMessage(enabled ? user.tl("teleportationEnabled") : user.tl("teleportationDisabled")); if (!sender.isPlayer() || !user.getBase().equals(sender.getPlayer())) { - sender.sendMessage(enabled ? tl("teleportationEnabledFor", user.getDisplayName()) : tl("teleportationDisabledFor", user.getDisplayName())); + sender.sendMessage(enabled ? user.tl("teleportationEnabledFor", user.getDisplayName()) : user.tl("teleportationDisabledFor", user.getDisplayName())); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtree.java b/Essentials/src/com/earth2me/essentials/commands/Commandtree.java index f57505057fb..6640d20f2da 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtree.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtree.java @@ -11,8 +11,6 @@ import java.util.List; import java.util.Locale; -import static com.earth2me.essentials.I18n.tl; - public class Commandtree extends EssentialsCommand { public Commandtree() { super("tree"); @@ -46,9 +44,9 @@ public void run(final Server server, final User user, final String commandLabel, final Location safeLocation = LocationUtil.getSafeDestination(loc); final boolean success = user.getWorld().generateTree(safeLocation, tree); if (success) { - user.sendMessage(tl("treeSpawned")); + user.sendTl("treeSpawned"); } else { - user.sendMessage(tl("treeFailure")); + user.sendTl("treeFailure"); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandunban.java b/Essentials/src/com/earth2me/essentials/commands/Commandunban.java index ba763b44f2a..50c99088071 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandunban.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandunban.java @@ -9,8 +9,6 @@ import java.util.logging.Level; -import static com.earth2me.essentials.I18n.tl; - public class Commandunban extends EssentialsCommand { public Commandunban() { @@ -31,14 +29,14 @@ public void run(final Server server, final CommandSource sender, final String co final OfflinePlayer player = server.getOfflinePlayer(args[0]); name = player.getName(); if (!player.isBanned()) { - throw new Exception(tl("playerNotFound"), e); + throw new Exception(sender.tl("playerNotFound"), e); } ess.getServer().getBanList(BanList.Type.NAME).pardon(name); } final String senderName = sender.isPlayer() ? sender.getPlayer().getDisplayName() : Console.NAME; - server.getLogger().log(Level.INFO, tl("playerUnbanned", senderName, name)); + server.getLogger().log(Level.INFO, sender.tl("playerUnbanned", senderName, name)); - ess.broadcastMessage("essentials.ban.notify", tl("playerUnbanned", senderName, name)); + ess.broadcastMessage("essentials.ban.notify", sender.tl("playerUnbanned", senderName, name)); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java b/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java index a96eb3595ea..13123ac65cd 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java @@ -44,6 +44,6 @@ public void run(final Server server, final CommandSource sender, final String co final String senderName = sender.isPlayer() ? sender.getPlayer().getDisplayName() : Console.NAME; server.getLogger().log(Level.INFO, tl("playerUnbanIpAddress", senderName, ipAddress)); - ess.broadcastMessage("essentials.ban.notify", tl("playerUnbanIpAddress", senderName, ipAddress)); + ess.broadcastTl("essentials.ban.notify", "playerUnbanIpAddress", senderName, ipAddress); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java b/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java index 36b34ca272b..8361e045522 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java @@ -8,8 +8,6 @@ import java.util.List; import java.util.Locale; -import static com.earth2me.essentials.I18n.tl; - public class Commandunlimited extends EssentialsCommand { public Commandunlimited() { @@ -48,11 +46,11 @@ public void run(final Server server, final User user, final String commandLabel, private String getList(final User target) { final StringBuilder output = new StringBuilder(); - output.append(tl("unlimitedItems")).append(" "); + output.append(target.tl("unlimitedItems")).append(" "); boolean first = true; final List items = target.getUnlimited(); if (items.isEmpty()) { - output.append(tl("none")); + output.append(target.tl("none")); } for (Material material : items) { if (!first) { @@ -72,7 +70,7 @@ private Boolean toggleUnlimited(final User user, final User target, final String final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""); if (ess.getSettings().permissionBasedItemSpawn() && (!user.isAuthorized("essentials.unlimited.item-all") && !user.isAuthorized("essentials.unlimited.item-" + itemname) && !((stack.getType() == Material.WATER_BUCKET || stack.getType() == Material.LAVA_BUCKET) && user.isAuthorized("essentials.unlimited.item-bucket")))) { - throw new Exception(tl("unlimitedItemPermission", itemname)); + throw new Exception(user.tl("unlimitedItemPermission", itemname)); } String message = "disableUnlimited"; @@ -86,9 +84,9 @@ private Boolean toggleUnlimited(final User user, final User target, final String } if (user != target) { - user.sendMessage(tl(message, itemname, target.getDisplayName())); + user.sendTl(message, itemname, target.getDisplayName()); } - target.sendMessage(tl(message, itemname, target.getDisplayName())); + target.sendTl(message, itemname, target.getDisplayName()); target.setUnlimited(stack, enableUnlimited); return true; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandvanish.java b/Essentials/src/com/earth2me/essentials/commands/Commandvanish.java index fdeba4a1045..10b8dcdc2e9 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandvanish.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandvanish.java @@ -4,8 +4,6 @@ import com.earth2me.essentials.User; import org.bukkit.Server; -import static com.earth2me.essentials.I18n.tl; - import net.ess3.api.events.VanishStatusChangeEvent; @@ -38,13 +36,13 @@ void togglePlayer(CommandSource sender, User user, Boolean enabled) throws NotEn } user.setVanished(enabled); - user.sendMessage(tl("vanish", user.getDisplayName(), enabled ? tl("enabled") : tl("disabled"))); + user.sendTl("vanish", user.getDisplayName(), enabled ? user.tl("enabled") : user.tl("disabled")); if (enabled) { - user.sendMessage(tl("vanished")); + user.sendTl("vanished"); } if (!sender.isPlayer() || !sender.getPlayer().equals(user.getBase())) { - sender.sendMessage(tl("vanish", user.getDisplayName(), enabled ? tl("enabled") : tl("disabled"))); + sender.sendTl("vanish", user.getDisplayName(), enabled ? user.tl("enabled") : user.tl("disabled")); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java index 07abc89b6e6..48f7c4c410a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java @@ -17,8 +17,6 @@ import java.util.Locale; import java.util.stream.Collectors; -import static com.earth2me.essentials.I18n.tl; - public class Commandwarp extends EssentialsCommand { private static final int WARPS_PER_PAGE = 20; @@ -31,7 +29,7 @@ public Commandwarp() { public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { if (args.length == 0 || args[0].matches("[0-9]+")) { if (!user.isAuthorized("essentials.warp.list")) { - throw new Exception(tl("warpListPermission")); + throw new Exception(user.tl("warpListPermission")); } warpList(user.getSource(), args, user); throw new NoChargeException(); @@ -67,7 +65,7 @@ private void warpList(final CommandSource sender, final String[] args, final IUs final List warpNameList = getAvailableWarpsFor(user); if (warpNameList.isEmpty()) { - throw new Exception(tl("noWarpsDefined")); + throw new Exception(user.tl("noWarpsDefined")); } int page = 1; if (args.length > 0 && NumberUtil.isInt(args[0])) { @@ -84,10 +82,10 @@ private void warpList(final CommandSource sender, final String[] args, final IUs final String warpList = StringUtil.joinList(warpNameList.subList(warpPage, warpPage + Math.min(warpNameList.size() - warpPage, WARPS_PER_PAGE))); if (warpNameList.size() > WARPS_PER_PAGE) { - sender.sendMessage(tl("warpsCount", warpNameList.size(), page, maxPages)); - sender.sendMessage(tl("warpList", warpList)); + sender.sendTl("warpsCount", warpNameList.size(), page, maxPages); + sender.sendTl("warpList", warpList); } else { - sender.sendMessage(tl("warps", warpList)); + sender.sendTl("warps", warpList); } } @@ -98,7 +96,7 @@ private void warpUser(final User owner, final User user, final String name) thro final Trade charge = new Trade(fullCharge, ess); charge.isAffordableFor(owner); if (ess.getSettings().getPerWarpPermission() && !owner.isAuthorized("essentials.warps." + name)) { - throw new Exception(tl("warpUsePermission")); + throw new Exception(owner.tl("warpUsePermission")); } owner.getTeleport().warp(user, name, charge, TeleportCause.COMMAND); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandweather.java b/Essentials/src/com/earth2me/essentials/commands/Commandweather.java index 57cbd6d03f9..e96ee11957f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandweather.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandweather.java @@ -9,8 +9,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandweather extends EssentialsCommand { public Commandweather() { @@ -37,10 +35,10 @@ public void run(final Server server, final User user, final String commandLabel, world.setStorm(isStorm); world.setWeatherDuration(Integer.parseInt(args[1]) * 20); - user.sendMessage(isStorm ? tl("weatherStormFor", world.getName(), args[1]) : tl("weatherSunFor", world.getName(), args[1])); + user.sendMessage(isStorm ? user.tl("weatherStormFor", world.getName(), args[1]) : user.tl("weatherSunFor", world.getName(), args[1])); } else { world.setStorm(isStorm); - user.sendMessage(isStorm ? tl("weatherStorm", world.getName()) : tl("weatherSun", world.getName())); + user.sendMessage(isStorm ? user.tl("weatherStorm", world.getName()) : user.tl("weatherSun", world.getName())); } } @@ -54,16 +52,16 @@ protected void run(final Server server, final CommandSource sender, final String final boolean isStorm = args[1].equalsIgnoreCase("storm"); final World world = server.getWorld(args[0]); if (world == null) { - throw new Exception(tl("weatherInvalidWorld", args[0])); + throw new Exception(sender.tl("weatherInvalidWorld", args[0])); } if (args.length > 2) { world.setStorm(isStorm); world.setWeatherDuration(Integer.parseInt(args[2]) * 20); - sender.sendMessage(isStorm ? tl("weatherStormFor", world.getName(), args[2]) : tl("weatherSunFor", world.getName(), args[2])); + sender.sendMessage(isStorm ? sender.tl("weatherStormFor", world.getName(), args[2]) : sender.tl("weatherSunFor", world.getName(), args[2])); } else { world.setStorm(isStorm); - sender.sendMessage(isStorm ? tl("weatherStorm", world.getName()) : tl("weatherSun", world.getName())); + sender.sendMessage(isStorm ? sender.tl("weatherStorm", world.getName()) : sender.tl("weatherSun", world.getName())); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java index c90cee919e0..62c0f3ba703 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java @@ -13,8 +13,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandwhois extends EssentialsCommand { // For some reason, in 1.13 PLAY_ONE_MINUTE = ticks played = what used to be PLAY_ONE_TICK @@ -33,43 +31,43 @@ public void run(final Server server, final CommandSource sender, final String co User user = getPlayer(server, sender, args, 0); - sender.sendMessage(tl("whoisTop", user.getName())); + sender.sendTl("whoisTop", user.getName()); user.setDisplayNick(); - sender.sendMessage(tl("whoisNick", user.getDisplayName())); - sender.sendMessage(tl("whoisUuid", user.getBase().getUniqueId().toString())); - sender.sendMessage(tl("whoisHealth", user.getBase().getHealth())); - sender.sendMessage(tl("whoisHunger", user.getBase().getFoodLevel(), user.getBase().getSaturation())); - sender.sendMessage(tl("whoisExp", SetExpFix.getTotalExperience(user.getBase()), user.getBase().getLevel())); - sender.sendMessage(tl("whoisLocation", user.getLocation().getWorld().getName(), user.getLocation().getBlockX(), user.getLocation().getBlockY(), user.getLocation().getBlockZ())); + sender.sendTl("whoisNick", user.getDisplayName()); + sender.sendTl("whoisUuid", user.getBase().getUniqueId().toString()); + sender.sendTl("whoisHealth", user.getBase().getHealth()); + sender.sendTl("whoisHunger", user.getBase().getFoodLevel(), user.getBase().getSaturation()); + sender.sendTl("whoisExp", SetExpFix.getTotalExperience(user.getBase()), user.getBase().getLevel()); + sender.sendTl("whoisLocation", user.getLocation().getWorld().getName(), user.getLocation().getBlockX(), user.getLocation().getBlockY(), user.getLocation().getBlockZ()); long playtimeMs = System.currentTimeMillis() - (user.getBase().getStatistic(PLAY_ONE_TICK) * 50); - sender.sendMessage(tl("whoisPlaytime", DateUtil.formatDateDiff(playtimeMs))); + sender.sendTl("whoisPlaytime", DateUtil.formatDateDiff(sender, playtimeMs)); if (!ess.getSettings().isEcoDisabled()) { - sender.sendMessage(tl("whoisMoney", NumberUtil.displayCurrency(user.getMoney(), ess))); + sender.sendTl("whoisMoney", NumberUtil.displayCurrency(user.getMoney(), ess)); } if (!sender.isPlayer() || ess.getUser(sender.getPlayer()).isAuthorized("essentials.whois.ip")) { - sender.sendMessage(tl("whoisIPAddress", user.getBase().getAddress().getAddress().toString())); + sender.sendTl("whoisIPAddress", user.getBase().getAddress().getAddress().toString()); } final String location = user.getGeoLocation(); if (location != null && (!sender.isPlayer() || ess.getUser(sender.getPlayer()).isAuthorized("essentials.geoip.show"))) { - sender.sendMessage(tl("whoisGeoLocation", location)); + sender.sendTl("whoisGeoLocation", location); } - sender.sendMessage(tl("whoisGamemode", tl(user.getBase().getGameMode().toString().toLowerCase(Locale.ENGLISH)))); - sender.sendMessage(tl("whoisGod", (user.isGodModeEnabled() ? tl("true") : tl("false")))); - sender.sendMessage(tl("whoisOp", (user.getBase().isOp() ? tl("true") : tl("false")))); - sender.sendMessage(tl("whoisFly", user.getBase().getAllowFlight() ? tl("true") : tl("false"), user.getBase().isFlying() ? tl("flying") : tl("notFlying"))); + sender.sendTl("whoisGamemode", sender.tl(user.getBase().getGameMode().toString().toLowerCase(Locale.ENGLISH))); + sender.sendTl("whoisGod", (user.isGodModeEnabled() ? sender.tl("true") : sender.tl("false"))); + sender.sendTl("whoisOp", (user.getBase().isOp() ? sender.tl("true") : sender.tl("false"))); + sender.sendTl("whoisFly", user.getBase().getAllowFlight() ? sender.tl("true") : sender.tl("false"), user.getBase().isFlying() ? sender.tl("flying") : sender.tl("notFlying")); if (user.isAfk()) { - sender.sendMessage(tl("whoisAFKSince", tl("true"), DateUtil.formatDateDiff(user.getAfkSince()))); + sender.sendTl("whoisAFKSince", sender.tl("true"), DateUtil.formatDateDiff(sender, user.getAfkSince())); } else { - sender.sendMessage(tl("whoisAFK", tl("false"))); + sender.sendTl("whoisAFK", sender.tl("false")); } - sender.sendMessage(tl("whoisJail", (user.isJailed() ? user.getJailTimeout() > 0 ? DateUtil.formatDateDiff(user.getJailTimeout()) : tl("true") : tl("false")))); + sender.sendTl("whoisJail", (user.isJailed() ? user.getJailTimeout() > 0 ? DateUtil.formatDateDiff(sender, user.getJailTimeout()) : sender.tl("true") : sender.tl("false"))); long muteTimeout = user.getMuteTimeout(); if (!user.hasMuteReason()) { - sender.sendMessage(tl("whoisMuted", (user.isMuted() ? (muteTimeout > 0 ? DateUtil.formatDateDiff(muteTimeout) : tl("true")) : tl("false")))); + sender.sendTl("whoisMuted", (user.isMuted() ? (muteTimeout > 0 ? DateUtil.formatDateDiff(sender, muteTimeout) : sender.tl("true")) : sender.tl("false"))); } else { - sender.sendMessage(tl("whoisMutedReason", (user.isMuted() ? (muteTimeout > 0 ? DateUtil.formatDateDiff(muteTimeout) : tl("true")) : tl("false")), - user.getMuteReason())); + sender.sendTl("whoisMutedReason", (user.isMuted() ? (muteTimeout > 0 ? DateUtil.formatDateDiff(sender, muteTimeout) : sender.tl("true")) : sender.tl("false")), + user.getMuteReason()); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandworld.java b/Essentials/src/com/earth2me/essentials/commands/Commandworld.java index 07a8da408ed..d0c47ac0913 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandworld.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandworld.java @@ -11,8 +11,6 @@ import java.util.Collections; import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class Commandworld extends EssentialsCommand { public Commandworld() { @@ -41,15 +39,15 @@ protected void run(final Server server, final User user, final String commandLab } else { world = ess.getWorld(getFinalArg(args, 0)); if (world == null) { - user.sendMessage(tl("invalidWorld")); - user.sendMessage(tl("possibleWorlds", server.getWorlds().size() - 1)); - user.sendMessage(tl("typeWorldName")); + user.sendTl("invalidWorld"); + user.sendTl("possibleWorlds", server.getWorlds().size() - 1); + user.sendTl("typeWorldName"); throw new NoChargeException(); } } if (ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + world.getName())) { - throw new Exception(tl("noPerm", "essentials.worlds." + world.getName())); + throw new Exception(user.tl("noPerm", "essentials.worlds." + world.getName())); } double factor; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java index 31b55be5544..1d90dbf9086 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java @@ -12,8 +12,6 @@ import java.util.List; import java.util.Locale; -import static com.earth2me.essentials.I18n.tl; - public class Commandworth extends EssentialsCommand { public Commandworth() { @@ -51,9 +49,9 @@ public void run(final Server server, final User user, final String commandLabel, } if (count > 1) { if (args.length > 0 && args[0].equalsIgnoreCase("blocks")) { - user.sendMessage(tl("totalSellableBlocks", type, NumberUtil.displayCurrency(totalWorth, ess))); + user.sendTl("totalSellableBlocks", type, NumberUtil.displayCurrency(totalWorth, ess)); } else { - user.sendMessage(tl("totalSellableAll", type, NumberUtil.displayCurrency(totalWorth, ess))); + user.sendTl("totalSellableAll", type, NumberUtil.displayCurrency(totalWorth, ess)); } } } @@ -87,7 +85,7 @@ private BigDecimal itemWorth(CommandSource sender, User user, ItemStack is, Stri BigDecimal worth = ess.getWorth().getPrice(ess, is); if (worth == null) { - throw new Exception(tl("itemCannotBeSold")); + throw new Exception(sender.tl("itemCannotBeSold")); } if (amount < 0) { @@ -96,7 +94,7 @@ private BigDecimal itemWorth(CommandSource sender, User user, ItemStack is, Stri BigDecimal result = worth.multiply(BigDecimal.valueOf(amount)); - sender.sendMessage(is.getDurability() != 0 ? tl("worthMeta", is.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""), is.getDurability(), NumberUtil.displayCurrency(result, ess), amount, NumberUtil.displayCurrency(worth, ess)) : tl("worth", is.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""), NumberUtil.displayCurrency(result, ess), amount, NumberUtil.displayCurrency(worth, ess))); + sender.sendMessage(is.getDurability() != 0 ? sender.tl("worthMeta", is.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""), is.getDurability(), NumberUtil.displayCurrency(result, ess), amount, NumberUtil.displayCurrency(worth, ess)) : sender.tl("worth", is.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""), NumberUtil.displayCurrency(result, ess), amount, NumberUtil.displayCurrency(worth, ess))); return result; } diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java index 6bf10b51d42..a7f635274e8 100644 --- a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java @@ -26,8 +26,6 @@ import java.util.UUID; import java.util.logging.Logger; -import static com.earth2me.essentials.I18n.tl; - public abstract class EssentialsCommand implements IEssentialsCommand { private final transient String name; @@ -172,7 +170,7 @@ public final void run(final Server server, final CommandSource sender, final Str } protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { - throw new Exception(tl("onlyPlayers", commandLabel)); + throw new Exception(sender.tl("onlyPlayers", commandLabel)); } @Override diff --git a/Essentials/src/com/earth2me/essentials/messaging/IMessageRecipient.java b/Essentials/src/com/earth2me/essentials/messaging/IMessageRecipient.java index d30eb91b9b0..c7cd0cbae1f 100644 --- a/Essentials/src/com/earth2me/essentials/messaging/IMessageRecipient.java +++ b/Essentials/src/com/earth2me/essentials/messaging/IMessageRecipient.java @@ -1,5 +1,7 @@ package com.earth2me.essentials.messaging; +import java.util.Locale; + /** * Represents an interface for message recipients. */ @@ -63,6 +65,13 @@ public interface IMessageRecipient { */ boolean isReachable(); + /** + * Return the locale of this message recipient + * + * @return The locale, never null + */ + Locale getLocale(); + /** * Returns the {@link IMessageRecipient} this recipient should send replies to. * diff --git a/Essentials/src/com/earth2me/essentials/messaging/SimpleMessageRecipient.java b/Essentials/src/com/earth2me/essentials/messaging/SimpleMessageRecipient.java index 370213c7f37..2abd18fae8f 100644 --- a/Essentials/src/com/earth2me/essentials/messaging/SimpleMessageRecipient.java +++ b/Essentials/src/com/earth2me/essentials/messaging/SimpleMessageRecipient.java @@ -5,6 +5,7 @@ import com.earth2me.essentials.User; import java.lang.ref.WeakReference; +import java.util.Locale; import static com.earth2me.essentials.I18n.tl; @@ -65,10 +66,10 @@ public String getName() { MessageResponse messageResponse = recipient.onReceiveMessage(this.parent, message); switch (messageResponse) { case UNREACHABLE: - sendMessage(tl("recentlyForeverAlone", recipient.getDisplayName())); + sendMessage(tl(getLocale(), "recentlyForeverAlone", recipient.getDisplayName())); break; case MESSAGES_IGNORED: - sendMessage(tl("msgIgnore", recipient.getDisplayName())); + sendMessage(tl(getLocale(), "msgIgnore", recipient.getDisplayName())); break; case SENDER_IGNORED: break; @@ -76,12 +77,12 @@ public String getName() { case SUCCESS_BUT_AFK: // Currently, only IUser can be afk, so we unsafely cast to get the afk message. if (((IUser) recipient).getAfkMessage() != null) { - sendMessage(tl("userAFKWithMessage", recipient.getDisplayName(), ((IUser) recipient).getAfkMessage())); + sendMessage(tl(getLocale(), "userAFKWithMessage", recipient.getDisplayName(), ((IUser) recipient).getAfkMessage())); } else { - sendMessage(tl("userAFK", recipient.getDisplayName())); + sendMessage(tl(getLocale(), "userAFK", recipient.getDisplayName())); } default: - sendMessage(tl("msgFormat", tl("me"), recipient.getDisplayName(), message)); + sendMessage(tl(getLocale(), "msgFormat", tl(getLocale(), "me"), recipient.getDisplayName(), message)); // Better Social Spy User senderUser = getUser(this); @@ -96,9 +97,9 @@ public String getName() { && !onlineUser.equals(senderUser) && !onlineUser.equals(recipient)) { if (senderUser.isMuted() && ess.getSettings().getSocialSpyListenMutedPlayers()) { - onlineUser.sendMessage(tl("socialMutedSpyPrefix") + tl("socialSpyMsgFormat", getDisplayName(), recipient.getDisplayName(), message)); + onlineUser.sendMessage(onlineUser.tl("socialMutedSpyPrefix") + onlineUser.tl("socialSpyMsgFormat", getDisplayName(), recipient.getDisplayName(), message)); } else { - onlineUser.sendMessage(tl("socialSpyPrefix") + tl("socialSpyMsgFormat", getDisplayName(), recipient.getDisplayName(), message)); + onlineUser.sendMessage(onlineUser.tl("socialSpyPrefix") + onlineUser.tl("socialSpyMsgFormat", getDisplayName(), recipient.getDisplayName(), message)); } } } @@ -132,7 +133,7 @@ public MessageResponse onReceiveMessage(IMessageRecipient sender, String message } } // Display the formatted message to this recipient. - sendMessage(tl("msgFormat", sender.getDisplayName(), tl("me"), message)); + sendMessage(tl(getLocale(), "msgFormat", sender.getDisplayName(), tl(getLocale(), "me"), message)); if (isLastMessageReplyRecipient) { // If this recipient doesn't have a reply recipient, initiate by setting the first @@ -153,6 +154,12 @@ public MessageResponse onReceiveMessage(IMessageRecipient sender, String message return this.parent.isReachable(); } + @Override + public Locale getLocale() { + User user = getUser(this); + return user != null ? user.getApplicableLocale() : ess.getI18n().getCurrentLocale(); + } + /** * {@inheritDoc} *

diff --git a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java index 46dcb4e0c92..dd69b271910 100644 --- a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java +++ b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java @@ -43,7 +43,7 @@ protected final boolean onSignCreate(final SignChangeEvent event, final IEssenti // they won't change it to §1[Signname] return true; } - sign.setLine(0, tl("signFormatFail", this.signName)); + sign.setLine(0, user.tl("signFormatFail", this.signName)); final SignCreateEvent signEvent = new SignCreateEvent(sign, this, user); ess.getServer().getPluginManager().callEvent(signEvent); @@ -270,12 +270,12 @@ private String getSignText(final ISign sign, final int lineNumber) { return sign.getLine(lineNumber).trim(); } - protected final void validateTrade(final ISign sign, final int index, final IEssentials ess) throws SignException { + protected final void validateTrade(final ISign sign, final int index, final User player, final IEssentials ess) throws SignException { final String line = getSignText(sign, index); if (line.isEmpty()) { return; } - final Trade trade = getTrade(sign, index, 0, ess); + final Trade trade = getTrade(player, sign, index, 0, ess); final BigDecimal money = trade.getMoney(); if (money != null) { sign.setLine(index, NumberUtil.shortCurrency(money, ess)); @@ -285,7 +285,7 @@ protected final void validateTrade(final ISign sign, final int index, final IEss protected final void validateTrade(final ISign sign, final int amountIndex, final int itemIndex, final User player, final IEssentials ess) throws SignException { final String itemType = getSignText(sign, itemIndex); if (itemType.equalsIgnoreCase("exp") || itemType.equalsIgnoreCase("xp")) { - int amount = getIntegerPositive(getSignText(sign, amountIndex)); + int amount = getIntegerPositive(player, getSignText(sign, amountIndex)); sign.setLine(amountIndex, Integer.toString(amount)); sign.setLine(itemIndex, "exp"); return; @@ -303,31 +303,31 @@ protected final Trade getTrade(final ISign sign, final int amountIndex, final in protected final Trade getTrade(final ISign sign, final int amountIndex, final int itemIndex, final User player, final boolean allowId, final IEssentials ess) throws SignException { final String itemType = getSignText(sign, itemIndex); if (itemType.equalsIgnoreCase("exp") || itemType.equalsIgnoreCase("xp")) { - final int amount = getIntegerPositive(getSignText(sign, amountIndex)); + final int amount = getIntegerPositive(player, getSignText(sign, amountIndex)); return new Trade(amount, ess); } final ItemStack item = getItemStack(itemType, 1, allowId, ess); - final int amount = Math.min(getIntegerPositive(getSignText(sign, amountIndex)), item.getType().getMaxStackSize() * player.getBase().getInventory().getSize()); + final int amount = Math.min(getIntegerPositive(player, getSignText(sign, amountIndex)), item.getType().getMaxStackSize() * player.getBase().getInventory().getSize()); if (item.getType() == Material.AIR || amount < 1) { - throw new SignException(tl("moreThanZero")); + throw new SignException(player.tl("moreThanZero")); } item.setAmount(amount); return new Trade(item, ess); } - protected final void validateInteger(final ISign sign, final int index) throws SignException { + protected final void validateInteger(User player, final ISign sign, final int index) throws SignException { final String line = getSignText(sign, index); if (line.isEmpty()) { throw new SignException("Empty line " + index); } - final int quantity = getIntegerPositive(line); + final int quantity = getIntegerPositive(player, line); sign.setLine(index, Integer.toString(quantity)); } - protected final int getIntegerPositive(final String line) throws SignException { + protected final int getIntegerPositive(User player, final String line) throws SignException { final int quantity = getInteger(line); if (quantity < 1) { - throw new SignException(tl("moreThanZero")); + throw new SignException(player.tl("moreThanZero")); } return quantity; } @@ -378,15 +378,15 @@ protected final ItemStack getItemMeta(final ItemStack item, final String meta, f return stack; } - protected final BigDecimal getMoney(final String line) throws SignException { + protected final BigDecimal getMoney(final User player, final String line) throws SignException { final boolean isMoney = line.matches("^[^0-9-\\.][\\.0-9]+$"); - return isMoney ? getBigDecimalPositive(line.substring(1)) : null; + return isMoney ? getBigDecimalPositive(player, line.substring(1)) : null; } - protected final BigDecimal getBigDecimalPositive(final String line) throws SignException { + protected final BigDecimal getBigDecimalPositive(final User player, final String line) throws SignException { final BigDecimal quantity = getBigDecimal(line); if (quantity.compareTo(MINTRANSACTION) < 0) { - throw new SignException(tl("moreThanZero")); + throw new SignException(player.tl("moreThanZero")); } return quantity; } @@ -401,27 +401,27 @@ protected final BigDecimal getBigDecimal(final String line) throws SignException } } - protected final Trade getTrade(final ISign sign, final int index, final IEssentials ess) throws SignException { - return getTrade(sign, index, 1, ess); + protected final Trade getTrade(final User player, final ISign sign, final int index, final IEssentials ess) throws SignException { + return getTrade(player, sign, index, 1, ess); } - protected final Trade getTrade(final ISign sign, final int index, final int decrement, final IEssentials ess) throws SignException { - return getTrade(sign, index, decrement, false, ess); + protected final Trade getTrade(final User player, final ISign sign, final int index, final int decrement, final IEssentials ess) throws SignException { + return getTrade(player, sign, index, decrement, false, ess); } - protected final Trade getTrade(final ISign sign, final int index, final int decrement, final boolean allowId, final IEssentials ess) throws SignException { + protected final Trade getTrade(final User player, final ISign sign, final int index, final int decrement, final boolean allowId, final IEssentials ess) throws SignException { final String line = getSignText(sign, index); if (line.isEmpty()) { return new Trade(signName.toLowerCase(Locale.ENGLISH) + "sign", ess); } - final BigDecimal money = getMoney(line); + final BigDecimal money = getMoney(player, line); if (money == null) { final String[] split = line.split("[ :]+", 2); if (split.length != 2) { - throw new SignException(tl("invalidCharge")); + throw new SignException(player.tl("invalidCharge")); } - final int quantity = getIntegerPositive(split[0]); + final int quantity = getIntegerPositive(player, split[0]); final String item = split[1].toLowerCase(Locale.ENGLISH); if (item.equalsIgnoreCase("times")) { diff --git a/Essentials/src/com/earth2me/essentials/signs/SignBalance.java b/Essentials/src/com/earth2me/essentials/signs/SignBalance.java index 6b9201499d7..343791568c4 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignBalance.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignBalance.java @@ -4,8 +4,6 @@ import com.earth2me.essentials.utils.NumberUtil; import net.ess3.api.IEssentials; -import static com.earth2me.essentials.I18n.tl; - public class SignBalance extends EssentialsSign { public SignBalance() { @@ -14,7 +12,7 @@ public SignBalance() { @Override protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException { - player.sendMessage(tl("balance", NumberUtil.displayCurrency(player.getMoney(), ess))); + player.sendTl("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 89b027a1b59..9cbf0cbefdb 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java @@ -1,6 +1,5 @@ package com.earth2me.essentials.signs; -import com.earth2me.essentials.I18n; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.EnumUtil; import com.earth2me.essentials.utils.FormatUtil; @@ -98,8 +97,7 @@ public void onSignSignChange2(final SignChangeEvent event) { // Top line and sign#getSuccessName() are both lowercased since contains is case-sensitive. String successName = sign.getSuccessName(ess); if (successName == null) { - event.getPlayer().sendMessage(I18n.tl("errorWithMessage", - "Please report this error to a staff member.")); + user.sendTl("errorWithMessage", "Please report this error to a staff member."); return; } String lSuccessName = ChatColor.stripColor(successName.toLowerCase()); diff --git a/Essentials/src/com/earth2me/essentials/signs/SignBuy.java b/Essentials/src/com/earth2me/essentials/signs/SignBuy.java index 2900e72ff82..6ddae666438 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignBuy.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignBuy.java @@ -19,14 +19,14 @@ public SignBuy() { @Override protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException { validateTrade(sign, 1, 2, player, ess); - validateTrade(sign, 3, ess); + validateTrade(sign, 3, player, ess); return true; } @Override protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException, MaxMoneyException { Trade items = getTrade(sign, 1, 2, player, ess); - Trade charge = getTrade(sign, 3, ess); + Trade charge = getTrade(player, sign, 3, ess); // Check if the player is trying to buy in bulk. if (ess.getSettings().isAllowBulkBuySell() && player.getBase().isSneaking()) { diff --git a/Essentials/src/com/earth2me/essentials/signs/SignEnchant.java b/Essentials/src/com/earth2me/essentials/signs/SignEnchant.java index 9e62c47e96b..ac48b9c6ebb 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignEnchant.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignEnchant.java @@ -10,8 +10,6 @@ import java.util.Locale; -import static com.earth2me.essentials.I18n.tl; - public class SignEnchant extends EssentialsSign { public SignEnchant() { @@ -30,12 +28,12 @@ protected boolean onSignCreate(final ISign sign, final User player, final String final String[] enchantLevel = sign.getLine(2).split(":"); if (enchantLevel.length != 2) { sign.setLine(2, "§c"); - throw new SignException(tl("invalidSignLine", 3)); + throw new SignException(player.tl("invalidSignLine", 3)); } final Enchantment enchantment = Enchantments.getByName(enchantLevel[0]); if (enchantment == null) { sign.setLine(2, "§c"); - throw new SignException(tl("enchantmentNotFound")); + throw new SignException(player.tl("enchantmentNotFound")); } int level; try { @@ -60,22 +58,22 @@ protected boolean onSignCreate(final ISign sign, final User player, final String } catch (Throwable ex) { throw new SignException(ex.getMessage(), ex); } - getTrade(sign, 3, ess); + getTrade(player, sign, 3, ess); return true; } @Override protected boolean onSignInteract(ISign sign, User player, String username, IEssentials ess) throws SignException, ChargeException { final ItemStack search = sign.getLine(1).equals("*") || sign.getLine(1).equalsIgnoreCase("any") ? null : getItemStack(sign.getLine(1), 1, ess); - final Trade charge = getTrade(sign, 3, ess); + final Trade charge = getTrade(player, sign, 3, ess); charge.isAffordableFor(player); final String[] enchantLevel = sign.getLine(2).split(":"); if (enchantLevel.length != 2) { - throw new SignException(tl("invalidSignLine", 3)); + throw new SignException(player.tl("invalidSignLine", 3)); } final Enchantment enchantment = Enchantments.getByName(enchantLevel[0]); if (enchantment == null) { - throw new SignException(tl("enchantmentNotFound")); + throw new SignException(player.tl("enchantmentNotFound")); } int level; try { @@ -86,10 +84,10 @@ protected boolean onSignInteract(ISign sign, User player, String username, IEsse final ItemStack playerHand = player.getBase().getItemInHand(); if (playerHand == null || playerHand.getAmount() != 1 || (playerHand.containsEnchantment(enchantment) && playerHand.getEnchantmentLevel(enchantment) == level)) { - throw new SignException(tl("missingItems", 1, sign.getLine(1))); + throw new SignException(player.tl("missingItems", 1, sign.getLine(1))); } if (search != null && playerHand.getType() != search.getType()) { - throw new SignException(tl("missingItems", 1, search.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' '))); + throw new SignException(player.tl("missingItems", 1, search.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' '))); } final ItemStack toEnchant = playerHand; @@ -109,9 +107,9 @@ protected boolean onSignInteract(ISign sign, User player, String username, IEsse final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH); if (level == 0) { - player.sendMessage(tl("enchantmentRemoved", enchantmentName.replace('_', ' '))); + player.sendTl("enchantmentRemoved", enchantmentName.replace('_', ' ')); } else { - player.sendMessage(tl("enchantmentApplied", enchantmentName.replace('_', ' '))); + player.sendTl("enchantmentApplied", enchantmentName.replace('_', ' ')); } charge.charge(player); diff --git a/Essentials/src/com/earth2me/essentials/signs/SignFree.java b/Essentials/src/com/earth2me/essentials/signs/SignFree.java index 617d29e0146..ca57475da5d 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignFree.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignFree.java @@ -8,8 +8,6 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import static com.earth2me.essentials.I18n.tl; - public class SignFree extends EssentialsSign { public SignFree() { @@ -36,7 +34,7 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri final ItemStack item = getItemMeta(itemStack, sign.getLine(3), ess); if (item.getType() == Material.AIR) { - throw new SignException(tl("cantSpawnItem", "Air")); + throw new SignException(player.tl("cantSpawnItem", "Air")); } item.setAmount(item.getType().getMaxStackSize()); diff --git a/Essentials/src/com/earth2me/essentials/signs/SignGameMode.java b/Essentials/src/com/earth2me/essentials/signs/SignGameMode.java index 820ecd84ce0..d2bea020f13 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignGameMode.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignGameMode.java @@ -5,12 +5,9 @@ import com.earth2me.essentials.User; import net.ess3.api.IEssentials; import org.bukkit.GameMode; -import org.bukkit.entity.Player; import java.util.Locale; -import static com.earth2me.essentials.I18n.tl; - public class SignGameMode extends EssentialsSign { public SignGameMode() { @@ -24,40 +21,40 @@ protected boolean onSignCreate(final ISign sign, final User player, final String sign.setLine(1, "Survival"); } - validateTrade(sign, 2, ess); + validateTrade(sign, 2, player, ess); return true; } @Override protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException { - final Trade charge = getTrade(sign, 2, ess); + final Trade charge = getTrade(player, sign, 2, ess); final String mode = sign.getLine(1).trim(); if (mode.isEmpty()) { - throw new SignException(tl("invalidSignLine", 2)); + throw new SignException(player.tl("invalidSignLine", 2)); } charge.isAffordableFor(player); - performSetMode(mode.toLowerCase(Locale.ENGLISH), player.getBase()); - player.sendMessage(tl("gameMode", tl(player.getBase().getGameMode().toString().toLowerCase(Locale.ENGLISH)), player.getDisplayName())); + performSetMode(mode.toLowerCase(Locale.ENGLISH), player); + player.sendTl("gameMode", player.tl(player.getBase().getGameMode().toString().toLowerCase(Locale.ENGLISH)), player.getDisplayName()); Trade.log("Sign", "gameMode", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess); charge.charge(player); return true; } - private void performSetMode(String mode, Player player) throws SignException { + private void performSetMode(String mode, User player) throws SignException { if (mode.contains("survi") || mode.equalsIgnoreCase("0")) { - player.setGameMode(GameMode.SURVIVAL); + player.getBase().setGameMode(GameMode.SURVIVAL); } else if (mode.contains("creat") || mode.equalsIgnoreCase("1")) { - player.setGameMode(GameMode.CREATIVE); + player.getBase().setGameMode(GameMode.CREATIVE); } else if (mode.contains("advent") || mode.equalsIgnoreCase("2")) { - player.setGameMode(GameMode.ADVENTURE); + player.getBase().setGameMode(GameMode.ADVENTURE); } else if (mode.contains("spec") || mode.equalsIgnoreCase("3")) { - player.setGameMode(GameMode.SPECTATOR); + player.getBase().setGameMode(GameMode.SPECTATOR); } else { - throw new SignException(tl("invalidSignLine", 2)); + throw new SignException(player.tl("invalidSignLine", 2)); } } } diff --git a/Essentials/src/com/earth2me/essentials/signs/SignHeal.java b/Essentials/src/com/earth2me/essentials/signs/SignHeal.java index a299e22147b..15ac1f9c39c 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignHeal.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignHeal.java @@ -5,8 +5,6 @@ import com.earth2me.essentials.User; import net.ess3.api.IEssentials; -import static com.earth2me.essentials.I18n.tl; - public class SignHeal extends EssentialsSign { public SignHeal() { @@ -15,21 +13,21 @@ public SignHeal() { @Override protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException { - validateTrade(sign, 1, ess); + validateTrade(sign, 1, player, ess); return true; } @Override protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException { if (player.getBase().getHealth() == 0) { - throw new SignException(tl("healDead")); + throw new SignException(player.tl("healDead")); } - final Trade charge = getTrade(sign, 1, ess); + final Trade charge = getTrade(player, sign, 1, ess); charge.isAffordableFor(player); player.getBase().setHealth(20); player.getBase().setFoodLevel(20); player.getBase().setFireTicks(0); - player.sendMessage(tl("youAreHealed")); + player.sendTl("youAreHealed"); charge.charge(player); Trade.log("Sign", "Heal", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess); return true; diff --git a/Essentials/src/com/earth2me/essentials/signs/SignInfo.java b/Essentials/src/com/earth2me/essentials/signs/SignInfo.java index c5df803bd38..5d4cbd054d0 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignInfo.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignInfo.java @@ -19,13 +19,13 @@ public SignInfo() { @Override protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException { - validateTrade(sign, 3, ess); + validateTrade(sign, 3, player, ess); return true; } @Override protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException { - final Trade charge = getTrade(sign, 3, ess); + final Trade charge = getTrade(player, sign, 3, ess); charge.isAffordableFor(player); String chapter = sign.getLine(1); diff --git a/Essentials/src/com/earth2me/essentials/signs/SignKit.java b/Essentials/src/com/earth2me/essentials/signs/SignKit.java index a9e569283ef..51baf4cdd46 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignKit.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignKit.java @@ -9,8 +9,6 @@ import java.util.Locale; -import static com.earth2me.essentials.I18n.tl; - public class SignKit extends EssentialsSign { public SignKit() { @@ -19,7 +17,7 @@ public SignKit() { @Override protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException { - validateTrade(sign, 3, ess); + validateTrade(sign, 3, player, ess); final String kitName = sign.getLine(1).toLowerCase(Locale.ENGLISH).trim(); @@ -45,7 +43,7 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri final String kitName = sign.getLine(1).toLowerCase(Locale.ENGLISH).trim(); final String group = sign.getLine(2).trim(); if ((!group.isEmpty() && ("§2Everyone".equals(group) || player.inGroup(group))) || (group.isEmpty() && (player.isAuthorized("essentials.kits." + kitName)))) { - final Trade charge = getTrade(sign, 3, ess); + final Trade charge = getTrade(player, sign, 3, ess); charge.isAffordableFor(player); try { final Kit kit = new Kit(kitName, ess); @@ -63,9 +61,9 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri return true; } else { if (group.isEmpty()) { - throw new SignException(tl("noKitPermission", "essentials.kits." + kitName)); + throw new SignException(player.tl("noKitPermission", "essentials.kits." + kitName)); } else { - throw new SignException(tl("noKitGroup", group)); + throw new SignException(player.tl("noKitGroup", group)); } } } diff --git a/Essentials/src/com/earth2me/essentials/signs/SignMail.java b/Essentials/src/com/earth2me/essentials/signs/SignMail.java index a20572a0494..6cfadc8ee37 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignMail.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignMail.java @@ -5,8 +5,6 @@ import java.util.List; -import static com.earth2me.essentials.I18n.tl; - public class SignMail extends EssentialsSign { public SignMail() { @@ -17,13 +15,13 @@ public SignMail() { protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException { final List mail = player.getMails(); if (mail.isEmpty()) { - player.sendMessage(tl("noNewMail")); + player.sendTl("noNewMail"); return false; } for (String s : mail) { player.sendMessage(s); } - player.sendMessage(tl("markMailAsRead")); + player.sendTl("markMailAsRead"); return true; } } diff --git a/Essentials/src/com/earth2me/essentials/signs/SignProtection.java b/Essentials/src/com/earth2me/essentials/signs/SignProtection.java index 9368ae60ee4..dfa3b2afe5b 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignProtection.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignProtection.java @@ -18,8 +18,6 @@ import java.util.*; -import static com.earth2me.essentials.I18n.tl; - @Deprecated // This sign will be removed soon public class SignProtection extends EssentialsSign { @@ -43,7 +41,7 @@ protected boolean onSignCreate(final ISign sign, final User player, final String return true; } } - player.sendMessage(tl("signProtectInvalidLocation")); + player.sendTl("signProtectInvalidLocation"); return false; } @@ -200,7 +198,7 @@ protected boolean onBlockPlace(final Block block, final User player, final Strin final SignProtectionState state = isBlockProtected(adjBlock, player, username, true); if ((state == SignProtectionState.ALLOWED || state == SignProtectionState.NOT_ALLOWED) && !player.isAuthorized("essentials.signs.protection.override")) { - player.sendMessage(tl("noPlacePermission", block.getType().toString().toLowerCase(Locale.ENGLISH))); + player.sendTl("noPlacePermission", block.getType().toString().toLowerCase(Locale.ENGLISH)); return false; } } @@ -221,7 +219,7 @@ protected boolean onBlockInteract(final Block block, final User player, final St } - player.sendMessage(tl("noAccessPermission", block.getType().toString().toLowerCase(Locale.ENGLISH))); + player.sendTl("noAccessPermission", block.getType().toString().toLowerCase(Locale.ENGLISH)); return false; } @@ -240,7 +238,7 @@ protected boolean onBlockBreak(final Block block, final User player, final Strin } - player.sendMessage(tl("noDestroyPermission", block.getType().toString().toLowerCase(Locale.ENGLISH))); + player.sendTl("noDestroyPermission", block.getType().toString().toLowerCase(Locale.ENGLISH)); return false; } diff --git a/Essentials/src/com/earth2me/essentials/signs/SignRepair.java b/Essentials/src/com/earth2me/essentials/signs/SignRepair.java index 3b028db272a..950909cf303 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignRepair.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignRepair.java @@ -7,8 +7,6 @@ import com.earth2me.essentials.commands.NotEnoughArgumentsException; import net.ess3.api.IEssentials; -import static com.earth2me.essentials.I18n.tl; - public class SignRepair extends EssentialsSign { public SignRepair() { @@ -22,15 +20,15 @@ protected boolean onSignCreate(final ISign sign, final User player, final String sign.setLine(1, "Hand"); } else if (!repairTarget.equalsIgnoreCase("all") && !repairTarget.equalsIgnoreCase("hand")) { sign.setLine(1, "§c"); - throw new SignException(tl("invalidSignLine", 2)); + throw new SignException(player.tl("invalidSignLine", 2)); } - validateTrade(sign, 2, ess); + validateTrade(sign, 2, player, ess); return true; } @Override protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException { - final Trade charge = getTrade(sign, 2, ess); + final Trade charge = getTrade(player, sign, 2, ess); charge.isAffordableFor(player); Commandrepair command = new Commandrepair(); diff --git a/Essentials/src/com/earth2me/essentials/signs/SignSell.java b/Essentials/src/com/earth2me/essentials/signs/SignSell.java index 8723b127170..8a76ea432a1 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignSell.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignSell.java @@ -20,14 +20,14 @@ public SignSell() { @Override protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException { validateTrade(sign, 1, 2, player, ess); - validateTrade(sign, 3, ess); + validateTrade(sign, 3, player, ess); return true; } @Override protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException, MaxMoneyException { Trade charge = getTrade(sign, 1, 2, player, ess); - Trade money = getTrade(sign, 3, ess); + Trade money = getTrade(player, sign, 3, ess); // Check if the player is trying to sell in bulk. if (ess.getSettings().isAllowBulkBuySell() && player.getBase().isSneaking()) { diff --git a/Essentials/src/com/earth2me/essentials/signs/SignSpawnmob.java b/Essentials/src/com/earth2me/essentials/signs/SignSpawnmob.java index 5a7f81643a4..bd35e92cc6a 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignSpawnmob.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignSpawnmob.java @@ -16,14 +16,14 @@ public SignSpawnmob() { @Override protected boolean onSignCreate(ISign sign, User player, String username, IEssentials ess) throws SignException, ChargeException { - validateInteger(sign, 1); - validateTrade(sign, 3, ess); + validateInteger(player, sign, 1); + validateTrade(sign, 3, player, ess); return true; } @Override protected boolean onSignInteract(ISign sign, User player, String username, IEssentials ess) throws SignException, ChargeException { - final Trade charge = getTrade(sign, 3, ess); + final Trade charge = getTrade(player, sign, 3, ess); charge.isAffordableFor(player); try { diff --git a/Essentials/src/com/earth2me/essentials/signs/SignTime.java b/Essentials/src/com/earth2me/essentials/signs/SignTime.java index 9cdcb9d3cce..55c8b259693 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignTime.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignTime.java @@ -5,8 +5,6 @@ import com.earth2me.essentials.User; import net.ess3.api.IEssentials; -import static com.earth2me.essentials.I18n.tl; - public class SignTime extends EssentialsSign { public SignTime() { @@ -15,7 +13,7 @@ public SignTime() { @Override protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException { - validateTrade(sign, 2, ess); + validateTrade(sign, 2, player, ess); final String timeString = sign.getLine(1); if ("Day".equalsIgnoreCase(timeString)) { sign.setLine(1, "§2Day"); @@ -25,12 +23,12 @@ protected boolean onSignCreate(final ISign sign, final User player, final String sign.setLine(1, "§2Night"); return true; } - throw new SignException(tl("onlyDayNight")); + throw new SignException(player.tl("onlyDayNight")); } @Override protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException { - final Trade charge = getTrade(sign, 2, ess); + final Trade charge = getTrade(player, sign, 2, ess); charge.isAffordableFor(player); final String timeString = sign.getLine(1); long time = player.getWorld().getTime(); @@ -47,6 +45,6 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri Trade.log("Sign", "TimeNight", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess); return true; } - throw new SignException(tl("onlyDayNight")); + throw new SignException(player.tl("onlyDayNight")); } } diff --git a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java index 990aaf31345..5b28288437e 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java @@ -14,8 +14,6 @@ import java.math.BigDecimal; import java.util.Map; -import static com.earth2me.essentials.I18n.tl; - //TODO: TL exceptions public class SignTrade extends EssentialsSign { public SignTrade() { @@ -24,10 +22,10 @@ public SignTrade() { @Override protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException { - validateTrade(sign, 1, false, ess); - validateTrade(sign, 2, true, ess); - final Trade trade = getTrade(sign, 2, AmountType.ROUNDED, true, true, ess); - final Trade charge = getTrade(sign, 1, AmountType.ROUNDED, false, true, ess); + validateTrade(sign, 1, false, player, ess); + validateTrade(sign, 2, true, player, ess); + final Trade trade = getTrade(sign, 2, AmountType.ROUNDED, true, true, player, ess); + final Trade charge = getTrade(sign, 1, AmountType.ROUNDED, false, true, player, ess); if (trade.getType() == charge.getType() && (trade.getType() != TradeType.ITEM || trade.getItemStack().isSimilar(charge.getItemStack()))) { throw new SignException("You cannot trade for the same item type."); } @@ -44,32 +42,32 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri final Trade store = rechargeSign(sign, ess, player); Trade stored; try { - stored = getTrade(sign, 1, AmountType.TOTAL, true, true, ess); - subtractAmount(sign, 1, stored, ess); + stored = getTrade(sign, 1, AmountType.TOTAL, true, true, player, ess); + subtractAmount(sign, 1, stored, player, ess); Map withdraw = stored.pay(player, OverflowType.RETURN); if (withdraw == null) { Trade.log("Sign", "Trade", "Withdraw", username, store, username, null, sign.getBlock().getLocation(), ess); } else { - setAmount(sign, 1, BigDecimal.valueOf(withdraw.get(0).getAmount()), ess); + setAmount(sign, 1, BigDecimal.valueOf(withdraw.get(0).getAmount()), player, ess); Trade.log("Sign", "Trade", "Withdraw", username, stored, username, new Trade(withdraw.get(0), ess), sign.getBlock().getLocation(), ess); } } catch (SignException e) { if (store == null) { - throw new SignException(tl("tradeSignEmptyOwner"), e); + throw new SignException(player.tl("tradeSignEmptyOwner"), e); } } Trade.log("Sign", "Trade", "Deposit", username, store, username, null, sign.getBlock().getLocation(), ess); } else { - final Trade charge = getTrade(sign, 1, AmountType.COST, false, true, ess); - final Trade trade = getTrade(sign, 2, AmountType.COST, true, true, ess); + final Trade charge = getTrade(sign, 1, AmountType.COST, false, true, player, ess); + final Trade trade = getTrade(sign, 2, AmountType.COST, true, true, player, ess); charge.isAffordableFor(player); - addAmount(sign, 1, charge, ess); - subtractAmount(sign, 2, trade, ess); + addAmount(sign, 1, charge, player, ess); + subtractAmount(sign, 2, trade, player, ess); if (!trade.pay(player)) { - subtractAmount(sign, 1, charge, ess); - addAmount(sign, 2, trade, ess); + subtractAmount(sign, 1, charge, player, ess); + addAmount(sign, 2, trade, player, ess); throw new ChargeException("Full inventory"); } charge.charge(player); @@ -80,7 +78,7 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri } private Trade rechargeSign(final ISign sign, final IEssentials ess, final User player) throws SignException, ChargeException { - final Trade trade = getTrade(sign, 2, AmountType.COST, false, true, ess); + final Trade trade = getTrade(sign, 2, AmountType.COST, false, true, player, ess); if (trade.getItemStack() != null && player.getBase().getItemInHand() != null && trade.getItemStack().getType() == player.getBase().getItemInHand().getType() && trade.getItemStack().getDurability() == player.getBase().getItemInHand().getDurability() && trade.getItemStack().getEnchantments().equals(player.getBase().getItemInHand().getEnchantments())) { int amount = player.getBase().getItemInHand().getAmount(); amount -= amount % trade.getItemStack().getAmount(); @@ -88,7 +86,7 @@ private Trade rechargeSign(final ISign sign, final IEssentials ess, final User p final ItemStack stack = player.getBase().getItemInHand().clone(); stack.setAmount(amount); final Trade store = new Trade(stack, ess); - addAmount(sign, 2, store, ess); + addAmount(sign, 2, store, player, ess); store.charge(player); return store; } @@ -106,8 +104,8 @@ protected boolean onSignBreak(final ISign sign, final User player, final String if (canBreak) { try { - final Trade stored1 = getTrade(sign, 1, AmountType.TOTAL, false, true, ess); - final Trade stored2 = getTrade(sign, 2, AmountType.TOTAL, false, true, ess); + final Trade stored1 = getTrade(sign, 1, AmountType.TOTAL, false, true, player, ess); + final Trade stored2 = getTrade(sign, 2, AmountType.TOTAL, false, true, player, ess); if (!canCollect) { Trade.log("Sign", "Trade", "Destroy", signOwner, stored2, username, stored1, sign.getBlock().getLocation(), ess); @@ -122,10 +120,10 @@ protected boolean onSignBreak(final ISign sign, final User player, final String return true; } - setAmount(sign, 1, BigDecimal.valueOf(withdraw1 == null ? 0L : withdraw1.get(0).getAmount()), ess); + setAmount(sign, 1, BigDecimal.valueOf(withdraw1 == null ? 0L : withdraw1.get(0).getAmount()), player, ess); Trade.log("Sign", "Trade", "Withdraw", signOwner, stored1, username, withdraw1 == null ? null : new Trade(withdraw1.get(0), ess), sign.getBlock().getLocation(), ess); - setAmount(sign, 2, BigDecimal.valueOf(withdraw2 == null ? 0L : withdraw2.get(0).getAmount()), ess); + setAmount(sign, 2, BigDecimal.valueOf(withdraw2 == null ? 0L : withdraw2.get(0).getAmount()), player, ess); Trade.log("Sign", "Trade", "Withdraw", signOwner, stored2, username, withdraw2 == null ? null : new Trade(withdraw2.get(0), ess), sign.getBlock().getLocation(), ess); sign.updateSign(); @@ -141,7 +139,7 @@ protected boolean onSignBreak(final ISign sign, final User player, final String } } - protected final void validateTrade(final ISign sign, final int index, final boolean amountNeeded, final IEssentials ess) throws SignException { + protected final void validateTrade(final ISign sign, final int index, final boolean amountNeeded, final User player, final IEssentials ess) throws SignException { final String line = sign.getLine(index).trim(); if (line.isEmpty()) { throw new SignException("Empty line"); @@ -149,7 +147,7 @@ protected final void validateTrade(final ISign sign, final int index, final bool final String[] split = line.split("[ :]+"); if (split.length == 1 && !amountNeeded) { - final BigDecimal money = getMoney(split[0]); + final BigDecimal money = getMoney(player, split[0]); if (money != null) { if (NumberUtil.shortCurrency(money, ess).length() * 2 > 15) { throw new SignException("Line can be too long!"); @@ -160,12 +158,12 @@ protected final void validateTrade(final ISign sign, final int index, final bool } if (split.length == 2 && amountNeeded) { - final BigDecimal money = getMoney(split[0]); - BigDecimal amount = getBigDecimalPositive(split[1]); + final BigDecimal money = getMoney(player, split[0]); + BigDecimal amount = getBigDecimalPositive(player, split[1]); if (money != null && amount != null) { amount = amount.subtract(amount.remainder(money)); if (amount.compareTo(MINTRANSACTION) < 0 || money.compareTo(MINTRANSACTION) < 0) { - throw new SignException(tl("moreThanZero")); + throw new SignException(player.tl("moreThanZero")); } sign.setLine(index, NumberUtil.shortCurrency(money, ess) + ":" + NumberUtil.shortCurrency(amount, ess).substring(1)); return; @@ -173,13 +171,13 @@ protected final void validateTrade(final ISign sign, final int index, final bool } if (split.length == 2 && !amountNeeded) { - final int amount = getIntegerPositive(split[0]); + final int amount = getIntegerPositive(player, split[0]); if (amount < 1) { - throw new SignException(tl("moreThanZero")); + throw new SignException(player.tl("moreThanZero")); } if (!(split[1].equalsIgnoreCase("exp") || split[1].equalsIgnoreCase("xp")) && getItemStack(split[1], amount, ess).getType() == Material.AIR) { - throw new SignException(tl("moreThanZero")); + throw new SignException(player.tl("moreThanZero")); } String newline = amount + " " + split[1] + ":0"; if ((newline + amount).length() > 15) { @@ -190,26 +188,26 @@ protected final void validateTrade(final ISign sign, final int index, final bool } if (split.length == 3 && amountNeeded) { - final int stackamount = getIntegerPositive(split[0]); - int amount = getIntegerPositive(split[2]); + final int stackamount = getIntegerPositive(player, split[0]); + int amount = getIntegerPositive(player, split[2]); amount -= amount % stackamount; if (amount < 1 || stackamount < 1) { - throw new SignException(tl("moreThanZero")); + throw new SignException(player.tl("moreThanZero")); } if (!(split[1].equalsIgnoreCase("exp") || split[1].equalsIgnoreCase("xp")) && getItemStack(split[1], stackamount, ess).getType() == Material.AIR) { - throw new SignException(tl("moreThanZero")); + throw new SignException(player.tl("moreThanZero")); } sign.setLine(index, stackamount + " " + split[1] + ":" + amount); return; } - throw new SignException(tl("invalidSignLine", index + 1)); + throw new SignException(player.tl("invalidSignLine", index + 1)); } - protected final Trade getTrade(final ISign sign, final int index, final AmountType amountType, final boolean notEmpty, final IEssentials ess) throws SignException { - return getTrade(sign, index, amountType, notEmpty, false, ess); + protected final Trade getTrade(final ISign sign, final int index, final AmountType amountType, final boolean notEmpty, final User player, final IEssentials ess) throws SignException { + return getTrade(sign, index, amountType, notEmpty, false, player, ess); } - protected final Trade getTrade(final ISign sign, final int index, final AmountType amountType, final boolean notEmpty, final boolean allowId, final IEssentials ess) throws SignException { + protected final Trade getTrade(final ISign sign, final int index, final AmountType amountType, final boolean notEmpty, final boolean allowId, final User player, final IEssentials ess) throws SignException { final String line = sign.getLine(index).trim(); if (line.isEmpty()) { throw new SignException("Empty line"); @@ -218,76 +216,76 @@ protected final Trade getTrade(final ISign sign, final int index, final AmountTy if (split.length == 2) { try { - final BigDecimal money = getMoney(split[0]); - final BigDecimal amount = notEmpty ? getBigDecimalPositive(split[1]) : getBigDecimal(split[1]); + final BigDecimal money = getMoney(player, split[0]); + final BigDecimal amount = notEmpty ? getBigDecimalPositive(player, split[1]) : getBigDecimal(split[1]); if (money != null && amount != null) { return new Trade(amountType == AmountType.COST ? money : amount, ess); } } catch (SignException e) { - throw new SignException(tl("tradeSignEmpty"), e); + throw new SignException(player.tl("tradeSignEmpty"), e); } } if (split.length == 3) { if (split[1].equalsIgnoreCase("exp") || split[1].equalsIgnoreCase("xp")) { - final int stackamount = getIntegerPositive(split[0]); + final int stackamount = getIntegerPositive(player, split[0]); int amount = getInteger(split[2]); if (amountType == AmountType.ROUNDED) { amount -= amount % stackamount; } if (notEmpty && (amount < 1 || stackamount < 1)) { - throw new SignException(tl("tradeSignEmpty")); + throw new SignException(player.tl("tradeSignEmpty")); } return new Trade((amountType == AmountType.COST ? stackamount : amount), ess); } else { - final int stackamount = getIntegerPositive(split[0]); + final int stackamount = getIntegerPositive(player, split[0]); final ItemStack item = getItemStack(split[1], stackamount, allowId, ess); int amount = getInteger(split[2]); if (amountType == AmountType.ROUNDED) { amount -= amount % stackamount; } if (notEmpty && (amount < 1 || stackamount < 1 || item.getType() == Material.AIR || amount < stackamount)) { - throw new SignException(tl("tradeSignEmpty")); + throw new SignException(player.tl("tradeSignEmpty")); } item.setAmount(amountType == AmountType.COST ? stackamount : amount); return new Trade(item, ess); } } - throw new SignException(tl("invalidSignLine", index + 1)); + throw new SignException(player.tl("invalidSignLine", index + 1)); } - protected final void subtractAmount(final ISign sign, final int index, final Trade trade, final IEssentials ess) throws SignException { + protected final void subtractAmount(final ISign sign, final int index, final Trade trade, final User player, final IEssentials ess) throws SignException { final BigDecimal money = trade.getMoney(); if (money != null) { - changeAmount(sign, index, money.negate(), ess); + changeAmount(sign, index, money.negate(), player, ess); } final ItemStack item = trade.getItemStack(); if (item != null) { - changeAmount(sign, index, BigDecimal.valueOf(-item.getAmount()), ess); + changeAmount(sign, index, BigDecimal.valueOf(-item.getAmount()), player, ess); } final Integer exp = trade.getExperience(); if (exp != null) { - changeAmount(sign, index, BigDecimal.valueOf(-exp.intValue()), ess); + changeAmount(sign, index, BigDecimal.valueOf(-exp.intValue()), player, ess); } } - protected final void addAmount(final ISign sign, final int index, final Trade trade, final IEssentials ess) throws SignException { + protected final void addAmount(final ISign sign, final int index, final Trade trade, final User player, final IEssentials ess) throws SignException { final BigDecimal money = trade.getMoney(); if (money != null) { - changeAmount(sign, index, money, ess); + changeAmount(sign, index, money, player, ess); } final ItemStack item = trade.getItemStack(); if (item != null) { - changeAmount(sign, index, BigDecimal.valueOf(item.getAmount()), ess); + changeAmount(sign, index, BigDecimal.valueOf(item.getAmount()), player, ess); } final Integer exp = trade.getExperience(); if (exp != null) { - changeAmount(sign, index, BigDecimal.valueOf(exp.intValue()), ess); + changeAmount(sign, index, BigDecimal.valueOf(exp.intValue()), player, ess); } } //TODO: Translate these exceptions. - private void changeAmount(final ISign sign, final int index, final BigDecimal value, final IEssentials ess) throws SignException { + private void changeAmount(final ISign sign, final int index, final BigDecimal value, final User player, final IEssentials ess) throws SignException { final String line = sign.getLine(index).trim(); if (line.isEmpty()) { throw new SignException("Empty line"); @@ -296,19 +294,19 @@ private void changeAmount(final ISign sign, final int index, final BigDecimal va if (split.length == 2) { final BigDecimal amount = getBigDecimal(split[1]).add(value); - setAmount(sign, index, amount, ess); + setAmount(sign, index, amount, player, ess); return; } if (split.length == 3) { final BigDecimal amount = getBigDecimal(split[2]).add(value); - setAmount(sign, index, amount, ess); + setAmount(sign, index, amount, player, ess); return; } - throw new SignException(tl("invalidSignLine", index + 1)); + throw new SignException(player.tl("invalidSignLine", index + 1)); } //TODO: Translate these exceptions. - private void setAmount(final ISign sign, final int index, final BigDecimal value, final IEssentials ess) throws SignException { + private void setAmount(final ISign sign, final int index, final BigDecimal value, final User player, final IEssentials ess) throws SignException { final String line = sign.getLine(index).trim(); if (line.isEmpty()) { @@ -317,7 +315,7 @@ private void setAmount(final ISign sign, final int index, final BigDecimal value final String[] split = line.split("[ :]+"); if (split.length == 2) { - final BigDecimal money = getMoney(split[0]); + final BigDecimal money = getMoney(player, split[0]); final BigDecimal amount = getBigDecimal(split[1]); if (money != null && amount != null) { final String newline = NumberUtil.shortCurrency(money, ess) + ":" + NumberUtil.shortCurrency(value, ess).substring(1); @@ -331,7 +329,7 @@ private void setAmount(final ISign sign, final int index, final BigDecimal value if (split.length == 3) { if (split[1].equalsIgnoreCase("exp") || split[1].equalsIgnoreCase("xp")) { - final int stackamount = getIntegerPositive(split[0]); + final int stackamount = getIntegerPositive(player, split[0]); final String newline = stackamount + " " + split[1] + ":" + (value.intValueExact()); if (newline.length() > 15) { throw new SignException("This sign is full: Line too long!"); @@ -339,7 +337,7 @@ private void setAmount(final ISign sign, final int index, final BigDecimal value sign.setLine(index, newline); return; } else { - final int stackamount = getIntegerPositive(split[0]); + final int stackamount = getIntegerPositive(player, split[0]); getItemStack(split[1], stackamount, ess); final String newline = stackamount + " " + split[1] + ":" + (value.intValueExact()); if (newline.length() > 15) { @@ -349,7 +347,7 @@ private void setAmount(final ISign sign, final int index, final BigDecimal value return; } } - throw new SignException(tl("invalidSignLine", index + 1)); + throw new SignException(player.tl("invalidSignLine", index + 1)); } diff --git a/Essentials/src/com/earth2me/essentials/signs/SignWarp.java b/Essentials/src/com/earth2me/essentials/signs/SignWarp.java index 2bdc5afdbb7..ed970f27bdf 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignWarp.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignWarp.java @@ -4,10 +4,9 @@ import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; import net.ess3.api.IEssentials; +import org.bukkit.ChatColor; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import static com.earth2me.essentials.I18n.tl; - public class SignWarp extends EssentialsSign { public SignWarp() { @@ -16,12 +15,12 @@ public SignWarp() { @Override protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException { - validateTrade(sign, 3, ess); + validateTrade(sign, 3, player, ess); final String warpName = sign.getLine(1); if (warpName.isEmpty()) { - sign.setLine(1, "§c"); - throw new SignException(tl("invalidSignLine", 1)); + sign.setLine(1, ChatColor.RED + ""); + throw new SignException(player.tl("invalidSignLine", 1)); } else { try { ess.getWarps().getWarp(warpName); @@ -30,7 +29,7 @@ protected boolean onSignCreate(final ISign sign, final User player, final String } final String group = sign.getLine(2); if ("Everyone".equalsIgnoreCase(group) || "Everybody".equalsIgnoreCase(group)) { - sign.setLine(2, "§2Everyone"); + sign.setLine(2, ChatColor.GREEN + "Everyone"); } return true; } @@ -43,15 +42,15 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri if (!group.isEmpty()) { if (!"§2Everyone".equals(group) && !player.inGroup(group)) { - throw new SignException(tl("warpUsePermission")); + throw new SignException(player.tl("warpUsePermission")); } } else { if (ess.getSettings().getPerWarpPermission() && !player.isAuthorized("essentials.warps." + warpName)) { - throw new SignException(tl("warpUsePermission")); + throw new SignException(player.tl("warpUsePermission")); } } - final Trade charge = getTrade(sign, 3, ess); + final Trade charge = getTrade(player, sign, 3, ess); try { player.getTeleport().warp(player, warpName, charge, TeleportCause.PLUGIN); Trade.log("Sign", "Warp", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess); diff --git a/Essentials/src/com/earth2me/essentials/signs/SignWeather.java b/Essentials/src/com/earth2me/essentials/signs/SignWeather.java index 534d1483225..d68df895063 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignWeather.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignWeather.java @@ -5,8 +5,6 @@ import com.earth2me.essentials.User; import net.ess3.api.IEssentials; -import static com.earth2me.essentials.I18n.tl; - public class SignWeather extends EssentialsSign { public SignWeather() { @@ -15,7 +13,7 @@ public SignWeather() { @Override protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException { - validateTrade(sign, 2, ess); + validateTrade(sign, 2, player, ess); final String timeString = sign.getLine(1); if ("Sun".equalsIgnoreCase(timeString)) { sign.setLine(1, "§2Sun"); @@ -26,12 +24,12 @@ protected boolean onSignCreate(final ISign sign, final User player, final String return true; } sign.setLine(1, "§c"); - throw new SignException(tl("onlySunStorm")); + throw new SignException(player.tl("onlySunStorm")); } @Override protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException { - final Trade charge = getTrade(sign, 2, ess); + final Trade charge = getTrade(player, sign, 2, ess); charge.isAffordableFor(player); final String weatherString = sign.getLine(1); if ("§2Sun".equalsIgnoreCase(weatherString)) { @@ -46,6 +44,6 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri Trade.log("Sign", "WeatherStorm", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess); return true; } - throw new SignException(tl("onlySunStorm")); + throw new SignException(player.tl("onlySunStorm")); } } diff --git a/Essentials/src/com/earth2me/essentials/textreader/HelpInput.java b/Essentials/src/com/earth2me/essentials/textreader/HelpInput.java index 036761be10b..e2f5e460fb8 100644 --- a/Essentials/src/com/earth2me/essentials/textreader/HelpInput.java +++ b/Essentials/src/com/earth2me/essentials/textreader/HelpInput.java @@ -28,7 +28,7 @@ public HelpInput(final User user, final String match, final IEssentials ess) thr String pluginName = ""; String pluginNameLow = ""; if (!match.equalsIgnoreCase("")) { - lines.add(tl("helpMatching", match)); + lines.add(user.tl("helpMatching", match)); } for (Plugin p : ess.getServer().getPluginManager().getPlugins()) { @@ -41,7 +41,7 @@ public HelpInput(final User user, final String match, final IEssentials ess) thr if (pluginNameLow.equals(match)) { lines.clear(); newLines.clear(); - lines.add(tl("helpFrom", p.getDescription().getName())); + lines.add(user.tl("helpFrom", p.getDescription().getName())); } final boolean isOnWhitelist = user.isAuthorized("essentials.help." + pluginNameLow); @@ -54,7 +54,7 @@ public HelpInput(final User user, final String match, final IEssentials ess) thr if (pluginNameLow.contains("essentials")) { final String node = "essentials." + k.getKey(); if (!ess.getSettings().isCommandDisabled(k.getKey()) && user.isAuthorized(node)) { - pluginLines.add(tl("helpLine", k.getKey(), k.getValue().get(DESCRIPTION))); + pluginLines.add(user.tl("helpLine", k.getKey(), k.getValue().get(DESCRIPTION))); } } else { if (ess.getSettings().showNonEssCommandsInHelp()) { @@ -66,7 +66,7 @@ public HelpInput(final User user, final String match, final IEssentials ess) thr permissions = value.get(PERMISSIONS); } if (isOnWhitelist || user.isAuthorized("essentials.help." + pluginNameLow + "." + k.getKey())) { - pluginLines.add(tl("helpLine", k.getKey(), value.get(DESCRIPTION))); + pluginLines.add(user.tl("helpLine", k.getKey(), value.get(DESCRIPTION))); } else if (permissions instanceof List && !((List) permissions).isEmpty()) { boolean enabled = false; for (Object o : (List) permissions) { @@ -76,15 +76,15 @@ public HelpInput(final User user, final String match, final IEssentials ess) thr } } if (enabled) { - pluginLines.add(tl("helpLine", k.getKey(), value.get(DESCRIPTION))); + pluginLines.add(user.tl("helpLine", k.getKey(), value.get(DESCRIPTION))); } } else if (permissions instanceof String && !"".equals(permissions)) { if (user.isAuthorized(permissions.toString())) { - pluginLines.add(tl("helpLine", k.getKey(), value.get(DESCRIPTION))); + pluginLines.add(user.tl("helpLine", k.getKey(), value.get(DESCRIPTION))); } } else { if (!ess.getSettings().hidePermissionlessHelp()) { - pluginLines.add(tl("helpLine", k.getKey(), value.get(DESCRIPTION))); + pluginLines.add(user.tl("helpLine", k.getKey(), value.get(DESCRIPTION))); } } } @@ -98,7 +98,7 @@ public HelpInput(final User user, final String match, final IEssentials ess) thr break; } if (match.equalsIgnoreCase("")) { - lines.add(tl("helpPlugin", pluginName, pluginNameLow)); + lines.add(user.tl("helpPlugin", pluginName, pluginNameLow)); } } } catch (NullPointerException ex) { diff --git a/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java b/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java index 2a1ed4caee2..11ffc46a880 100644 --- a/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java +++ b/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java @@ -8,6 +8,7 @@ import com.earth2me.essentials.utils.DescParseTickFormat; import com.earth2me.essentials.utils.NumberUtil; import net.ess3.api.IEssentials; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; @@ -21,8 +22,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import static com.earth2me.essentials.I18n.tl; - public class KeywordReplacer implements IText { private static final Pattern KEYWORD = Pattern.compile("\\{([^\\{\\}]+)\\}"); @@ -119,6 +118,7 @@ private String replaceLine(String line, final String fullMatch, final String[] m if (replacer == null) { replacer = ""; + Locale locale = user != null ? user.getApplicableLocale() : ess.getI18n().getCurrentLocale(); switch (validKeyword) { case PLAYER: case DISPLAYNAME: @@ -188,7 +188,7 @@ private String replaceLine(String line, final String fullMatch, final String[] m for (String groupName : playerList.keySet()) { final List groupUsers = playerList.get(groupName); if (groupUsers != null && !groupUsers.isEmpty()) { - outputList.put(groupName, PlayerList.listUsers(ess, groupUsers, " ")); + outputList.put(groupName, PlayerList.listUsers(ess, user != null ? user.getSource() : new CommandSource(Bukkit.getConsoleSender()), groupUsers, " ")); } } @@ -219,10 +219,10 @@ private String replaceLine(String line, final String fullMatch, final String[] m keywordCache.put(validKeyword, outputList); break; case TIME: - replacer = DateFormat.getTimeInstance(DateFormat.MEDIUM, ess.getI18n().getCurrentLocale()).format(new Date()); + replacer = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale).format(new Date()); break; case DATE: - replacer = DateFormat.getDateInstance(DateFormat.MEDIUM, ess.getI18n().getCurrentLocale()).format(new Date()); + replacer = DateFormat.getDateInstance(DateFormat.MEDIUM, locale).format(new Date()); break; case WORLDTIME12: if (user != null) { @@ -236,13 +236,13 @@ private String replaceLine(String line, final String fullMatch, final String[] m break; case WORLDDATE: if (user != null) { - replacer = DateFormat.getDateInstance(DateFormat.MEDIUM, ess.getI18n().getCurrentLocale()).format(DescParseTickFormat.ticksToDate(user.getWorld() == null ? 0 : user.getWorld().getFullTime())); + replacer = DateFormat.getDateInstance(DateFormat.MEDIUM, locale).format(DescParseTickFormat.ticksToDate(user.getWorld() == null ? 0 : user.getWorld().getFullTime())); } break; case COORDS: if (user != null) { final Location location = user.getLocation(); - replacer = tl("coordsKeyword", location.getBlockX(), location.getBlockY(), location.getBlockZ()); + replacer = user.tl("coordsKeyword", location.getBlockX(), location.getBlockY(), location.getBlockZ()); } break; case TPS: diff --git a/Essentials/src/com/earth2me/essentials/textreader/TextPager.java b/Essentials/src/com/earth2me/essentials/textreader/TextPager.java index 408698fcbaa..e2cdd73dc46 100644 --- a/Essentials/src/com/earth2me/essentials/textreader/TextPager.java +++ b/Essentials/src/com/earth2me/essentials/textreader/TextPager.java @@ -37,7 +37,7 @@ public void showPage(final String pageStr, final String chapterPageStr, final St if (onePage) { return; } - sender.sendMessage(tl("infoChapter")); + sender.sendTl("infoChapter"); final StringBuilder sb = new StringBuilder(); boolean first = true; for (String string : chapters) { @@ -71,7 +71,7 @@ public void showPage(final String pageStr, final String chapterPageStr, final St int pages = end / 9 + (end % 9 > 0 ? 1 : 0); if (page > pages) { - sender.sendMessage(tl("infoUnknownChapter")); + sender.sendTl("infoUnknownChapter"); return; } if (!onePage && commandName != null) { @@ -84,13 +84,13 @@ public void showPage(final String pageStr, final String chapterPageStr, final St } else { content.append(I18n.capitalCase(commandName)); } - sender.sendMessage(tl("infoPages", page, pages, content)); + sender.sendTl("infoPages", page, pages, content); } for (int i = start; i < end && i < start + (onePage ? 20 : 9); i++) { sender.sendMessage("§r" + lines.get(i)); } if (!onePage && page < pages && commandName != null) { - sender.sendMessage(tl("readNextPage", commandName, page + 1)); + sender.sendTl("readNextPage", commandName, page + 1); } return; } @@ -111,7 +111,7 @@ public void showPage(final String pageStr, final String chapterPageStr, final St //This checks to see if we have the chapter in the index if (!bookmarks.containsKey(pageStr.toLowerCase(Locale.ENGLISH))) { - sender.sendMessage(tl("infoUnknownChapter")); + sender.sendTl("infoUnknownChapter"); return; } @@ -133,13 +133,13 @@ public void showPage(final String pageStr, final String chapterPageStr, final St StringBuilder content = new StringBuilder(); content.append(I18n.capitalCase(commandName)).append(": "); content.append(pageStr); - sender.sendMessage(tl("infoChapterPages", content, page, pages)); + sender.sendTl("infoChapterPages", content, page, pages); } for (int i = start; i < chapterend && i < start + (onePage ? 20 : 9); i++) { sender.sendMessage("§r" + lines.get(i)); } if (!onePage && page < pages && commandName != null) { - sender.sendMessage(tl("readNextPage", commandName, pageStr + " " + (page + 1))); + sender.sendTl("readNextPage", commandName, pageStr + " " + (page + 1)); } } } diff --git a/Essentials/src/com/earth2me/essentials/utils/DateUtil.java b/Essentials/src/com/earth2me/essentials/utils/DateUtil.java index 913f4806bb2..38cef3f8eb6 100644 --- a/Essentials/src/com/earth2me/essentials/utils/DateUtil.java +++ b/Essentials/src/com/earth2me/essentials/utils/DateUtil.java @@ -1,5 +1,8 @@ package com.earth2me.essentials.utils; +import com.earth2me.essentials.CommandSource; +import org.bukkit.Bukkit; + import java.util.Calendar; import java.util.GregorianCalendar; import java.util.regex.Matcher; @@ -120,13 +123,25 @@ static int dateDiff(int type, Calendar fromDate, Calendar toDate, boolean future } public static String formatDateDiff(long date) { + return formatDateDiff(new CommandSource(Bukkit.getConsoleSender()), date); + } + + public static String formatDateDiff(CommandSource sender, long date) { Calendar c = new GregorianCalendar(); c.setTimeInMillis(date); Calendar now = new GregorianCalendar(); - return DateUtil.formatDateDiff(now, c); + return DateUtil.formatDateDiff(sender, now, c); } + /** + * @deprecated Use {@link #formatDateDiff(CommandSource, Calendar, Calendar)} + */ + @Deprecated public static String formatDateDiff(Calendar fromDate, Calendar toDate) { + return formatDateDiff(new CommandSource(Bukkit.getConsoleSender()), fromDate, toDate); + } + + public static String formatDateDiff(CommandSource sender, Calendar fromDate, Calendar toDate) { boolean future = false; if (toDate.equals(fromDate)) { return tl("now"); diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 5cb81260777..a394a9e7c30 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -364,13 +364,16 @@ list: # More output to the console. debug: false -# Set the locale for all messages. +# Set the default locale for all messages when a player's locale isn't found. # If you don't set this, the default locale of the server will be used. # For example, to set language to English, set locale to en, to use the file "messages_en.properties". # Don't forget to remove the # in front of the line. # For more information, visit http://wiki.ess3.net/wiki/Locale #locale: en +# Disable this if you want the locale to always be the default locale no matter what the user has selected. +change-locale: true + # Turn off god mode when people leave the server. remove-god-on-disconnect: false diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index c9e2e8b3635..e33ef7ff0af 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -257,6 +257,12 @@ listAmountHidden=\u00a76There are \u00a7c{0}\u00a76/\u00a7c{1}\u00a76 out of max listGroupTag=\u00a76{0}\u00a7r\: listHiddenTag=\u00a77[HIDDEN]\u00a7r loadWarpError=\u00a74Failed to load warp {0}. +localeChange=\u00a74You have to enable change-locale in Essentials config. +localeChanged=\u00a76Locale changed. +localeInUse=\u00a74Locale \u00a7c{0}\u00a7 already used. +localeNoMore=\u00a76You no longer have a custom locale. +localeSet=\u00a76Your locale is now \u00a7c{0}\u00a76. +localeUnknown=\u00a74No locale \u00a7c{0}\u00a7 found. localFormat=[L]<{0}> {1} localNoOne= mailClear=\u00a76To clear your mail, type\u00a7c /mail clear\u00a76. diff --git a/Essentials/src/net/ess3/api/IEssentials.java b/Essentials/src/net/ess3/api/IEssentials.java index 1e76dda1747..fec1f7da647 100644 --- a/Essentials/src/net/ess3/api/IEssentials.java +++ b/Essentials/src/net/ess3/api/IEssentials.java @@ -1,5 +1,6 @@ package net.ess3.api; +import net.ess3.nms.PlayerLocaleProvider; import net.ess3.nms.PotionMetaProvider; import net.ess3.nms.SpawnEggProvider; @@ -12,4 +13,6 @@ public interface IEssentials extends com.earth2me.essentials.IEssentials { SpawnEggProvider getSpawnEggProvider(); PotionMetaProvider getPotionMetaProvider(); + + PlayerLocaleProvider getPlayerLocaleProvider(); } diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml index 459f3f2e667..7a66924f4ec 100644 --- a/Essentials/src/plugin.yml +++ b/Essentials/src/plugin.yml @@ -244,6 +244,10 @@ commands: description: List all online players. usage: / [group] aliases: [elist,online,eonline,playerlist,eplayerlist,plist,eplist,who,ewho] + locale: + description: Change your locale or that of another player. + usage: / [player] + aliases: [elocale,language,elanguage,lang,elang] mail: description: Manages inter-player, intra-server mail. usage: / [read|clear|send [to] [message]|sendall [message]] diff --git a/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java b/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java index a9cff948f93..e0b0e13ef77 100644 --- a/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java +++ b/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java @@ -25,8 +25,6 @@ import java.util.logging.Logger; -import static com.earth2me.essentials.I18n.tl; - public class EssentialsAntiBuildListener implements Listener { private static final Logger logger = Logger.getLogger("EssentialsAntiBuild"); @@ -94,7 +92,7 @@ public void onBlockPlace(final BlockPlaceEvent event) { if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build") && !metaPermCheck(user, "place", block)) { if (ess.getSettings().warnOnBuildDisallow()) { - user.sendMessage(tl("antiBuildPlace", type.toString())); + user.sendTl("antiBuildPlace", type.toString()); } event.setCancelled(true); return; @@ -102,14 +100,14 @@ public void onBlockPlace(final BlockPlaceEvent event) { if (prot.checkProtectionItems(AntiBuildConfig.blacklist_placement, type) && !user.isAuthorized("essentials.protect.exemptplacement")) { if (ess.getSettings().warnOnBuildDisallow()) { - user.sendMessage(tl("antiBuildPlace", type.toString())); + user.sendTl("antiBuildPlace", type.toString()); } event.setCancelled(true); return; } if (prot.checkProtectionItems(AntiBuildConfig.alert_on_placement, type) && !user.isAuthorized("essentials.protect.alerts.notrigger")) { - prot.getEssentialsConnect().alert(user, type.toString(), tl("alertPlaced")); + prot.getEssentialsConnect().alert(user, type.toString(), user.tl("alertPlaced")); } } @@ -121,7 +119,7 @@ public void onBlockBreak(final BlockBreakEvent event) { if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build") && !metaPermCheck(user, "break", block)) { if (ess.getSettings().warnOnBuildDisallow()) { - user.sendMessage(tl("antiBuildBreak", type.toString())); + user.sendTl("antiBuildBreak", type.toString()); } event.setCancelled(true); return; @@ -129,14 +127,14 @@ public void onBlockBreak(final BlockBreakEvent event) { if (prot.checkProtectionItems(AntiBuildConfig.blacklist_break, type) && !user.isAuthorized("essentials.protect.exemptbreak")) { if (ess.getSettings().warnOnBuildDisallow()) { - user.sendMessage(tl("antiBuildBreak", type.toString())); + user.sendTl("antiBuildBreak", type.toString()); } event.setCancelled(true); return; } if (prot.checkProtectionItems(AntiBuildConfig.alert_on_break, type) && !user.isAuthorized("essentials.protect.alerts.notrigger")) { - prot.getEssentialsConnect().alert(user, type.toString(), tl("alertBroke")); + prot.getEssentialsConnect().alert(user, type.toString(), user.tl("alertBroke")); } } @@ -150,12 +148,12 @@ public void onHangingBreak(final HangingBreakByEntityEvent event) { if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build")) { if (type == EntityType.PAINTING && !metaPermCheck(user, "break", Material.PAINTING)) { if (warn) { - user.sendMessage(tl("antiBuildBreak", Material.PAINTING.toString())); + user.sendTl("antiBuildBreak", Material.PAINTING.toString()); } event.setCancelled(true); } else if (type == EntityType.ITEM_FRAME && !metaPermCheck(user, "break", Material.ITEM_FRAME)) { if (warn) { - user.sendMessage(tl("antiBuildBreak", Material.ITEM_FRAME.toString())); + user.sendTl("antiBuildBreak", Material.ITEM_FRAME.toString()); } event.setCancelled(true); } @@ -192,28 +190,28 @@ public void onPlayerInteract(final PlayerInteractEvent event) { if (item != null && prot.checkProtectionItems(AntiBuildConfig.blacklist_usage, item.getType()) && !user.isAuthorized("essentials.protect.exemptusage")) { if (ess.getSettings().warnOnBuildDisallow()) { - user.sendMessage(tl("antiBuildUse", item.getType().toString())); + user.sendTl("antiBuildUse", item.getType().toString()); } event.setCancelled(true); return; } if (item != null && prot.checkProtectionItems(AntiBuildConfig.alert_on_use, item.getType()) && !user.isAuthorized("essentials.protect.alerts.notrigger")) { - prot.getEssentialsConnect().alert(user, item.getType().toString(), tl("alertUsed")); + prot.getEssentialsConnect().alert(user, item.getType().toString(), user.tl("alertUsed")); } if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) { if (event.hasItem() && !metaPermCheck(user, "interact", item.getType(), item.getDurability())) { event.setCancelled(true); if (ess.getSettings().warnOnBuildDisallow()) { - user.sendMessage(tl("antiBuildUse", item.getType().toString())); + user.sendTl("antiBuildUse", item.getType().toString()); } return; } if (event.hasBlock() && !metaPermCheck(user, "interact", event.getClickedBlock())) { event.setCancelled(true); if (ess.getSettings().warnOnBuildDisallow()) { - user.sendMessage(tl("antiBuildInteract", event.getClickedBlock().getType().toString())); + user.sendTl("antiBuildInteract", event.getClickedBlock().getType().toString()); } } } @@ -231,7 +229,7 @@ public void onCraftItemEvent(final CraftItemEvent event) { if (!metaPermCheck(user, "craft", item.getType(), item.getDurability())) { event.setCancelled(true); if (ess.getSettings().warnOnBuildDisallow()) { - user.sendMessage(tl("antiBuildCraft", item.getType().toString())); + user.sendTl("antiBuildCraft", item.getType().toString()); } } } @@ -249,7 +247,7 @@ public void onPlayerDropItem(final PlayerDropItemEvent event) { event.setCancelled(true); user.getBase().updateInventory(); if (ess.getSettings().warnOnBuildDisallow()) { - user.sendMessage(tl("antiBuildDrop", item.getType().toString())); + user.sendTl("antiBuildDrop", item.getType().toString()); } } } diff --git a/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsConnect.java b/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsConnect.java index 41de89449be..313ff53ba73 100644 --- a/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsConnect.java +++ b/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsConnect.java @@ -35,7 +35,7 @@ IEssentials getEssentials() { void alert(final User user, final String item, final String type) { final Location loc = user.getLocation(); - final String warnMessage = tl("alertFormat", user.getName(), type, item, loc.getWorld().getName() + "," + loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ()); + final String warnMessage = user.tl("alertFormat", user.getName(), type, item, loc.getWorld().getName() + "," + loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ()); logger.log(Level.WARNING, warnMessage); for (Player p : ess.getServer().getOnlinePlayers()) { final User alertUser = ess.getUser(p); diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerNormal.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerNormal.java index 3157701a6aa..fa7df01d675 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerNormal.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerNormal.java @@ -46,11 +46,11 @@ public void onPlayerChat(final AsyncPlayerChatEvent event) { if (user.isAuthorized(permission.toString())) { event.setMessage(event.getMessage().substring(1)); - event.setFormat(tl(chatStore.getType() + "Format", event.getFormat())); + event.setFormat(user.tl(chatStore.getType() + "Format", event.getFormat())); return; } - user.sendMessage(tl("notAllowedTo" + chatStore.getType().substring(0, 1).toUpperCase(Locale.ENGLISH) + chatStore.getType().substring(1))); + user.sendTl("notAllowedTo" + chatStore.getType().substring(0, 1).toUpperCase(Locale.ENGLISH) + chatStore.getType().substring(1)); event.setCancelled(true); return; } @@ -75,7 +75,7 @@ public void onPlayerChat(final AsyncPlayerChatEvent event) { } final String format = event.getFormat(); - event.setFormat(tl("chatTypeLocal").concat(event.getFormat())); + event.setFormat(user.tl("chatTypeLocal").concat(event.getFormat())); logger.info(tl("localFormat", user.getName(), event.getMessage())); @@ -104,7 +104,7 @@ public void onPlayerChat(final AsyncPlayerChatEvent event) { } if (outList.size() < 2) { - user.sendMessage(tl("localNoOne")); + user.sendTl("localNoOne"); } LocalChatSpyEvent spyEvent = new LocalChatSpyEvent(event.isAsynchronous(), event.getPlayer(), format, event.getMessage(), spyList); diff --git a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java index 86175e6ad33..ea160c301cb 100644 --- a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java +++ b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java @@ -105,7 +105,7 @@ private void delayedJoin(Player player) { for (Player onlinePlayer : player.getServer().getOnlinePlayers()) { User user = ess.getUser(onlinePlayer); if (user.isAuthorized("essentials.geoip.show")) { - user.sendMessage(tl("geoipJoinFormat", u.getDisplayName(), sb.toString())); + user.sendTl("geoipJoinFormat", u.getDisplayName(), sb.toString()); } } } diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java index c0d876f83cd..acfbad0175e 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java @@ -4,8 +4,6 @@ import com.earth2me.essentials.commands.EssentialsCommand; import org.bukkit.Server; -import static com.earth2me.essentials.I18n.tl; - public class Commandsetspawn extends EssentialsCommand { public Commandsetspawn() { @@ -16,6 +14,6 @@ public Commandsetspawn() { public void run(final Server server, final User user, final String commandLabel, final String[] args) { final String group = args.length > 0 ? getFinalArg(args, 0) : "default"; ((SpawnStorage) module).setSpawn(user.getLocation(), group); - user.sendMessage(tl("spawnSet", group)); + user.sendTl("spawnSet", group); } } diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java index c903f404fee..ee170c262cf 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java @@ -11,8 +11,6 @@ import org.bukkit.Server; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import static com.earth2me.essentials.I18n.tl; - public class Commandspawn extends EssentialsCommand { public Commandspawn() { @@ -27,7 +25,7 @@ public void run(final Server server, final User user, final String commandLabel, final User otherUser = getPlayer(server, user, args, 0); respawn(user.getSource(), user, otherUser, charge); if (!otherUser.equals(user)) { - otherUser.sendMessage(tl("teleportAtoB", user.getDisplayName(), "spawn")); + otherUser.sendTl("teleportAtoB", user.getDisplayName(), "spawn"); } } else { respawn(user.getSource(), user, user, charge); @@ -42,14 +40,14 @@ protected void run(final Server server, final CommandSource sender, final String } final User user = getPlayer(server, args, 0, true, false); respawn(sender, null, user, null); - user.sendMessage(tl("teleportAtoB", Console.NAME, "spawn")); + user.sendTl("teleportAtoB", Console.NAME, "spawn"); } private void respawn(final CommandSource sender, final User teleportOwner, final User teleportee, final Trade charge) throws Exception { final SpawnStorage spawns = (SpawnStorage) this.module; final Location spawn = spawns.getSpawn(teleportee.getGroup()); - sender.sendMessage(tl("teleporting", spawn.getWorld().getName(), spawn.getBlockX(), spawn.getBlockY(), spawn.getBlockZ())); + sender.sendTl("teleporting", spawn.getWorld().getName(), spawn.getBlockX(), spawn.getBlockY(), spawn.getBlockZ()); if (teleportOwner == null) { teleportee.getTeleport().now(spawn, false, TeleportCause.COMMAND); } else { diff --git a/nms/LocaleApiProvider/pom.xml b/nms/LocaleApiProvider/pom.xml new file mode 100644 index 00000000000..cbc4e4e5b27 --- /dev/null +++ b/nms/LocaleApiProvider/pom.xml @@ -0,0 +1,22 @@ + + + + EssentialsXParent + net.ess3 + 2.16.1 + ../../pom.xml + + 4.0.0 + + LocaleApiProvider + + + + net.ess3 + NMSProvider + 2.16.1 + + + \ No newline at end of file diff --git a/nms/LocaleApiProvider/src/net/ess3/nms/localeapi/ApiPlayerLocaleProvider.java b/nms/LocaleApiProvider/src/net/ess3/nms/localeapi/ApiPlayerLocaleProvider.java new file mode 100644 index 00000000000..165abf7b1ad --- /dev/null +++ b/nms/LocaleApiProvider/src/net/ess3/nms/localeapi/ApiPlayerLocaleProvider.java @@ -0,0 +1,26 @@ +package net.ess3.nms.localeapi; + +import net.ess3.nms.PlayerLocaleProvider; +import org.bukkit.entity.Player; + +public class ApiPlayerLocaleProvider extends PlayerLocaleProvider { + @Override + public String getLocale(Player player) { + return player.getLocale(); + } + + @Override + public boolean tryProvider() { + try { + Player.class.getMethod("getLocale"); + return true; + } catch (NoSuchMethodException e) { + return false; + } + } + + @Override + public String getHumanName() { + return "player locale api provider"; + } +} diff --git a/nms/NMSProvider/src/net/ess3/nms/PlayerLocaleProvider.java b/nms/NMSProvider/src/net/ess3/nms/PlayerLocaleProvider.java new file mode 100644 index 00000000000..5a967a552b0 --- /dev/null +++ b/nms/NMSProvider/src/net/ess3/nms/PlayerLocaleProvider.java @@ -0,0 +1,10 @@ +package net.ess3.nms; + +import net.ess3.providers.Provider; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public abstract class PlayerLocaleProvider implements Provider { + public abstract String getLocale(Player player); +} diff --git a/nms/ReflectionProvider/src/net/ess3/nms/refl/ReflPlayerLocaleProvider.java b/nms/ReflectionProvider/src/net/ess3/nms/refl/ReflPlayerLocaleProvider.java new file mode 100644 index 00000000000..acdf4919aec --- /dev/null +++ b/nms/ReflectionProvider/src/net/ess3/nms/refl/ReflPlayerLocaleProvider.java @@ -0,0 +1,50 @@ +package net.ess3.nms.refl; + +import net.ess3.nms.PlayerLocaleProvider; +import org.bukkit.entity.Player; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class ReflPlayerLocaleProvider extends PlayerLocaleProvider { + + private final Method getHandleMethod; + private final Field localeField; + + public ReflPlayerLocaleProvider() { + Class craftPlayerClass = ReflUtil.getOBCClass("entity.CraftPlayer"); + Class nmsEntityPlayerClass = ReflUtil.getNMSClass("EntityPlayer"); + if (craftPlayerClass != null && nmsEntityPlayerClass != null) { + getHandleMethod = ReflUtil.getMethodCached(craftPlayerClass, "getHandle"); + localeField = ReflUtil.getFieldCached(nmsEntityPlayerClass, "locale"); + } else { + getHandleMethod = null; + localeField = null; + } + } + + @Override + public String getLocale(Player player) { + if (tryProvider()) { + try { + Object nmsEntityPlayer = getHandleMethod.invoke(player); + if (nmsEntityPlayer != null) { + return (String) localeField.get(nmsEntityPlayer); + } + } catch (IllegalAccessException | InvocationTargetException ignored) { + } + } + return null; + } + + @Override + public boolean tryProvider() { + return getHandleMethod != null && localeField != null; + } + + @Override + public String getHumanName() { + return "api player locale provider"; + } +} diff --git a/pom.xml b/pom.xml index 8513d210808..438ee269293 100644 --- a/pom.xml +++ b/pom.xml @@ -52,6 +52,7 @@ nms/LegacyProvider nms/ReflectionProvider nms/FlattenedProvider + nms/LocaleApiProvider