Can't get my event handler to work can someone help

Discussion in 'Plugin Development' started by PepsiYourCoke, Apr 27, 2015.

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

    PepsiYourCoke

    Hello for some reason i cant get my EventHandler to work im going to put my main class and my main class in here, i had it working when i didn't have a if(p.hasPermissions("MCA.Use")) but now that it doesn't work i don't know where to go from there!



    PlayerListener Class |
    \/
    Code:
    package me.Eric.MCAEventHandler;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    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.plugin.Plugin;
    
    public class PlayerListener implements Listener {
    
        public PlayerListener() {
            Bukkit.getServer().getPluginManager().registerEvents(this, (Plugin) this);
        }
        @EventHandler
        public void playerInteract(PlayerInteractEvent e) {
            Player p = e.getPlayer();
            Action a = e.getAction();
            Material b = e.getClickedBlock().getType();
                if (a == Action.RIGHT_CLICK_BLOCK) {
                if (b == Material.WOODEN_DOOR || b == Material.FENCE_GATE
                        || b == Material.ACACIA_DOOR
                        || b == Material.ACACIA_FENCE_GATE
                        || b == Material.BIRCH_DOOR
                        || b == Material.BIRCH_FENCE_GATE
                        || b == Material.DARK_OAK_DOOR
                        || b == Material.DARK_OAK_FENCE_GATE
                        || b == Material.SPRUCE_DOOR
                        || b == Material.SPRUCE_FENCE_GATE
                        || b == Material.JUNGLE_DOOR
                        || b == Material.JUNGLE_FENCE_GATE
                        || b == Material.TRAP_DOOR == true){
                     e.setCancelled(true);       
                     p.sendMessage(ChatColor.RED
                            + "Please dont change the oriantaion of the "
                            + e.getClickedBlock().getType().toString()); }
            }
          }
        }

    Main Class |
    \/
    Code:
    package me.Eric.MCAEventHandler;
    
    import me.Eric.MCAEventHandler.PlayerListener;
    
    import org.bukkit.Bukkit;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
        java.util.logging.Logger myPluginLogger = Bukkit.getLogger();
    
        @Override
        public void onEnable() {
            new PlayerListener();
            myPluginLogger.info("MCAEventHandler By PepsiYourCoke Enabling ");
        }
    
        @Override
        public void onDisable() {
            myPluginLogger.info("MCAEventHandler By PepsiYourCoke Disabling ");
        }
    }
     
  2. Offline

    mythbusterma

    @PepsiYourCoke

    Why would a Listener be an acceptable replacement for a Plugin class?
     
  3. Offline

    PepsiYourCoke

    now it wont work at all
     
  4. Offline

    pie_flavor

    @PepsiYourCoke First of all, don't use Bukkit's logger. Use your own (JavaPlugin#getLogger()).
    Second, don't log enable/disable messages. Bukkit does that automatically.
    Now on to your question:
    Instead of public PlayerListener() put public PlayerListener(Main plugin).
    Instead of new PlayerListener() put new PlayerListener(this).
    Instead of (Plugin) this put plugin.
    Problem solved.
     
  5. Offline

    PepsiYourCoke

    @mythbusterma

    idk it keeps saying some stuffs wrong can't seem to find it out let me update it ill send the code again

    Thank you @pie_flavor and @mythbusterma

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
Thread Status:
Not open for further replies.

Share This Page