Solved EntityExplodeEvent keeps destroying my signs

Discussion in 'Plugin Development' started by Panda_Crafter, Jul 27, 2016.

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

    Panda_Crafter

    Hello, what I want is that the explosion doesn't break my sign and chest, but it still breaks my sign no matter what. Can somebody helps me?

    Code:
        @EventHandler
        public void onBlockExplode(EntityExplodeEvent event){
          
            for(Block block : new ArrayList<Block>(event.blockList())){
                if(isProtected(block)){
                    event.blockList().remove(block);
                    event.setCancelled(true);
                }
              
                if(hasSign(block)){
                    Sign sign = (Sign) getSign(block);
                    if(sign.getLine(0).equalsIgnoreCase("[Protection]")){
                        event.blockList().remove(block);
                        event.setCancelled(true);
                    }
                }
              
                if (nextToChest(block)){
                    if(hasSign(getNextChest(block))){
                        Sign sign = (Sign) getSign(getNextChest(block));
                        if(sign.getLine(0).equalsIgnoreCase("[Protection]")){
                            event.blockList().remove(block);
                            event.setCancelled(true);
                        }
                    }
                }
            }
        }
      
        public boolean isProtected(Block block){
            Material mat = block.getType();
          
            if(mat == Material.WALL_SIGN){
                Sign sign = (Sign) block.getState();
                String text = sign.getLine(0);
                if(text.equals("[Private]")){
                    return true;
                }
            }
            return false;
        }
    
     
  2. Offline

    mine-care

  3. Offline

    Panda_Crafter

    Yes, but it only returns AIR when I return the exploded blocks

    EDIT: I found the bug, I had another class that handeld the EntityExplodeEvent and that class changed every block into AIR
     
  4. Offline

    mine-care

Thread Status:
Not open for further replies.

Share This Page