Player Event Question

Discussion in 'Plugin Development' started by Eggspurt, Apr 15, 2015.

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

    Eggspurt

    I want to constantly check what the user is wearing, what would be the best solution for that? Non laggiest solution as well too.
    public void CheckItems(WhichEventHandler e) {
    player.getInventory().getHelmet().getType() == Material.DIAMOND_BOOTS) {
    Do stuff

    }
    }
    Thanks
     
  2. Invisible

    nverdier

  3. Offline

    mine-care

    Follow Java Naming Conventions
     
    teej107 likes this.
  4. Offline

    Eggspurt

  5. Offline

    mine-care

    @Eggspurt it is indeed, but pointing out other mistakes in code is useful for the coder to make his code better or learn something new, in the last few years my eyes are trained and go straight to such imperfections xD
     
  6. Invisible

    nverdier

    Anytime ;3
     
  7. Offline

    Eggspurt

    I didn't mean to sound rude; as I did. Thanks for pointing it out.
    InventoryClickEvent did not work but I did use SneakEvent... But for some reason if I try sneaking again it does not re-add the potion effect I have to wait until it's gone.
     
  8. Offline

    Eggspurt

    Code:
        @EventHandler
        public void SpeedAbilities(PlayerToggleSneakEvent e) {
            Player player = e.getPlayer();
            ItemStack boots = player.getInventory().getBoots();
            ItemStack helm = player.getInventory().getHelmet();
            ItemStack leg = player.getInventory().getLeggings();
            ItemStack body = player.getInventory().getChestplate();
          
            ItemStack[] equip = {boots, helm, leg, body};
          
            if (equip != null) {
            if (boots.getType() == Material.GOLD_BOOTS
                    && helm.getType() == Material.GOLD_HELMET
                    && leg.getType() == Material.IRON_LEGGINGS
                    && body.getType() == Material.IRON_CHESTPLATE) {
                player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 300, 1));
                        }
                    }
                }
            }
     
  9. Offline

    SirMonkeyFood

    @Eggspurt Use some schedulers to test for armor being worn. May be laggier, but that would bypass the need to test for armor equipped, and armor de-equipped.
     
  10. Offline

    Zombie_Striker

    Why do you need the array? It is never used. Also, you don't check to see if boots/helm/leg/body is == null. If someone shifts while not wearing any armour, it will throw a NPE.
     
Thread Status:
Not open for further replies.

Share This Page