How could i cancel anvil repair events? I want it to cancel everything but putting a book on a weapon . Also could some one tell me how i could create a chest for each players and have it save exactly the content for whenever they next trigger the event? Similarly to ender chests fireblast709 psst .
InventoryClickEvent. Check the slots (as there are no AnvilInventory related events atm) Bukkit.createInventory(params), you should save the inventory somewhere onInvClose() and load again onInvOpen()
Frazz86 For your first question: There currently are no anvil events, however, there's still a way to cancel them. You'll have to listen for InventoryClickEvent, check if they're clicking inside of an anvil, and see if they're clicking in the result slot(slot #2 for anvils). Then, you can get the item from that slot, check the enchantments or whatever, and then cancel the event if you need to. I haven't tested this myself, so it may or may not work exactly as wanted. Your second question: The easiest way to do this is to simply save and load the ItemStack's from YAML. Example code: Code: private ItemStack[] loadPlayerChest(String player) { player = player.toLowerCase(); File playerFile = new File(root, player+".yml"); if (!playerFile.exists()) { return new ItemStack[54]; } FileConfiguration config = YamlConfiguration.loadConfiguration(playerFile); List<ItemStack> list = (List<ItemStack>) config.getList("items"); // Ensure that the returned array is of the correct length. ItemStack[] items = new ItemStack[54]; return list.toArray(items); } private void save(String player, ItemStack[] items) { player = player.toLowerCase(); FileConfiguration config = new YamlConfiguration(); config.set("items", Arrays.asList(items)); try { config.save(new File(root, player+".yml")); } catch (IOException e) { e.printStackTrace(); } } This code is used in a plugin I've made privately for someone which has a separate file for the inventory of each player. Something I haven't done, but would be a great idea to do, is to use a list that doesn't contain all the null elements in the array. If you don't do this, you end up with larger config files, such as: Spoiler (Move your mouse to the spoiler area to reveal the content) Show Spoiler Hide Spoiler Code: items: - ==: org.bukkit.inventory.ItemStack type: ITEM_FRAME amount: 64 - ==: org.bukkit.inventory.ItemStack type: PAINTING amount: 32 - ==: org.bukkit.inventory.ItemStack type: CHEST amount: 64 - ==: org.bukkit.inventory.ItemStack type: PUMPKIN - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null - null
Yeah, i'm reviving this post ONE YEAR AND A HALF later and still no Anvil events :l Do anyone know any plugin that does that? (not a problem for me to make this "manually", but APIs are easier...) @EDIT: this may help people who are searching! And about reviving a post: I find it valid when it is unresolved, people may find this and are still looking for answers, so that link may help some of them.. So please be nice with reviving unresolved threads