Help with Player move event

Discussion in 'Plugin Development' started by arnie231, Jun 3, 2012.

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

    arnie231

    OK so I'm trying to check if a player is standing on Ender_Stone and if they are, are they wearing a Diamond helmet and if there not //do nothing

    else if there wearing anything other it adds a bunch of potion effects and a message

    but it seems i cant get it to work at all heres my code
    Code:java
    1.  
    2. package com.arnie.space.listeners;
    3.  
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Material;
    6. import org.bukkit.block.Block;
    7. import org.bukkit.block.BlockFace;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.player.PlayerMoveEvent;
    11. import org.bukkit.potion.PotionEffect;
    12. import org.bukkit.potion.PotionEffectType;
    13.  
    14.  
    15. public class PlayerListener implements Listener{
    16.  
    17.  
    18. public void SpaceCheck(PlayerMoveEvent event){
    19. Player player = event.getPlayer();
    20. Block block = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
    21.  
    22. if (block.getType() == Material.ENDER_STONE){
    23. if (player.getInventory().getHelmet().getType() == Material.DIAMOND_HELMET){
    24. // do nothing
    25. } else {
    26. if (player.getInventory().getHelmet().getType() == Material.LEATHER_HELMET){
    27.  
    28. player.sendMessage(ChatColor.RED + "WARNING:" + ChatColor.YELLOW + "Helmet malfunction Oxygen levels depleting!");
    29. player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 20, 10));
    30. player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20, 10));
    31. player.addPotionEffect(new PotionEffect(PotionEffectType.HARM, 20, 10));
    32. player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 20, 10));
    33.  
    34. [syntax][/syntax]
     
  2. you forgot the @EventHandler annotation.
     
    ferrybig likes this.
  3. Offline

    arnie231

    I'm a Retard ¬_¬

    Thanks

    Sorry i have another issue now

    I get a null point on line 25 :/

    Which is
    Code:java
    1.  
    2.  
    3. if (player.getInventory().getHelmet().getType() == Material.DIAMOND_HELMET){[syntax]
    4.  
    5. EDIT by Moderator: merged posts, please use the edit button instead of double posting.[/syntax]
     
    Last edited by a moderator: May 26, 2016
  4. Offline

    colony88

    use a null-check: if(player == null){ return; }
     
  5. Offline

    arnie231

    fixed it by checking if the helmet slot was empty first not if it was a diamond one

    thanks for help guys

    I have another Question if someone could help I dont seem to understand how to Delay the tasks so it doesnt spam the user but i cant seem to get my head round it

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  6. Offline

    LexLaiden

    you should put this or its equivalent as the first bit of code in your SpaceCheck event. this way you only do your code if the player as changed block possition not every little movement.


    int fromX=(int)event.getFrom().getX();
    int fromY=(int)event.getFrom().getY();
    int fromZ=(int)event.getFrom().getZ();
    int toX=(int)event.getTo().getX();
    int toY=(int)event.getTo().getY();
    int toZ=(int)event.getTo().getZ();

    if(fromX!=toX||fromZ!=toZ||fromY!=toY){
    PUT YOU CODE INSIDE HERE
    }
     
Thread Status:
Not open for further replies.

Share This Page