diff --git a/src/main/java/org/maxgamer/quickshop/Economy/Economy_Vault.java b/src/main/java/org/maxgamer/quickshop/Economy/Economy_Vault.java index 16d91c982..9ac00aa57 100644 --- a/src/main/java/org/maxgamer/quickshop/Economy/Economy_Vault.java +++ b/src/main/java/org/maxgamer/quickshop/Economy/Economy_Vault.java @@ -4,7 +4,6 @@ import java.util.UUID; import net.milkbowl.vault.economy.Economy; -import org.apache.logging.log4j.core.config.plugins.Plugin; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.plugin.RegisteredServiceProvider; diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index 44c36a35b..35414ff28 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -11,15 +11,12 @@ import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; -import java.util.List; -import java.util.Map; import java.util.Map.Entry; import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.OfflinePlayer; import org.bukkit.World; import org.bukkit.configuration.ConfigurationSection; @@ -132,7 +129,6 @@ public class QuickShop extends JavaPlugin { getLogger().info("Original author:Netherfoam, Timtower, KaiNoMood"); getLogger().info("Let's us start load plugin"); //NMS.init(); - instance = this; saveDefaultConfig(); // Creates the config folder and copies config.yml // (If one doesn't exist) as required. @@ -275,6 +271,8 @@ public class QuickShop extends JavaPlugin { PreparedStatement ps = con.prepareStatement("SELECT * FROM shops"); ResultSet rs = ps.executeQuery(); int errors = 0; + MsgUtil.loadItemi18n(); + MsgUtil.loadEnchi18n(); while (rs.next()) { int x = 0; int y = 0; @@ -346,9 +344,7 @@ public class QuickShop extends JavaPlugin { } getLogger().info("Loaded " + count + " shops."); - MsgUtil.loadTransactionMessages(); - MsgUtil.loadItemi18n(); - MsgUtil.clean(); + // Register events getLogger().info("Registering Listeners"); blockListener = new BlockListener(this); @@ -400,6 +396,8 @@ public class QuickShop extends JavaPlugin { // added for compatibility reasons with OpenInv - see https://github.com/KaiKikuchi/QuickShop/issues/139 this.openInvPlugin = Bukkit.getPluginManager().getPlugin("OpenInv"); + MsgUtil.loadTransactionMessages(); + MsgUtil.clean(); getLogger().info("QuickShop loaded!"); } diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java b/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java index 56166389c..382004410 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java @@ -29,8 +29,6 @@ import org.maxgamer.quickshop.Util.MsgUtil; import org.maxgamer.quickshop.Util.Permissions; import org.maxgamer.quickshop.Util.Util; -import com.sk89q.worldguard.protection.FlagValueCalculator.Result; - public class ShopManager { private QuickShop plugin; private HashMap actions = new HashMap(); diff --git a/src/main/java/org/maxgamer/quickshop/Util/MsgUtil.java b/src/main/java/org/maxgamer/quickshop/Util/MsgUtil.java index 7e730908b..12436e5ca 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/MsgUtil.java +++ b/src/main/java/org/maxgamer/quickshop/Util/MsgUtil.java @@ -12,6 +12,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.logging.Level; import java.util.UUID; + import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -25,14 +26,11 @@ import org.maxgamer.quickshop.QuickShop; import org.maxgamer.quickshop.Shop.Shop; public class MsgUtil { - private static QuickShop plugin; + static QuickShop plugin = QuickShop.instance; private static YamlConfiguration messages; private static YamlConfiguration itemi18n; + private static YamlConfiguration enchi18n; private static HashMap> player_messages = new HashMap>(); - static { - plugin = QuickShop.instance; - } - /** * Loads all the messages from messages.yml */ @@ -76,7 +74,6 @@ public class MsgUtil { } } public static void loadItemi18n() { - plugin.getLogger().info("Starting loading itemname i18n..."); File itemi18nFile = new File(plugin.getDataFolder(), "itemi18n.yml"); if (!itemi18nFile.exists()) { plugin.getLogger().info("Creating itemi18n.yml"); @@ -87,7 +84,7 @@ public class MsgUtil { itemi18n.options().copyDefaults(true); YamlConfiguration itemi18nYAML = YamlConfiguration.loadConfiguration(new InputStreamReader(plugin.getResource("itemi18n.yml"))); itemi18n.setDefaults(itemi18nYAML); - Util.parseColours(messages); + Util.parseColours(itemi18n); Material[] itemsi18n = Material.values(); for (Material material : itemsi18n) { String itemname = itemi18n.getString("itemi18n."+material.name()); @@ -128,7 +125,60 @@ public class MsgUtil { return Itemname_i18n; } } - + public static void loadEnchi18n() { + plugin.getLogger().info("Starting loading Enchantment i18n..."); + File enchi18nFile = new File(plugin.getDataFolder(), "enchi18n.yml"); + if (!enchi18nFile.exists()) { + plugin.getLogger().info("Creating enchi18n.yml"); + plugin.saveResource("enchi18n.yml", true); + } + // Store it + YamlConfiguration enchi18n = YamlConfiguration.loadConfiguration(enchi18nFile); + enchi18n.options().copyDefaults(true); + YamlConfiguration enchi18nYAML = YamlConfiguration.loadConfiguration(new InputStreamReader(plugin.getResource("enchi18n.yml"))); + itemi18n.setDefaults(enchi18nYAML); + Util.parseColours(enchi18n); + Enchantment[] enchsi18n = Enchantment.values(); + for (Enchantment ench : enchsi18n) { + String enchname = enchi18n.getString("enchi18n."+ench.getKey().toString()); + if(enchname==null || enchname.equals("")) { + plugin.getLogger().info("Found new ench ["+ench.getKey().toString()+"] ,add it in config..."); + enchi18n.set("enchi18n."+ench.getKey().toString(), ench.getKey().toString()); + } + } + try { + enchi18n.save(enchi18nFile); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + plugin.getLogger().log(Level.WARNING, "Could not load/save transaction enchname from itemi18n.yml. Skipping."); + } + plugin.getLogger().info("Complete to load Itemname i18n."); + } + public static String getEnchi18n(Enchantment EnchBukkitName) { + Enchantment finalEnch = null; + for (Enchantment ench : Enchantment.values()) { + if(ench instanceof Enchantment) { + finalEnch = ench; + break; + } + } + if(finalEnch==null) { + return "ERROR"; + } + String finalEnchString = finalEnch.getKey().toString(); + String finalEnch_i18n = null; + try { + finalEnch_i18n = enchi18n.getString("enchi18n."+finalEnchString).trim().replaceAll(" ", "_"); + }catch (Exception e) { + finalEnch_i18n = null; + } + if(finalEnch_i18n==null) { + return finalEnch.getKey().toString(); + }else { + return finalEnch_i18n; + } + } /** * @param player * The name of the player to message @@ -220,7 +270,7 @@ public class MsgUtil { if (enchs != null && !enchs.isEmpty()) { p.sendMessage(ChatColor.DARK_PURPLE + "+--------------------" + MsgUtil.getMessage("menu.enchants") + "-----------------------+"); for (Entry entries : enchs.entrySet()) { - p.sendMessage(ChatColor.DARK_PURPLE + "| " + ChatColor.YELLOW + entries.getKey() + " " + entries.getValue()); + p.sendMessage(ChatColor.DARK_PURPLE + "| " + ChatColor.YELLOW + MsgUtil.getEnchi18n(entries.getKey()) + " " + entries.getValue()); } } try { @@ -232,7 +282,7 @@ public class MsgUtil { if (enchs != null && !enchs.isEmpty()) { p.sendMessage(ChatColor.DARK_PURPLE + "+-----------------" + MsgUtil.getMessage("menu.stored-enchants") + "--------------------+"); for (Entry entries : enchs.entrySet()) { - p.sendMessage(ChatColor.DARK_PURPLE + "| " + ChatColor.YELLOW + entries.getKey() + " " + entries.getValue()); + p.sendMessage(ChatColor.DARK_PURPLE + "| " + ChatColor.YELLOW + MsgUtil.getEnchi18n(entries.getKey()) + " " + entries.getValue()); } } } @@ -251,14 +301,14 @@ public class MsgUtil { if (enchs != null && !enchs.isEmpty()) { p.sendMessage(ChatColor.DARK_PURPLE + "+--------------------" + MsgUtil.getMessage("menu.enchants") + "-----------------------+"); for (Entry entries : enchs.entrySet()) { - p.sendMessage(ChatColor.DARK_PURPLE + "| " + ChatColor.YELLOW + entries.getKey() + " " + entries.getValue()); + p.sendMessage(ChatColor.DARK_PURPLE + "| " + ChatColor.YELLOW +MsgUtil.getEnchi18n(entries.getKey()) + " " + entries.getValue()); } } enchs = shop.getItem().getItemMeta().getEnchants(); if (enchs != null && !enchs.isEmpty()) { p.sendMessage(ChatColor.DARK_PURPLE + "+-----------------" + MsgUtil.getMessage("menu.stored-enchants") + "--------------------+"); for (Entry entries : enchs.entrySet()) { - p.sendMessage(ChatColor.DARK_PURPLE + "| " + ChatColor.YELLOW + entries.getKey() + " " + entries.getValue()); + p.sendMessage(ChatColor.DARK_PURPLE + "| " + ChatColor.YELLOW + MsgUtil.getEnchi18n(entries.getKey()) + " " + entries.getValue()); } } try { @@ -270,7 +320,7 @@ public class MsgUtil { if (enchs != null && !enchs.isEmpty()) { p.sendMessage(ChatColor.DARK_PURPLE + "+-----------------" + MsgUtil.getMessage("menu.stored-enchants") + "--------------------+"); for (Entry entries : enchs.entrySet()) { - p.sendMessage(ChatColor.DARK_PURPLE + "| " + ChatColor.YELLOW + entries.getKey() + " " + entries.getValue()); + p.sendMessage(ChatColor.DARK_PURPLE + "| " + ChatColor.YELLOW + MsgUtil.getEnchi18n(entries.getKey())+ " " + entries.getValue()); } } } @@ -300,7 +350,7 @@ public class MsgUtil { if (enchs != null && !enchs.isEmpty()) { p.sendMessage(ChatColor.DARK_PURPLE + "+--------------------" + MsgUtil.getMessage("menu.enchants") + "-----------------------+"); for (Entry entries : enchs.entrySet()) { - p.sendMessage(ChatColor.DARK_PURPLE + "| " + ChatColor.YELLOW + entries.getKey() + " " + entries.getValue()); + p.sendMessage(ChatColor.DARK_PURPLE + "| " + ChatColor.YELLOW + MsgUtil.getEnchi18n(entries.getKey()) + " " + entries.getValue()); } } try { @@ -312,7 +362,7 @@ public class MsgUtil { if (enchs != null && !enchs.isEmpty()) { p.sendMessage(ChatColor.DARK_PURPLE + "+--------------------" + MsgUtil.getMessage("menu.stored-enchants") + "-----------------------+"); for (Entry entries : enchs.entrySet()) { - p.sendMessage(ChatColor.DARK_PURPLE + "| " + ChatColor.YELLOW + entries.getKey() + " " + entries.getValue()); + p.sendMessage(ChatColor.DARK_PURPLE + "| " + ChatColor.YELLOW + MsgUtil.getEnchi18n(entries.getKey()) + " " + entries.getValue()); } } } diff --git a/src/main/resources/enchi18n.yml b/src/main/resources/enchi18n.yml new file mode 100644 index 000000000..e69de29bb