Stop a player from wearing diamond armor?

Discussion in 'Plugin Development' started by mike0631, Feb 10, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    mike0631

    How do I stop the player from trying to wear diamond armor.
     
  2. Offline

    chasechocolate

    InventoryClickEvent.
     
  3. Offline

    mike0631

    Yeah and then?
     
  4. Offline

    nopresnik

    I would personally create a method that checks if a player has diamond armour, then run a scheduled check every 5 seconds or so, then another method can remove the armour.
     
  5. Offline

    Craftiii4

    Would require a lot of resources.

    One way would be to listen to InventoryClickEvent and see if they place diamond armour in the armour slots, however this would not work for auto equip.

    A similar method could be to check the armour they are wearing when ever they close their inventory.
     
  6. Offline

    mike0631

    I dont want to EQUIP it, not `de-quip`.
     
  7. Offline

    RainoBoy97

    If you read again, he didnt say anything about that :p
     
  8. Offline

    Geekola

    This should do it. Sure you can figure out the rest of the armor code.

    Code:
        @EventHandler(priority = EventPriority.LOWEST)
        public void onInventoryClose(InventoryCloseEvent evt) {
       
            if (evt.getView().getType() == InventoryType.CRAFTING && evt.getPlayer() instanceof Player ) {
           
            Player p = (Player) evt.getPlayer();
            if ( p.getInventory().getHelmet() != null && p.getInventory().getHelmet().getType().equals( Material.DIAMOND_HELMET  ) ) {
            p.getWorld().dropItemNaturally( p.getLocation(), p.getInventory().getHelmet() );
            p.getInventory().setHelmet( null );
            }                 
           
            }
               
        }
    
     
    Fuzzwolf likes this.
  9. Offline

    mike0631

    Ah, sorry
    That should do the trick, thanks.
     
Thread Status:
Not open for further replies.

Share This Page