diff --git a/build.gradle b/build.gradle index 777d134..f7a5064 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group = 'me.tychsen' -version = '1.5.9' +version = '1.5.10' sourceCompatibility = 1.8 targetCompatibility = 1.8 diff --git a/src/main/java/me/tychsen/enchantgui/Main.java b/src/main/java/me/tychsen/enchantgui/Main.java index 043ab73..f3a31bb 100644 --- a/src/main/java/me/tychsen/enchantgui/Main.java +++ b/src/main/java/me/tychsen/enchantgui/Main.java @@ -1,5 +1,6 @@ package me.tychsen.enchantgui; +import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; import me.tychsen.enchantgui.commands.ShopCommand; @@ -14,16 +15,23 @@ import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + public class Main extends JavaPlugin implements Listener { - @Setter + @Setter (AccessLevel.PRIVATE) @Getter private static Main instance; + @Setter (AccessLevel.PRIVATE) @Getter - @Setter private static Economy economy = null; @Getter @Setter private static MenuSystem menuSystem; + @Getter + @Setter (AccessLevel.PRIVATE) + private static Set toggleRightClickPlayers = new HashSet<>(); @Override @@ -45,7 +53,8 @@ public void onEnable() { Common.registerCommand(new ShopCommand()); // Enable Metrics - Metrics metrics = new Metrics(this); + if(!getConfig().getBoolean("opt-out")) + new Metrics(this); getLogger().info(getName() + " " + getDescription().getVersion() + " enabled!"); } @@ -55,6 +64,7 @@ public void onDisable() { setInstance(null); setEconomy(null); setMenuSystem(null); + setToggleRightClickPlayers(null); getLogger().info(getName() + " " + getDescription().getVersion() + " disabled!"); } @@ -63,7 +73,7 @@ public static String getMinecraftVersion(){ } public static void debug(String msg) { - if (EShopConfig.getInstance().getDebug()) + if (EShopConfig.getDebug()) Main.getInstance().getLogger().warning(String.format("DEBUG %s", msg)); } @@ -81,4 +91,6 @@ private boolean setupEconomy() { return economy != null; } + + } \ No newline at end of file diff --git a/src/main/java/me/tychsen/enchantgui/commands/PlayerCommand.java b/src/main/java/me/tychsen/enchantgui/commands/PlayerCommand.java index 0ccc399..08f0d15 100644 --- a/src/main/java/me/tychsen/enchantgui/commands/PlayerCommand.java +++ b/src/main/java/me/tychsen/enchantgui/commands/PlayerCommand.java @@ -50,7 +50,7 @@ protected void returnTell(String message) { } protected void tell(String message) { - Common.tell(player, (prefix != null ? "&8[&7" + prefix + "&8] " : "") + "&7" + message); + Common.tell(player, (prefix != null ? prefix + " " : "") + message); } @RequiredArgsConstructor diff --git a/src/main/java/me/tychsen/enchantgui/commands/ShopCommand.java b/src/main/java/me/tychsen/enchantgui/commands/ShopCommand.java index d4d16c8..bae1f76 100644 --- a/src/main/java/me/tychsen/enchantgui/commands/ShopCommand.java +++ b/src/main/java/me/tychsen/enchantgui/commands/ShopCommand.java @@ -22,6 +22,7 @@ public ShopCommand() { setDescription("Command for the EnchantGUI plugin."); setUsage("/eshop"); setPermission("eshop.use"); + setPrefix(LocalizationManager.getInstance().getString("prefix")); menuSystem = Main.getMenuSystem(); } @@ -30,14 +31,37 @@ protected void run(final Player player, final String[] args) { if(args.length > 1){ returnTell("&cToo many arguments."); } + LocalizationManager lm = LocalizationManager.getInstance(); if(args.length > 0 && args[0].equalsIgnoreCase("reload")){ - EShopConfig.getInstance().reloadConfig(player); + if(!player.hasPermission("eshop.reload")) { + tell(lm.getString("no-permission")); + return; + } + + EShopConfig.reloadConfig(player); LocalizationManager.getInstance().reload(player); EShopShop.getInstance().reload(player); return; } + if(args.length > 0 && args[0].equalsIgnoreCase("toggle")){ + if(!player.hasPermission("eshop.enchantingtable.toggle")) { + tell(lm.getString("no-permission")); + return; + } + + if(Main.getToggleRightClickPlayers().contains(player.getUniqueId())){ + Main.getToggleRightClickPlayers().remove(player.getUniqueId()); + tell(lm.getString("toggle-on")); + } + else { + Main.getToggleRightClickPlayers().add(player.getUniqueId()); + tell(lm.getString("toggle-off")); + } + return; + } + menuSystem.showMainMenu(player); } diff --git a/src/main/java/me/tychsen/enchantgui/config/AConfig.java b/src/main/java/me/tychsen/enchantgui/config/AConfig.java new file mode 100644 index 0000000..683b6da --- /dev/null +++ b/src/main/java/me/tychsen/enchantgui/config/AConfig.java @@ -0,0 +1,83 @@ +package me.tychsen.enchantgui.config; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.StandardCharsets; + +/** + * @author sarhatabaot + */ +public abstract class AConfig { + @Setter + @Getter (AccessLevel.PROTECTED) + private String fileName; + private File configFile; + private JavaPlugin plugin; + private FileConfiguration config; + + /** + * + * @param fileName file name including the type. + * @param plugin plugin instance. + */ + public AConfig(final String fileName, final JavaPlugin plugin) { + this.fileName = fileName; + this.plugin = plugin; + } + + /** + * Reloads the file + */ + protected void reloadConfig(){ + if (configFile == null) { + configFile = new File(plugin.getDataFolder(), getFileName()); + } + config = YamlConfiguration.loadConfiguration(configFile); + + // Look for defaults in the jar + Reader defaultConfigStream; + InputStream defaultConfigInputStream = plugin.getResource(getFileName()); + if (defaultConfigInputStream != null) { + defaultConfigStream = new InputStreamReader(defaultConfigInputStream, StandardCharsets.UTF_8); + YamlConfiguration defaultConfig = YamlConfiguration.loadConfiguration(defaultConfigStream); + config.setDefaults(defaultConfig); + } + + plugin.getLogger().info(getFileName()+" reloaded."); + } + + /** + * Saves the default configuration from the jar. + */ + protected void saveDefaultConfiguration(){ + if (configFile == null) { + configFile = new File(plugin.getDataFolder(), getFileName()); + } + if (!configFile.exists()) { + plugin.saveResource(getFileName(), false); + } + } + + /** + * @return FileConfiguration config. + */ + protected FileConfiguration getConfig() { + if (config == null) { + reloadConfig(); + } + return config; + } + + public abstract String getString(String path); + + +} diff --git a/src/main/java/me/tychsen/enchantgui/config/EShopConfig.java b/src/main/java/me/tychsen/enchantgui/config/EShopConfig.java index 85e26f9..40f7e95 100644 --- a/src/main/java/me/tychsen/enchantgui/config/EShopConfig.java +++ b/src/main/java/me/tychsen/enchantgui/config/EShopConfig.java @@ -9,19 +9,24 @@ import me.tychsen.enchantgui.localization.LocalizationManager; import me.tychsen.enchantgui.menu.DefaultMenuSystem; import me.tychsen.enchantgui.Main; +import me.tychsen.enchantgui.util.Common; import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.enchantments.Enchantment; import java.util.Map; +/** + * TODO: make this a static accessor class. + */ public class EShopConfig { @Setter @Getter private static EShopConfig instance; @Setter private static FileConfiguration config; - private PaymentStrategy economy; + @Setter + private static PaymentStrategy economy; public EShopConfig() { setInstance(this); @@ -63,19 +68,19 @@ public static boolean getShowPerItem(){ return config.getBoolean("show-per-item"); } - public void reloadConfig(CommandSender sender) { + public static void reloadConfig(CommandSender sender) { LocalizationManager lm = LocalizationManager.getInstance(); if (sender.isOp() || sender.hasPermission("eshop.admin")) { Main.getInstance().reloadConfig(); setConfig(Main.getInstance().getConfig()); economy = null; - sender.sendMessage(DefaultMenuSystem.START + lm.getString("config-reloaded")); + Common.tell(sender,DefaultMenuSystem.PREFIX + lm.getString("config-reloaded")); } else { - sender.sendMessage(DefaultMenuSystem.START + lm.getString("no-permission")); + Common.tell(sender,DefaultMenuSystem.PREFIX + lm.getString("no-permission")); } } - public String[] getEnchantLevels(Enchantment enchantment) { + public static String[] getEnchantLevels(Enchantment enchantment) { String path = enchantment.getKey().toString().toLowerCase(); path = path.split(":")[1]; Main.debug(path); @@ -91,7 +96,7 @@ public String[] getEnchantLevels(Enchantment enchantment) { return enchantLevels; } - public String getEconomyCurrency(){ + public static String getEconomyCurrency(){ switch (config.getString("payment-currency").toLowerCase()) { case "money": return Main.getEconomy().currencyNameSingular(); @@ -106,13 +111,13 @@ public PaymentStrategy getEconomy() { if (economy == null) { switch (config.getString("payment-currency").toLowerCase()) { case "money": - economy = new MoneyPayment(); + setEconomy(new MoneyPayment()); break; case "xp": - economy = new XPPayment(); + setEconomy(new XPPayment()); break; default: - economy = new NullPayment(); + setEconomy(new NullPayment()); break; } } diff --git a/src/main/java/me/tychsen/enchantgui/config/EShopShop.java b/src/main/java/me/tychsen/enchantgui/config/EShopShop.java index 469e19f..83a877b 100644 --- a/src/main/java/me/tychsen/enchantgui/config/EShopShop.java +++ b/src/main/java/me/tychsen/enchantgui/config/EShopShop.java @@ -2,69 +2,27 @@ import me.tychsen.enchantgui.Main; import me.tychsen.enchantgui.localization.LocalizationManager; -import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.plugin.Plugin; - -import java.io.*; -import java.nio.charset.StandardCharsets; /** * @author sarhatabaot */ -public class EShopShop { - private static final String FILE_NAME_SHOP = "shop.yml"; +public class EShopShop extends AConfig{ private static EShopShop instance; - private Plugin plugin; - private File configFile; - private FileConfiguration config; private EShopShop(){ - plugin = Main.getInstance(); + super("shop.yml", Main.getInstance()); saveDefaultConfiguration(); } public void reload(CommandSender sender) { reloadConfig(); - String start = ChatColor.AQUA + LocalizationManager.getInstance().getString("prefix") + " " + ChatColor.WHITE; - sender.sendMessage(start + LocalizationManager.getInstance().getString("shop-reloaded")); - } - - public String getString(String string){ - return getConfig().getString(string); - } - - private void saveDefaultConfiguration(){ - if(configFile == null){ - configFile = new File(plugin.getDataFolder(),FILE_NAME_SHOP); - } - if(!configFile.exists()){ - plugin.saveResource(FILE_NAME_SHOP,false); - } - } - - private void reloadConfig(){ - if(configFile == null){ - configFile = new File(plugin.getDataFolder(),FILE_NAME_SHOP); - } - config = YamlConfiguration.loadConfiguration(configFile); - Reader defaultConfigStream; - InputStream defaultConfigInputStream = plugin.getResource(FILE_NAME_SHOP); - if (defaultConfigInputStream != null) { - defaultConfigStream = new InputStreamReader(defaultConfigInputStream, StandardCharsets.UTF_8); - YamlConfiguration defaultConfig = YamlConfiguration.loadConfiguration(defaultConfigStream); - config.setDefaults(defaultConfig); - } - Main.debug("Config reloaded."); + sender.sendMessage(LocalizationManager.getInstance().getString("prefix") +" "+ LocalizationManager.getInstance().getString("shop-reloaded")); } - - private FileConfiguration getConfig(){ - if(config==null) - reloadConfig(); - return config; + @Override + public String getString(String path){ + return getConfig().getString(path); } public static EShopShop getInstance(){ diff --git a/src/main/java/me/tychsen/enchantgui/event/EventManager.java b/src/main/java/me/tychsen/enchantgui/event/EventManager.java index eb58ce5..d6a351f 100644 --- a/src/main/java/me/tychsen/enchantgui/event/EventManager.java +++ b/src/main/java/me/tychsen/enchantgui/event/EventManager.java @@ -29,7 +29,7 @@ public void onCreativeClickEvent(InventoryCreativeEvent event){ @EventHandler public void onInventoryClickEvent(InventoryClickEvent e) { String inventoryName = e.getView().getTitle().toLowerCase(); - String configInventoryName = EShopConfig.getInstance().getMenuName().toLowerCase(); + String configInventoryName = EShopConfig.getMenuName().toLowerCase(); boolean correctEvent = inventoryName.startsWith(configInventoryName); if (correctEvent) { @@ -46,6 +46,14 @@ public void onInventoryClickEvent(InventoryClickEvent e) { @EventHandler public void onPlayerInteractEvent(PlayerInteractEvent e) { + if (!EShopConfig.getBoolean("right-click-enchanting-table")) { + return; + } + if (Main.getToggleRightClickPlayers().contains(e.getPlayer().getUniqueId())) + return; + if(!e.getPlayer().hasPermission("eshop.enchantingtable")) + return; + if (e.getAction() == Action.RIGHT_CLICK_BLOCK && e.getClickedBlock().getType() == Material.ENCHANTING_TABLE) { e.setCancelled(true); handlePlayerInteractEvent(e); @@ -57,13 +65,16 @@ private void handleInventoryClickEvent(InventoryClickEvent e) { if (e.getCurrentItem().getType() == Material.AIR) return; if (e.getInventory().getType() != InventoryType.CHEST) return; - Player p = (Player) e.getWhoClicked(); system.handleMenuClick(p, e); } private void handlePlayerInteractEvent(PlayerInteractEvent e) { - if (EShopConfig.getBoolean("right-click-enchanting-table") && e.getPlayer().hasPermission("eshop.enchantingtable")) { + if (e.getPlayer().hasPermission("eshop.enchantingtable")) { + if (Main.getToggleRightClickPlayers().contains(e.getPlayer().getUniqueId())) { + return; + } + system.showMainMenu(e.getPlayer()); } } diff --git a/src/main/java/me/tychsen/enchantgui/localization/LocalizationManager.java b/src/main/java/me/tychsen/enchantgui/localization/LocalizationManager.java index d0cca70..cf5926d 100644 --- a/src/main/java/me/tychsen/enchantgui/localization/LocalizationManager.java +++ b/src/main/java/me/tychsen/enchantgui/localization/LocalizationManager.java @@ -1,69 +1,26 @@ package me.tychsen.enchantgui.localization; import me.tychsen.enchantgui.Main; +import me.tychsen.enchantgui.config.AConfig; import me.tychsen.enchantgui.util.Common; -import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.plugin.Plugin; -import java.io.*; -import java.nio.charset.StandardCharsets; - -public class LocalizationManager { - private static final String FILE_NAME_LOCALIZATION = "localization.yml"; +public class LocalizationManager extends AConfig { private static LocalizationManager instance; - private Plugin plugin; - private File configFile; - private FileConfiguration config; private LocalizationManager() { - plugin = Main.getInstance(); - + super("localization.yml", Main.getInstance()); saveDefaultConfiguration(); } - public String getString(String key) { - return Common.colorize(getConfig().getString(key)); + @Override + public String getString(String path) { + return Common.colorize(getConfig().getString(path)); } public void reload(CommandSender sender) { reloadConfig(); - String start = ChatColor.AQUA + LocalizationManager.getInstance().getString("prefix") + " " + ChatColor.WHITE; - sender.sendMessage(start + LocalizationManager.getInstance().getString("localization-reloaded")); - } - - private void saveDefaultConfiguration() { - if (configFile == null) { - configFile = new File(plugin.getDataFolder(), FILE_NAME_LOCALIZATION); - } - if (!configFile.exists()) { - plugin.saveResource(FILE_NAME_LOCALIZATION, false); - } - } - - private FileConfiguration getConfig() { - if (config == null) { - reloadConfig(); - } - return config; - } - - private void reloadConfig() { - if (configFile == null) { - configFile = new File(plugin.getDataFolder(), FILE_NAME_LOCALIZATION); - } - config = YamlConfiguration.loadConfiguration(configFile); - - // Look for defaults in the jar - Reader defaultConfigStream; - InputStream defaultConfigInputStream = plugin.getResource(FILE_NAME_LOCALIZATION); - if (defaultConfigInputStream != null) { - defaultConfigStream = new InputStreamReader(defaultConfigInputStream, StandardCharsets.UTF_8); - YamlConfiguration defaultConfig = YamlConfiguration.loadConfiguration(defaultConfigStream); - config.setDefaults(defaultConfig); - } + Common.tell(sender,instance.getString("prefix") +" "+ instance.getString("localization-reloaded")); } /** diff --git a/src/main/java/me/tychsen/enchantgui/menu/DefaultMenuGenerator.java b/src/main/java/me/tychsen/enchantgui/menu/DefaultMenuGenerator.java index 3a9fad4..938dac3 100644 --- a/src/main/java/me/tychsen/enchantgui/menu/DefaultMenuGenerator.java +++ b/src/main/java/me/tychsen/enchantgui/menu/DefaultMenuGenerator.java @@ -6,6 +6,7 @@ import me.tychsen.enchantgui.economy.NullPayment; import me.tychsen.enchantgui.Main; import me.tychsen.enchantgui.permissions.EShopPermissionSys; +import me.tychsen.enchantgui.util.Common; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; @@ -20,6 +21,8 @@ import java.util.List; import java.util.Map; +import static me.tychsen.enchantgui.config.EShopConfig.*; + //TODO: Cache itemstacks public class DefaultMenuGenerator implements MenuGenerator { private int inventorySize; @@ -32,11 +35,10 @@ public DefaultMenuGenerator(int inventorySize, EShopConfig config, EShopPermissi this.config = config; this.enchants = new EShopEnchants(); this.permSys = permSys; - } public Inventory mainMenu(@NotNull Player p) { - Inventory inv = p.getServer().createInventory(p, inventorySize, config.getMenuName()); + Inventory inv = p.getServer().createInventory(p, inventorySize, getMenuName()); generateMainMenu(p, inv); return inv; @@ -62,48 +64,45 @@ private void generateMainMenu(Player p, Inventory inv) { for (ItemStack item : enchantList) { if (permSys.hasEnchantPermission(p, item)) { - if (config.getShowPerItem()) { + if (getShowPerItem()) { itemList = showPerItem(itemList, item, p); } else { itemList.add(item); } } } - inv.setContents(itemList.toArray(new ItemStack[itemList.size()])); + inv.setContents(itemList.toArray(new ItemStack[0])); } @NotNull private String format(int type, String name) { - EShopShop shop = EShopShop.getInstance(); - String string = shop.getString("shop." + name); - string = ChatColor.translateAlternateColorCodes('&', string); - return MessageFormat.format(string, type); + String string = EShopShop.getInstance().getString("shop." + name); + return MessageFormat.format(Common.colorize(string), type); } private ItemStack generateItemWithMeta(@NotNull ItemStack item, int level, Enchantment enchantment) { - ItemStack tmp = item.clone(); - ItemMeta meta = tmp.getItemMeta(); + ItemStack temp = item.clone(); + ItemMeta meta = temp.getItemMeta(); List lores = new ArrayList<>(); lores.add(format(level, "level")); if (!(config.getEconomy() instanceof NullPayment)) { - int price = config.getPrice(enchantment, level); - lores.add(format(price, "price")); + lores.add(format(getPrice(enchantment, level), "price")); } meta.setLore(lores); - tmp.setItemMeta(meta); - return tmp; + temp.setItemMeta(meta); + return temp; } private Inventory generateEnchantMenu(@NotNull Player p, @NotNull ItemStack item, Map playerLevels) { - Inventory inv = p.getServer().createInventory(p, inventorySize, config.getMenuName()); + Inventory inv = p.getServer().createInventory(p, inventorySize, getMenuName()); Enchantment enchantment = item.getEnchantments().keySet().toArray(new Enchantment[1])[0]; List itemList = new ArrayList<>(); // Generate the correct items for the player. // Based on permissions or OP status. - String[] enchantLevels = config.getEnchantLevels(enchantment); + String[] enchantLevels = getEnchantLevels(enchantment); List levels = new ArrayList<>(); for (String enchantLevel : enchantLevels) { @@ -119,17 +118,21 @@ private Inventory generateEnchantMenu(@NotNull Player p, @NotNull ItemStack item } // Put the generated item list in the inventory - inv.setContents(itemList.toArray(new ItemStack[itemList.size()])); + inv.setContents(itemList.toArray(new ItemStack[0])); // Generate and insert a back button inv.setItem(27, generateBackItem()); - playerLevels.put(p.getName(), levels.toArray(new String[levels.size()])); + playerLevels.put(p.getName(), levels.toArray(new String[0])); return inv; } private ItemStack generateBackItem() { Material material = Material.matchMaterial(EShopShop.getInstance().getString("shop.back-item")); + + if(material == null) + material = Material.EMERALD; + ItemStack backItem = new ItemStack(material); ItemMeta meta = backItem.getItemMeta(); meta.setDisplayName("Go back"); diff --git a/src/main/java/me/tychsen/enchantgui/menu/DefaultMenuSystem.java b/src/main/java/me/tychsen/enchantgui/menu/DefaultMenuSystem.java index 54088c2..61569db 100644 --- a/src/main/java/me/tychsen/enchantgui/menu/DefaultMenuSystem.java +++ b/src/main/java/me/tychsen/enchantgui/menu/DefaultMenuSystem.java @@ -7,7 +7,6 @@ import me.tychsen.enchantgui.Main; import me.tychsen.enchantgui.permissions.EShopPermissionSys; import me.tychsen.enchantgui.util.Common; -import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; @@ -18,9 +17,11 @@ import java.util.HashMap; import java.util.Map; +import static me.tychsen.enchantgui.config.EShopConfig.getIgnoreItemType; +import static me.tychsen.enchantgui.config.EShopConfig.getPrice; + public class DefaultMenuSystem implements MenuSystem { - public static final String START = - ChatColor.AQUA + LocalizationManager.getInstance().getString("prefix") + " " + ChatColor.WHITE; + public static final String PREFIX = LocalizationManager.getInstance().getString("prefix") + " "; private Map playerLevels; @@ -35,17 +36,18 @@ public DefaultMenuSystem() { generator = new DefaultMenuGenerator(36, config, permsys); } + private void tell(Player player, String message){ + Common.tell(player, PREFIX +message); + } + @Override public void showMainMenu(Player p) { LocalizationManager lm = LocalizationManager.getInstance(); - if (playerLevels.containsKey(p.getName())) playerLevels.remove(p.getName()); + playerLevels.remove(p.getName()); if (permsys.hasUsePermission(p)) { - Inventory inv = generator.mainMenu(p); - - p.openInventory(inv); + p.openInventory(generator.mainMenu(p)); } else { - p.sendMessage(ChatColor.DARK_RED + lm.getString("prefix") + " " + - ChatColor.RED + lm.getString("no-permission")); + tell(p,lm.getString("no-permission")); } } @@ -61,9 +63,9 @@ public void handleMenuClick(Player p, InventoryClickEvent event) { playerLevels.remove(p.getName()); showMainMenu(p); } else if (event.getCurrentItem().getType() != Material.AIR) { - // TODO: Figure out better way of purchasing enchants. - // For example a seperate class to call purchaseEnchant on. - // Required to enable Enchanting Table menu opener.. + // FIXME: Figure out better way of purchasing enchants. + // For example a seperate class to call purchaseEnchant on. + // Required to enable Enchanting Table menu opener.. purchaseEnchant(p, event); } } else { @@ -80,29 +82,29 @@ private void purchaseEnchant(Player p, InventoryClickEvent event) { ItemStack playerHand = p.getInventory().getItemInMainHand(); int level = Integer.parseInt(playerLevels.get(p.getName())[event.getSlot()]); - int price = config.getPrice(enchantment, level); + int price = getPrice(enchantment, level); Main.debug("Slot: " + event.getSlot() + " Level: " + level); if (playerHand.getType() == Material.AIR) { - p.sendMessage(START + lm.getString("cant-enchant")); + tell(p,lm.getString("cant-enchant")); p.closeInventory(); return; } - if (enchantment.canEnchantItem(playerHand) || config.getIgnoreItemType()) { + if (enchantment.canEnchantItem(playerHand) || getIgnoreItemType()) { PaymentStrategy payment = config.getEconomy(); if (payment.withdraw(p, price)) { enchantItem(playerHand, enchantment, level); - String message = String.format("%s %s &d %s %d &f for &6 %d %s", START, lm.getString("item-enchanted"), item.getItemMeta().getDisplayName(), level, price, EShopConfig.getInstance().getEconomyCurrency()); - Common.tell(p,message); + String message = String.format("%s &d%s %d &ffor &6%d %s", lm.getString("item-enchanted"), item.getItemMeta().getDisplayName(), level, price, EShopConfig.getEconomyCurrency()); + tell(p,message); p.closeInventory(); } else { - p.sendMessage(START + lm.getString("insufficient-funds")); + tell(p,lm.getString("insufficient-funds")); } } else { - p.sendMessage(START + lm.getString("item-cant-be-enchanted")); + tell(p,lm.getString("item-cant-be-enchanted")); //TODO p.closeInventory(); add option for this } } diff --git a/src/main/java/me/tychsen/enchantgui/permissions/EShopPermissionSys.java b/src/main/java/me/tychsen/enchantgui/permissions/EShopPermissionSys.java index f3732b6..206349e 100644 --- a/src/main/java/me/tychsen/enchantgui/permissions/EShopPermissionSys.java +++ b/src/main/java/me/tychsen/enchantgui/permissions/EShopPermissionSys.java @@ -34,12 +34,9 @@ public boolean hasEnchantPermission(Player p, Enchantment ench, int level) { public boolean hasUsePermission(Player p) { if (p.isOp()) return true; - - String base = "eshop."; - String perm = base + "use"; - - return p.hasPermission(perm); + return p.hasPermission("eshop.use"); } + @RequiredArgsConstructor private final class TooManyEnchantmentsException extends RuntimeException { private static final long serialVersionUID = 1L; diff --git a/src/main/resources/localization.yml b/src/main/resources/localization.yml index ee7ad80..14601e2 100644 --- a/src/main/resources/localization.yml +++ b/src/main/resources/localization.yml @@ -1,4 +1,4 @@ -prefix: "[EnchantGUI]" +prefix: "&f[&bEnchantGUI&f]" enchant: power: "Power" @@ -38,11 +38,13 @@ enchant: multishot: "Multishot" command-from-console: "Can't use this command from console..." -no-permission: "Sorry, you do not have permission for this." +no-permission: "&cSorry, you do not have permission for this." config-reloaded: "Configuration file has been reloaded!" localization-reloaded: "Localization file has been reloaded!" shop-reloaded: "Shop file has been reloaded!" cant-enchant: "You can't enchant that!" item-enchanted: "Your item was enchanted with" insufficient-funds: "Insufficient funds." -item-cant-be-enchanted: "Enchant can't be applied to the item in your hand..." \ No newline at end of file +item-cant-be-enchanted: "Enchant can't be applied to the item in your hand..." +toggle-on: "Right click on enchanting table was turned &aon&f." +toggle-off: "Right click on enchanting table was turned &4off&f." \ No newline at end of file