Help with PlayerInteractEvent

Discussion in 'Plugin Development' started by Jackson489, May 3, 2016.

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

    Jackson489

    This doesn't seen to work and i'm most positive i have done everything right anyone know why it's not working?

    Code:
    package me.Jackson489.listeners;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    
    import me.Jackson489.opPrison;
    
    public class onPickaxeClick implements Listener {
        private opPrison plugin;
       
        public onPickaxeClick(opPrison plugin) {
            this.plugin = plugin;
        }
    
        @EventHandler
        public void onPickRightClick(PlayerInteractEvent e) {
            if ((e.getAction() == Action.RIGHT_CLICK_AIR) || (e.getAction() == Action.RIGHT_CLICK_BLOCK)) {
                if ((e.getAction() == Action.RIGHT_CLICK_BLOCK) && e.getPlayer().getItemInHand().equals(Material.DIAMOND_PICKAXE)) {
                    Bukkit.dispatchCommand(e.getPlayer(), "upgrade");
                }
                if ((e.getAction() == Action.RIGHT_CLICK_AIR) && e.getPlayer().getItemInHand().equals(Material.DIAMOND_PICKAXE)) {
                    Bukkit.dispatchCommand(e.getPlayer(), "upgrade");
                }
             }
        }
    }
    
     
  2. Offline

    567legodude

    @Jackson489 Well, there are so many things that could affect why it isn't working. You need to tell us things like what you think is wrong, or what have you tried to solve it. You can't just say "It doesn't work, why?"
    And so the other guy doesn't have to annoy you: You should use the naming conventions, and your if statements can be simplified.
     
  3. Offline

    Jackson489

    Well theirs no stack traces in the Console it just doesn't work in game
     
  4. Offline

    567legodude

    @Jackson489 Do you know if your plugin is even being enabled? Is the plugin.yml properly configured. Are you registering your events? etc.
     
  5. Offline

    XxTimexX

    @Jackson489
    Check in the console is the plugin even enabled, as 567legodude said. Also, did you register the listeners properly. And I would use
    Code:
    e.getPlayer().getItemInHand().getType() == Material.DIAMOND_PICKAXE
    because you would be checking is it material or something else. As far as I know, .equals() is used when it is about String or something similiar.
     
  6. Offline

    Firestar311

    @Jackson489 You didn't register the event
    In your constructor for the listener put the following below
    Code:java
    1. plugin.getServer().getPluginManager().registerEvents(this, plugin)
     
  7. Offline

    Jackson489

    yes the plugin is enabled

    i changed it to that and it works now

    i had it registered in my main class


    i more question how would i make it double right click?
     
Thread Status:
Not open for further replies.

Share This Page