Helmet detection problem

Discussion in 'Plugin Development' started by Streetpass4993, Apr 14, 2014.

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

    Streetpass4993

    I'm trying to make a space logic plugin however I can't seem to get the Player Event to work
    this is what I have for it:

    @SuppressWarnings("deprecation")
    @EventHandler
    public void onPlayerJoinEvent(PlayerJoinEvent event){
    Player player = event.getPlayer();



    if(player.getInventory().getHelmet().getType() == Material.GLASS){

    }

    if(player.getInventory().getHelmet().getType() == Material.STAINED_GLASS){

    }

    else{
    player.sendMessage("YOU ARE NOT WEARING A HELMET!");
    player.damage(2);
    }
    }


    It should be making the player get damaged if they do not have glass on their head
     
  2. Offline

    Shadowwolf97

    Did you register the listener in your onEnable portion of the plugin?
     
  3. Offline

    tehTyA

    What exactly is not working with it? It appears that you are not checking to ensure they actually have a helmet on before seeing what kind of helmet they are wearing, which can cause a NullPointerException. Furthermore your first if statement doesn't do anything, as it just checks to see if they are wearing a glass helmet, but doesn't act on it as the code block after it is empty and there is no else block on it.

    Just looking at it, it would appear to only cause the player damage when they first join the game as well, as this is the onPlayerJoinEvent.
     
Thread Status:
Not open for further replies.

Share This Page