Updated locale system

This commit is contained in:
Lilac 2019-07-25 17:15:42 +01:00
parent 6f0c8a8ee2
commit d902a71857
50 changed files with 721 additions and 598 deletions

View File

@ -4,7 +4,7 @@ stages:
variables:
name: "UltimateModeration"
path: "/builds/$CI_PROJECT_PATH"
version: "1.1.8"
version: "1.1.9"
build:
stage: build

View File

@ -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<Locale> 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<String, String> 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<Locale> 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<String> 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<String, String> 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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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<AbstractCommand> getCommands() {

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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("");

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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<ItemStack> 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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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()) {

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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");

View File

@ -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()));

View File

@ -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

View File

@ -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<String> 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);

View File

@ -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<String> 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);

View File

@ -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<String> 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();
}
}
}

View File

@ -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) {

View File

@ -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<Template> templates = new ArrayList<>(plugin.getTemplateManager().getTemplates().values());
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.templateselector.click"));
createButton(18 + i, Material.MAP, "&6&l" + template.getTemplateName(),
plugin.getLocale().getMessage("gui.templateselector.click").getMessage());
registerClickable(18 + i, ((player1, inventory1, cursor, slot, type) -> {
punish.setType(template.getPunishmentType());

View File

@ -36,7 +36,8 @@ public class GUITicket extends AbstractGUI {
this.plugin = plugin;
this.toModerate = toModerate;
init(plugin.getLocale().getMessage("gui.ticket.title", ticket.getTicketId()), 54);
init(plugin.getLocale().getMessage("gui.ticket.title")
.processPlaceholder("id", ticket.getTicketId()).getMessage(), 54);
}
@Override
@ -52,7 +53,7 @@ public class GUITicket 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();
@ -60,7 +61,7 @@ public class GUITicket 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();
@ -70,12 +71,16 @@ public class GUITicket extends AbstractGUI {
if (player.hasPermission("um.ticket.openclose"))
createButton(5, Material.REDSTONE, "&6" + ticket.getStatus().getStatus());
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());
if (player.hasPermission("um.ticket.clicktotele") && ticket.getLocation() != null)
createButton(7, Material.REDSTONE, plugin.getLocale().getMessage("gui.ticket.clicktotele"));
createButton(7, Material.REDSTONE,
plugin.getLocale().getMessage("gui.ticket.clicktotele").getMessage());
createButton(6, Material.REDSTONE, plugin.getLocale().getMessage("gui.ticket.respond"));
createButton(6, Material.REDSTONE, plugin.getLocale().getMessage("gui.ticket.respond").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");
@ -108,8 +113,10 @@ public class GUITicket extends AbstractGUI {
SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy");
lore.add(plugin.getLocale().getMessage("gui.ticket.postedby", Bukkit.getOfflinePlayer(ticketResponse.getAuthor()).getName() ));
lore.add(plugin.getLocale().getMessage("gui.ticket.createdon", format.format(new Date(ticketResponse.getPostedDate()))));
lore.add(plugin.getLocale().getMessage("gui.ticket.postedby")
.processPlaceholder("player", Bukkit.getOfflinePlayer(ticketResponse.getAuthor()).getName()).getMessage());
lore.add(plugin.getLocale().getMessage("gui.ticket.createdon")
.processPlaceholder("sent", format.format(new Date(ticketResponse.getPostedDate()))).getMessage());
createButton(18 + i, Material.MAP, name, lore);
}
@ -133,7 +140,7 @@ public class GUITicket extends AbstractGUI {
}
registerClickable(6, ((player1, inventory1, cursor, slot, type) -> {
player.sendMessage(plugin.getLocale().getMessage("gui.ticket.what"));
player.sendMessage(plugin.getLocale().getMessage("gui.ticket.what").getMessage());
AbstractChatConfirm abstractChatConfirm = new AbstractChatConfirm(player, event2 -> {
ticket.addResponse(new TicketResponse(player, event2.getMessage(), System.currentTimeMillis()));
constructGUI();

View File

@ -38,7 +38,8 @@ public class GUITicketManager extends AbstractGUI {
this.plugin = plugin;
this.toModerate = toModerate;
init(plugin.getLocale().getMessage(toModerate != null ? "gui.tickets.titlesingle" : "gui.tickets.title", toModerate != null ? toModerate.getName() : ""), 54);
init(plugin.getLocale().getMessage(toModerate != null ? "gui.tickets.titlesingle" : "gui.tickets.title")
.processPlaceholder("toModerate", toModerate != null ? toModerate.getName() : "").getMessage(), 54);
}
@Override
@ -55,7 +56,7 @@ public class GUITicketManager extends AbstractGUI {
tickets = tickets.stream().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();
@ -63,7 +64,7 @@ public class GUITicketManager extends AbstractGUI {
}
if (maxPage >= 36) {
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();
@ -73,10 +74,13 @@ public class GUITicketManager extends AbstractGUI {
createButton(3 ,Material.DIAMOND_SWORD, Methods.formatText("&6" + status.getStatus()));
if (toModerate != null)
createButton(7, Material.REDSTONE, plugin.getLocale().getMessage("gui.tickets.create"));
createButton(7, Material.REDSTONE, plugin.getLocale().getMessage("gui.tickets.create").getMessage());
if (player.hasPermission("um.ticket"))
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");
@ -108,13 +112,17 @@ public class GUITicketManager extends AbstractGUI {
SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy");
lore.add(plugin.getLocale().getMessage("gui.ticket.status", ticket.getStatus().getStatus()));
lore.add(plugin.getLocale().getMessage("gui.ticket.status")
.processPlaceholder("status", ticket.getStatus().getStatus()).getMessage());
if (toModerate != null)
lore.add(plugin.getLocale().getMessage("gui.tickets.player", Bukkit.getOfflinePlayer(ticket.getVictim()).getName()));
lore.add(plugin.getLocale().getMessage("gui.ticket.type", ticket.getType()));
lore.add(plugin.getLocale().getMessage("gui.ticket.createdon", format.format(new Date(ticket.getCreationDate()))));
lore.add(plugin.getLocale().getMessage("gui.tickets.click"));
lore.add(plugin.getLocale().getMessage("gui.tickets.player")
.processPlaceholder("player", Bukkit.getOfflinePlayer(ticket.getVictim()).getName()).getMessage());
lore.add(plugin.getLocale().getMessage("gui.ticket.type")
.processPlaceholder("type", ticket.getType()).getMessage());
lore.add(plugin.getLocale().getMessage("gui.ticket.createdon")
.processPlaceholder("sent", format.format(new Date(ticket.getCreationDate()))).getMessage());
lore.add(plugin.getLocale().getMessage("gui.tickets.click").getMessage());
createButton(18 + i, Material.MAP, name, lore);
@ -156,7 +164,7 @@ public class GUITicketManager extends AbstractGUI {
ItemStack item = new ItemStack(Material.PAPER);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(plugin.getLocale().getMessage("gui.tickets.subject"));
meta.setDisplayName(plugin.getLocale().getMessage("gui.tickets.subject").getMessage());
item.setItemMeta(meta);
gui.setSlot(AbstractAnvilGUI.AnvilSlot.INPUT_LEFT, item);

View File

@ -25,7 +25,7 @@ public class GUITicketType extends AbstractGUI {
this.toModerate = toModerate;
this.subject = subject;
init(plugin.getLocale().getMessage("gui.ticket.picktype"), 27);
init(plugin.getLocale().getMessage("gui.ticket.picktype").getMessage(), 27);
}
@Override
@ -41,7 +41,7 @@ public class GUITicketType extends AbstractGUI {
final int fi = i;
registerClickable(i, (player1, inventory1, cursor, slot, type) -> {
Ticket ticket = new Ticket(toModerate, subject, types.get(fi));
player.sendMessage(plugin.getLocale().getMessage("gui.tickets.what"));
player.sendMessage(plugin.getLocale().getMessage("gui.tickets.what").getMessage());
AbstractChatConfirm abstractChatConfirm = new AbstractChatConfirm(player, event2 -> {
plugin.getTicketManager().addTicket(ticket);
if (player == toModerate)

View File

@ -60,7 +60,7 @@ public class ChatListener implements Listener {
if (!isChatToggled && !player.hasPermission("um.togglechat.bypass")) {
event.setCancelled(true);
player.sendMessage(instance.getReferences().getPrefix() + Methods.formatText(instance.getLocale().getMessage("command.togglechat.muted")));
instance.getLocale().getMessage("command.togglechat.muted").sendPrefixedMessage(player);
}
List<AppliedPunishment> appliedPunishments = instance.getPunishmentManager().getPlayer(player).getActivePunishments(PunishmentType.MUTE);

View File

@ -44,14 +44,17 @@ public class CommandListener implements Listener {
&& !player.hasPermission("um.commandblock.bypass")) {
event.setCancelled(true);
event.setMessage("-");
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.command.blocked"));
instance.getLocale().getMessage("event.command.blocked").sendPrefixedMessage(player);
}
}
if (!player.hasPermission("um.commandspy.immune")) {
for (Player pl : Bukkit.getOnlinePlayers()) {
if (pl.hasPermission("um.commandspy") && CommandCommandSpy.isSpying(pl))
pl.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.commandspy.deny", player.getName(), StringEscapeUtils.escapeJava(command)));
instance.getLocale().getMessage("command.commandspy.deny")
.processPlaceholder("player", player.getName())
.processPlaceholder("command", StringEscapeUtils.escapeJava(command))
.sendPrefixedMessage(player);
}
}
}

View File

@ -20,7 +20,7 @@ public class DropListener implements Listener {
Player player = event.getPlayer();
if (CommandFreeze.isFrozen(player)) {
event.setCancelled(true);
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.freeze.nope"));
instance.getLocale().getMessage("command.freeze.nope").sendPrefixedMessage(player);
}
}
}

View File

@ -21,7 +21,7 @@ public class InventoryListener implements Listener {
Player player = (Player) event.getWhoClicked();
if (CommandFreeze.isFrozen(player)) {
event.setCancelled(true);
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.freeze.nope"));
instance.getLocale().getMessage("command.freeze.nope").sendPrefixedMessage(player);
}
}
}

View File

@ -32,9 +32,10 @@ public class LoginListener implements Listener {
AppliedPunishment appliedPunishment = playerPunishData.getActivePunishments(PunishmentType.BAN).get(0);
event.setKickMessage(instance.getLocale().getMessage("event.ban.message",
appliedPunishment.getReason() == null ? "" : appliedPunishment.getReason(),
Methods.makeReadable(appliedPunishment.getTimeRemaining())));
event.setKickMessage(instance.getLocale().getMessage("event.ban.message")
.processPlaceholder("reason", appliedPunishment.getReason() == null ? "" : appliedPunishment.getReason())
.processPlaceholder("duration", Methods.makeReadable(appliedPunishment.getTimeRemaining())).getMessage());
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_BANNED);
}

View File

@ -20,7 +20,7 @@ public class MoveListener implements Listener {
Player player = event.getPlayer();
if (CommandFreeze.isFrozen(player)) {
event.setCancelled(true);
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.freeze.nope"));
instance.getLocale().getMessage("command.freeze.nope").sendPrefixedMessage(player);
}
}
}

View File

@ -49,7 +49,7 @@ public class Punishment {
UltimateModeration plugin = UltimateModeration.getInstance();
if (!punisher.hasPermission("Um." + punishmentType)) {
punisher.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.general.nopermission"));
plugin.getLocale().getMessage("event.general.nopermission").sendPrefixedMessage(punisher);
return;
}
@ -57,29 +57,29 @@ public class Punishment {
switch (punishmentType) {
case BAN:
if (!playerPunishData.getActivePunishments(PunishmentType.BAN).isEmpty()) {
punisher.sendMessage(plugin.getReferences().getPrefix()
+ plugin.getLocale().getMessage("event.ban.already"));
plugin.getLocale().getMessage("event.ban.already").sendPrefixedMessage(punisher);
return;
}
if (victim.isOnline()) {
victim.getPlayer().kickPlayer(plugin.getLocale().getMessage("event.ban.message",
reason == null ? "" : reason,
Methods.makeReadable(duration)));
victim.getPlayer().kickPlayer(plugin.getLocale()
.getMessage("event.ban.message")
.processPlaceholder("reason", reason == null ? "" : reason)
.processPlaceholder("duration", Methods.makeReadable(duration)).getMessage());
}
break;
case MUTE:
if (!playerPunishData.getActivePunishments(PunishmentType.MUTE).isEmpty()) {
punisher.sendMessage(plugin.getReferences().getPrefix()
+ plugin.getLocale().getMessage("event.mute.already"));
plugin.getLocale().getMessage("event.mute.already").sendPrefixedMessage(punisher);
return;
}
sendMessage(victim);
break;
case KICK:
if (victim.isOnline()) {
victim.getPlayer().kickPlayer(plugin.getLocale().getMessage("event.kick.message",
reason == null ? "" : reason,
Methods.makeReadable(duration)));
victim.getPlayer().kickPlayer(plugin.getLocale()
.getMessage("event.kick.message")
.processPlaceholder("reason", reason == null ? "" : reason)
.processPlaceholder("duration", Methods.makeReadable(duration)).getMessage());
}
break;
case WARNING:
@ -87,14 +87,18 @@ public class Punishment {
break;
}
String punishSuccess = plugin.getReferences().getPrefix()
+ plugin.getLocale().getMessage("event." + punishmentType.name().toLowerCase() + ".success", victim.getName());
String punishSuccess = plugin.getLocale()
.getMessage("event." + punishmentType.name().toLowerCase() + ".success")
.processPlaceholder("player", victim.getName())
.getPrefixedMessage();
if (reason != null)
punishSuccess += plugin.getLocale().getMessage("event.punish.reason", reason);
punishSuccess += plugin.getLocale().getMessage("event.punish.reason")
.processPlaceholder("reason", reason).getMessage();
if (duration != -1)
punishSuccess += plugin.getLocale().getMessage("event.punish.theirduration", Methods.makeReadable(duration));
punishSuccess += plugin.getLocale().getMessage("event.punish.theirduration")
.processPlaceholder("duration", Methods.makeReadable(duration)).getMessage();
punisher.sendMessage(punishSuccess + Methods.formatText("&7."));
@ -106,14 +110,16 @@ public class Punishment {
Player victim = offlineVictim.getPlayer();
UltimateModeration plugin = UltimateModeration.getInstance();
String punishSuccess = plugin.getReferences().getPrefix()
+ plugin.getLocale().getMessage("event." + punishmentType.name().toLowerCase() + ".message");
String punishSuccess = plugin.getLocale()
.getMessage("event." + punishmentType.name().toLowerCase() + ".message").getPrefixedMessage();
if (reason != null)
punishSuccess += plugin.getLocale().getMessage("event.punish.reason", reason);
punishSuccess += plugin.getLocale().getMessage("event.punish.reason")
.processPlaceholder("reason", reason).getMessage();
if (duration != -1)
punishSuccess += plugin.getLocale().getMessage("event.punish.yourduration", Methods.makeReadable(duration));
punishSuccess += plugin.getLocale().getMessage("event.punish.yourduration")
.processPlaceholder("duration", Methods.makeReadable(duration)).getMessage();
victim.sendMessage(punishSuccess + Methods.formatText("&7."));
}

View File

@ -22,6 +22,6 @@ public enum PunishmentType {
}
public String getTranslation() {
return UltimateModeration.getInstance().getLocale().getMessage("gui.punishmenttypes." + this.name().toLowerCase());
return UltimateModeration.getInstance().getLocale().getMessage("gui.punishmenttypes." + this.name().toLowerCase()).getMessage();
}
}

View File

@ -36,16 +36,29 @@ public class StaffChannel {
if (chatLog.size() > 5) {
chatLog.stream().skip(chatLog.size() - 3).forEach(message -> player.sendMessage(Methods.formatText(message)));
}
messageAll(UltimateModeration.getInstance().getLocale().getMessage("event.staffchat.format.join", chatChar, channelName, player.getDisplayName()));
messageAll(UltimateModeration.getInstance().getLocale()
.getMessage("event.staffchat.format.join")
.processPlaceholder("color", chatChar)
.processPlaceholder("channel", channelName)
.processPlaceholder("player", player.getDisplayName()).getMessage());
}
public void removeMember(Player player) {
members.remove(player.getUniqueId());
messageAll(UltimateModeration.getInstance().getLocale().getMessage("event.staffchat.format.leave", chatChar, channelName, player.getDisplayName()));
messageAll(UltimateModeration.getInstance().getLocale()
.getMessage("event.staffchat.format.leave")
.processPlaceholder("color", chatChar)
.processPlaceholder("channel", channelName)
.processPlaceholder("player", player.getDisplayName()).getMessage());
}
public void processMessage(String message, Player player) {
messageAll(UltimateModeration.getInstance().getLocale().getMessage("event.staffchat.format", chatChar, channelName, player.getDisplayName(), chatChar, message));
messageAll(UltimateModeration.getInstance().getLocale()
.getMessage("event.staffchat.format")
.processPlaceholder("color", chatChar)
.processPlaceholder("channel", channelName)
.processPlaceholder("player", player.getDisplayName())
.processPlaceholder("message", message).getMessage());
}
private void messageAll(String message) {

View File

@ -50,7 +50,9 @@ public class SlowModeTask extends BukkitRunnable {
if ((System.currentTimeMillis() - last.getSent()) < (slowmode + 1000)) {
int remaining = (int)((slowmode / 1000) - (System.currentTimeMillis() - last.getSent()) / 1000);
if (plugin.isServerVersionAtLeast(ServerVersion.V1_9))
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(remaining == 0 ? plugin.getLocale().getMessage("event.slowmode.done") : plugin.getLocale().getMessage("event.slowmode.wait", remaining)));
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(remaining == 0
? plugin.getLocale().getMessage("event.slowmode.done").getMessage()
: plugin.getLocale().getMessage("event.slowmode.wait").processPlaceholder("delay", remaining).getMessage()));
}
});

View File

@ -0,0 +1,311 @@
package com.songoda.ultimatemoderation.utils.locale;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList;
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 utilization of localization files.
* Created to be used by the Songoda Team.
*
* @author Brianna O'Keefe - Songoda
*/
public class Locale {
private static final List<Locale> LOCALES = new ArrayList<>();
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 final Map<String, String> nodes = new HashMap<>();
private static String defaultLocale;
private File file;
private String name;
/**
* Instantiate the Locale class for future use
*
* @param name the name of the instantiated language
*/
private Locale(String name) {
if (plugin == null)
return;
this.name = name;
String fileName = name + FILE_EXTENSION;
this.file = new File(localeFolder, fileName);
if (!this.reloadMessages()) return;
plugin.getLogger().info("Loaded locale \"" + fileName + "\"");
}
/**
* Initialize the class to load all existing language files and update them.
* This must be called before any other methods in this class as otherwise
* the methods will fail to invoke
*
* @param plugin the plugin instance
* @param defaultLocale the default language
*/
public Locale(JavaPlugin plugin, String defaultLocale) {
Locale.plugin = plugin;
Locale.localeFolder = new File(plugin.getDataFolder(), "locales/");
if (!localeFolder.exists()) localeFolder.mkdirs();
//Save the default locale file.
Locale.defaultLocale = defaultLocale;
saveLocale(defaultLocale);
for (File file : localeFolder.listFiles()) {
String fileName = file.getName();
if (!fileName.endsWith(FILE_EXTENSION)) continue;
String name = fileName.substring(0, fileName.lastIndexOf('.'));
if (name.split("_").length != 2) continue;
if (localeLoaded(name)) continue;
LOCALES.add(new Locale(name));
}
}
/**
* Save a locale file from the InputStream, 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 saveLocale(String fileName) {
return saveLocale(plugin.getResource(defaultLocale + FILE_EXTENSION), fileName);
}
/**
* Save a locale file from the InputStream, 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 saveLocale(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(in, destinationFile);
try (OutputStream outputStream = new FileOutputStream(destinationFile)) {
copy(in, outputStream);
fileName = fileName.substring(0, fileName.lastIndexOf('.'));
if (fileName.split("_").length != 2) return false;
LOCALES.add(new Locale(fileName));
if (defaultLocale == null) defaultLocale = fileName;
return true;
} catch (IOException e) {
return false;
}
}
// Write new changes to existing files, if any at all
private static boolean compareFiles(InputStream in, File existingFile) {
InputStream defaultFile =
in == null ? plugin.getResource((defaultLocale != null ? defaultLocale : "en_US") + FILE_EXTENSION) : in;
boolean changed = false;
List<String> 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();
// Leave a note alerting the user of the newly added messages.
writer.write("# New messages for " + plugin.getName() + " v" + plugin.getDescription().getVersion() + ".");
// If changes were found outside of the default file leave a note explaining that.
if (in == null) {
writer.newLine();
writer.write("# These translations were found untranslated, join");
writer.newLine();
writer.write("# our translation Discord https://discord.gg/f7fpZEf");
writer.newLine();
writer.write("# to request an official update!");
}
}
writer.newLine();
writer.write(defaultValue);
changed = true;
}
}
if (in != null && !changed) compareFiles(null, existingFile);
} catch (IOException e) {
return false;
}
return changed;
}
/**
* 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 localeLoaded(String name) {
for (Locale locale : LOCALES)
if (locale.getName().equals(name)) return true;
return false;
}
/**
* 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.getName().equalsIgnoreCase(name)) return locale;
return null;
}
/**
* 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;
}
/**
* Supply the Message object with the plugins prefix.
*
* @param message message to be applied
* @return applied message
*/
private Message supplyPrefix(Message message) {
return message.setPrefix(this.nodes.getOrDefault("general.nametag.prefix", "[Plugin]"));
}
/**
* Create a new unsaved Message
*
* @param message the message to create
* @return the created message
*/
public Message newMessage(String message) {
return supplyPrefix(new Message(message));
}
/**
* Get a message set for a specific node.
*
* @param node the node to get
* @return the message for the specified node
*/
public Message getMessage(String node) {
return this.getMessageOrDefault(node, node);
}
/**
* 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 Message getMessageOrDefault(String node, String defaultValue) {
return supplyPrefix(new Message(this.nodes.getOrDefault(node, defaultValue)));
}
/**
* Return the locale name (i.e. "en_US")
*
* @return the locale name
*/
public String getName() {
return name;
}
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();
}
}
}

View File

@ -0,0 +1,115 @@
package com.songoda.ultimatemoderation.utils.locale;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* The Message object. This holds the message to be sent
* as well as the plugins prefix so that they can both be
* easily manipulated then deployed
*/
public class Message {
private String prefix = null;
private String message;
/**
* create a new message
*
* @param message the message text
*/
public Message(String message) {
this.message = message;
}
/**
* Format and send the held message to a player
*
* @param player player to send the message to
*/
public void sendMessage(Player player) {
player.sendMessage(this.getMessage());
}
/**
* Format and send the held message with the
* appended plugin prefix to a player
*
* @param player player to send the message to
*/
public void sendPrefixedMessage(Player player) {
player.sendMessage(this.getPrefixedMessage());
}
/**
* Format and send the held message to a player
*
* @param sender command sender to send the message to
*/
public void sendMessage(CommandSender sender) {
sender.sendMessage(this.getMessage());
}
/**
* Format and send the held message with the
* appended plugin prefix to a command sender
*
* @param sender command sender to send the message to
*/
public void sendPrefixedMessage(CommandSender sender) {
sender.sendMessage(this.getPrefixedMessage());
}
/**
* Format the held message and append the plugins
* prefix
*
* @return the prefixed message
*/
public String getPrefixedMessage() {
return ChatColor.translateAlternateColorCodes('&',(prefix == null ? "" : this.prefix)
+ " " + this.message);
}
/**
* Get and format the held message
*
* @return the message
*/
public String getMessage() {
return ChatColor.translateAlternateColorCodes('&', this.message);
}
/**
* Get the held message
*
* @return the message
*/
public String getUnformattedMessage() {
return this.message;
}
/**
* Replace the provided placeholder with the
* provided object
*
* @param placeholder the placeholder to replace
* @param replacement the replacement object
* @return the modified Message
*/
public Message processPlaceholder(String placeholder, Object replacement) {
this.message = message.replace("%" + placeholder + "%", replacement.toString());
return this;
}
Message setPrefix(String prefix) {
this.prefix = prefix;
return this;
}
@Override
public String toString() {
return this.message;
}
}

View File

@ -22,7 +22,7 @@ public class LocaleModule implements Module {
if (file.get("type").equals("locale")) {
InputStream in = new URL((String) file.get("link")).openStream();
UltimateModeration.getInstance().getLocale().saveDefaultLocale(in, (String) file.get("name"));
UltimateModeration.getInstance().getLocale().saveLocale(in, (String) file.get("name"));
}
}
} catch (IOException e) {