PlayerInteractEvent not being triggered on block interaction

Discussion in 'Plugin Development' started by PQE, Jan 31, 2017.

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

    PQE

    This is the first event plugin I've made, and essentially what it's meant to do is, if there is a lever on top of a packed ice block AND the lever is right clicked, water will spawn underneath the Packed Ice (if the block under it is air). Here is the code I've put together:

    Code:
    package me.Alex.AntiSwear;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockFace;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class AntiSwear extends JavaPlugin implements Listener{
       
       
        @EventHandler
        public void PlayerInteractEvent(Player who, Action action, ItemStack item, Block clickedBlock, BlockFace clickedFace) {
            who.sendMessage("test");
            if (action == Action.RIGHT_CLICK_BLOCK) {
                if (clickedBlock.getType() == Material.LEVER) {
                    int x = clickedBlock.getX();
                    int y = clickedBlock.getY();
                    int z = clickedBlock.getZ();
                    World w = clickedBlock.getWorld();
                    y--;
                   
                    if (w.getBlockAt(x, y, z).getType() == Material.PACKED_ICE) {
                        y--;
                        Block toManipulate = w.getBlockAt(x, y, z);
                        if (toManipulate.getType() == Material.AIR) {
                            toManipulate.setType(Material.WATER);
                            who.sendMessage(ChatColor.GREEN + "Tap turned on!");
                        }
                        else {
                            who.sendMessage(ChatColor.RED + "There must be an air block below the packed ice!");
                        }
                    }
                   
                }
            }
               
        }
       
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
        }   
    }
    
    Here's my plugin.yml (not sure if I need to do extra stuff for events)

    Code:
    name: AntiSwear
    version: 1.0
    main: me.Alex.AntiSwear.AntiSwear
    
     
  2. Offline

    Zombie_Striker

    @PQE
    And? What does it currently do? What is the issue? What have you tried to fix the problem?

    Edit: You are not making an event. You are providing parameters instead of requiring the event. Listener to PlayerInteractEvent and remove all those other variables.
     
Thread Status:
Not open for further replies.

Share This Page