[Simple] Disable armor slot changing on user end.

Discussion in 'Archived: Plugin Requests' started by TheFluffey, Nov 24, 2012.

  1. Offline

    TheFluffey

    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 :D

    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.
     
  2. Offline

    1mpre55

    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.
     
  3. Offline

    aciid

    Code:
    @EventHandler(priority = EventPriority.MONITOR)
        public void inventory(InventoryClickEvent event) {
            if (event.getRawSlot() == 6) {
                event.setCancelled(true);
            }
        }
    
    Edit: 1mpre55 beat me to it :p-
     
  4. Offline

    1mpre55

    The time difference is under a minute, wow
     
  5. Offline

    TheFluffey

    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.
     
  6. Offline

    1mpre55

    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.
     
  7. Offline

    TheFluffey

    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.
     
  8. Offline

    1mpre55

    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);
        }
     

Share This Page