This is simple, yet I am terrible with java. If anyone could guide me through what they did, even better - If not, I will take the plugin anyways All I need is a simple plugin which listens for click on a players armorslot and cancels them, so that players may not dequip armor that has been auto equipped to them.
Code: public class AwesomePluginName extends JavaPlugin implements Listener { public void onEnable() { getServer().getPluginManager().registerEvents(this, this); getLogger().info(getName() + " enabled"); } @Override public void onDisable() { getLogger().info(getName() + " disabled"); } @EventHandler (ignoreCancelled = true) public void onArmorSlot(InventoryClickEvent event) { if (event.getSlotType().equals(SlotType.ARMOR) && event.getInventory().getItem(event.getSlot()) != null) event.setCancelled(true); } } I think that should do it. Add imports and test. This does not prevent players from equipping armor if target slot is empty.
Code: @EventHandler(priority = EventPriority.MONITOR) public void inventory(InventoryClickEvent event) { if (event.getRawSlot() == 6) { event.setCancelled(true); } } Edit: 1mpre55 beat me to it -
Thanks to both of you, I really appreciate it a lot! Awesome support. Any good resources for learning java/bukkit? I want to get into it.
I found the official Plugin Tutorial a great resource for plugin development, and it has links to a few java tutorials as well. You can also check out the API and ask questions on the Plugin Development forum. If you don't know how to do something, you can find a plugin that does it and read it's source code; just make sure that you aren't copying the whole thing.
Neither codes work for me. 1mpre55's code doesn't do anything, properly exported, with plugin.yml, and all imports - no errors. aciid's code works, but only for the chestplate slot.
Same. I'm debugging it. EDIT: It seems like event.getInventory().getItem(event.getSlot()) always returns null, as if there was no item in that slot. Due to this, the plugin thinks that that armor slot is empty and allows the InventoryClickEvent to happen. Removing that check will fix the problem, but it won't allow your players to equip new armor, except by shift-clicking armor items in their inventory. EDIT2: Well, it seems like event.getCurrentItem() works like it's supposed to. Code: @EventHandler (ignoreCancelled = true) public void onArmorSlot(InventoryClickEvent event) { if (event.getSlotType().equals(SlotType.ARMOR) && !event.getCurrentItem().getType().equals(Material.AIR)) event.setCancelled(true); }