diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index d686bab0..3b669253 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -266,7 +266,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag */ @Override public void onEnable() { - this.messaging = new MVMessaging(); + this.messaging = new MVMessaging(this); this.banker = new AllPay(this, LOG_TAG + " "); // Output a little snippet to show it's enabled. this.log(Level.INFO, "- Version " + this.getDescription().getVersion() + " (API v" + PROTOCOL + ") Enabled - By " + getAuthors()); @@ -308,7 +308,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag this.worldManager.loadDefaultWorlds(); this.worldManager.loadWorlds(true); } else { - this.log(Level.SEVERE, this.getMessageProvider().getMessage(MultiverseMessage.ERROR_LOAD)); + this.log(Level.SEVERE, "Your configs were not loaded. Very little will function in Multiverse."); } this.anchorManager.loadAnchors(); @@ -863,7 +863,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag @Override public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) { if (!this.isEnabled()) { - sender.sendMessage(this.getMessageProvider().getMessage(MultiverseMessage.GENERIC_PLUGIN_DISABLED)); + this.messaging.sendMessage(sender, MultiverseMessage.CH_PLUGIN_DISABLED); return true; } ArrayList allArgs = new ArrayList(Arrays.asList(args)); @@ -872,11 +872,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag return this.commandHandler.locateAndRunCommand(sender, allArgs, getMVConfig().getDisplayPermErrors()); } catch (Exception e) { e.printStackTrace(); - sender.sendMessage(ChatColor.RED + "An internal error occurred when attempting to perform this command."); - if (sender.isOp()) - sender.sendMessage(ChatColor.RED + "Details were printed to the server console and logs, please add that to your bug report."); - else - sender.sendMessage(ChatColor.RED + "Try again and contact the server owner or an admin if this problem persists."); + this.messaging.sendMessage(sender, MultiverseMessage.CH_INTERNAL_ERROR); + this.messaging.sendMessage(sender, sender.isOp() ? MultiverseMessage.CH_ADMIN_DEBUG : MultiverseMessage.CH_USER_DEBUG); return true; } } @@ -970,8 +967,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag * @param worldName The name of the invalid world */ public void showNotMVWorldMessage(CommandSender sender, String worldName) { - sender.sendMessage("Multiverse doesn't know about " + ChatColor.DARK_AQUA + worldName + ChatColor.WHITE + " yet."); - sender.sendMessage("Type " + ChatColor.DARK_AQUA + "/mv import ?" + ChatColor.WHITE + " for help!"); + // TODO remove this method because we can now send this message in one line + this.messaging.sendMessage(sender, MultiverseMessage.GENERIC_NOT_MV_WORLD, worldName); } /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseMessaging.java b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseMessaging.java index ae2bd004..52a80f41 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseMessaging.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseMessaging.java @@ -4,6 +4,8 @@ import java.util.Collection; import org.bukkit.command.CommandSender; +import com.onarandombox.MultiverseCore.localization.MultiverseMessage; + /** * Multiverse-messaging. */ @@ -14,6 +16,27 @@ public interface MultiverseMessaging { */ void setCooldown(int milliseconds); + /** + * Sends a message to the specified sender if the cooldown has passed. + * + * @param sender The person/console to send the message to. + * @param message The message to send. + * @param formatArgs Format arguments for the message. + * @return true if the message was sent, false if not. + */ + boolean sendMessage(CommandSender sender, MultiverseMessage message, Object...formatArgs); + + /** + * Sends a message to the specified sender if the cooldown has passed. + * + * @param sender The person/console to send the message to. + * @param message The message to send. + * @param ignoreCooldown If true this message will always be sent. Useful for things like menus + * @param formatArgs Format arguments for the message. + * @return true if the message was sent, false if not. + */ + boolean sendMessage(CommandSender sender, MultiverseMessage message, boolean ignoreCooldown, Object... formatArgs); + /** * Sends a message to the specified sender if the cooldown has passed. * diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MultiversePlugin.java b/src/main/java/com/onarandombox/MultiverseCore/api/MultiversePlugin.java index b010d9ed..06a83878 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MultiversePlugin.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MultiversePlugin.java @@ -12,6 +12,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.plugin.java.JavaPlugin; import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.localization.MultiverseMessage; import com.onarandombox.MultiverseCore.utils.DebugLog; import com.pneumaticraft.commandhandler.CommandHandler; @@ -106,7 +107,7 @@ public abstract class MultiversePlugin extends JavaPlugin implements MVPlugin { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!this.isEnabled()) { - sender.sendMessage("This plugin is Disabled!"); + this.core.getMessaging().sendMessage(sender, MultiverseMessage.CH_PLUGIN_DISABLED); return true; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java index 0c584d19..5358639e 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java @@ -24,19 +24,18 @@ import java.util.List; * Displays a listing of all worlds that a player can enter. */ public class ListCommand extends PaginatedCoreCommand { - private MessageProvider provider; public ListCommand(MultiverseCore plugin) { super(plugin); provider = plugin.getMessageProvider(); - this.setName(provider.getMessage(MultiverseMessage.LIST_NAME)); + this.setName(provider.getMessage(MultiverseMessage.CMD_LIST_NAME)); this.setCommandUsage("/mv list"); this.setArgRange(0, 2); this.addKey("mvlist"); this.addKey("mvl"); this.addKey("mv list"); - this.setPermission("multiverse.core.list.worlds", provider.getMessage(MultiverseMessage.LIST_DESC), PermissionDefault.OP); + this.setPermission("multiverse.core.list.worlds", provider.getMessage(MultiverseMessage.CMD_LIST_DESC), PermissionDefault.OP); this.setItemsPerPage(8); // SUPPRESS CHECKSTYLE: MagicNumberCheck } @@ -71,7 +70,7 @@ public class ListCommand extends PaginatedCoreCommand { } for (String name : this.plugin.getMVWorldManager().getUnloadedWorlds()) { if (p == null || this.plugin.getMVPerms().hasPermission(p, "multiverse.access." + name, true)) { - worldList.add(ChatColor.GRAY + name + " - " + provider.getMessage(MultiverseMessage.GENERIC_UNLOADED)); + worldList.add(ChatColor.GRAY + name + " - " + "UNLOADED"); } } return worldList; @@ -96,7 +95,7 @@ public class ListCommand extends PaginatedCoreCommand { @Override public void runCommand(CommandSender sender, List args) { - sender.sendMessage(ChatColor.LIGHT_PURPLE + "====[ " + this.provider.getMessage(MultiverseMessage.LIST_TITLE) + " ]===="); + sender.sendMessage(ChatColor.LIGHT_PURPLE + "====[ " + this.provider.getMessage(MultiverseMessage.CMD_LIST_TITLE) + " ]===="); Player p = null; if (sender instanceof Player) { p = (Player) sender; @@ -109,7 +108,7 @@ public class ListCommand extends PaginatedCoreCommand { if (filterObject.getFilter().length() > 0) { availableWorlds = this.getFilteredItems(availableWorlds, filterObject.getFilter()); if (availableWorlds.size() == 0) { - sender.sendMessage(ChatColor.RED + provider.getMessage(MultiverseMessage.GENERIC_SORRY) + " " + ChatColor.WHITE + provider.getMessage(MultiverseMessage.LIST_NO_MATCH) + " " + ChatColor.AQUA + filterObject.getFilter()); + sender.sendMessage(ChatColor.RED + "Sorry... " + ChatColor.WHITE + provider.getMessage(MultiverseMessage.CMD_LIST_NO_MATCH) + " " + ChatColor.AQUA + filterObject.getFilter()); return; } } @@ -127,7 +126,7 @@ public class ListCommand extends PaginatedCoreCommand { filterObject.setPage(totalPages); } - sender.sendMessage(ChatColor.AQUA + " " + provider.getMessage(MultiverseMessage.GENERIC_PAGE) + " " + filterObject.getPage() + " " + provider.getMessage(MultiverseMessage.GENERIC_OF) + " " + totalPages); + sender.sendMessage(ChatColor.AQUA + " Page " + filterObject.getPage() + " of " + totalPages); this.showPage(filterObject.getPage(), sender, availableWorlds); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java index ed8c0397..2306485d 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java @@ -11,6 +11,7 @@ import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.event.MVRespawnEvent; +import com.onarandombox.MultiverseCore.localization.MultiverseMessage; import com.onarandombox.MultiverseCore.utils.PermissionTools; import org.bukkit.Location; import org.bukkit.Material; @@ -119,7 +120,7 @@ public class MVPlayerListener implements Listener { this.plugin.log(Level.FINER, "Player joined AGAIN!"); if (this.plugin.getMVConfig().getEnforceAccess() // check this only if we're enforcing access! && !this.plugin.getMVPerms().hasPermission(p, "multiverse.access." + p.getWorld().getName(), false)) { - p.sendMessage("[MV] - Sorry you can't be in this world anymore!"); + this.plugin.getMessaging().sendMessage(p, MultiverseMessage.LISTENER_PLAYER_LOSTACCESSPERM); this.sendPlayerToDefaultWorld(p); } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/localization/MultiverseMessage.java b/src/main/java/com/onarandombox/MultiverseCore/localization/MultiverseMessage.java index 49429cde..b26bc672 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/localization/MultiverseMessage.java +++ b/src/main/java/com/onarandombox/MultiverseCore/localization/MultiverseMessage.java @@ -8,23 +8,36 @@ public enum MultiverseMessage { // BEGIN CHECKSTYLE-SUPPRESSION: JavadocVariable TEST_STRING("a test-string from the enum"), - // Generic Strings - GENERIC_SORRY("Sorry..."), - GENERIC_PAGE("Page"), - GENERIC_OF("of"), - GENERIC_UNLOADED("UNLOADED"), - GENERIC_PLUGIN_DISABLED("This plugin is Disabled!"), + //// Command handling error messages + CH_PLUGIN_DISABLED("This plugin is disabled!"), + CH_INTERNAL_ERROR("&cAn internal error occurred when attempting to perform this command."), + CH_ADMIN_DEBUG("&cDetails were printed to the server console and logs, please add that to your bug report."), + CH_USER_DEBUG("&cTry again and contact the server owner or an admin if this problem persists."), - // Errors - ERROR_LOAD("Your configs were not loaded. Very little will function in Multiverse."), + //// Not MV world message + GENERIC_NOT_MV_WORLD("Multiverse doesn't know about &3%s&f yet.\nType &3/mv import ?&f for help!"), //// Commands // List Command - LIST_NAME("World Listing"), - LIST_DESC("Displays a listing of all worlds that you can enter."), - LIST_TITLE("Multiverse World List"), - LIST_NO_MATCH("No worlds matched your filter:"); + CMD_LIST_NAME("World Listing"), + CMD_LIST_DESC("Displays a listing of all worlds that you can enter."), + CMD_LIST_TITLE("Multiverse World List"), + CMD_LIST_NO_MATCH("No worlds matched your filter:"), + + //// Listeners + // PlayerListener + LISTENER_PLAYER_LOSTACCESSPERM("[MV] - Sorry you can't be in this world anymore!"), + + //// Permissions + PERMS_NOACCESS_SELF("You don't have access to go here..."), + PERMS_NOACCESS_OTHER("You can't send %s here..."), + PERMS_NOACCESS_BLACKLIST_SELF("You don't have access to go to %s from %s"), + PERMS_NOACCESS_BLACKLIST_OTHER("You don't have access to send %s from %s to %s"), + + //// World purger + PURGER_ENTITIESKILLED("%d entities purged from the world '%s'"), // END CHECKSTYLE-SUPPRESSION: JavadocVariable + ; private final String def; diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/MVMessaging.java b/src/main/java/com/onarandombox/MultiverseCore/utils/MVMessaging.java index 8363c12d..a8060803 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/MVMessaging.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/MVMessaging.java @@ -11,6 +11,8 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.onarandombox.MultiverseCore.api.MultiverseMessaging; +import com.onarandombox.MultiverseCore.localization.MessageProviding; +import com.onarandombox.MultiverseCore.localization.MultiverseMessage; import java.util.Collection; import java.util.HashMap; @@ -20,10 +22,12 @@ import java.util.Map; * The default-implementation of {@link MultiverseMessaging}. */ public class MVMessaging implements MultiverseMessaging { + private final MessageProviding msgProviding; private Map sentList; private int cooldown; - public MVMessaging() { + public MVMessaging(MessageProviding msgProviding) { + this.msgProviding = msgProviding; this.sentList = new HashMap(); this.cooldown = 5000; // SUPPRESS CHECKSTYLE: MagicNumberCheck } @@ -50,7 +54,6 @@ public class MVMessaging implements MultiverseMessaging { @Override public boolean sendMessages(CommandSender sender, String[] messages, boolean ignoreCooldown) { if (!(sender instanceof Player) || ignoreCooldown) { - sendMessages(sender, messages); return true; } @@ -90,4 +93,20 @@ public class MVMessaging implements MultiverseMessaging { public int getCooldown() { return cooldown; } + + /** + * {@inheritDoc} + */ + @Override + public boolean sendMessage(CommandSender sender, MultiverseMessage message, Object... args) { + return this.sendMessage(sender, message, true, args); // TODO what is a good default value? + } + + /** + * {@inheritDoc} + */ + @Override + public boolean sendMessage(CommandSender sender, MultiverseMessage message, boolean ignoreCooldown, Object...args) { + return this.sendMessage(sender, this.msgProviding.getMessageProvider().getMessage(message, args), ignoreCooldown); + } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java b/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java index 780f0a89..2b115abe 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java @@ -10,6 +10,8 @@ package com.onarandombox.MultiverseCore.utils; import com.fernferret.allpay.GenericBank; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MultiverseWorld; +import com.onarandombox.MultiverseCore.localization.MultiverseMessage; + import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; @@ -208,11 +210,10 @@ public class PermissionTools { // Actual checks if (toWorld != null) { if (!this.plugin.getMVPerms().canEnterWorld(teleporterPlayer, toWorld)) { - if (teleportee.equals(teleporter)) { - teleporter.sendMessage("You don't have access to go here..."); - } else { - teleporter.sendMessage("You can't send " + teleportee.getName() + " here..."); - } + if (teleportee.equals(teleporter)) + this.plugin.getMessaging().sendMessage(teleporter, MultiverseMessage.PERMS_NOACCESS_SELF); + else + this.plugin.getMessaging().sendMessage(teleporter, MultiverseMessage.PERMS_NOACCESS_OTHER, teleportee.getName()); return false; } @@ -223,12 +224,10 @@ public class PermissionTools { } if (fromWorld != null) { if (fromWorld.getWorldBlacklist().contains(toWorld.getName())) { - if (teleportee.equals(teleporter)) { - teleporter.sendMessage("You don't have access to go to " + toWorld.getColoredWorldString() + " from " + fromWorld.getColoredWorldString()); - } else { - teleporter.sendMessage("You don't have access to send " + teleportee.getName() + " from " - + fromWorld.getColoredWorldString() + " to " + toWorld.getColoredWorldString()); - } + if (teleportee.equals(teleporter)) + this.plugin.getMessaging().sendMessage(teleporter, MultiverseMessage.PERMS_NOACCESS_BLACKLIST_SELF, toWorld.getColoredWorldString(), fromWorld.getColoredWorldString()); + else + this.plugin.getMessaging().sendMessage(teleporter, MultiverseMessage.PERMS_NOACCESS_BLACKLIST_OTHER, teleportee.getName(), fromWorld.getColoredWorldString(), toWorld.getColoredWorldString()); return false; } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/SimpleWorldPurger.java b/src/main/java/com/onarandombox/MultiverseCore/utils/SimpleWorldPurger.java index df86abd4..4110e671 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/SimpleWorldPurger.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/SimpleWorldPurger.java @@ -10,6 +10,7 @@ package com.onarandombox.MultiverseCore.utils; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.api.WorldPurger; +import com.onarandombox.MultiverseCore.localization.MultiverseMessage; import org.bukkit.World; import org.bukkit.command.CommandSender; @@ -95,9 +96,8 @@ public class SimpleWorldPurger implements WorldPurger { entitiesKilled++; } } - if (sender != null) { - sender.sendMessage(entitiesKilled + " entities purged from the world '" + world.getName() + "'"); - } + if (sender != null) + this.plugin.getMessaging().sendMessage(sender, MultiverseMessage.PURGER_ENTITIESKILLED, entitiesKilled, world.getName()); } private boolean killDecision(Entity e, List thingsToKill, boolean negateAnimals,