Solved Need help with EventHandler!

Discussion in 'Plugin Help/Development/Requests' started by RBHB16, Oct 25, 2015.

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


    So in the code I've pasted below, I am trying to get the plugin to take effect when the player is sneaking, then if he right clicks a block or air, then if the player is holding sugarcane (weed) to give him potion effects for being high. Could someone explain to me what I'm doing wrong? I was going to try to use PlayerInteractEntityEvent, but then for the event.getaction it has to be a PlayerInteractEvent... When I go in game to test it, absolutely nothing happens.

    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    import com.redstery.prisondrugs.MainClass;
    public class WeedEffect implements Listener {
        public WeedEffect(MainClass mainClass) {
        public void onPlayerInteract(PlayerInteractEvent e) {
            if (e.getPlayer().isSneaking()){ //check if player is sneaking
                if (e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){ //then check if player right clicks air or right clicks a block while sneaking
                    if (e.getPlayer().getItemInHand().equals(Material.SUGAR_CANE)){ //then check if the player is holding sugar cane all at the same time
                        Player player = e.getPlayer();
                        player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 360, 5)); //if all checks are true, should get these effects
    Last edited: Oct 25, 2015
Thread Status:
Not open for further replies.

Share This Page