diff --git a/config.yml b/config.yml index df4a261..dfe7ac6 100644 --- a/config.yml +++ b/config.yml @@ -1,16 +1,16 @@ # Do not touch this, if you are not asked to # If you get an error about your config not being up-to-date, then # go to the EnchantGUI bukkit page for instructions. -version: 1.3.2 +version: 1.1 # This plugin is gathering some basic info about how many players/servers is using it. # All data is collected anonymously and will not harm your server in any way. # If you wish to opt-out of this service, though, just change this setting to true. opt-out: false -# If set to true, the enchant icons will be shown as the item they can enchant. -# If set to false, the enchant icons will all be enchanted books. -show-enchants-as-items: true +# The name in the /eshop menu. +# Max 32 characters! +menu-name: EnchantGUI # Payment currency can be one of two. Either 'money' for regular money (using Vault+Economy system) # or 'xp' for experience points. diff --git a/plugin.yml b/plugin.yml index 6c4b737..47521eb 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,5 +1,5 @@ name: EnchantGUI -version: 1.0 +version: 1.1 main: me.tychsen.enchantgui.Main author: Dentych diff --git a/src/me/tychsen/enchantgui/EshopConfig.java b/src/me/tychsen/enchantgui/EshopConfig.java index 000b7c0..1300344 100644 --- a/src/me/tychsen/enchantgui/EshopConfig.java +++ b/src/me/tychsen/enchantgui/EshopConfig.java @@ -1,25 +1,50 @@ package me.tychsen.enchantgui; +import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfigurationOptions; import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; public class EshopConfig { + private static EshopConfig instance; private JavaPlugin plugin; private FileConfiguration config; public EshopConfig() { + instance = this; this.plugin = Main.getInstance(); config = plugin.getConfig(); } public int getPrice(Enchantment ench, int level) { - return config.getInt(ench.getName().toLowerCase() + ".level" + level); + String path = ench.getName().toLowerCase() + ".level" + level; + return config.getInt(path); } - public void reloadConfig() { - plugin.reloadConfig(); - config = plugin.getConfig(); + public String getMenuName() { + String path = "menu-name"; + if (config.contains(path) && config.isSet(path) && config.isString(path)) { + if (config.getString(path).length() > 32) { + return config.getString(path).substring(0, 32); + } else { + return config.getString(path); + } + } else { + return "EnchantGUI"; + } + } + + public void reloadConfig(CommandSender sender) { + if (sender.isOp() || sender.hasPermission("eshop.admin")) { + plugin.reloadConfig(); + config = plugin.getConfig(); + sender.sendMessage(EshopSystem.start + "Configuration file has been reloaded!"); + } + } + + public static EshopConfig getInstance() { + return instance; } } diff --git a/src/me/tychsen/enchantgui/EshopEventManager.java b/src/me/tychsen/enchantgui/EshopEventManager.java index bd80546..30a41bd 100644 --- a/src/me/tychsen/enchantgui/EshopEventManager.java +++ b/src/me/tychsen/enchantgui/EshopEventManager.java @@ -61,11 +61,6 @@ public boolean handleCommand(CommandSender sender, Command cmd) { return true; } - public void handleReload(CommandSender sender) { - esys.reloadConfig(); - sender.sendMessage(esys.start + "Configuration file has been reloaded!"); - } - /* Private methods */ /** diff --git a/src/me/tychsen/enchantgui/EshopSystem.java b/src/me/tychsen/enchantgui/EshopSystem.java index 5bdb715..33ca05f 100644 --- a/src/me/tychsen/enchantgui/EshopSystem.java +++ b/src/me/tychsen/enchantgui/EshopSystem.java @@ -35,7 +35,7 @@ public EshopSystem() { public void showMainMenu(Player p) { playerNavigation.put(p.getName(), 0); - Inventory inv = p.getServer().createInventory(p, inventorySize, "EnchantGUI"); + Inventory inv = p.getServer().createInventory(p, inventorySize, config.getMenuName()); generateMainMenu(p, inv); p.openInventory(inv); } @@ -84,10 +84,6 @@ public void purchaseEnchant(Player p, ItemStack item, int level) { } } - public void reloadConfig() { - config.reloadConfig(); - } - private void generateMainMenu(Player p, Inventory inv) { List enchList = enchants.getEnchantList(); List itemlist = new ArrayList<>(); diff --git a/src/me/tychsen/enchantgui/Main.java b/src/me/tychsen/enchantgui/Main.java index 5f642fa..13f1900 100644 --- a/src/me/tychsen/enchantgui/Main.java +++ b/src/me/tychsen/enchantgui/Main.java @@ -53,7 +53,7 @@ public void onInventoryClickEvent(InventoryClickEvent e) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (command.getName().equalsIgnoreCase("eshop")) { if (args.length > 0 && args[0].equalsIgnoreCase("reload")) { - eshop.handleReload(sender); + EshopConfig.getInstance().reloadConfig(sender); } else { eshop.handleCommand(sender, command); }