diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c0cb49a..a960154 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ stages: variables: name: "UltimateModeration" path: "/builds/$CI_PROJECT_PATH" - version: "1.1.8" + version: "1.1.9" build: stage: build diff --git a/src/main/java/com/songoda/ultimatemoderation/Locale.java b/src/main/java/com/songoda/ultimatemoderation/Locale.java deleted file mode 100644 index 5be92d0..0000000 --- a/src/main/java/com/songoda/ultimatemoderation/Locale.java +++ /dev/null @@ -1,375 +0,0 @@ -package com.songoda.ultimatemoderation; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; -import org.bukkit.ChatColor; -import org.bukkit.plugin.java.JavaPlugin; - -import java.io.*; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - -/** - * Assists in the creation of multiple localizations and languages, - * as well as the generation of default .lang files - * - * @author Parker Hawke - 2008Choco - */ -public class Locale { - - private static final List LOCALES = Lists.newArrayList(); - private static final Pattern NODE_PATTERN = Pattern.compile("(\\w+(?:\\.{1}\\w+)*)\\s*=\\s*\"(.*)\""); - private static final String FILE_EXTENSION = ".lang"; - private static JavaPlugin plugin; - private static File localeFolder; - - private static String defaultLocale; - - private final Map nodes = new HashMap<>(); - - private final File file; - private final String name, region; - - private Locale(String name, String region) { - if (plugin == null) - throw new IllegalStateException("Cannot generate locales without first initializing the class (Locale#init(JavaPlugin))"); - - this.name = name.toLowerCase(); - this.region = region.toUpperCase(); - - String fileName = name + "_" + region + FILE_EXTENSION; - this.file = new File(localeFolder, fileName); - - if (this.reloadMessages()) return; - - plugin.getLogger().info("Loaded locale " + fileName); - } - - /** - * Initialize the locale class to generate information and search for localizations. - * This must be called before any other methods in the Locale class can be invoked. - * Note that this will also call {@link #searchForLocales()}, so there is no need to - * invoke it for yourself after the initialization - * - * @param plugin the plugin instance - */ - public static void init(JavaPlugin plugin) { - Locale.plugin = plugin; - - if (localeFolder == null) { - localeFolder = new File(plugin.getDataFolder(), "locales/"); - } - - localeFolder.mkdirs(); - Locale.searchForLocales(); - } - - /** - * Find all .lang file locales under the "locales" folder - */ - public static void searchForLocales() { - if (!localeFolder.exists()) localeFolder.mkdirs(); - - for (File file : localeFolder.listFiles()) { - String name = file.getName(); - if (!name.endsWith(".lang")) continue; - - String fileName = name.substring(0, name.lastIndexOf('.')); - String[] localeValues = fileName.split("_"); - - if (localeValues.length != 2) continue; - if (localeExists(localeValues[0] + "_" + localeValues[1])) continue; - - LOCALES.add(new Locale(localeValues[0], localeValues[1])); - plugin.getLogger().info("Found and loaded locale \"" + fileName + "\""); - } - } - - /** - * Get a locale by its entire proper name (i.e. "en_US") - * - * @param name the full name of the locale - * @return locale of the specified name - */ - public static Locale getLocale(String name) { - for (Locale locale : LOCALES) - if (locale.getLanguageTag().equalsIgnoreCase(name)) return locale; - return null; - } - - /** - * Get a locale from the cache by its name (i.e. "en" from "en_US") - * - * @param name the name of the language - * @return locale of the specified language. Null if not cached - */ - public static Locale getLocaleByName(String name) { - for (Locale locale : LOCALES) - if (locale.getName().equalsIgnoreCase(name)) return locale; - return null; - } - - /** - * Get a locale from the cache by its region (i.e. "US" from "en_US") - * - * @param region the name of the region - * @return locale of the specified region. Null if not cached - */ - public static Locale getLocaleByRegion(String region) { - for (Locale locale : LOCALES) - if (locale.getRegion().equalsIgnoreCase(region)) return locale; - return null; - } - - /** - * Check whether a locale exists and is registered or not - * - * @param name the whole language tag (i.e. "en_US") - * @return true if it exists - */ - public static boolean localeExists(String name) { - for (Locale locale : LOCALES) - if (locale.getLanguageTag().equals(name)) return true; - return false; - } - - /** - * Get an immutable list of all currently loaded locales - * - * @return list of all locales - */ - public static List getLocales() { - return ImmutableList.copyOf(LOCALES); - } - - /** - * Save a default locale file from the project source directory, to the locale folder - * - * @param in file to save - * @param fileName the name of the file to save - * @return true if the operation was successful, false otherwise - */ - public static boolean saveDefaultLocale(InputStream in, String fileName) { - if (!localeFolder.exists()) localeFolder.mkdirs(); - - if (!fileName.endsWith(FILE_EXTENSION)) - fileName = (fileName.lastIndexOf(".") == -1 ? fileName : fileName.substring(0, fileName.lastIndexOf('.'))) + FILE_EXTENSION; - - File destinationFile = new File(localeFolder, fileName); - if (destinationFile.exists()) { - return compareFiles(plugin.getResource(fileName), destinationFile); - } - - try (OutputStream outputStream = new FileOutputStream(destinationFile)) { - copy(in == null ? plugin.getResource(fileName) : in, outputStream); - - fileName = fileName.substring(0, fileName.lastIndexOf('.')); - String[] localeValues = fileName.split("_"); - - if (localeValues.length != 2) return false; - - LOCALES.add(new Locale(localeValues[0], localeValues[1])); - if (defaultLocale == null) defaultLocale = fileName; - - return true; - } catch (IOException e) { - return false; - } - } - - /** - * Save a default locale file from the project source directory, to the locale folder - * - * @param fileName the name of the file to save - * @return true if the operation was successful, false otherwise - */ - public static boolean saveDefaultLocale(String fileName) { - return saveDefaultLocale(null, fileName); - } - - /** - * Clear all current locale data - */ - public static void clearLocaleData() { - for (Locale locale : LOCALES) - locale.nodes.clear(); - LOCALES.clear(); - } - - // Write new changes to existing files, if any at all - private static boolean compareFiles(InputStream defaultFile, File existingFile) { - // Look for default - if (defaultFile == null) { - defaultFile = plugin.getResource(defaultLocale != null ? defaultLocale : "en_US"); - if (defaultFile == null) return false; // No default at all - } - - boolean changed = false; - - List defaultLines, existingLines; - try (BufferedReader defaultReader = new BufferedReader(new InputStreamReader(defaultFile)); - BufferedReader existingReader = new BufferedReader(new FileReader(existingFile)); - BufferedWriter writer = new BufferedWriter(new FileWriter(existingFile, true))) { - defaultLines = defaultReader.lines().collect(Collectors.toList()); - existingLines = existingReader.lines().map(s -> s.split("\\s*=")[0]).collect(Collectors.toList()); - - for (String defaultValue : defaultLines) { - if (defaultValue.isEmpty() || defaultValue.startsWith("#")) continue; - - String key = defaultValue.split("\\s*=")[0]; - - if (!existingLines.contains(key)) { - if (!changed) { - writer.newLine(); - writer.newLine(); - writer.write("# New messages for " + plugin.getName() + " v" + plugin.getDescription().getVersion()); - } - - writer.newLine(); - writer.write(defaultValue); - - changed = true; - } - } - } catch (IOException e) { - return false; - } - - return changed; - } - - private static void copy(InputStream input, OutputStream output) { - int n; - byte[] buffer = new byte[1024 * 4]; - - try { - while ((n = input.read(buffer)) != -1) { - output.write(buffer, 0, n); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - /** - * Get the name of the language that this locale is based on. - * (i.e. "en" for English, or "fr" for French) - * - * @return the name of the language - */ - public String getName() { - return name; - } - - /** - * Get the name of the region that this locale is from. - * (i.e. "US" for United States or "CA" for Canada) - * - * @return the name of the region - */ - public String getRegion() { - return region; - } - - /** - * Return the entire locale tag (i.e. "en_US") - * - * @return the language tag - */ - public String getLanguageTag() { - return name + "_" + region; - } - - /** - * Get the file that represents this locale - * - * @return the locale file (.lang) - */ - public File getFile() { - return file; - } - - /** - * Get a message set for a specific node - * - * @param node the node to get - * @return the message for the specified node - */ - public String getMessage(String node) { - return ChatColor.translateAlternateColorCodes('&', this.getMessageOrDefault(node, node)); - } - - /** - * Get a message set for a specific node and replace its params with a supplied arguments. - * - * @param node the node to get - * @param args the replacement arguments - * @return the message for the specified node - */ - public String getMessage(String node, Object... args) { - String message = getMessage(node); - for (Object arg : args) { - message = message.replaceFirst("\\%.*?\\%", arg.toString()); - } - return message; - } - - /** - * Get a message set for a specific node - * - * @param node the node to get - * @param defaultValue the default value given that a value for the node was not found - * @return the message for the specified node. Default if none found - */ - public String getMessageOrDefault(String node, String defaultValue) { - return this.nodes.getOrDefault(node, defaultValue); - } - - /** - * Get the key-value map of nodes to messages - * - * @return node-message map - */ - public Map getMessageNodeMap() { - return ImmutableMap.copyOf(nodes); - } - - /** - * Clear the previous message cache and load new messages directly from file - * - * @return reload messages from file - */ - public boolean reloadMessages() { - if (!this.file.exists()) { - plugin.getLogger().warning("Could not find file for locale " + this.name); - return false; - } - - this.nodes.clear(); // Clear previous data (if any) - - try (BufferedReader reader = new BufferedReader(new FileReader(file))) { - String line; - for (int lineNumber = 0; (line = reader.readLine()) != null; lineNumber++) { - if (line.trim().isEmpty() || line.startsWith("#") /* Comment */) continue; - - Matcher matcher = NODE_PATTERN.matcher(line); - if (!matcher.find()) { - System.err.println("Invalid locale syntax at (line=" + lineNumber + ")"); - continue; - } - - nodes.put(matcher.group(1), matcher.group(2)); - } - } catch (IOException e) { - e.printStackTrace(); - return false; - } - return true; - } - -} \ No newline at end of file diff --git a/src/main/java/com/songoda/ultimatemoderation/References.java b/src/main/java/com/songoda/ultimatemoderation/References.java deleted file mode 100644 index 7a1ba71..0000000 --- a/src/main/java/com/songoda/ultimatemoderation/References.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.songoda.ultimatemoderation; - -public class References { - - private String prefix; - - public References() { - prefix = UltimateModeration.getInstance().getLocale().getMessage("general.nametag.prefix") + " "; - } - - public String getPrefix() { - return this.prefix; - } -} diff --git a/src/main/java/com/songoda/ultimatemoderation/UltimateModeration.java b/src/main/java/com/songoda/ultimatemoderation/UltimateModeration.java index d1a9a11..a07d754 100644 --- a/src/main/java/com/songoda/ultimatemoderation/UltimateModeration.java +++ b/src/main/java/com/songoda/ultimatemoderation/UltimateModeration.java @@ -23,6 +23,7 @@ import com.songoda.ultimatemoderation.utils.Methods; import com.songoda.ultimatemoderation.utils.Metrics; import com.songoda.ultimatemoderation.utils.ServerVersion; import com.songoda.ultimatemoderation.utils.gui.AbstractGUI; +import com.songoda.ultimatemoderation.utils.locale.Locale; import com.songoda.ultimatemoderation.utils.settings.Setting; import com.songoda.ultimatemoderation.utils.settings.SettingsManager; import com.songoda.ultimatemoderation.utils.updateModules.LocaleModule; @@ -38,7 +39,6 @@ import java.util.UUID; public class UltimateModeration extends JavaPlugin { private static CommandSender console = Bukkit.getConsoleSender(); private static UltimateModeration INSTANCE; - private References references; private ServerVersion serverVersion = ServerVersion.fromPackageName(Bukkit.getServer().getClass().getPackage().getName()); @@ -69,17 +69,14 @@ public class UltimateModeration extends JavaPlugin { // Setup language String langMode = Setting.LANGUGE_MODE.getString(); - Locale.init(this); - Locale.saveDefaultLocale("en_US"); - this.locale = Locale.getLocale(getConfig().getString("System.Language Mode", langMode)); + locale = new Locale(this, "en_US"); + this.locale = Locale.getLocale(getConfig().getString("System.Language Mode")); //Running Songoda Updater Plugin plugin = new Plugin(this, 29); plugin.addModule(new LocaleModule()); SongodaUpdate.load(plugin); - this.references = new References(); - // Setup Managers this.ticketManager = new TicketManager(); this.templateManager = new TemplateManager(); @@ -219,8 +216,8 @@ public class UltimateModeration extends JavaPlugin { } public void reload() { - locale.reloadMessages(); - references = new References(); + this.locale = Locale.getLocale(getConfig().getString("System.Language Mode")); + this.locale.reloadMessages(); this.settingsManager.reloadConfig(); } @@ -236,10 +233,6 @@ public class UltimateModeration extends JavaPlugin { return locale; } - public References getReferences() { - return references; - } - public TemplateManager getTemplateManager() { return templateManager; } diff --git a/src/main/java/com/songoda/ultimatemoderation/command/CommandManager.java b/src/main/java/com/songoda/ultimatemoderation/command/CommandManager.java index 810c146..9f9e542 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/CommandManager.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/CommandManager.java @@ -101,7 +101,7 @@ public class CommandManager implements CommandExecutor { } } } - commandSender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&7The command you entered does not exist or is spelt incorrectly.")); + instance.getLocale().newMessage("&7The command you entered does not exist or is spelt incorrectly.").sendPrefixedMessage(commandSender); return true; } @@ -113,12 +113,12 @@ public class CommandManager implements CommandExecutor { if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) { AbstractCommand.ReturnType returnType = command.runCommand(instance, sender, strings); if (returnType == AbstractCommand.ReturnType.SYNTAX_ERROR) { - sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&cInvalid Syntax!")); - sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&7The valid syntax is: &6" + command.getSyntax() + "&7.")); + instance.getLocale().newMessage("&cInvalid Syntax!").sendPrefixedMessage(sender); + instance.getLocale().newMessage("&7The valid syntax is: &6" + command.getSyntax() + "&7.").sendPrefixedMessage(sender); } return; } - sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.general.nopermission")); + instance.getLocale().getMessage("event.general.nopermission").sendPrefixedMessage(sender); } public List getCommands() { diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandBan.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandBan.java index df4dca2..f6d7013 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandBan.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandBan.java @@ -46,13 +46,13 @@ public class CommandBan extends AbstractCommand { OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]); if (player == null) { - sender.sendMessage(instance.getReferences().getPrefix() + "That player does not exist."); + instance.getLocale().newMessage("That player does not exist.").sendMessage(sender); return ReturnType.FAILURE; } if (instance.getPunishmentManager().getPlayer(player).getActivePunishments() .stream().anyMatch(appliedPunishment -> appliedPunishment.getPunishmentType() == PunishmentType.BAN)) { - sender.sendMessage(instance.getReferences().getPrefix() + "That player is already banned."); + instance.getLocale().newMessage("That player is already banned.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandClearChat.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandClearChat.java index da24000..0caa305 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandClearChat.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandClearChat.java @@ -31,10 +31,11 @@ public class CommandClearChat extends AbstractCommand { player.sendMessage(toSend); } - player.sendMessage(instance.getReferences().getPrefix() + Methods.formatText(instance.getLocale().getMessage("command.clearchat.cleared", sender.getName()))); + instance.getLocale().getMessage("command.clearchat.cleared") + .processPlaceholder("player", sender.getName()).sendPrefixedMessage(player); if (player.hasPermission("um.clearchat.bypass") && !isForced(args)) { - player.sendMessage(instance.getLocale().getMessage("command.clearchat.immune")); + instance.getLocale().getMessage("command.clearchat.immune").sendMessage(player); } } return ReturnType.SUCCESS; diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandCommandSpy.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandCommandSpy.java index d6609dd..694bc8d 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandCommandSpy.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandCommandSpy.java @@ -27,10 +27,10 @@ public class CommandCommandSpy extends AbstractCommand { if (inSpy.contains(player.getUniqueId())) { inSpy.remove(player.getUniqueId()); - player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.commandspy.toggleOn")); + instance.getLocale().getMessage("command.commandspy.toggleOn").sendPrefixedMessage(player); } else { inSpy.add(player.getUniqueId()); - player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.commandspy.toggleOff")); + instance.getLocale().getMessage("command.commandspy.toggleOff").sendPrefixedMessage(player); } return ReturnType.SUCCESS; } diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandFreeze.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandFreeze.java index ddf6622..e4f88f2 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandFreeze.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandFreeze.java @@ -21,12 +21,14 @@ public class CommandFreeze extends AbstractCommand { UltimateModeration instance = UltimateModeration.getInstance(); if (frozen.contains(player.getUniqueId())) { frozen.remove(player.getUniqueId()); - sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.freeze.remove", player.getPlayer().getDisplayName())); - player.getPlayer().sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.freeze.alertremove")); + instance.getLocale().getMessage("command.freeze.remove") + .processPlaceholder("player", player.getPlayer().getDisplayName()).sendPrefixedMessage(sender); + instance.getLocale().getMessage("command.freeze.alertremove").sendPrefixedMessage(sender); } else { frozen.add(player.getUniqueId()); - sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.freeze.add", player.getPlayer().getDisplayName())); - player.getPlayer().sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.freeze.alertadd")); + instance.getLocale().getMessage("command.freeze.add") + .processPlaceholder("player", player.getPlayer().getDisplayName()).sendPrefixedMessage(sender); + instance.getLocale().getMessage("command.freeze.alertadd").sendPrefixedMessage(player.getPlayer()); } } @@ -42,7 +44,7 @@ public class CommandFreeze extends AbstractCommand { Player player = Bukkit.getPlayer(args[0]); if (player == null) { - sender.sendMessage(instance.getReferences().getPrefix() + "That player does not exist or is not online."); + instance.getLocale().newMessage("That player does not exist or is not online.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandHelp.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandHelp.java index 783f935..ffb3d85 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandHelp.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandHelp.java @@ -16,7 +16,8 @@ public class CommandHelp extends AbstractCommand { @Override protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { sender.sendMessage(""); - sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oSongoda")); + instance.getLocale().getMessage("&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oSongoda") + .sendPrefixedMessage(sender); sender.sendMessage(""); sender.sendMessage(Methods.formatText("&7Welcome to UltimateModeration! To get started try using the /um command to access the moderation panel.")); sender.sendMessage(""); diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandInvSee.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandInvSee.java index ba663fa..9c3ccdc 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandInvSee.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandInvSee.java @@ -25,7 +25,7 @@ public class CommandInvSee extends AbstractCommand { Player player = Bukkit.getPlayer(args[0]); if (player == null) { - sender.sendMessage(instance.getReferences().getPrefix() + "That player does not exist or is not online."); + instance.getLocale().newMessage("That player does not exist or is not online").sendPrefixedMessage(sender); return ReturnType.FAILURE; } diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandKick.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandKick.java index e1e365c..2f23391 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandKick.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandKick.java @@ -39,7 +39,7 @@ public class CommandKick extends AbstractCommand { OfflinePlayer player = Bukkit.getPlayer(args[0]); if (player == null) { - sender.sendMessage(instance.getReferences().getPrefix() + "That player does not exist or is not online."); + instance.getLocale().newMessage("That player does not exist or is not online.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandMute.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandMute.java index 1a6207e..734219f 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandMute.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandMute.java @@ -46,13 +46,13 @@ public class CommandMute extends AbstractCommand { OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]); if (player == null) { - sender.sendMessage(instance.getReferences().getPrefix() + "That player does not exist."); + instance.getLocale().newMessage("That player does not exist.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } if (instance.getPunishmentManager().getPlayer(player).getActivePunishments() .stream().anyMatch(appliedPunishment -> appliedPunishment.getPunishmentType() == PunishmentType.MUTE)) { - sender.sendMessage(instance.getReferences().getPrefix() + "That player is already muted."); + instance.getLocale().newMessage("That player is already muted.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandRandomPlayer.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandRandomPlayer.java index c1f5803..7f063a4 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandRandomPlayer.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandRandomPlayer.java @@ -24,7 +24,7 @@ public class CommandRandomPlayer extends AbstractCommand { players.remove(sender); if (players.size() == 0) { - sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&c You are the only one online!")); + instance.getLocale().newMessage("&c You are the only one online!").sendPrefixedMessage(sender); return ReturnType.FAILURE; } diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandReload.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandReload.java index 42ae98b..fb3bf77 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandReload.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandReload.java @@ -16,7 +16,7 @@ public class CommandReload extends AbstractCommand { @Override protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { instance.reload(); - sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Configuration and Language files reloaded.")); + instance.getLocale().newMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender); return ReturnType.SUCCESS; } diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandRevive.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandRevive.java index bd0a1c4..84649f6 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandRevive.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandRevive.java @@ -25,14 +25,15 @@ public class CommandRevive extends AbstractCommand { Player player = Bukkit.getPlayer(args[0]); if (player == null) { - sender.sendMessage(instance.getReferences().getPrefix() + "That player does not exist or is not online."); + instance.getLocale().newMessage("That player does not exist or is not online.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } if (!(revive(player, sender))) return ReturnType.FAILURE; - player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.revive.revived")); - sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.revive.success", player.getName())); + instance.getLocale().getMessage("command.revive.revived").sendPrefixedMessage(player); + instance.getLocale().getMessage("command.revive.success") + .processPlaceholder("player", player.getName()).sendPrefixedMessage(sender); return ReturnType.SUCCESS; } @@ -53,7 +54,7 @@ public class CommandRevive extends AbstractCommand { List drops = DeathListener.getLastDrop(player); if (drops == null) { - sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.revive.noloot")); + instance.getLocale().getMessage("command.revive.noloot").sendPrefixedMessage(sender); return false; } diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandRunTemplate.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandRunTemplate.java index dc4a8b9..56f01bb 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandRunTemplate.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandRunTemplate.java @@ -30,7 +30,7 @@ public class CommandRunTemplate extends AbstractCommand { OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]); if (player == null) { - sender.sendMessage(instance.getReferences().getPrefix() + "That player does not exist."); + instance.getLocale().newMessage("That player does not exist.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandSlowMode.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandSlowMode.java index e01d288..b90b3d8 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandSlowMode.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandSlowMode.java @@ -21,7 +21,7 @@ public class CommandSlowMode extends AbstractCommand { protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { if (args.length == 0) { ChatListener.setSlowModeOverride(0); - sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.slowmode.disabled")); + instance.getLocale().getMessage("event.slowmode.disabled").sendPrefixedMessage(sender); return ReturnType.SUCCESS; } else if (args.length != 1) return ReturnType.SYNTAX_ERROR; @@ -31,8 +31,8 @@ public class CommandSlowMode extends AbstractCommand { ChatListener.setSlowModeOverride(delay); Bukkit.getOnlinePlayers().forEach(player -> - player.sendMessage(instance.getReferences().getPrefix() + - instance.getLocale().getMessage("event.slowmode.enabled", Methods.makeReadable(delay)))); + instance.getLocale().getMessage("event.slowmode.enabled") + .processPlaceholder("delay", Methods.makeReadable(delay)).sendPrefixedMessage(player)); return ReturnType.SUCCESS; } diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandSpy.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandSpy.java index e663db1..cddd563 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandSpy.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandSpy.java @@ -23,19 +23,19 @@ public class CommandSpy extends AbstractCommand { UltimateModeration instance = UltimateModeration.getInstance(); if (!UltimateModeration.getInstance().isServerVersionAtLeast(ServerVersion.V1_12)) { - senderP.sendMessage(instance.getReferences().getPrefix() + "This feature is not compatible with this version of spigot."); + instance.getLocale().newMessage("This feature is not compatible with this version of spigot.").sendPrefixedMessage(senderP); return; } Player player = oPlayer.getPlayer(); if (player == null) { - senderP.sendMessage(instance.getReferences().getPrefix() + "That player does not exist or is not online."); + instance.getLocale().newMessage("That player does not exist or is not online.").sendPrefixedMessage(senderP); return; } if (player == senderP) { - senderP.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.spy.cant")); + instance.getLocale().getMessage("command.spy.cant").sendPrefixedMessage(senderP); return; } @@ -49,7 +49,8 @@ public class CommandSpy extends AbstractCommand { spying.put(senderP.getUniqueId(), new Spy(senderP.getLocation(), didVanish)); player.getPlayer().addPassenger(senderP); - senderP.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.spy.success", player.getName())); + instance.getLocale().getMessage("command.spy.success") + .processPlaceholder("player", player.getName()).sendPrefixedMessage(senderP); } @Override @@ -67,14 +68,14 @@ public class CommandSpy extends AbstractCommand { CommandVanish.vanish(senderP); spying.remove(senderP.getUniqueId()); - senderP.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.spy.returned")); + instance.getLocale().getMessage("command.spy.returned").sendPrefixedMessage(sender); return ReturnType.SUCCESS; } Player player = Bukkit.getPlayer(args[0]); if (player == null) { - sender.sendMessage(instance.getReferences().getPrefix() + "That player does not exist or is not online."); + instance.getLocale().newMessage("That player does not exist or is not online.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandStaffChat.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandStaffChat.java index 82fb4e4..448c3fd 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandStaffChat.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandStaffChat.java @@ -28,10 +28,11 @@ public class CommandStaffChat extends AbstractCommand { for (StaffChannel channel : instance.getStaffChatManager().getChats().values()) { if (!channel.listMembers().contains(player.getUniqueId())) continue; channel.removeMember(player); - player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.staffchat.leave", channel.getChannelName())); + instance.getLocale().getMessage("event.staffchat.leave") + .processPlaceholder("channel", channel.getChannelName()).sendPrefixedMessage(player); return ReturnType.SUCCESS; } - player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.staffchat.nochannels")); + instance.getLocale().getMessage("event.staffchat.nochannels").sendPrefixedMessage(player); return ReturnType.FAILURE; } diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandToggleChat.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandToggleChat.java index 1eb32c0..78a5a2d 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandToggleChat.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandToggleChat.java @@ -1,10 +1,10 @@ package com.songoda.ultimatemoderation.command.commands; -import com.songoda.ultimatemoderation.Locale; import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.command.AbstractCommand; import com.songoda.ultimatemoderation.listeners.ChatListener; import com.songoda.ultimatemoderation.utils.Methods; +import com.songoda.ultimatemoderation.utils.locale.Message; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -25,27 +25,24 @@ public class CommandToggleChat extends AbstractCommand { @Override protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { toggled = !toggled; - String prefix = instance.getReferences().getPrefix(); - Locale locale = instance.getLocale(); - String strToggledOn = locale.getMessage("command.togglechat.toggledOn"); - String strToggledOff = locale.getMessage("command.togglechat.toggledOff"); - String messageToSend = prefix + Methods.formatText(toggled ? strToggledOn : strToggledOff); + Message message = toggled ? instance.getLocale().getMessage("command.togglechat.toggledOn") + : instance.getLocale().getMessage("command.togglechat.toggledOff"); ChatListener.setChatToggled(toggled); for (Player player : Bukkit.getOnlinePlayers()) { - player.sendMessage(messageToSend); + message.sendPrefixedMessage(player); if (!player.hasPermission(getPermissionNode() + ".bypass")) continue; - player.sendMessage(Methods.formatText(locale.getMessage("command.togglechat.bypass"))); + instance.getLocale().getMessage("command.togglechat.bypass").sendMessage(player); } if (!(sender instanceof Player)) - sender.sendMessage(messageToSend); + message.sendPrefixedMessage(sender); return ReturnType.SUCCESS; } diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandUnBan.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandUnBan.java index 1f4a0ed..8873ee2 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandUnBan.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandUnBan.java @@ -29,13 +29,13 @@ public class CommandUnBan extends AbstractCommand { OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]); if (player == null) { - sender.sendMessage(instance.getReferences().getPrefix() + "That player does not exist."); + instance.getLocale().newMessage("That player does not exist.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } if (!instance.getPunishmentManager().getPlayer(player).getActivePunishments() .stream().anyMatch(appliedPunishment -> appliedPunishment.getPunishmentType() == PunishmentType.BAN)) { - sender.sendMessage(instance.getReferences().getPrefix() + "That player isn't banned."); + instance.getLocale().newMessage("That player isn't banned.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } @@ -43,7 +43,8 @@ public class CommandUnBan extends AbstractCommand { playerPunishData.expirePunishments(PunishmentType.BAN); - sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.unban.success", player.getName())); + instance.getLocale().getMessage("event.unban.success") + .processPlaceholder("player", player.getName()).sendPrefixedMessage(sender); return ReturnType.SUCCESS; } diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandUnMute.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandUnMute.java index 1184347..9e7a8ac 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandUnMute.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandUnMute.java @@ -28,13 +28,13 @@ public class CommandUnMute extends AbstractCommand { OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]); if (player == null) { - sender.sendMessage(instance.getReferences().getPrefix() + "That player does not exist."); + instance.getLocale().newMessage("That player does not exist.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } if (!instance.getPunishmentManager().getPlayer(player).getActivePunishments() .stream().anyMatch(appliedPunishment -> appliedPunishment.getPunishmentType() == PunishmentType.MUTE)) { - sender.sendMessage(instance.getReferences().getPrefix() + "That player isn't muted."); + instance.getLocale().newMessage("That player isn't muted.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } @@ -42,7 +42,8 @@ public class CommandUnMute extends AbstractCommand { playerPunishData.expirePunishments(PunishmentType.MUTE); - sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.unmute.success", player.getName())); + instance.getLocale().newMessage(instance.getLocale().getMessage("event.unmute.success") + .processPlaceholder("player", player.getName()).getMessage()).sendPrefixedMessage(sender); return ReturnType.SUCCESS; } diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandVanish.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandVanish.java index 02d934f..9b4f549 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandVanish.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandVanish.java @@ -48,13 +48,13 @@ public class CommandVanish extends AbstractCommand { if (instance.isServerVersionAtLeast(ServerVersion.V1_9)) player.setInvulnerable(false); player.setCanPickupItems(true); - player.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.vanish.toggledOff"))); + instance.getLocale().getMessage("command.vanish.toggledOff").sendPrefixedMessage(player); } else { inVanish.add(uuid); player.setCanPickupItems(false); if (instance.isServerVersionAtLeast(ServerVersion.V1_9)) player.setInvulnerable(true); - player.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.vanish.toggledOn"))); + instance.getLocale().getMessage("command.vanish.toggledOn").sendPrefixedMessage(player); } if (Setting.VANISH_EFFECTS.getBoolean()) { diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandViewEnderChest.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandViewEnderChest.java index 796aa4a..a0aa29c 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandViewEnderChest.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandViewEnderChest.java @@ -26,7 +26,7 @@ public class CommandViewEnderChest extends AbstractCommand { Player player = Bukkit.getPlayer(args[0]); if (player == null) { - sender.sendMessage(instance.getReferences().getPrefix() + "That player does not exist or is not online."); + instance.getLocale().newMessage("That player does not exist or is not online.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandWarn.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandWarn.java index 055dbfb..40bbabf 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandWarn.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandWarn.java @@ -46,7 +46,7 @@ public class CommandWarn extends AbstractCommand { OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]); if (player == null) { - sender.sendMessage(instance.getReferences().getPrefix() + "That player does not exist."); + instance.getLocale().newMessage("That player does not exist.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } diff --git a/src/main/java/com/songoda/ultimatemoderation/gui/GUIModerate.java b/src/main/java/com/songoda/ultimatemoderation/gui/GUIModerate.java index c06d273..acb9a21 100644 --- a/src/main/java/com/songoda/ultimatemoderation/gui/GUIModerate.java +++ b/src/main/java/com/songoda/ultimatemoderation/gui/GUIModerate.java @@ -23,13 +23,16 @@ public class GUIModerate extends AbstractGUI { this.plugin = plugin; this.toModerate = toModerate; - init(plugin.getLocale().getMessage("gui.moderate.title", toModerate.getName()), 45); + init(plugin.getLocale().getMessage("gui.moderate.title") + .processPlaceholder("toModerate", toModerate.getName()).getMessage(), 45); } @Override protected void constructGUI() { - createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.OAK_DOOR : Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back")); + createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) + ? Material.OAK_DOOR + : Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back").getMessage()); createButton(10, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.BLUE_ICE : Material.valueOf("PACKED_ICE"), "&6&lFreeze", "&7Stop this player from moving.", "", "&7Currently:&6 " + (CommandFreeze.isFrozen(toModerate) ? "Frozen" : "Unfrozen")); createButton(12, Material.SADDLE, "&6&lSpy", "&7Spy on this player"); diff --git a/src/main/java/com/songoda/ultimatemoderation/gui/GUINotesManager.java b/src/main/java/com/songoda/ultimatemoderation/gui/GUINotesManager.java index af4c118..12c5d80 100644 --- a/src/main/java/com/songoda/ultimatemoderation/gui/GUINotesManager.java +++ b/src/main/java/com/songoda/ultimatemoderation/gui/GUINotesManager.java @@ -32,7 +32,8 @@ public class GUINotesManager extends AbstractGUI { this.plugin = plugin; this.toModerate = toModerate; - init(plugin.getLocale().getMessage("gui.notes.title", player.getName()), 54); + init(plugin.getLocale().getMessage("gui.notes.title") + .processPlaceholder("tonotes", player.getName()).getMessage(), 54); } @Override @@ -51,7 +52,7 @@ public class GUINotesManager extends AbstractGUI { .skip(page * 36).limit(36).collect(Collectors.toList()); if (page != 0) { - createButton(1, Material.ARROW, plugin.getLocale().getMessage("gui.general.previous")); + createButton(1, Material.ARROW, plugin.getLocale().getMessage("gui.general.previous").getMessage()); registerClickable(1, ((player1, inventory1, cursor, slot, type) -> { page --; constructGUI(); @@ -59,16 +60,18 @@ public class GUINotesManager extends AbstractGUI { } if (page != maxPage) { - createButton(3, Material.ARROW, plugin.getLocale().getMessage("gui.general.next")); + createButton(3, Material.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage()); registerClickable(3, ((player1, inventory1, cursor, slot, type) -> { page ++; constructGUI(); })); } - createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.OAK_DOOR : Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back")); + createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) + ? Material.OAK_DOOR + : Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back").getMessage()); - createButton(6, Material.REDSTONE, plugin.getLocale().getMessage("gui.notes.create")); + createButton(6, Material.REDSTONE, plugin.getLocale().getMessage("gui.notes.create").getMessage()); for (int i = 0; i < notes.size(); i++) { PunishmentNote note = notes.get(i); @@ -97,9 +100,13 @@ public class GUINotesManager extends AbstractGUI { SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy"); - lore.add(plugin.getLocale().getMessage("gui.notes.createdby", Bukkit.getOfflinePlayer(note.getAuthor()).getName())); - lore.add(plugin.getLocale().getMessage("gui.notes.createdon", format.format(new Date(note.getCreationDate())))); - lore.add(plugin.getLocale().getMessage("gui.notes.remove")); + lore.add(plugin.getLocale().getMessage("gui.notes.createdby") + .processPlaceholder("player", Bukkit.getOfflinePlayer(note.getAuthor()).getName()) + .getMessage()); + lore.add(plugin.getLocale().getMessage("gui.notes.createdon") + .processPlaceholder("sent", format.format(new Date(note.getCreationDate()))) + .getMessage()); + lore.add(plugin.getLocale().getMessage("gui.notes.remove").getMessage()); createButton(18 + i, Material.MAP, name, lore); @@ -117,7 +124,7 @@ public class GUINotesManager extends AbstractGUI { new GUIPlayer(plugin, toModerate, player1))); registerClickable(6, ((player1, inventory1, cursor, slot, type) -> { - player.sendMessage(plugin.getLocale().getMessage("gui.notes.type")); + plugin.getLocale().getMessage("gui.notes.type").sendMessage(player); AbstractChatConfirm abstractChatConfirm = new AbstractChatConfirm(player, event -> { plugin.getPunishmentManager().getPlayer(toModerate).addNotes(new PunishmentNote(event.getMessage(), player.getUniqueId(), toModerate.getUniqueId(), System.currentTimeMillis())); diff --git a/src/main/java/com/songoda/ultimatemoderation/gui/GUIPlayer.java b/src/main/java/com/songoda/ultimatemoderation/gui/GUIPlayer.java index ee75432..94e0133 100644 --- a/src/main/java/com/songoda/ultimatemoderation/gui/GUIPlayer.java +++ b/src/main/java/com/songoda/ultimatemoderation/gui/GUIPlayer.java @@ -20,7 +20,8 @@ public class GUIPlayer extends AbstractGUI { this.plugin = plugin; this.toModerate = toModerate; - init(plugin.getLocale().getMessage("gui.player.title", toModerate.getName()), 54); + init(plugin.getLocale().getMessage("gui.player.title") + .processPlaceholder("toModerate", toModerate.getName()).getMessage(), 54); } @Override @@ -36,14 +37,16 @@ public class GUIPlayer extends AbstractGUI { createButton(13, head, "&7&l" + toModerate.getName(), player.isOnline() ? "&a" + plugin.getLocale().getMessage("gui.players.online.online") : "&c" + plugin.getLocale().getMessage("gui.players.online.offline")); - createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.OAK_DOOR : Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back")); + createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) + ? Material.OAK_DOOR + : Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back").getMessage()); - createButton(38, Material.ANVIL, plugin.getLocale().getMessage("gui.player.punish")); - createButton(30, Material.CHEST, plugin.getLocale().getMessage("gui.player.tickets")); + createButton(38, Material.ANVIL, plugin.getLocale().getMessage("gui.player.punish").getMessage()); + createButton(30, Material.CHEST, plugin.getLocale().getMessage("gui.player.tickets").getMessage()); if (player.isOnline()) - createButton(32, Material.DIAMOND_SWORD, plugin.getLocale().getMessage("gui.player.punishments")); - createButton(42, Material.MAP, plugin.getLocale().getMessage("gui.player.notes")); - createButton(40, Material.DIAMOND_CHESTPLATE, plugin.getLocale().getMessage("gui.player.moderate")); + createButton(32, Material.DIAMOND_SWORD, plugin.getLocale().getMessage("gui.player.punishments").getMessage()); + createButton(42, Material.MAP, plugin.getLocale().getMessage("gui.player.notes").getMessage()); + createButton(40, Material.DIAMOND_CHESTPLATE, plugin.getLocale().getMessage("gui.player.moderate").getMessage()); } @Override diff --git a/src/main/java/com/songoda/ultimatemoderation/gui/GUIPlayers.java b/src/main/java/com/songoda/ultimatemoderation/gui/GUIPlayers.java index 9b184cd..cb36608 100644 --- a/src/main/java/com/songoda/ultimatemoderation/gui/GUIPlayers.java +++ b/src/main/java/com/songoda/ultimatemoderation/gui/GUIPlayers.java @@ -32,7 +32,7 @@ public class GUIPlayers extends AbstractGUI { super(player); this.plugin = plugin; - init(plugin.getLocale().getMessage("gui.players.title"), 54); + init(plugin.getLocale().getMessage("gui.players.title").getMessage(), 54); runTask(); } @@ -64,7 +64,7 @@ public class GUIPlayers extends AbstractGUI { .skip(page * 36).limit(36).collect(Collectors.toList()); if (page != 0) { - createButton(46, Material.ARROW, plugin.getLocale().getMessage("gui.general.previous")); + createButton(46, Material.ARROW, plugin.getLocale().getMessage("gui.general.previous").getMessage()); registerClickable(46, ((player1, inventory1, cursor, slot, type) -> { page --; constructGUI(); @@ -72,7 +72,7 @@ public class GUIPlayers extends AbstractGUI { } if (maxPage != page) { - createButton(48, Material.ARROW, plugin.getLocale().getMessage("gui.general.next")); + createButton(48, Material.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage()); registerClickable(48, ((player1, inventory1, cursor, slot, type) -> { page ++; constructGUI(); @@ -93,30 +93,32 @@ public class GUIPlayers extends AbstractGUI { head.setItemMeta(meta); ArrayList lore = new ArrayList<>(); - lore.add(plugin.getLocale().getMessage("gui.players.click")); + lore.add(plugin.getLocale().getMessage("gui.players.click").getMessage()); lore.add(""); int ticketAmt = (int) plugin.getTicketManager().getTicketsAbout(pl).stream() .filter(t -> t.getStatus() == TicketStatus.OPEN).count(); if (ticketAmt == 0) - lore.add(plugin.getLocale().getMessage("gui.players.notickets")); + lore.add(plugin.getLocale().getMessage("gui.players.notickets").getMessage()); else { if (ticketAmt == 1) - lore.add(plugin.getLocale().getMessage("gui.players.ticketsone")); + lore.add(plugin.getLocale().getMessage("gui.players.ticketsone").getMessage()); else - lore.add(plugin.getLocale().getMessage("gui.players.tickets",ticketAmt)); + lore.add(plugin.getLocale().getMessage("gui.players.tickets") + .processPlaceholder("amount", ticketAmt).getMessage()); } int warningAmt = playerPunishData.getActivePunishments(PunishmentType.WARNING).size(); if (warningAmt == 0) - lore.add(plugin.getLocale().getMessage("gui.players.nowarnings")); + lore.add(plugin.getLocale().getMessage("gui.players.nowarnings").getMessage()); else { if (warningAmt == 1) - lore.add(plugin.getLocale().getMessage("gui.players.warningsone")); + lore.add(plugin.getLocale().getMessage("gui.players.warningsone").getMessage()); else - lore.add(plugin.getLocale().getMessage("gui.players.warnings",warningAmt)); + lore.add(plugin.getLocale().getMessage("gui.players.warnings") + .processPlaceholder("amount", warningAmt).getMessage()); } @@ -127,11 +129,11 @@ public class GUIPlayers extends AbstractGUI { for (int i = 0; i < 9; i++) createButton(36 + i, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : new ItemStack(Material.valueOf("STAINED_GLASS_PANE")), "&1"); - createButton(46, Material.ENDER_PEARL, plugin.getLocale().getMessage("gui.players.search")); + createButton(46, Material.ENDER_PEARL, plugin.getLocale().getMessage("gui.players.search").getMessage()); createButton(47, Material.HOPPER, "&6" + currentOnline.getTranslation()); - createButton(51, Material.CHEST, plugin.getLocale().getMessage("gui.players.button.tickets")); - createButton(52, Material.MAP, plugin.getLocale().getMessage("gui.players.button.templatemanager")); + createButton(51, Material.CHEST, plugin.getLocale().getMessage("gui.players.button.tickets").getMessage()); + createButton(52, Material.MAP, plugin.getLocale().getMessage("gui.players.button.templatemanager").getMessage()); } @@ -146,7 +148,8 @@ public class GUIPlayers extends AbstractGUI { } public String getTranslation() { - return UltimateModeration.getInstance().getLocale().getMessage("gui.players.online." + this.name().toLowerCase()); + return UltimateModeration.getInstance().getLocale() + .getMessage("gui.players.online." + this.name().toLowerCase()).getMessage(); } } @@ -171,14 +174,14 @@ public class GUIPlayers extends AbstractGUI { if (found.size() == 1) { new GUIPlayer(plugin, Bukkit.getOfflinePlayer(found.get(0)), player); } else { - player.sendMessage(plugin.getLocale().getMessage("gui.players.nonefound")); + plugin.getLocale().getMessage("gui.players.nonefound").sendMessage(player); } }); ItemStack item = new ItemStack(Material.PAPER); ItemMeta meta = item.getItemMeta(); - meta.setDisplayName(plugin.getLocale().getMessage("gui.players.name")); + meta.setDisplayName(plugin.getLocale().getMessage("gui.players.name").getMessage()); item.setItemMeta(meta); gui.setSlot(AbstractAnvilGUI.AnvilSlot.INPUT_LEFT, item); diff --git a/src/main/java/com/songoda/ultimatemoderation/gui/GUIPunish.java b/src/main/java/com/songoda/ultimatemoderation/gui/GUIPunish.java index 4922bdd..82c459c 100644 --- a/src/main/java/com/songoda/ultimatemoderation/gui/GUIPunish.java +++ b/src/main/java/com/songoda/ultimatemoderation/gui/GUIPunish.java @@ -47,8 +47,9 @@ public class GUIPunish extends AbstractGUI { this.templateName = template.getTemplateName(); } - init(toModerate == null ? plugin.getLocale().getMessage("gui.punish.title.template") - : plugin.getLocale().getMessage("gui.punish.title", toModerate.getName()), 45); + init(toModerate == null ? plugin.getLocale().getMessage("gui.punish.title.template").getMessage() + : plugin.getLocale().getMessage("gui.punish.title") + .processPlaceholder("toModerate", toModerate.getName()).getMessage(), 45); if (toModerate != null) runTask(); } @@ -68,42 +69,61 @@ public class GUIPunish extends AbstractGUI { createButton(13, head, "&7&l" + toModerate.getName()); } - createButton(22, Material.EMERALD_BLOCK, plugin.getLocale().getMessage("gui.punish.submit")); + createButton(22, Material.EMERALD_BLOCK, plugin.getLocale().getMessage("gui.punish.submit").getMessage()); - createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.OAK_DOOR : Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back")); + createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) + ? Material.OAK_DOOR + : Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back").getMessage()); - createButton(28, Material.ANVIL, plugin.getLocale().getMessage("gui.punish.type.punishment"), + createButton(28, Material.ANVIL, + plugin.getLocale().getMessage("gui.punish.type.punishment").getMessage(), "&7" + type.getTranslation(), "", - plugin.getLocale().getMessage("gui.punish.type.punishment.click")); + plugin.getLocale().getMessage("gui.punish.type.punishment.click").getMessage()); if (toModerate != null) { - createButton(30, Material.MAP, plugin.getLocale().getMessage("gui.punish.type.template"), - plugin.getLocale().getMessage("gui.punish.type.template.current", - (template == null ? plugin.getLocale().getMessage("gui.general.none") : template.getTemplateName())), + createButton(30, Material.MAP, + plugin.getLocale().getMessage("gui.punish.type.template").getMessage(), + plugin.getLocale().getMessage("gui.punish.type.template.current") + .processPlaceholder("template", + template == null + ? plugin.getLocale().getMessage("gui.general.none") + : template.getTemplateName()).getMessage(), "", - plugin.getLocale().getMessage(plugin.getTemplateManager().getTemplates().size() == 0 ? "gui.punish.type.template.none" : "gui.punish.type.template.click")); + plugin.getLocale().getMessage(plugin.getTemplateManager().getTemplates().size() == 0 + ? "gui.punish.type.template.none" + : "gui.punish.type.template.click").getMessage()); } else { - createButton(30, Material.MAP, plugin.getLocale().getMessage("gui.punish.type.name"), - plugin.getLocale().getMessage("gui.punish.type.name.current", - (templateName == null ? plugin.getLocale().getMessage("gui.general.none") : templateName)), + createButton(30, Material.MAP, + plugin.getLocale().getMessage("gui.punish.type.name").getMessage(), + plugin.getLocale().getMessage("gui.punish.type.name.current") + .processPlaceholder("template", + templateName == null + ? plugin.getLocale().getMessage("gui.punish.type.name.current").getMessage() + : templateName).getMessage(), "", - plugin.getLocale().getMessage("gui.punish.type.name.current.click")); + plugin.getLocale().getMessage("gui.punish.type.name.current.click").getMessage()); } if (type != PunishmentType.KICK) { - createButton(32, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH"), plugin.getLocale().getMessage("gui.punish.type.duration"), - plugin.getLocale().getMessage("gui.punish.type.duration.leftclick"), - plugin.getLocale().getMessage("gui.punish.type.duration.rightclick"), + createButton(32, plugin.isServerVersionAtLeast(ServerVersion.V1_13) + ? Material.CLOCK + : Material.valueOf("WATCH"), + plugin.getLocale().getMessage("gui.punish.type.duration").getMessage(), + plugin.getLocale().getMessage("gui.punish.type.duration.leftclick").getMessage(), + plugin.getLocale().getMessage("gui.punish.type.duration.rightclick").getMessage(), "", - plugin.getLocale().getMessage("gui.punish.type.duration.current"), - "&6" + (duration == -1 ? plugin.getLocale().getMessage("gui.general.permanent") : Methods.makeReadable(duration))); + plugin.getLocale().getMessage("gui.punish.type.duration.current").getMessage(), + "&6" + (duration == -1 ? plugin.getLocale().getMessage("gui.general.permanent").getMessage() + : Methods.makeReadable(duration))); } - createButton(34, Material.PAPER, plugin.getLocale().getMessage("gui.punish.type.reason"), - plugin.getLocale().getMessage("gui.punish.type.reason.click"), + createButton(34, Material.PAPER, + plugin.getLocale().getMessage("gui.punish.type.reason").getMessage(), + plugin.getLocale().getMessage("gui.punish.type.reason.click").getMessage(), "", - plugin.getLocale().getMessage("gui.punish.type.reason.current"), "&6" + reason); + plugin.getLocale().getMessage("gui.punish.type.reason.current").getMessage(), + "&6" + reason); } private void notifyTemplate() { @@ -113,16 +133,17 @@ public class GUIPunish extends AbstractGUI { } Material material = plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.WHITE_WOOL : Material.valueOf("WOOL"); - String name = plugin.getLocale().getMessage("gui.punish.template.create"); + String name = plugin.getLocale().getMessage("gui.punish.template.create").getMessage(); ArrayList lore = new ArrayList<>(); - lore.add(plugin.getLocale().getMessage("gui.punish.template.create2")); + lore.add(plugin.getLocale().getMessage("gui.punish.template.create2").getMessage()); if (!justSaved && template != null) { - name = plugin.getLocale().getMessage("gui.punish.template.leftclick"); + name = plugin.getLocale().getMessage("gui.punish.template.leftclick").getMessage(); lore.clear(); - lore.add(plugin.getLocale().getMessage("gui.punish.template.leftclick2", template.getTemplateName())); + lore.add(plugin.getLocale().getMessage("gui.punish.template.leftclick2") + .processPlaceholder("template", template.getTemplateName()).getMessage()); lore.add(""); - lore.add(plugin.getLocale().getMessage("gui.punish.template.rightclick")); + lore.add(plugin.getLocale().getMessage("gui.punish.template.rightclick").getMessage()); } if (plugin.isServerVersionAtLeast(ServerVersion.V1_13) && inventory.getItem(4) != null && inventory.getItem(4).getType() == Material.WHITE_WOOL) @@ -204,7 +225,7 @@ public class GUIPunish extends AbstractGUI { ItemStack item = new ItemStack(Material.PAPER); ItemMeta meta = item.getItemMeta(); - meta.setDisplayName(reason == null ? plugin.getLocale().getMessage("gui.general.reason") : reason); + meta.setDisplayName(reason == null ? plugin.getLocale().getMessage("gui.general.reason").getMessage() : reason); item.setItemMeta(meta); gui.setSlot(AbstractAnvilGUI.AnvilSlot.INPUT_LEFT, item); @@ -256,7 +277,7 @@ public class GUIPunish extends AbstractGUI { ItemStack item = new ItemStack(Material.PAPER); ItemMeta meta = item.getItemMeta(); - meta.setDisplayName(plugin.getLocale().getMessage("gui.general.templatename")); + meta.setDisplayName(plugin.getLocale().getMessage("gui.general.templatename").getMessage()); item.setItemMeta(meta); gui.setSlot(AbstractAnvilGUI.AnvilSlot.INPUT_LEFT, item); diff --git a/src/main/java/com/songoda/ultimatemoderation/gui/GUIPunishments.java b/src/main/java/com/songoda/ultimatemoderation/gui/GUIPunishments.java index d1b802f..5c1ae55 100644 --- a/src/main/java/com/songoda/ultimatemoderation/gui/GUIPunishments.java +++ b/src/main/java/com/songoda/ultimatemoderation/gui/GUIPunishments.java @@ -34,7 +34,8 @@ public class GUIPunishments extends AbstractGUI { this.plugin = plugin; this.toModerate = toModerate; - init(plugin.getLocale().getMessage("gui.punishments.title", toModerate.getName()), 54); + init(plugin.getLocale().getMessage("gui.punishments.title") + .processPlaceholder("toModerate", toModerate.getName()).getMessage(), 54); } @Override @@ -74,7 +75,7 @@ public class GUIPunishments extends AbstractGUI { .collect(Collectors.toList()); if (page != 0) { - createButton(1, Material.ARROW, plugin.getLocale().getMessage("gui.general.previous")); + createButton(1, Material.ARROW, plugin.getLocale().getMessage("gui.general.previous").getMessage()); registerClickable(1, ((player1, inventory1, cursor, slot, type) -> { page --; constructGUI(); @@ -82,14 +83,16 @@ public class GUIPunishments extends AbstractGUI { } if (page != maxPage) { - createButton(6, Material.ARROW, plugin.getLocale().getMessage("gui.general.next")); + createButton(6, Material.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage()); registerClickable(6, ((player1, inventory1, cursor, slot, type) -> { page ++; constructGUI(); })); } - createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.OAK_DOOR : Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back")); + createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) + ? Material.OAK_DOOR + : Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back").getMessage()); createButton(3, Material.APPLE, Methods.formatText("&6" + currentActivity.getTranslation())); createButton(4, Material.DIAMOND_SWORD, Methods.formatText("&6" + punishmentType.name())); @@ -104,25 +107,25 @@ public class GUIPunishments extends AbstractGUI { ArrayList lore = new ArrayList<>(); lore.add(""); - lore.add(plugin.getLocale().getMessage("gui.punishments.reason")); + lore.add(plugin.getLocale().getMessage("gui.punishments.reason").getMessage()); lore.add("&7" + appliedPunishment.getReason()); if (appliedPunishment.getPunishmentType() != PunishmentType.KICK) { lore.add(""); - lore.add(plugin.getLocale().getMessage("gui.punishments.duration")); + lore.add(plugin.getLocale().getMessage("gui.punishments.duration").getMessage()); lore.add("&7" + (appliedPunishment.getDuration() != -1 ? Methods.makeReadable(appliedPunishment.getDuration()) : plugin.getLocale().getMessage("gui.general.permanent"))); lore.add(""); - lore.add(plugin.getLocale().getMessage("gui.punishments.punisher")); + lore.add(plugin.getLocale().getMessage("gui.punishments.punisher").getMessage()); lore.add("&7" + (appliedPunishment.getPunisher() == null ? "Console" : Bukkit.getOfflinePlayer(appliedPunishment.getPunisher()).getName())); if (activity == Activity.ACTIVE) { lore.add(""); if (appliedPunishment.getDuration() != -1) { - lore.add(plugin.getLocale().getMessage("gui.punishments.remaining")); + lore.add(plugin.getLocale().getMessage("gui.punishments.remaining").getMessage()); lore.add("&7" + Methods.makeReadable(appliedPunishment.getTimeRemaining())); lore.add(""); } - lore.add(plugin.getLocale().getMessage("gui.punishments.click")); + lore.add(plugin.getLocale().getMessage("gui.punishments.click").getMessage()); registerClickable(currentSlot, ((player1, inventory1, cursor, slot, type) -> { appliedPunishment.expire(); @@ -191,7 +194,7 @@ public class GUIPunishments extends AbstractGUI { } public String getTranslation() { - return UltimateModeration.getInstance().getLocale().getMessage("gui.punishments.activity." + this.name().toLowerCase()); + return UltimateModeration.getInstance().getLocale().getMessage("gui.punishments.activity." + this.name().toLowerCase()).getMessage(); } } } diff --git a/src/main/java/com/songoda/ultimatemoderation/gui/GUITemplateManager.java b/src/main/java/com/songoda/ultimatemoderation/gui/GUITemplateManager.java index 25d69e6..fa45217 100644 --- a/src/main/java/com/songoda/ultimatemoderation/gui/GUITemplateManager.java +++ b/src/main/java/com/songoda/ultimatemoderation/gui/GUITemplateManager.java @@ -28,7 +28,7 @@ public class GUITemplateManager extends AbstractGUI { super(player); this.plugin = plugin; - init(plugin.getLocale().getMessage("gui.templatemanager.title"), 54); + init(plugin.getLocale().getMessage("gui.templatemanager.title").getMessage(), 54); } @Override @@ -44,7 +44,7 @@ public class GUITemplateManager extends AbstractGUI { .collect(Collectors.toList()); if (page != 0) { - createButton(1, Material.ARROW, plugin.getLocale().getMessage("gui.general.previous")); + createButton(1, Material.ARROW, plugin.getLocale().getMessage("gui.general.previous").getMessage()); registerClickable(1, ((player1, inventory1, cursor, slot, type) -> { page --; constructGUI(); @@ -52,7 +52,7 @@ public class GUITemplateManager extends AbstractGUI { } if (page != maxPage) { - createButton(5, Material.ARROW, plugin.getLocale().getMessage("gui.general.next")); + createButton(5, Material.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage()); registerClickable(5, ((player1, inventory1, cursor, slot, type) -> { page ++; constructGUI(); @@ -61,9 +61,12 @@ public class GUITemplateManager extends AbstractGUI { createButton(3 ,Material.DIAMOND_SWORD, Methods.formatText("&6" + punishmentType.name())); - createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.OAK_DOOR : Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back")); + createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) + ? Material.OAK_DOOR + : Material.valueOf("WOOD_DOOR"), + plugin.getLocale().getMessage("gui.general.back").getMessage()); - createButton(7, Material.REDSTONE, plugin.getLocale().getMessage("gui.templatemanager.create")); + createButton(7, Material.REDSTONE, plugin.getLocale().getMessage("gui.templatemanager.create").getMessage()); for (int i = 0; i < 9; i++) createButton(9 + i, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : new ItemStack(Material.valueOf("STAINED_GLASS_PANE")), "&1"); @@ -73,8 +76,8 @@ public class GUITemplateManager extends AbstractGUI { for (int i = 0; i < templates.size(); i++) { Template template = templates.get(i); createButton(18 + i, Material.MAP, "&6&l" + template.getTemplateName(), - plugin.getLocale().getMessage("gui.templatemanager.leftclick"), - plugin.getLocale().getMessage("gui.templatemanager.rightclick")); + plugin.getLocale().getMessage("gui.templatemanager.leftclick").getMessage(), + plugin.getLocale().getMessage("gui.templatemanager.rightclick").getMessage()); registerClickable(18 + i, ((player1, inventory1, cursor, slot, type) -> { if (type == ClickType.LEFT) { diff --git a/src/main/java/com/songoda/ultimatemoderation/gui/GUITemplateSelector.java b/src/main/java/com/songoda/ultimatemoderation/gui/GUITemplateSelector.java index 2fd1d70..d0865bf 100644 --- a/src/main/java/com/songoda/ultimatemoderation/gui/GUITemplateSelector.java +++ b/src/main/java/com/songoda/ultimatemoderation/gui/GUITemplateSelector.java @@ -22,12 +22,15 @@ public class GUITemplateSelector extends AbstractGUI { this.plugin = plugin; this.punish = punish; - init(plugin.getLocale().getMessage("gui.templateselector.title"), 54); + init(plugin.getLocale().getMessage("gui.templateselector.title").getMessage(), 54); } @Override protected void constructGUI() { - createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.OAK_DOOR : Material.valueOf("WOOD_DOOR"), plugin.getLocale().getMessage("gui.general.back")); + createButton(8, plugin.isServerVersionAtLeast(ServerVersion.V1_13) + ? Material.OAK_DOOR + : Material.valueOf("WOOD_DOOR"), + plugin.getLocale().getMessage("gui.general.back").getMessage()); for (int i = 0; i < 9; i++) createButton(9 + i, plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.GRAY_STAINED_GLASS_PANE : new ItemStack(Material.valueOf("STAINED_GLASS_PANE")), "&1"); @@ -35,7 +38,8 @@ public class GUITemplateSelector extends AbstractGUI { ArrayList