Solved Eventhandler doesn't do anything but gives no errors?

Discussion in 'Plugin Development' started by jorrik98, Sep 17, 2014.

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

    jorrik98

    I recently started coding so don't judge me on my code if it's bad, thank you.

    So i tried making a plugin that stops my players from fence glitching.
    In eclipse I don't get any errors.
    In the console I don't get any errors.

    But when trying to fence glitch it just lets me do it and it looks like my plugin isn't even there.

    AntiFence.java

    Code:java
    1. package me.jorrik98;
    2.  
    3. import org.bukkit.event.Listener;
    4. import org.bukkit.plugin.java.JavaPlugin;
    5.  
    6. public class AntiFence extends JavaPlugin implements Listener{
    7.  
    8. @Override
    9. public void onEnable() {
    10. getLogger().info("PollosAntiFence by jorrik98 has been enabled!");
    11. new PlayerListener(this);
    12. }
    13.  
    14. @Override
    15. public void onDisable() {
    16. getLogger().info("PollosAntiFence by jorrik98 has been disabled!");
    17. }
    18. }
    19.  


    PlayerListener.java

    Code:java
    1. package me.jorrik98;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Material;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.block.Action;
    8. import org.bukkit.event.player.PlayerInteractEvent;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. import me.jorrik98.AntiFence;
    12.  
    13. public class PlayerListener implements Listener {
    14.  
    15. public PlayerListener(AntiFence plugin) {
    16. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    17. }
    18.  
    19. @EventHandler
    20. public void onPlayerInteract(PlayerInteractEvent e) {
    21. Player p = e.getPlayer();
    22. if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    23. if(e.getClickedBlock().getType().equals(Material.FENCE) || e.getClickedBlock().getType().equals(Material.NETHER_FENCE)) {
    24. e.setCancelled(true);
    25. p.sendMessage(ChatColor.RED + "Fence glitching is not allowed and can get you banned!1");
    26. p.chat("I just tried to fence glitch because i'm a noob!");
    27. }
    28. }
    29. }
    30. }
    31.  



    Could anyone help me out with this?

    Thanks
     
  2. Offline

    fireblast709

    jorrik98 try debugging the event handler (by adding in System.out.println("debug message"), for example)

    Also make sure the plugin is in the list you get with /pl
     
  3. Offline

    jorrik98

    fireblast709 The plugin is in the /pl list, the console also says it loaded succesfully, i tried debugging the eventhandler but still no succes :(
     
  4. Offline

    Minesuchtiiii

    Try to add to your onEnable() part:

    Code:java
    1. this.getServer().getPluginManager().registerEvents(new PlayerListener(this), this);


    To get sure that your event is registered!
     
  5. Offline

    fireblast709

  6. Offline

    jorrik98

    fireblast709 Minesuchtiiii Thanks for the help but i managed to fix it :)

    i won't tell what I did wrong as it's too emberassing
     
  7. jorrik98 Bare in mind, though, that sharing mistakes has a good chance to help others out, and there's nothing wrong with making mistakes.
     
  8. Offline

    jorrik98

    AdamQpzm Well then, @EventHandler was underlined, but when i hovered over it didn't say i could import it.
    So i thought it was just a bug in eclipse or something :/
    When i manually imported it it worked
     
  9. jorrik98 Ah yes, IDEs are prone to hiccups now and then :) I find that refreshing/cleaning the project often helps if you get something like this (an error with no message, an error even though you've already fixed, etc.)
     
  10. Offline

    Garris0n

    Obligatory "or not using Eclipse".
     
  11. Garris0n I've had other IDEs do weird things too :) Something as complicated as an IDE is bound to have the occasional flaw at best.
     
  12. Offline

    Garris0n

    I was (mostly) joking :p

    Mostly...
     
  13. Garris0n You have a point though :p For example, I find that IntelliJ is easier to use, has more (or at least easier to accidentally find) features, and is just overall 'better'.

    Having said that, I stick with Eclipse because I've used it long enough that it's really hard not too. New programmers, listen to me! Try out different IDEs while you can!
     
  14. Offline

    Garris0n

    It doesn't take long to adjust to it. It was awful for a couple days, unpleasant for a week, and now it's been fantastic for many months.

    I already disliked Eclipse, I just didn't know there was something better because every tutorial under the sun (heh) uses it.
     
    AdamQpzm likes this.
Thread Status:
Not open for further replies.

Share This Page