Solved BlockBreakEvent Problem/Possible Bug

Discussion in 'Plugin Development' started by lordbobby104, Nov 27, 2013.

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

    lordbobby104

    I have been working on a plugin for my friends server for the last few hours. I have come to a problem or possible bug in the code below. It works fun UNLESS the player is an op. If the the player is OPed then the event wont be cancelled. If anyone has any suggestions that would be wonderful!
    Code:
        @EventHandler
        public void onPlayerBreakBlockEvent(BlockBreakEvent e) {
            if(e.getPlayer().getGameMode().equals(GameMode.SURVIVAL)) {
                e.setCancelled(true);
            }
        }
     
  2. Offline

    CookieGamer100

    try

    if(e.getPlayer().getGameMode() == GameMode.SURVIVAL) {
    e.setCancelled(true);
    }
     
  3. Offline

    lordbobby104

    CookieGamer100 i tried this but the same problem is still ocurring. Anymore suggestions?
     
  4. Offline

    Mathias Eklund

    Got plugins that this is colliding with?
     
  5. Offline

    lordbobby104

    Mathias Eklund I deleted all other plugins but am still ahving the same problem...

    Mathias Eklund Could you try doing this and see if it wroks for you?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  6. Offline

    Commander9292

    lordbobby104 I'll take a look and try to fix this real quick
     
  7. Offline

    Mathias Eklund

    can you post your full code?
     
  8. Offline

    lordbobby104

    Code:
    package me.bobthebuilder.hgsquad;
     
    import java.util.logging.Logger;
     
    import org.bukkit.GameMode;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin implements Listener {
        private static final Logger log = Logger.getLogger("Minecraft");
     
        @Override
        public void onEnable() {
            log.info("Starting up....");
            log.info("Started!");
        }
       
        @Override
        public void onDisable() {
            log.info("Shutting down...");
            log.info("Successfully shut down!");
        }
       
        @EventHandler
        public void onPlayerBreakBlockEvent(BlockBreakEvent e) {
            if(e.getPlayer().getGameMode() == GameMode.SURVIVAL) {
                e.setCancelled(true);
            }
        }
    }
    
    Mathias Eklund
     
  9. Offline

    Mathias Eklund

    lordbobby104 xd You haven't registered your event ...
    Code:
    getServer().getPluginManager().registerEvents(this, this);
    Put that in your onEnable
     
  10. Offline

    lordbobby104

    Mathias Eklund Thank you for curing my stupidity! I was looking in the wrong place the whole time. Thanks for the help! You too! CookieGamer100 FIXED!
     
Thread Status:
Not open for further replies.

Share This Page