@EventHandler(priority = EventPriority.HIGHEST) public void SignChangeEvent(SignChangeEvent e) { if (e.getLine(0).equals("[CustomEnchant]")) if (!e.getPlayer().isOp()) e.setCancelled(true); else { String ench = e.getLine(1); CEnchantment ce = Tools.getEnchantmentByDisplayname(ench); if (ce == null) ce = Tools.getEnchantmentByOriginalname(ench); if (ce == null) for (CEnchantment ceT : Main.enchantments) if (Tools.checkForEnchantment(ench, ceT)) ce = ceT; if (ce == null) { e.getPlayer() .sendMessage(ChatColor.RED + "[CE] Could not find Custom Enchantment " + ench + "."); e.setCancelled(true); return; } try { Integer.parseInt(e.getLine(3).replaceAll("\\D+", "")); } catch (NumberFormatException ex) { e.getPlayer().sendMessage(ChatColor.RED + "[CE] The cost you entered is invalid."); e.setCancelled(true); return; } e.getPlayer() .sendMessage( ChatColor.GREEN + "[CE] Successfully created a sign shop for the enchantment " + ench + "."); } }
@EventHandler(priority = EventPriority.HIGHEST) public void PlayerInteractEvent(PlayerInteractEvent e) { Player p = e.getPlayer(); CEventHandler.handleEvent(p, e, interact); if (e.getAction().toString().startsWith("LEFT")) CEventHandler.handleEvent(p, e, interactL); else if (e.getAction().toString().startsWith("RIGHT")) { CEventHandler.handleEvent(p, e, interactR); // Check if the player has put armor on by rightclicking if (p.getItemInHand().getType() != Material.AIR) { ItemStack i = p.getItemInHand(); String mat = i.getType().toString(); PlayerInventory inv = p.getInventory(); if ((mat.endsWith("BOOTS") && inv.getBoots() == null) || (mat.endsWith("LEGGINGS") && inv.getLeggings() == null) || (mat.endsWith("CHESTPLATE") && inv.getChestplate() == null) || (mat.endsWith("HELMET") && inv.getHelmet() == null)) CEventHandler.handleArmor(p, e.getItem(), false, e); } } // Sign shop if (e.getClickedBlock() != null && e.getClickedBlock().getType().toString().contains("SIGN")) if (((Sign) e.getClickedBlock().getState()).getLine(0).equals("[CustomEnchant]")) { if (!Main.hasEconomy) { p.performCommand("ce menu"); } else if (p.getItemInHand().getType() != Material.AIR) { Sign sign = ((Sign) e.getClickedBlock().getState()); CEnchantment ce = Tools.getEnchantmentByDisplayname(sign.getLine(1)); if (ce == null) Tools.getEnchantmentByOriginalname(sign.getLine(1)); if (ce == null) for (CEnchantment ceT : Main.enchantments) if (Tools.checkForEnchantment(sign.getLine(1), ceT)) ce = ceT; if (ce == null) return; ItemStack inHand = p.getItemInHand(); if (!Tools.isApplicable(inHand, ce)) { p.sendMessage(ChatColor.RED + "[CE] This enchantment can not be applied to this item."); return; } int cost = 0; try { cost = Integer.parseInt(sign.getLine(3).replaceAll("\\D+", "")); } catch (NumberFormatException ex) { return; } if (inHand.hasItemMeta() && inHand.getItemMeta().hasLore()) { List<String> lore = inHand.getItemMeta().getLore(); for (int i = 0; i < lore.size(); i++) if (Tools.checkForEnchantment(lore.get(i), ce)) { int newLevel = Tools.getLevel(lore.get(i)) + 1; if (newLevel <= ce.getEnchantmentMaxLevel()) { if (Main.econ.getBalance(p.getName()) >= cost) { EconomyResponse ecr = Main.econ.withdrawPlayer(p.getName(), cost); if (ecr.transactionSuccess()) p.sendMessage( ChatColor.GREEN + "[CE] Upgraded enchantment " + ce.getDisplayName() + ChatColor.RESET + "" + ChatColor.GREEN + " for " + cost + " " + ((cost == 1) ? Main.econ.currencyNameSingular() : Main.econ.currencyNamePlural())); else { p.sendMessage(ChatColor.RED + "[CE] An economy error has occured:"); p.sendMessage(ChatColor.RED + ecr.errorMessage); p.closeInventory(); return; } } else { p.sendMessage(ChatColor.RED + "[CE] You do not have enough money to buy this!"); p.closeInventory(); return; } lore.set(i, ce.getDisplayName() + " " + Tools.intToLevel(newLevel)); ItemMeta im = inHand.getItemMeta(); im.setLore(lore); inHand.setItemMeta(im); return; } else { p.sendMessage( ChatColor.RED + "[CE] You already have the maximum level of this enchantment!"); return; } } } List<String> lore = new ArrayList<String>(); ItemMeta im = inHand.getItemMeta(); if (inHand.getItemMeta().hasLore()) lore = im.getLore(); if (Main.econ.getBalance(p.getName()) >= cost) { EconomyResponse ecr = Main.econ.withdrawPlayer(p.getName(), cost); if (ecr.transactionSuccess()) p.sendMessage( ChatColor.GREEN + "[CE] Bought enchantment " + ce.getDisplayName() + ChatColor.RESET + "" + ChatColor.GREEN + " for " + cost + " " + ((cost == 1) ? Main.econ.currencyNameSingular() : Main.econ.currencyNamePlural())); else { Bukkit.getConsoleSender() .sendMessage(ChatColor.RED + "[CE] An economy error has occured:"); Bukkit.getConsoleSender().sendMessage(ChatColor.RED + ecr.errorMessage); p.closeInventory(); return; } } else { p.sendMessage(ChatColor.RED + "[CE] You do not have enough money to buy this!"); p.closeInventory(); return; } lore.add(ce.getDisplayName() + " I"); im.setLore(lore); inHand.setItemMeta(im); return; } else { p.sendMessage(ChatColor.RED + "[CE] You do not have an item in your hand."); return; } } }