mirror of
https://github.com/songoda/UltimateKits.git
synced 2024-11-08 11:41:28 +01:00
Locale QoL
This commit is contained in:
parent
898ee269e8
commit
0977b4faae
@ -1,375 +0,0 @@
|
||||
package com.songoda.ultimatekits;
|
||||
|
||||
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.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;
|
||||
}
|
||||
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.songoda.ultimatekits;
|
||||
|
||||
import com.songoda.ultimatekits.utils.Debugger;
|
||||
import org.bukkit.Sound;
|
||||
|
||||
public class References {
|
||||
|
||||
private String prefix = null;
|
||||
private boolean playSound = false;
|
||||
private Sound sound = null;
|
||||
|
||||
References() {
|
||||
try {
|
||||
prefix = UltimateKits.getInstance().getLocale().getMessage("general.nametag.prefix") + " ";
|
||||
|
||||
playSound = UltimateKits.getInstance().getConfig().getBoolean("Main.Sounds Enabled");
|
||||
|
||||
if (playSound) {
|
||||
sound = Sound.valueOf(UltimateKits.getInstance().getConfig().getString("Main.Sound Played While Clicking In Inventories"));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
|
||||
public boolean isPlaySound() {
|
||||
return this.playSound;
|
||||
}
|
||||
|
||||
public Sound getSound() {
|
||||
return this.sound;
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ import com.songoda.ultimatekits.listeners.ChatListeners;
|
||||
import com.songoda.ultimatekits.listeners.EntityListeners;
|
||||
import com.songoda.ultimatekits.listeners.InteractListeners;
|
||||
import com.songoda.ultimatekits.utils.*;
|
||||
import com.songoda.ultimatekits.utils.locale.Locale;
|
||||
import com.songoda.ultimatekits.utils.updateModules.LocaleModule;
|
||||
import com.songoda.update.Plugin;
|
||||
import com.songoda.update.SongodaUpdate;
|
||||
@ -35,7 +36,6 @@ public class UltimateKits extends JavaPlugin {
|
||||
private static UltimateKits INSTANCE;
|
||||
|
||||
private static CommandSender console = Bukkit.getConsoleSender();
|
||||
private References references;
|
||||
|
||||
private Locale locale;
|
||||
|
||||
@ -92,18 +92,14 @@ public class UltimateKits extends JavaPlugin {
|
||||
settingsManager.updateSettings();
|
||||
setupConfig();
|
||||
|
||||
String langMode = getConfig().getString("System.Language Mode");
|
||||
Locale.init(this);
|
||||
Locale.saveDefaultLocale("en_US");
|
||||
this.locale = Locale.getLocale(getConfig().getString("System.Language Mode", langMode));
|
||||
new Locale(this, "en_US");
|
||||
this.locale = Locale.getLocale(getConfig().getString("System.Language Mode"));
|
||||
|
||||
//Running Songoda Updater
|
||||
Plugin plugin = new Plugin(this, 14);
|
||||
plugin.addModule(new LocaleModule());
|
||||
SongodaUpdate.load(plugin);
|
||||
|
||||
this.references = new References();
|
||||
|
||||
this.kitManager = new KitManager();
|
||||
this.keyManager = new KeyManager();
|
||||
this.commandManager = new CommandManager(this);
|
||||
@ -322,10 +318,9 @@ public class UltimateKits extends JavaPlugin {
|
||||
try {
|
||||
reloadConfig();
|
||||
kitFile.reloadConfig();
|
||||
String langMode = getConfig().getString("System.Language Mode");
|
||||
this.locale = Locale.getLocale(getConfig().getString("System.Language Mode", langMode));
|
||||
|
||||
this.locale = Locale.getLocale(getConfig().getString("System.Language Mode"));
|
||||
this.locale.reloadMessages();
|
||||
this.references = new References();
|
||||
this.setupConfig();
|
||||
loadFromFile();
|
||||
} catch (Exception ex) {
|
||||
@ -400,10 +395,6 @@ public class UltimateKits extends JavaPlugin {
|
||||
return locale;
|
||||
}
|
||||
|
||||
public References getReferences() {
|
||||
return references;
|
||||
}
|
||||
|
||||
public DisplayItemHandler getDisplayItemHandler() {
|
||||
return displayItemHandler;
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ public class CommandManager implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
}
|
||||
commandSender.sendMessage(plugin.getReferences().getPrefix() + Methods.formatText("&7The command you entered does not exist or is spelt incorrectly."));
|
||||
plugin.getLocale().newMessage("&7The command you entered does not exist or is spelt incorrectly.").sendPrefixedMessage(commandSender);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -71,12 +71,12 @@ public class CommandManager implements CommandExecutor {
|
||||
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
|
||||
AbstractCommand.ReturnType returnType = command.runCommand(plugin, sender, strings);
|
||||
if (returnType == AbstractCommand.ReturnType.SYNTAX_ERROR) {
|
||||
sender.sendMessage(plugin.getReferences().getPrefix() + Methods.formatText("&cInvalid Syntax!"));
|
||||
sender.sendMessage(plugin.getReferences().getPrefix() + Methods.formatText("&7The valid syntax is: &6" + command.getSyntax() + "&7."));
|
||||
plugin.getLocale().newMessage("&cInvalid Syntax!").sendPrefixedMessage(sender);
|
||||
plugin.getLocale().newMessage("&7The valid syntax is: &6" + command.getSyntax() + "&7.").sendPrefixedMessage(sender);
|
||||
}
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("command.general.noperms"));
|
||||
plugin.getLocale().newMessage("event.general.nopermission").sendPrefixedMessage(sender);
|
||||
}
|
||||
|
||||
public List<AbstractCommand> getCommands() {
|
||||
|
@ -20,11 +20,11 @@ public class CommandCreatekit extends AbstractCommand {
|
||||
if (args.length != 2) return ReturnType.SYNTAX_ERROR;
|
||||
String kitStr = args[1].toLowerCase();
|
||||
if (instance.getKitManager().getKit(kitStr) != null) {
|
||||
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.kit.kitalreadyexists"));
|
||||
instance.getLocale().getMessage("command.kit.kitalreadyexists").sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
player.sendMessage(UltimateKits.getInstance().getReferences().getPrefix() + Methods.formatText("&aThat kit doesn't exist. Creating it now."));
|
||||
instance.getLocale().newMessage("&aThat kit doesn't exist. Creating it now.").sendPrefixedMessage(player);
|
||||
Kit kit = new Kit(kitStr.trim());
|
||||
UltimateKits.getInstance().getKitManager().addKit(kit);
|
||||
new GUIKitEditor(instance, player, kit, null, null, 0);
|
||||
|
@ -25,14 +25,14 @@ public class CommandEdit extends AbstractCommand {
|
||||
|
||||
if (args.length == 1) {
|
||||
if (kitBlockData == null) {
|
||||
player.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&8This block does not contain a kit."));
|
||||
instance.getLocale().newMessage("&8This block does not contain a kit.").sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
new GUIBlockEditor(instance, player, block.getLocation());
|
||||
} else {
|
||||
String kitStr = args[1].toLowerCase().trim();
|
||||
if (instance.getKitManager().getKit(kitStr) == null) {
|
||||
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.kit.kitdoesntexist"));
|
||||
instance.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
|
@ -22,11 +22,11 @@ public class CommandKey extends AbstractCommand {
|
||||
}
|
||||
Kit kit = instance.getKitManager().getKit(args[1]);
|
||||
if (kit == null && !args[1].toLowerCase().equals("all")) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.kit.kitdoesntexist"));
|
||||
instance.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
if (Bukkit.getPlayer(args[3]) == null && !args[3].trim().equalsIgnoreCase("all")) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&cThat username does not exist, or the user is offline!"));
|
||||
instance.getLocale().newMessage("&cThat username does not exist, or the user is offline!").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
int amt = 1;
|
||||
@ -38,13 +38,13 @@ public class CommandKey extends AbstractCommand {
|
||||
}
|
||||
}
|
||||
if (amt == 0) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&a" + args[3] + " &cis not a number."));
|
||||
instance.getLocale().newMessage("&a" + args[3] + " &cis not a number.").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
Key key = instance.getKeyManager().getKey(args[2]);
|
||||
if (key == null) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&a" + args[3] + " &cis not a key."));
|
||||
instance.getLocale().newMessage("&a" + args[3] + " &cis not a key.").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
@ -52,12 +52,16 @@ public class CommandKey extends AbstractCommand {
|
||||
if (!args[3].trim().equals("all")) {
|
||||
Player p = Bukkit.getPlayer(args[3]);
|
||||
p.getInventory().addItem(key.getKeyItem(kit, amt));
|
||||
p.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.key.given", kit == null ? "Any" : kit.getShowableName()));
|
||||
instance.getLocale().getMessage("event.key.given")
|
||||
.processPlaceholder("kit", kit == null ? "Any" : kit.getShowableName())
|
||||
.sendPrefixedMessage(p);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
for (Player pl : instance.getServer().getOnlinePlayers()) {
|
||||
pl.getInventory().addItem(key.getKeyItem(kit, amt));
|
||||
pl.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.key.given", kit == null ? "Any" : kit.getShowableName()));
|
||||
instance.getLocale().getMessage("event.key.given")
|
||||
.processPlaceholder("kit", kit == null ? "Any" : kit.getShowableName())
|
||||
.sendPrefixedMessage(pl);
|
||||
}
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public class CommandKit extends AbstractCommand {
|
||||
Player player = (Player) sender;
|
||||
String kitName = args[0].toLowerCase();
|
||||
if (instance.getKitManager().getKit(kitName) == null) {
|
||||
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.kit.kitdoesntexist"));
|
||||
instance.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
Kit kit = instance.getKitManager().getKit(kitName);
|
||||
@ -46,25 +46,27 @@ public class CommandKit extends AbstractCommand {
|
||||
if (args.length == 2) {
|
||||
String kitName = args[0].toLowerCase();
|
||||
if (instance.getKitManager().getKit(kitName) == null) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.kit.kitdoesntexist"));
|
||||
instance.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
if (Bukkit.getPlayerExact(args[1]) == null) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.kit.playernotfound"));
|
||||
instance.getLocale().getMessage("command.kit.playernotfound").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
Player player2 = Bukkit.getPlayer(args[1]);
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
if (!Methods.canGiveKit(player)) {
|
||||
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.general.noperms"));
|
||||
UltimateKits.getInstance().getLocale().getMessage("command.general.noperms")
|
||||
.sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
}
|
||||
Kit kit = instance.getKitManager().getKit(kitName);
|
||||
kit.processGenericUse(player2, true);
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&7You gave &9" + player2.getDisplayName() + "&7 kit &9" + kit.getShowableName() + "&7."));
|
||||
instance.getLocale().newMessage("&7You gave &9" + player2.getDisplayName() + "&7 kit &9" + kit.getShowableName() + "&7.")
|
||||
.sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
|
@ -16,12 +16,12 @@ public class CommandPreviewKit extends AbstractCommand {
|
||||
protected ReturnType runCommand(UltimateKits plugin, CommandSender sender, String... args) {
|
||||
Player player = (Player) sender;
|
||||
if (args.length != 1) {
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("command.kit.nokitsupplied"));
|
||||
plugin.getLocale().getMessage("command.kit.nokitsupplied").sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
Kit kit = plugin.getKitManager().getKit(args[0].toLowerCase().trim());
|
||||
if (kit == null) {
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("command.kit.kitdoesntexist"));
|
||||
plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
kit.display(player, null);
|
||||
|
@ -14,7 +14,7 @@ public class CommandReload extends AbstractCommand {
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateKits instance, CommandSender sender, String... args) {
|
||||
instance.reload();
|
||||
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Configuration and Language files reloaded."));
|
||||
instance.getLocale().getMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,6 @@ package com.songoda.ultimatekits.command.commands;
|
||||
import com.songoda.ultimatekits.UltimateKits;
|
||||
import com.songoda.ultimatekits.command.AbstractCommand;
|
||||
import com.songoda.ultimatekits.kit.Kit;
|
||||
import com.songoda.ultimatekits.utils.Methods;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -17,7 +16,7 @@ public class CommandRemove extends AbstractCommand {
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateKits instance, CommandSender sender, String... args) {
|
||||
if (args.length != 1) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.kit.nokitsupplied"));
|
||||
instance.getLocale().getMessage("command.kit.nokitsupplied").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
@ -27,7 +26,7 @@ public class CommandRemove extends AbstractCommand {
|
||||
|
||||
if (instance.getHologram() != null)
|
||||
instance.getHologram().remove(kit);
|
||||
player.sendMessage(Methods.formatText(UltimateKits.getInstance().getReferences().getPrefix() + "&8Kit &9" + kit.getName() + " &8unassigned from: &a" + block.getType().toString() + "&8."));
|
||||
instance.getLocale().newMessage("&8Kit &9" + kit.getName() + " &8unassigned from: &a" + block.getType().toString() + "&8.").sendPrefixedMessage(player);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -16,18 +16,19 @@ public class CommandSet extends AbstractCommand {
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateKits instance, CommandSender sender, String... args) {
|
||||
if (args.length != 2) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.kit.nokitsupplied"));
|
||||
instance.getLocale().getMessage("command.kit.nokitsupplied").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
String kit = args[1].toLowerCase();
|
||||
if (instance.getKitManager().getKit(kit) == null) {
|
||||
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.kit.kitdoesntexist"));
|
||||
instance.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
Block b = player.getTargetBlock(null, 200);
|
||||
instance.getKitManager().addKitToLocation(instance.getKitManager().getKit(kit), b.getLocation());
|
||||
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&8Kit &a" + kit + " &8set to: &a" + b.getType().toString() + "&8."));
|
||||
instance.getLocale().newMessage("&8Kit &a" + kit + " &8set to: &a" + b.getType().toString() + "&8.")
|
||||
.sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,8 @@ public class CommandUltimateKits extends AbstractCommand {
|
||||
@Override
|
||||
protected AbstractCommand.ReturnType runCommand(UltimateKits instance, CommandSender sender, String... args) {
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oBrianna"));
|
||||
instance.getLocale().newMessage("&7Version " + instance.getDescription().getVersion()
|
||||
+ " Created with <3 by &5&l&oSongoda").sendPrefixedMessage(sender);
|
||||
|
||||
for (AbstractCommand command : instance.getCommandManager().getCommands()) {
|
||||
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
|
||||
|
@ -45,7 +45,7 @@ public class GUIBlockEditor extends AbstractGUI {
|
||||
inventory.setItem(26, Methods.getBackgroundGlass(true));
|
||||
|
||||
createButton(8, Material.valueOf(UltimateKits.getInstance().getConfig().getString("Interfaces.Exit Icon")),
|
||||
UltimateKits.getInstance().getLocale().getMessage("interface.button.exit"));
|
||||
UltimateKits.getInstance().getLocale().getMessage("interface.button.exit").getMessage());
|
||||
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
lore.add(Methods.formatText("&7Click to swap this kit blocks function."));
|
||||
|
@ -23,7 +23,8 @@ public class GUIConfirmBuy extends AbstractGUI {
|
||||
this.kit = kit;
|
||||
this.player = player;
|
||||
this.plugin = plugin;
|
||||
init(plugin.getLocale().getMessage("interface.yesno.title", kit.getPrice()), 27);
|
||||
init(plugin.getLocale().getMessage("interface.yesno.title")
|
||||
.processPlaceholder("price", kit.getPrice()).getMessage(), 27);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -66,12 +67,12 @@ public class GUIConfirmBuy extends AbstractGUI {
|
||||
|
||||
ItemStack item2 = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.Buy Icon")), 1);
|
||||
ItemMeta itemmeta2 = item2.getItemMeta();
|
||||
itemmeta2.setDisplayName(plugin.getLocale().getMessage("interface.yesno.yes"));
|
||||
itemmeta2.setDisplayName(plugin.getLocale().getMessage("interface.yesno.yes").getMessage());
|
||||
item2.setItemMeta(itemmeta2);
|
||||
|
||||
ItemStack item3 = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.Exit Icon")), 1);
|
||||
ItemMeta itemmeta3 = item3.getItemMeta();
|
||||
itemmeta3.setDisplayName(plugin.getLocale().getMessage("interface.yesno.no"));
|
||||
itemmeta3.setDisplayName(plugin.getLocale().getMessage("interface.yesno.no").getMessage());
|
||||
item3.setItemMeta(itemmeta3);
|
||||
|
||||
inventory.setItem(4, item);
|
||||
@ -87,7 +88,7 @@ public class GUIConfirmBuy extends AbstractGUI {
|
||||
}));
|
||||
|
||||
registerClickable(15, ((player1, inventory1, cursor, slot, type) -> {
|
||||
player.sendMessage(Methods.formatText(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.purchase.cancelled")));
|
||||
plugin.getLocale().getMessage("event.purchase.cancelled").sendPrefixedMessage(player);
|
||||
player.closeInventory();
|
||||
}));
|
||||
}
|
||||
|
@ -50,13 +50,13 @@ public class GUIDecorOptions extends AbstractGUI {
|
||||
inventory.setItem(26, Methods.getBackgroundGlass(true));
|
||||
|
||||
createButton(8, Material.valueOf(UltimateKits.getInstance().getConfig().getString("Interfaces.Exit Icon")),
|
||||
UltimateKits.getInstance().getLocale().getMessage("interface.button.exit"));
|
||||
UltimateKits.getInstance().getLocale().getMessage("interface.button.exit").getMessage());
|
||||
|
||||
ItemStack head = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3);
|
||||
ItemStack back = Methods.addTexture(head, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
inventory.setItem(0, back);
|
||||
|
||||
createButton(0, back, UltimateKits.getInstance().getLocale().getMessage("interface.button.back"));
|
||||
createButton(0, back, UltimateKits.getInstance().getLocale().getMessage("interface.button.back").getMessage());
|
||||
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
if (kitBlockData.showHologram()) {
|
||||
|
@ -34,9 +34,11 @@ public class GUIDisplayKit extends AbstractGUI {
|
||||
this.plugin = plugin;
|
||||
this.back = back;
|
||||
|
||||
String guititle = Methods.formatTitle(plugin.getLocale().getMessage("interface.preview.title", kit.getShowableName()));
|
||||
String guititle = Methods.formatTitle(plugin.getLocale().getMessage("interface.preview.title")
|
||||
.processPlaceholder("kit", kit.getShowableName()).getMessage());
|
||||
if (kit.getTitle() != null) {
|
||||
guititle = plugin.getLocale().getMessage("interface.preview.title", Methods.formatText(kit.getTitle(), true));
|
||||
guititle = plugin.getLocale().getMessage("interface.preview.title")
|
||||
.processPlaceholder("kit", Methods.formatText(kit.getTitle(), true)).getMessage();
|
||||
}
|
||||
|
||||
list = kit.getReadableContents(player, true, true, false);
|
||||
@ -89,7 +91,7 @@ public class GUIDisplayKit extends AbstractGUI {
|
||||
if (!plugin.getConfig().getBoolean("Interfaces.Do Not Use Glass Borders")) {
|
||||
ItemStack exit = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.Exit Icon")), 1);
|
||||
ItemMeta exitmeta = exit.getItemMeta();
|
||||
exitmeta.setDisplayName(UltimateKits.getInstance().getLocale().getMessage("interface.button.exit"));
|
||||
exitmeta.setDisplayName(plugin.getLocale().getMessage("interface.button.exit").getMessage());
|
||||
exit.setItemMeta(exitmeta);
|
||||
while (num != 10) {
|
||||
inventory.setItem(num, Methods.getGlass());
|
||||
@ -126,10 +128,11 @@ public class GUIDisplayKit extends AbstractGUI {
|
||||
if (buyable) {
|
||||
ItemStack link = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.Buy Icon")), 1);
|
||||
ItemMeta linkmeta = link.getItemMeta();
|
||||
linkmeta.setDisplayName(plugin.getLocale().getMessage("interface.button.buynow"));
|
||||
linkmeta.setDisplayName(plugin.getLocale().getMessage("interface.button.buynow").getMessage());
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
if (kit.hasPermission(player) && plugin.getConfig().getBoolean("Main.Allow Players To Receive Kits For Free If They Have Permission")) {
|
||||
lore.add(plugin.getLocale().getMessage("interface.button.clickeco", "0"));
|
||||
lore.add(plugin.getLocale().getMessage("interface.button.clickeco")
|
||||
.processPlaceholder("price", "0").getMessage());
|
||||
if (player.isOp()) {
|
||||
lore.add("");
|
||||
lore.add(Methods.formatText("&7This is free because"));
|
||||
@ -138,7 +141,8 @@ public class GUIDisplayKit extends AbstractGUI {
|
||||
lore.add(Methods.formatText("&7this for &a$" + Methods.formatEconomy(kit.getPrice()) + "&7."));
|
||||
}
|
||||
} else {
|
||||
lore.add(plugin.getLocale().getMessage("interface.button.clickeco", Methods.formatEconomy(kit.getPrice())));
|
||||
lore.add(plugin.getLocale().getMessage("interface.button.clickeco")
|
||||
.processPlaceholder("price", Methods.formatEconomy(kit.getPrice())).getMessage());
|
||||
}
|
||||
if (kit.getDelay() != 0 && player.isOp()) {
|
||||
lore.add("");
|
||||
@ -210,7 +214,7 @@ public class GUIDisplayKit extends AbstractGUI {
|
||||
ItemStack skull2 = Methods.addTexture(head, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
SkullMeta skull2Meta = (SkullMeta) skull2.getItemMeta();
|
||||
skull2.setDurability((short) 3);
|
||||
skull2Meta.setDisplayName(UltimateKits.getInstance().getLocale().getMessage("interface.button.back"));
|
||||
skull2Meta.setDisplayName(plugin.getLocale().getMessage("interface.button.back").getMessage());
|
||||
skull2.setItemMeta(skull2Meta);
|
||||
inventory.setItem(0, skull2);
|
||||
}
|
||||
|
@ -52,13 +52,13 @@ public class GUIGUIOptions extends AbstractGUI {
|
||||
inventory.setItem(26, Methods.getBackgroundGlass(true));
|
||||
|
||||
createButton(8, Material.valueOf(UltimateKits.getInstance().getConfig().getString("Interfaces.Exit Icon")),
|
||||
UltimateKits.getInstance().getLocale().getMessage("interface.button.exit"));
|
||||
UltimateKits.getInstance().getLocale().getMessage("interface.button.exit").getMessage());
|
||||
|
||||
ItemStack head = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3);
|
||||
ItemStack back = Methods.addTexture(head, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
SkullMeta skull2Meta = (SkullMeta) back.getItemMeta();
|
||||
back.setDurability((short) 3);
|
||||
skull2Meta.setDisplayName(UltimateKits.getInstance().getLocale().getMessage("interface.button.back"));
|
||||
skull2Meta.setDisplayName(UltimateKits.getInstance().getLocale().getMessage("interface.button.back").getMessage());
|
||||
back.setItemMeta(skull2Meta);
|
||||
|
||||
inventory.setItem(0, back);
|
||||
@ -120,7 +120,8 @@ public class GUIGUIOptions extends AbstractGUI {
|
||||
String msg = event.getName();
|
||||
kit.setTitle(msg);
|
||||
plugin.saveConfig();
|
||||
player.sendMessage(Methods.formatText(plugin.getReferences().getPrefix() + "&8Title &5" + msg + "&8 added to Kit &a" + kit.getShowableName() + "&8."));
|
||||
plugin.getLocale().newMessage("&8Title &5" + msg + "&8 added to Kit &a" + kit.getShowableName() + "&8.")
|
||||
.sendPrefixedMessage(player);
|
||||
if (plugin.getHologram() != null)
|
||||
plugin.getHologram().update(kit);
|
||||
});
|
||||
@ -145,15 +146,15 @@ public class GUIGUIOptions extends AbstractGUI {
|
||||
registerClickable(13, ((player1, inventory1, cursor, slot, type) -> {
|
||||
if (type.isLeftClick()) {
|
||||
ItemStack is = player.getItemInHand();
|
||||
if (is == null || is.getType() == Material.AIR) {
|
||||
player.sendMessage(Methods.formatText(plugin.getReferences().getPrefix() + "&8You must be holding an item to use this function."));
|
||||
if (is.getType() == Material.AIR) {
|
||||
plugin.getLocale().newMessage("&8You must be holding an item to use this function.").sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
kit.setDisplayItem(is.getType());
|
||||
player.sendMessage(Methods.formatText(plugin.getReferences().getPrefix() + "&8Custom Item Display set for kit &a" + kit.getShowableName() + "&8."));
|
||||
plugin.getLocale().newMessage("&8Custom Item Display set for kit &a" + kit.getShowableName() + "&8.").sendPrefixedMessage(player);
|
||||
} else {
|
||||
kit.setDisplayItem(null);
|
||||
player.sendMessage(Methods.formatText(plugin.getReferences().getPrefix() + "&8Custom Item Display removed from kit &a" + kit.getShowableName() + "&8."));
|
||||
plugin.getLocale().newMessage("&8Custom Item Display removed from kit &a" + kit.getShowableName() + "&8.").sendPrefixedMessage(player);
|
||||
}
|
||||
constructGUI();
|
||||
}));
|
||||
|
@ -7,7 +7,6 @@ import com.songoda.ultimatekits.utils.ServerVersion;
|
||||
import com.songoda.ultimatekits.utils.gui.AbstractAnvilGUI;
|
||||
import com.songoda.ultimatekits.utils.gui.AbstractGUI;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@ -51,13 +50,14 @@ public class GUIGeneralOptions extends AbstractGUI {
|
||||
inventory.setItem(26, Methods.getBackgroundGlass(true));
|
||||
|
||||
createButton(8, Material.valueOf(UltimateKits.getInstance().getConfig().getString("Interfaces.Exit Icon")),
|
||||
UltimateKits.getInstance().getLocale().getMessage("interface.button.exit"));
|
||||
UltimateKits.getInstance().getLocale().getMessage("interface.button.exit").getMessage());
|
||||
|
||||
ItemStack head = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3);
|
||||
ItemStack back = Methods.addTexture(head, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
SkullMeta skull2Meta = (SkullMeta) back.getItemMeta();
|
||||
back.setDurability((short) 3);
|
||||
skull2Meta.setDisplayName(UltimateKits.getInstance().getLocale().getMessage("interface.button.back"));
|
||||
skull2Meta.setDisplayName(UltimateKits.getInstance().getLocale().getMessage("interface.button.back")
|
||||
.getMessage());
|
||||
back.setItemMeta(skull2Meta);
|
||||
|
||||
inventory.setItem(0, back);
|
||||
@ -90,9 +90,9 @@ public class GUIGeneralOptions extends AbstractGUI {
|
||||
plugin.getKitManager().removeKit(kit);
|
||||
if (plugin.getHologram() != null)
|
||||
plugin.getHologram().update(kit);
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + Methods.formatText("&cKit destroyed successfully."));
|
||||
plugin.getLocale().newMessage("&cKit destroyed successfully.").sendPrefixedMessage(player);
|
||||
} else {
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + Methods.formatText("&cKit was not Destroyed."));
|
||||
plugin.getLocale().newMessage("&cKit was not Destroyed.").sendPrefixedMessage(player);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -65,14 +65,14 @@ public class GUIKitEditor extends AbstractGUI {
|
||||
player.updateInventory();
|
||||
|
||||
createButton(8, Material.valueOf(UltimateKits.getInstance().getConfig().getString("Interfaces.Exit Icon")),
|
||||
UltimateKits.getInstance().getLocale().getMessage("interface.button.exit"));
|
||||
UltimateKits.getInstance().getLocale().getMessage("interface.button.exit").getMessage());
|
||||
|
||||
ItemStack head = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3);
|
||||
ItemStack back;
|
||||
back = Methods.addTexture(head, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
SkullMeta skull2Meta = (SkullMeta) back.getItemMeta();
|
||||
back.setDurability((short) 3);
|
||||
skull2Meta.setDisplayName(UltimateKits.getInstance().getLocale().getMessage("interface.button.back"));
|
||||
skull2Meta.setDisplayName(UltimateKits.getInstance().getLocale().getMessage("interface.button.back").getMessage());
|
||||
back.setItemMeta(skull2Meta);
|
||||
|
||||
ItemStack it = new ItemStack(Material.CHEST, 1);
|
||||
@ -277,7 +277,8 @@ public class GUIKitEditor extends AbstractGUI {
|
||||
|
||||
kit.saveKit(Arrays.asList(items));
|
||||
if (!muteSave)
|
||||
player.sendMessage(Methods.formatText(plugin.getReferences().getPrefix() + "&8Changes to &a" + kit.getShowableName() + " &8saved successfully."));
|
||||
plugin.getLocale().newMessage("&8Changes to &a" + kit.getShowableName() + " &8saved successfully.")
|
||||
.sendPrefixedMessage(player);
|
||||
muteSave = false;
|
||||
}
|
||||
|
||||
@ -303,84 +304,84 @@ public class GUIKitEditor extends AbstractGUI {
|
||||
constructGUI();
|
||||
break;
|
||||
case DISPLAY_ITEM: {
|
||||
muteSave = true;
|
||||
saveKit(player, this.inventory);
|
||||
AbstractAnvilGUI gui = new AbstractAnvilGUI(player, event -> {
|
||||
String msg = event.getName();
|
||||
ItemStack toReplace = null;
|
||||
try {
|
||||
Material material = Material.valueOf(msg.trim().toUpperCase());
|
||||
muteSave = true;
|
||||
saveKit(player, this.inventory);
|
||||
AbstractAnvilGUI gui = new AbstractAnvilGUI(player, event -> {
|
||||
String msg = event.getName();
|
||||
ItemStack toReplace = null;
|
||||
try {
|
||||
Material material = Material.valueOf(msg.trim().toUpperCase());
|
||||
|
||||
KitItem item2 = new KitItem(itemStack);
|
||||
item2.setDisplayItem(material);
|
||||
KitItem item2 = new KitItem(itemStack);
|
||||
item2.setDisplayItem(material);
|
||||
|
||||
toReplace = item2.getMoveableItem();
|
||||
} catch (Exception e) {
|
||||
player.sendMessage(Methods.formatText("&a" + msg + " &8is not a valid material."));
|
||||
}
|
||||
this.slot = slot;
|
||||
this.toReplace = toReplace;
|
||||
});
|
||||
toReplace = item2.getMoveableItem();
|
||||
} catch (Exception e) {
|
||||
player.sendMessage(Methods.formatText("&a" + msg + " &8is not a valid material."));
|
||||
}
|
||||
this.slot = slot;
|
||||
this.toReplace = toReplace;
|
||||
});
|
||||
|
||||
gui.setOnClose((player1, inventory1) -> init(title, 54));
|
||||
gui.setOnClose((player1, inventory1) -> init(title, 54));
|
||||
|
||||
ItemStack item2 = new ItemStack(Material.NAME_TAG);
|
||||
ItemMeta meta2 = item2.getItemMeta();
|
||||
meta2.setDisplayName("Enter a Material");
|
||||
item2.setItemMeta(meta2);
|
||||
ItemStack item2 = new ItemStack(Material.NAME_TAG);
|
||||
ItemMeta meta2 = item2.getItemMeta();
|
||||
meta2.setDisplayName("Enter a Material");
|
||||
item2.setItemMeta(meta2);
|
||||
|
||||
gui.setSlot(AbstractAnvilGUI.AnvilSlot.INPUT_LEFT, item2);
|
||||
gui.open();
|
||||
}
|
||||
break;
|
||||
gui.setSlot(AbstractAnvilGUI.AnvilSlot.INPUT_LEFT, item2);
|
||||
gui.open();
|
||||
}
|
||||
break;
|
||||
case DISPLAY_NAME: {
|
||||
muteSave = true;
|
||||
saveKit(player, this.inventory);
|
||||
AbstractAnvilGUI gui = new AbstractAnvilGUI(player, event -> {
|
||||
String msg = event.getName();
|
||||
KitItem item2 = new KitItem(itemStack);
|
||||
item2.setDisplayName(msg);
|
||||
muteSave = true;
|
||||
saveKit(player, this.inventory);
|
||||
AbstractAnvilGUI gui = new AbstractAnvilGUI(player, event -> {
|
||||
String msg = event.getName();
|
||||
KitItem item2 = new KitItem(itemStack);
|
||||
item2.setDisplayName(msg);
|
||||
|
||||
this.toReplace = item2.getMoveableItem();
|
||||
this.toReplace = item2.getMoveableItem();
|
||||
|
||||
this.slot = slot;
|
||||
});
|
||||
this.slot = slot;
|
||||
});
|
||||
|
||||
gui.setOnClose((player1, inventory1) -> init(title, 54));
|
||||
gui.setOnClose((player1, inventory1) -> init(title, 54));
|
||||
|
||||
ItemStack item2 = new ItemStack(Material.NAME_TAG);
|
||||
ItemMeta meta2 = item2.getItemMeta();
|
||||
meta2.setDisplayName("Enter a name");
|
||||
item2.setItemMeta(meta2);
|
||||
ItemStack item2 = new ItemStack(Material.NAME_TAG);
|
||||
ItemMeta meta2 = item2.getItemMeta();
|
||||
meta2.setDisplayName("Enter a name");
|
||||
item2.setItemMeta(meta2);
|
||||
|
||||
gui.setSlot(AbstractAnvilGUI.AnvilSlot.INPUT_LEFT, item2);
|
||||
gui.open();
|
||||
}
|
||||
break;
|
||||
gui.setSlot(AbstractAnvilGUI.AnvilSlot.INPUT_LEFT, item2);
|
||||
gui.open();
|
||||
}
|
||||
break;
|
||||
case DISPLAY_LORE: {
|
||||
muteSave = true;
|
||||
saveKit(player, this.inventory);
|
||||
AbstractAnvilGUI gui = new AbstractAnvilGUI(player, event -> {
|
||||
String msg = event.getName();
|
||||
KitItem item2 = new KitItem(itemStack);
|
||||
item2.setDisplayLore(msg);
|
||||
muteSave = true;
|
||||
saveKit(player, this.inventory);
|
||||
AbstractAnvilGUI gui = new AbstractAnvilGUI(player, event -> {
|
||||
String msg = event.getName();
|
||||
KitItem item2 = new KitItem(itemStack);
|
||||
item2.setDisplayLore(msg);
|
||||
|
||||
this.toReplace = item2.getMoveableItem();
|
||||
this.toReplace = item2.getMoveableItem();
|
||||
|
||||
this.slot = slot;
|
||||
});
|
||||
this.slot = slot;
|
||||
});
|
||||
|
||||
gui.setOnClose((player1, inventory1) -> init(title, 54));
|
||||
gui.setOnClose((player1, inventory1) -> init(title, 54));
|
||||
|
||||
ItemStack item2 = new ItemStack(Material.NAME_TAG);
|
||||
ItemMeta meta2 = item2.getItemMeta();
|
||||
meta2.setDisplayName("Enter lore");
|
||||
item2.setItemMeta(meta2);
|
||||
ItemStack item2 = new ItemStack(Material.NAME_TAG);
|
||||
ItemMeta meta2 = item2.getItemMeta();
|
||||
meta2.setDisplayName("Enter lore");
|
||||
item2.setItemMeta(meta2);
|
||||
|
||||
gui.setSlot(AbstractAnvilGUI.AnvilSlot.INPUT_LEFT, item2);
|
||||
gui.open();
|
||||
}
|
||||
break;
|
||||
gui.setSlot(AbstractAnvilGUI.AnvilSlot.INPUT_LEFT, item2);
|
||||
gui.open();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -419,10 +420,11 @@ public class GUIKitEditor extends AbstractGUI {
|
||||
index2 += 30;
|
||||
}
|
||||
meta2.setLore(lore2);
|
||||
meta2.setDisplayName(plugin.getLocale().getMessage("general.type.money"));
|
||||
meta2.setDisplayName(plugin.getLocale().getMessage("general.type.money").getMessage());
|
||||
parseStack2.setItemMeta(meta2);
|
||||
|
||||
player.sendMessage(Methods.formatText(plugin.getReferences().getPrefix() + "&8Money &5$" + msg + "&8 has been added to your kit."));
|
||||
plugin.getLocale().newMessage("&8Money &5$" + msg + "&8 has been added to your kit.")
|
||||
.sendPrefixedMessage(player);
|
||||
|
||||
this.slot = 0;
|
||||
this.toReplace = parseStack2;
|
||||
@ -455,10 +457,11 @@ public class GUIKitEditor extends AbstractGUI {
|
||||
index += 30;
|
||||
}
|
||||
meta.setLore(lore);
|
||||
meta.setDisplayName(plugin.getLocale().getMessage("general.type.command"));
|
||||
meta.setDisplayName(plugin.getLocale().getMessage("general.type.command").getMessage());
|
||||
parseStack.setItemMeta(meta);
|
||||
|
||||
player.sendMessage(Methods.formatText(plugin.getReferences().getPrefix() + "&8Command &5" + msg + "&8 has been added to your kit."));
|
||||
plugin.getLocale().newMessage("&8Command &5" + msg + "&8 has been added to your kit.")
|
||||
.sendPrefixedMessage(player);
|
||||
|
||||
this.slot = 0;
|
||||
this.toReplace = parseStack;
|
||||
@ -531,7 +534,7 @@ public class GUIKitEditor extends AbstractGUI {
|
||||
player.updateInventory();
|
||||
}
|
||||
|
||||
player.playSound(player.getLocation(), plugin.isServerVersionAtLeast(ServerVersion.V1_9) ? Sound.ENTITY_VILLAGER_YES : Sound.valueOf("VILLAGER_YES"), 1F, 1F);
|
||||
player.playSound(player.getLocation(), plugin.isServerVersionAtLeast(ServerVersion.V1_9) ? Sound.ENTITY_VILLAGER_YES : Sound.valueOf("VILLAGER_YES"), 1F, 1F);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ public class GUIKitSelector extends AbstractGUI {
|
||||
}
|
||||
if (glassless) max -= 18;
|
||||
|
||||
init(plugin.getLocale().getMessage("interface.selector.title"), max);
|
||||
init(plugin.getLocale().getMessage("interface.selector.title").getMessage(), max);
|
||||
|
||||
timer = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
|
||||
if (inventory.getViewers().isEmpty()) return;
|
||||
@ -94,7 +94,8 @@ public class GUIKitSelector extends AbstractGUI {
|
||||
|
||||
ItemStack exit = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.Exit Icon")), 1);
|
||||
ItemMeta exitmeta = exit.getItemMeta();
|
||||
exitmeta.setDisplayName(UltimateKits.getInstance().getLocale().getMessage("interface.button.exit"));
|
||||
exitmeta.setDisplayName(UltimateKits.getInstance().getLocale().getMessage("interface.button.exit")
|
||||
.getMessage());
|
||||
exit.setItemMeta(exitmeta);
|
||||
|
||||
int num = 0;
|
||||
@ -145,7 +146,9 @@ public class GUIKitSelector extends AbstractGUI {
|
||||
|
||||
Kit kit = plugin.getKitManager().getKit(kitItem);
|
||||
|
||||
String title = plugin.getLocale().getMessage("interface.selector.kit", Methods.formatText(kitItem, true));
|
||||
String title = plugin.getLocale().getMessage("interface.selector.kit")
|
||||
.processPlaceholder("kit", Methods.formatText(kitItem, true)).getMessage();
|
||||
|
||||
if (kit.getTitle() != null)
|
||||
title = Methods.formatText(kit.getTitle());
|
||||
|
||||
@ -158,34 +161,36 @@ public class GUIKitSelector extends AbstractGUI {
|
||||
if (kit.getPrice() != 0)
|
||||
lore.add(Methods.formatText("&7This kit costs &a$" + kit.getPrice() + "&7."));
|
||||
else if (kit.getLink() != null)
|
||||
lore.add(plugin.getLocale().getMessage("general.type.link"));
|
||||
lore.add(plugin.getLocale().getMessage("general.type.link").getMessage());
|
||||
|
||||
|
||||
if (!kitsmode) {
|
||||
if (!plugin.getLocale().getMessage("interface.selector.aboutkit").trim().equals("")) {
|
||||
String[] parts = plugin.getLocale().getMessage("interface.selector.aboutkit").split("\\|");
|
||||
if (!plugin.getLocale().getMessage("interface.selector.aboutkit").getMessage().trim().equals("")) {
|
||||
String[] parts = plugin.getLocale().getMessage("interface.selector.aboutkit").getMessage().split("\\|");
|
||||
lore.add("");
|
||||
for (String line : parts)
|
||||
lore.add(Methods.formatText(line));
|
||||
}
|
||||
if (kit.hasPermission(player)) {
|
||||
if (kit.getNextUse(player) == -1) {
|
||||
lore.add(plugin.getLocale().getMessage("event.claim.once"));
|
||||
lore.add(plugin.getLocale().getMessage("event.claim.once").getMessage());
|
||||
} else if (kit.getNextUse(player) > 0) {
|
||||
if (!plugin.getLocale().getMessage("event.claim.wait").trim().equals("")) {
|
||||
lore.add(plugin.getLocale().getMessage("event.claim.wait", Methods.makeReadable(kit.getNextUse(player))));
|
||||
if (!plugin.getLocale().getMessage("event.claim.wait").getMessage().trim().equals("")) {
|
||||
lore.add(plugin.getLocale().getMessage("event.claim.wait")
|
||||
.processPlaceholder("wait", Methods.makeReadable(kit.getNextUse(player)))
|
||||
.getMessage());
|
||||
}
|
||||
} else if (!plugin.getLocale().getMessage("event.claim.ready").trim().equals("")) {
|
||||
lore.add(plugin.getLocale().getMessage("event.claim.ready"));
|
||||
} else if (!plugin.getLocale().getMessage("event.claim.ready").getMessage().trim().equals("")) {
|
||||
lore.add(plugin.getLocale().getMessage("event.claim.ready").getMessage());
|
||||
}
|
||||
} else
|
||||
lore.add(plugin.getLocale().getMessage("event.claim.noaccess"));
|
||||
lore.add(plugin.getLocale().getMessage("event.claim.noaccess").getMessage());
|
||||
lore.add("");
|
||||
lore.add(plugin.getLocale().getMessage("interface.selector.leftpreview"));
|
||||
lore.add(plugin.getLocale().getMessage("interface.selector.leftpreview").getMessage());
|
||||
if (kit.hasPermission(player)) {
|
||||
lore.add(plugin.getLocale().getMessage("interface.selector.rightclaim"));
|
||||
lore.add(plugin.getLocale().getMessage("interface.selector.rightclaim").getMessage());
|
||||
} else if (kit.getPrice() != 0 || kit.getLink() != null) {
|
||||
lore.add(plugin.getLocale().getMessage("interface.selector.rightbuy"));
|
||||
lore.add(plugin.getLocale().getMessage("interface.selector.rightbuy").getMessage());
|
||||
}
|
||||
|
||||
if (player.hasPermission("ultimatekits.admin")) {
|
||||
@ -243,7 +248,8 @@ public class GUIKitSelector extends AbstractGUI {
|
||||
ItemStack info = new ItemStack(Material.BOOK, 1);
|
||||
ItemMeta infometa = info.getItemMeta();
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
String[] parts = plugin.getLocale().getMessage("interface.selector.details", player.getName()).split("\\|");
|
||||
String[] parts = plugin.getLocale().getMessage("interface.selector.details")
|
||||
.processPlaceholder("player", player.getName()).getMessage().split("\\|");
|
||||
boolean hit = false;
|
||||
for (String line : parts) {
|
||||
if (!hit)
|
||||
@ -259,13 +265,13 @@ public class GUIKitSelector extends AbstractGUI {
|
||||
ItemStack skull = Methods.addTexture(head, "http://textures.minecraft.net/texture/1b6f1a25b6bc199946472aedb370522584ff6f4e83221e5946bd2e41b5ca13b");
|
||||
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
|
||||
skull.setDurability((short) 3);
|
||||
skullMeta.setDisplayName(plugin.getLocale().getMessage("interface.button.next"));
|
||||
skullMeta.setDisplayName(plugin.getLocale().getMessage("interface.button.next").getMessage());
|
||||
skull.setItemMeta(skullMeta);
|
||||
|
||||
ItemStack skull2 = Methods.addTexture(head, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
SkullMeta skull2Meta = (SkullMeta) skull2.getItemMeta();
|
||||
skull2.setDurability((short) 3);
|
||||
skull2Meta.setDisplayName(plugin.getLocale().getMessage("interface.button.next"));
|
||||
skull2Meta.setDisplayName(plugin.getLocale().getMessage("interface.button.next").getMessage());
|
||||
skull2.setItemMeta(skull2Meta);
|
||||
|
||||
if (!plugin.getConfig().getBoolean("Interfaces.Do Not Use Glass Borders"))
|
||||
|
@ -52,13 +52,14 @@ public class GUISellingOptions extends AbstractGUI {
|
||||
inventory.setItem(26, Methods.getBackgroundGlass(true));
|
||||
|
||||
createButton(8, Material.valueOf(UltimateKits.getInstance().getConfig().getString("Interfaces.Exit Icon")),
|
||||
UltimateKits.getInstance().getLocale().getMessage("interface.button.exit"));
|
||||
UltimateKits.getInstance().getLocale().getMessage("interface.button.exit").getMessage());
|
||||
|
||||
ItemStack head = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3);
|
||||
ItemStack back = Methods.addTexture(head, "http://textures.minecraft.net/texture/3ebf907494a935e955bfcadab81beafb90fb9be49c7026ba97d798d5f1a23");
|
||||
SkullMeta skull2Meta = (SkullMeta) back.getItemMeta();
|
||||
back.setDurability((short) 3);
|
||||
skull2Meta.setDisplayName(UltimateKits.getInstance().getLocale().getMessage("interface.button.back"));
|
||||
skull2Meta.setDisplayName(UltimateKits.getInstance().getLocale().getMessage("interface.button.back")
|
||||
.getMessage());
|
||||
back.setItemMeta(skull2Meta);
|
||||
|
||||
inventory.setItem(0, back);
|
||||
@ -115,14 +116,17 @@ public class GUISellingOptions extends AbstractGUI {
|
||||
String msg = event.getName();
|
||||
|
||||
if (plugin.getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + Methods.formatText("&8You must have &aVault &8installed to utilize economy.."));
|
||||
plugin.getLocale().newMessage("&8You must have &aVault &8installed to utilize economy..")
|
||||
.sendPrefixedMessage(player);
|
||||
} else if (!Methods.isNumeric(msg)) {
|
||||
player.sendMessage(Methods.formatText("&a" + msg + " &8is not a number. Please do not include a &a$&8."));
|
||||
} else {
|
||||
|
||||
if (kit.getLink() != null) {
|
||||
kit.setLink(null);
|
||||
player.sendMessage(Methods.formatText(plugin.getReferences().getPrefix() + "&8LINK has been removed from this kit. Note you cannot have ECO & LINK set at the same time.."));
|
||||
|
||||
plugin.getLocale().newMessage("&8LINK has been removed from this kit. Note you cannot have ECO & LINK set at the same time..")
|
||||
.sendPrefixedMessage(player);
|
||||
}
|
||||
Double eco = Double.parseDouble(msg);
|
||||
kit.setPrice(eco);
|
||||
@ -148,7 +152,8 @@ public class GUISellingOptions extends AbstractGUI {
|
||||
|
||||
if (kit.getPrice() != 0) {
|
||||
kit.setPrice(0);
|
||||
player.sendMessage(Methods.formatText(plugin.getReferences().getPrefix() + "&8ECO has been removed from this kit. Note you cannot have ECO & LINK set at the same time.."));
|
||||
plugin.getLocale().newMessage("&8ECO has been removed from this kit. Note you cannot have ECO & LINK set at the same time..")
|
||||
.sendPrefixedMessage(player);
|
||||
}
|
||||
kit.setLink(msg);
|
||||
if (plugin.getHologram() != null)
|
||||
|
@ -91,26 +91,35 @@ public abstract class Hologram {
|
||||
break;
|
||||
case "{RIGHT-CLICK}":
|
||||
if (kitType == KitType.CRATE) {
|
||||
lines.add(Methods.formatText(instance.getLocale().getMessage("interface.hologram.crate")));
|
||||
lines.add(Methods.formatText(instance.getLocale().getMessage("interface.hologram.crate")
|
||||
.getMessage()));
|
||||
break;
|
||||
}
|
||||
if (kit.getLink() != null) {
|
||||
lines.add(Methods.formatText(instance.getLocale().getMessage("interface.hologram.buylink")));
|
||||
lines.add(Methods.formatText(instance.getLocale().getMessage("interface.hologram.buylink")
|
||||
.getMessage()));
|
||||
break;
|
||||
}
|
||||
if (kit.getPrice() != 0) {
|
||||
lines.add(Methods.formatText(instance.getLocale().getMessage("interface.hologram.buyeco", kit.getPrice() != 0 ? Methods.formatEconomy(kit.getPrice()) : instance.getLocale().getMessage("general.type.free"))));
|
||||
lines.add(Methods.formatText(instance.getLocale().getMessage("interface.hologram.buyeco")
|
||||
.processPlaceholder("price", kit.getPrice() != 0
|
||||
? Methods.formatEconomy(kit.getPrice())
|
||||
: instance.getLocale().getMessage("general.type.free").getMessage())
|
||||
.getMessage()));
|
||||
}
|
||||
break;
|
||||
case "{LEFT-CLICK}":
|
||||
if (kitType == KitType.CLAIM) {
|
||||
lines.add(Methods.formatText(instance.getLocale().getMessage("interface.hologram.daily")));
|
||||
lines.add(Methods.formatText(instance.getLocale().getMessage("interface.hologram.daily")
|
||||
.getMessage()));
|
||||
break;
|
||||
}
|
||||
if (kit.getLink() == null && kit.getPrice() == 0) {
|
||||
lines.add(Methods.formatText(instance.getLocale().getMessage("interface.hologram.previewonly")));
|
||||
lines.add(Methods.formatText(instance.getLocale().getMessage("interface.hologram.previewonly")
|
||||
.getMessage()));
|
||||
} else {
|
||||
lines.add(Methods.formatText(instance.getLocale().getMessage("interface.hologram.preview")));
|
||||
lines.add(Methods.formatText(instance.getLocale().getMessage("interface.hologram.preview")
|
||||
.getMessage()));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -43,13 +43,15 @@ public class Key {
|
||||
kitName = "Any";
|
||||
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
meta.setDisplayName(plugin.getLocale().getMessage("interface.key.title", kitName));
|
||||
meta.setDisplayName(plugin.getLocale().getMessage("interface.key.title")
|
||||
.processPlaceholder("kit", kitName).getMessage());
|
||||
|
||||
meta.addEnchant(Enchantment.DURABILITY, 1, true);
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(Methods.formatText("&e" + name + " &fKey"));
|
||||
|
||||
String desc1 = plugin.getLocale().getMessage("interface.key.description1", kitName);
|
||||
String desc1 = plugin.getLocale().getMessage("interface.key.description1")
|
||||
.processPlaceholder("kit", kitName).getMessage();
|
||||
|
||||
if (kitName.equals("Any"))
|
||||
desc1 = desc1.replaceAll("\\[.*?\\]", "");
|
||||
@ -58,11 +60,12 @@ public class Key {
|
||||
|
||||
lore.add(Methods.formatText(desc1));
|
||||
if (this.amt == -1)
|
||||
lore.add(plugin.getLocale().getMessage("interface.key.description2"));
|
||||
lore.add(plugin.getLocale().getMessage("interface.key.description2").getMessage());
|
||||
else
|
||||
lore.add(plugin.getLocale().getMessage("interface.key.description3"));
|
||||
lore.add(plugin.getLocale().getMessage("interface.key.description3").getMessage());
|
||||
if (kitAmount > 1)
|
||||
lore.add(plugin.getLocale().getMessage("interface.key.description4", this.kitAmount));
|
||||
lore.add(plugin.getLocale().getMessage("interface.key.description4")
|
||||
.processPlaceholder("amt", this.kitAmount).getMessage());
|
||||
meta.setLore(lore);
|
||||
|
||||
is.setItemMeta(meta);
|
||||
|
@ -65,19 +65,21 @@ public class Kit {
|
||||
}
|
||||
|
||||
if (!player.hasPermission("ultimatekits.buy." + name)) {
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + UltimateKits.getInstance().getLocale().getMessage("command.general.noperms"));
|
||||
UltimateKits.getInstance().getLocale().getMessage("command.general.noperms")
|
||||
.sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (link != null) {
|
||||
player.sendMessage("");
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + Methods.formatText("&a" + link));
|
||||
plugin.getLocale().newMessage("&a" + link).sendPrefixedMessage(player);
|
||||
player.sendMessage("");
|
||||
player.closeInventory();
|
||||
} else if (price != 0) {
|
||||
new GUIConfirmBuy(plugin, player, this);
|
||||
} else {
|
||||
player.sendMessage(UltimateKits.getInstance().getLocale().getMessage("command.general.noperms"));
|
||||
UltimateKits.getInstance().getLocale().getMessage("command.general.noperms")
|
||||
.sendPrefixedMessage(player);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
@ -114,9 +116,11 @@ public class Kit {
|
||||
}
|
||||
Key key = plugin.getKeyManager().getKey(ChatColor.stripColor(item.getItemMeta().getLore().get(0)).replace(" Key", ""));
|
||||
|
||||
if (!item.getItemMeta().getDisplayName().equals(plugin.getLocale().getMessage("interface.key.title", showableName))
|
||||
&& !item.getItemMeta().getDisplayName().equals(plugin.getLocale().getMessage("interface.key.title", "Any"))) {
|
||||
player.sendMessage(Methods.formatText(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.crate.wrongkey")));
|
||||
if (!item.getItemMeta().getDisplayName().equals(plugin.getLocale().getMessage("interface.key.title")
|
||||
.processPlaceholder("kit", showableName).getMessage())
|
||||
&& !item.getItemMeta().getDisplayName().equals(plugin.getLocale().getMessage("interface.key.title")
|
||||
.processPlaceholder("kit", "Any").getMessage())) {
|
||||
plugin.getLocale().getMessage("event.crate.wrongkey").sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
boolean worked = false;
|
||||
@ -125,7 +129,8 @@ public class Kit {
|
||||
worked = true;
|
||||
}
|
||||
if (worked) {
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.key.success", showableName));
|
||||
plugin.getLocale().getMessage("event.key.success")
|
||||
.processPlaceholder("kit", showableName).sendPrefixedMessage(player);
|
||||
if (player.getInventory().getItemInHand().getAmount() != 1) {
|
||||
ItemStack is = item;
|
||||
is.setAmount(is.getAmount() - 1);
|
||||
@ -140,18 +145,21 @@ public class Kit {
|
||||
if (plugin.getEconomy() == null) return;
|
||||
|
||||
if (!hasPermission(player)) {
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + Methods.formatText(plugin.getLocale()
|
||||
.getMessage(plugin.getLocale().getMessage("command.general.noperms"))));
|
||||
UltimateKits.getInstance().getLocale().getMessage("command.general.noperms")
|
||||
.sendPrefixedMessage(player);
|
||||
return;
|
||||
} else if (!plugin.getEconomy().hasBalance(player, price)) {
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + Methods.formatText(plugin.getLocale().getMessage("event.claim.cannotafford", showableName)));
|
||||
plugin.getLocale().getMessage("event.claim.cannotafford")
|
||||
.processPlaceholder("kit", showableName).sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
if (this.delay > 0) {
|
||||
if (getNextUse(player) == -1) {
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + Methods.formatText(plugin.getLocale().getMessage("event.claim.nottwice")));
|
||||
plugin.getLocale().getMessage("event.claim.nottwice").sendPrefixedMessage(player);
|
||||
} else if (getNextUse(player) != 0) {
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.claim.delay", Methods.makeReadable(getNextUse(player))));
|
||||
plugin.getLocale().getMessage("event.claim.delay")
|
||||
.processPlaceholder("time", Methods.makeReadable(this.getNextUse(player)))
|
||||
.sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -161,20 +169,24 @@ public class Kit {
|
||||
updateDelay(player); //updates delay on buy
|
||||
}
|
||||
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.claim.purchasesuccess", showableName));
|
||||
plugin.getLocale().getMessage("event.claim.purchasesuccess")
|
||||
.processPlaceholder("kit", showableName).sendPrefixedMessage(player);
|
||||
}
|
||||
|
||||
public void processGenericUse(Player player, boolean forced) {
|
||||
if (getNextUse(player) == -1 && !forced) {
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.claim.nottwice"));
|
||||
plugin.getLocale().getMessage("event.claim.nottwice").sendPrefixedMessage(player);
|
||||
} else if (getNextUse(player) <= 0 || forced) {
|
||||
if (giveKit(player)) {
|
||||
updateDelay(player);
|
||||
if (kitAnimation == KitAnimation.NONE)
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.claim.givesuccess", showableName));
|
||||
plugin.getLocale().getMessage("event.claim.givesuccess")
|
||||
.processPlaceholder("kit", showableName).sendPrefixedMessage(player);
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.claim.delay", Methods.makeReadable(getNextUse(player))));
|
||||
plugin.getLocale().getMessage("event.claim.delay")
|
||||
.processPlaceholder("time", Methods.makeReadable(getNextUse(player)))
|
||||
.sendPrefixedMessage(player);
|
||||
}
|
||||
}
|
||||
|
||||
@ -185,15 +197,17 @@ public class Kit {
|
||||
&& !player.hasPermission("previewkit." + name)
|
||||
&& !player.hasPermission("ultimatekits.use")
|
||||
&& !player.hasPermission("ultimatekits." + name)) {
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + UltimateKits.getInstance().getLocale().getMessage("command.general.noperms"));
|
||||
UltimateKits.getInstance().getLocale().getMessage("command.general.noperms")
|
||||
.sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
if (name == null) {
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("command.kit.kitdoesntexist"));
|
||||
plugin.getLocale().getMessage("command.kit.kitdoesntexist").sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.preview.kit", showableName));
|
||||
plugin.getLocale().getMessage("event.preview.kit")
|
||||
.processPlaceholder("kit", showableName).sendPrefixedMessage(player);
|
||||
new GUIDisplayKit(plugin, back, player, this);
|
||||
} catch (Exception ex) {
|
||||
Debugger.runReport(ex);
|
||||
@ -274,7 +288,7 @@ public class Kit {
|
||||
private boolean giveKit(Player player, Key key) {
|
||||
try {
|
||||
if (plugin.getConfig().getBoolean("Main.Prevent The Redeeming of a Kit When Inventory Is Full") && !hasRoom(player)) {
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.claim.full"));
|
||||
plugin.getLocale().getMessage("event.claim.full").sendPrefixedMessage(player);
|
||||
return false;
|
||||
}
|
||||
if (plugin.getConfig().getBoolean("Main.Sounds Enabled")
|
||||
@ -297,7 +311,9 @@ public class Kit {
|
||||
if (item.getContent() instanceof KitContentEconomy) {
|
||||
try {
|
||||
Methods.pay(player, ((KitContentEconomy) item.getContent()).getAmount());
|
||||
player.sendMessage(plugin.getLocale().getMessage("event.claim.eco", Methods.formatEconomy(((KitContentEconomy) item.getContent()).getAmount())));
|
||||
plugin.getLocale().getMessage("event.claim.eco")
|
||||
.processPlaceholder("amt", Methods.formatEconomy(((KitContentEconomy) item.getContent()).getAmount()))
|
||||
.sendPrefixedMessage(player);
|
||||
} catch (NumberFormatException ex) {
|
||||
Debugger.runReport(ex);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class KitContentCommand implements KitContent {
|
||||
index += 30;
|
||||
}
|
||||
meta.setLore(lore);
|
||||
meta.setDisplayName(UltimateKits.getInstance().getLocale().getMessage("general.type.command"));
|
||||
meta.setDisplayName(UltimateKits.getInstance().getLocale().getMessage("general.type.command").getMessage());
|
||||
stack.setItemMeta(meta);
|
||||
return stack;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class KitContentEconomy implements KitContent {
|
||||
index += 30;
|
||||
}
|
||||
meta.setLore(lore);
|
||||
meta.setDisplayName(UltimateKits.getInstance().getLocale().getMessage("general.type.money"));
|
||||
meta.setDisplayName(UltimateKits.getInstance().getLocale().getMessage("general.type.money").getMessage());
|
||||
parseStack.setItemMeta(meta);
|
||||
return parseStack;
|
||||
}
|
||||
|
@ -36,7 +36,8 @@ public class BlockListeners implements Listener {
|
||||
|
||||
instance.getKitManager().removeKitFromLocation(block.getLocation());
|
||||
|
||||
event.getPlayer().sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&8Kit &9" + kit.getName() + " &8unassigned from: &a" + block.getType() + "&8."));
|
||||
instance.getLocale().newMessage("&8Kit &9" + kit.getName() + " &8unassigned from: &a" + block.getType() + "&8.")
|
||||
.sendPrefixedMessage(event.getPlayer());
|
||||
|
||||
} catch (Exception e) {
|
||||
Debugger.runReport(e);
|
||||
|
@ -57,7 +57,7 @@ public class InteractListeners implements Listener {
|
||||
|
||||
if (kitBlockData.getType() != KitType.PREVIEW) {
|
||||
if (!kit.hasPermission(player)) {
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("command.general.noperms"));
|
||||
plugin.getLocale().getMessage("command.general.noperms").sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
if (kit.getNextUse(player) <= 0) {
|
||||
@ -65,8 +65,8 @@ public class InteractListeners implements Listener {
|
||||
kit.updateDelay(player);
|
||||
} else {
|
||||
long time = kit.getNextUse(player);
|
||||
player.sendMessage(Methods.formatText(plugin.getReferences().getPrefix()
|
||||
+ plugin.getLocale().getMessage("event.crate.notyet", Methods.makeReadable(time))));
|
||||
plugin.getLocale().getMessage("event.crate.notyet").processPlaceholder("time",
|
||||
Methods.makeReadable(time)).sendPrefixedMessage(player);
|
||||
}
|
||||
} else if (kit.getLink() != null || kit.getPrice() != 0) {
|
||||
kit.buy(player);
|
||||
|
@ -16,7 +16,6 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.*;
|
||||
@ -114,7 +113,9 @@ public class CrateAnimateTask extends BukkitRunnable {
|
||||
player.getWorld().dropItemNaturally(player.getLocation(), item2);
|
||||
}
|
||||
player.playSound(player.getLocation(), UltimateKits.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? Sound.ENTITY_PLAYER_LEVELUP : Sound.valueOf("LEVEL_UP"), 10f, 10f);
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.create.won", WordUtils.capitalize(give.getType().name().toLowerCase().replace("_", " "))));
|
||||
plugin.getLocale().getMessage("event.create.won")
|
||||
.processPlaceholder("item", WordUtils.capitalize(give.getType().name().toLowerCase().replace("_", " ")))
|
||||
.sendPrefixedMessage(player);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, this::finish, 50);
|
||||
}
|
||||
done = true;
|
||||
@ -128,7 +129,7 @@ public class CrateAnimateTask extends BukkitRunnable {
|
||||
private void finish() {
|
||||
instance.cancel();
|
||||
HandlerList.unregisterAll(listener);
|
||||
listener = null;
|
||||
player.closeInventory();
|
||||
listener = null;
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
302
src/main/java/com/songoda/ultimatekits/utils/locale/Locale.java
Normal file
302
src/main/java/com/songoda/ultimatekits/utils/locale/Locale.java
Normal file
@ -0,0 +1,302 @@
|
||||
package com.songoda.ultimatekits.utils.locale;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.*;
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
115
src/main/java/com/songoda/ultimatekits/utils/locale/Message.java
Normal file
115
src/main/java/com/songoda/ultimatekits/utils/locale/Message.java
Normal file
@ -0,0 +1,115 @@
|
||||
package com.songoda.ultimatekits.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;
|
||||
}
|
||||
}
|
@ -22,7 +22,7 @@ public class LocaleModule implements Module {
|
||||
|
||||
if (file.get("type").equals("locale")) {
|
||||
InputStream in = new URL((String) file.get("link")).openStream();
|
||||
UltimateKits.getInstance().getLocale().saveDefaultLocale(in, (String) file.get("name"));
|
||||
UltimateKits.getInstance().getLocale().saveLocale(in, (String) file.get("name"));
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
@ -32,6 +32,7 @@ interface.preview.title = "&9Previewing kit: &8%kit%"
|
||||
interface.yesno.title = "&9Buy for &a$%price%&9?"
|
||||
interface.yesno.yes = "&a&lYes"
|
||||
interface.yesno.no = "&c&lNo"
|
||||
interface.yesno.no = "&c&lNo"
|
||||
interface.key.title = "&5%kit% &fKit Key"
|
||||
interface.key.description1 = "&rRight-Click on [a ]&c&l%kit%&r kit"
|
||||
interface.key.description2 = "&rand receive its contents!"
|
||||
|
Loading…
Reference in New Issue
Block a user