Need some help debugging my listener?

Discussion in 'Plugin Development' started by zack6849, Sep 12, 2012.

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

    zack6849

    Im unsure why, but after changing some code around, one part of my plugin stopped working entirely.
    The event listener is registered correctly and all broadcasts and whatnot work except one
    Code:
        @EventHandler
        public void BucketEmptyLava(PlayerBucketEmptyEvent event){
            Block b = event.getBlockClicked();
            String p = event.getPlayer().getName();
            String kickmsg = plugin.getConfig().getString("kick-message");
            Boolean kick = plugin.getConfig().getBoolean("kick");
            String location = b.getX() + "," + b.getY() + "," + b.getZ();
            if(event.getBucket().equals(Material.LAVA_BUCKET)){
                Bukkit.broadcastMessage("debug");
                System.out.println(event.getBucket());
                if(plugin.getConfig().getBoolean("lava-blocked")){
                    if(!event.getPlayer().hasPermission("griefshield.bucket.lava.use")){
                        event.setCancelled(true);
                        Bukkit.broadcast(prefix + "player " + p + " Tried to use a bucket of lava at " + location + " in world " + event.getPlayer().getWorld().getName(), "griefshield.alert");
                        if(kick){
                            event.getPlayer().kickPlayer(kickmsg);
                        }
                    }
                }
            }
        }
        @EventHandler
        public void BucketEmptyWater(PlayerBucketEmptyEvent event){
            Block b = event.getBlockClicked();
            String p = event.getPlayer().getName();
            String kickmsg = plugin.getConfig().getString("kick-message");
            Boolean kick = plugin.getConfig().getBoolean("kick");
            String location = b.getX() + "," + b.getY() + "," + b.getZ();
            if(event.getBucket().equals(Material.WATER_BUCKET)){
                System.out.println(event.getBucket());
                Bukkit.broadcastMessage("debug");
                if(plugin.getConfig().getBoolean("water-blocked")){
                    if(!event.getPlayer().hasPermission("griefshield.bucket.water.use")){
                        event.setCancelled(true);
                        Bukkit.broadcast(prefix + "player " + p + " Tried to use a bucket of water at " + location + " in world " + event.getPlayer().getWorld().getName(), "griefshield.alert");
                        if(kick){
                            event.getPlayer().kickPlayer(kickmsg);
                        }
                    }
                }
            }
        }
    The water event gets called and works just fine, and the debug message works fine too
    however, the lava event doesn't seem to be fired at all, they are both in the same class so it isn't that the registration of the event is busted, im really stumped here. any help would be greatly appreciated
     
  2. Offline

    V10lator

    Why not join the both into one, like this (quick & dirty):
    Code:java
    1. @EventHandler
    2. public void BucketEmptyLava(PlayerBucketEmptyEvent event){
    3. Block b = event.getBlockClicked();
    4. String p = event.getPlayer().getName();
    5. String kickmsg = plugin.getConfig().getString("kick-message");
    6. Boolean kick = plugin.getConfig().getBoolean("kick");
    7. String location = b.getX() + "," + b.getY() + "," + b.getZ();
    8. if(event.getBucket().equals(Material.LAVA_BUCKET)){
    9. Bukkit.broadcastMessage("debug");
    10. System.out.println(event.getBucket());
    11. if(plugin.getConfig().getBoolean("lava-blocked")){
    12. if(!event.getPlayer().hasPermission("griefshield.bucket.lava.use")){
    13. event.setCancelled(true);
    14. Bukkit.broadcast(prefix + "player " + p + " Tried to use a bucket of lava at " + location + " in world " + event.getPlayer().getWorld().getName(), "griefshield.alert");
    15. if(kick){
    16. event.getPlayer().kickPlayer(kickmsg);
    17. }
    18. }
    19. }
    20. }
    21. else if(event.getBucket().equals(Material.WATER_BUCKET)){
    22. System.out.println(event.getBucket());
    23. Bukkit.broadcastMessage("debug");
    24. if(plugin.getConfig().getBoolean("water-blocked")){
    25. if(!event.getPlayer().hasPermission("griefshield.bucket.water.use")){
    26. event.setCancelled(true);
    27. Bukkit.broadcast(prefix + "player " + p + " Tried to use a bucket of water at " + location + " in world " + event.getPlayer().getWorld().getName(), "griefshield.alert");
    28. if(kick){
    29. event.getPlayer().kickPlayer(kickmsg);
    30. }
    31. }
    32. }
    33. }
    34. }
     
  3. Offline

    zack6849

    I did them as multiple for neatness, but i don't think that really would fix my issue.

    Bump? D:

    Anyone that knows what i've done wrong? D:

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  4. Offline

    StevasaurousREX

    Honestly I just c&p'd your code into a listener class and it worked just fine, stopped the lava and water and gave me a message in the console saying that I did it. (I changed kick to equal false and removed the if config=blah stuff so that it would work with out recreating configs) are your permissions defined properly in your plugin.yml? thats the only thing i can think of, when I didnt put the perm for the broadcast in the plugin.yml (was trying to do it quick and missed it) it didnt display the broadcast, not even in the console
     
  5. Offline

    zack6849

    It turns out it was a compatibility issue with essenitals protect.
     
Thread Status:
Not open for further replies.

Share This Page