Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AnvilListener implements Listener {
- public AnvilListener(Main instance) {
- instance.getServer().getPluginManager().registerEvents(this, instance);
- }
- @EventHandler(priority = EventPriority.MONITOR)
- public void onInventoryClick(InventoryClickEvent e) {
- // check if the event has been cancelled by another plugin
- if (!e.isCancelled()) {
- HumanEntity ent = e.getWhoClicked();
- // not really necessary
- if (ent instanceof Player) {
- Player player = (Player) ent;
- Inventory inv = e.getInventory();
- // see if the event is about an anvil
- if (inv instanceof AnvilInventory) {
- InventoryView view = e.getView();
- int rawSlot = e.getRawSlot();
- // compare the raw slot with the inventory view to make sure we are talking about the upper inventory
- if (rawSlot == view.convertSlot(rawSlot)) {
- /*
- slot 0 = left item slot
- slot 1 = right item slot
- slot 2 = result item slot
- see if the player clicked in the result item slot of the anvil inventory
- */
- if (rawSlot == 2) {
- /*
- get the current item in the result slot
- I think inv.getItem(rawSlot) would be possible too
- */
- ItemStack item = e.getCurrentItem();
- // check if there is an item in the result slot
- if (item != null) {
- ItemMeta meta = item.getItemMeta();
- // it is possible that the item does not have meta data
- if (meta != null) {
- // see whether the item is beeing renamed
- if (meta.hasDisplayName()) {
- String displayName = meta.getDisplayName();
- //if (item.getType() == Material.NAME_TAG) {
- Main.getPluginConfig().set("playerdata." + player.getUniqueId().toString() + ".prefix", displayName);
- Main.getInstance().saveConfig();
- player.closeInventory();
- //} else if (item.getType() == Material.PAPER) {
- /*Main.getPluginConfig().set("playerdata." + player.getUniqueId().toString() + ".nick", displayName);
- Main.getInstance().saveConfig();
- player.closeInventory();*/
- //}
- }
- }
- }
- }
- }
- }
- }
- }
- }
- /*@EventHandler
- public void onClose(InventoryCloseEvent e) {
- Player player = (Player) e.getPlayer();
- Inventory inv = e.getInventory();
- if (inv instanceof AnvilInventory) {
- player.openInventory(Main.effector);
- }
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement