From ddd6fa76f478900b5162d9853e94589116fa8144 Mon Sep 17 00:00:00 2001 From: mathiascode Date: Fri, 15 Nov 2019 17:30:36 +0200 Subject: [PATCH] Mitigate command block bugs --- .../extras/modules/block/BlockCheck.java | 23 ------------------- .../extras/modules/block/BlockPhysics.java | 6 +++++ .../extras/modules/entity/EntitySpawn.java | 15 +++++------- 3 files changed, 12 insertions(+), 32 deletions(-) diff --git a/src/main/java/pw/kaboom/extras/modules/block/BlockCheck.java b/src/main/java/pw/kaboom/extras/modules/block/BlockCheck.java index 2217727..5cc7224 100644 --- a/src/main/java/pw/kaboom/extras/modules/block/BlockCheck.java +++ b/src/main/java/pw/kaboom/extras/modules/block/BlockCheck.java @@ -1,16 +1,11 @@ package pw.kaboom.extras; -import org.bukkit.block.BlockState; -import org.bukkit.block.CommandBlock; - import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.SignChangeEvent; -import org.bukkit.event.world.ChunkLoadEvent; - class BlockCheck implements Listener { @EventHandler void onBlockPlace(BlockPlaceEvent event) { @@ -25,24 +20,6 @@ class BlockCheck implements Listener { } } - @EventHandler - void onChunkLoad(final ChunkLoadEvent event) { - if (!event.isNewChunk()) { - try { - for (BlockState block : event.getChunk().getTileEntities()) { - if (block instanceof CommandBlock) { - block.update(); - } - } - } catch (Exception exception) { - event.getChunk().getWorld().regenerateChunk( - event.getChunk().getX(), - event.getChunk().getZ() - ); - } - } - } - @EventHandler void onSignChange(SignChangeEvent event) { try { diff --git a/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java b/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java index 047f9c3..c8bd3f1 100644 --- a/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java +++ b/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java @@ -9,6 +9,8 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.CommandBlock; +import org.bukkit.block.ShulkerBox; import org.bukkit.block.data.Levelled; @@ -74,6 +76,10 @@ class BlockPhysics implements Listener { if (material == Material.FARMLAND) { event.setCancelled(true); + } else if (event.getSourceBlock().getState() instanceof CommandBlock) { + event.getSourceBlock().getState().update(); + } else if (event.getBlock().getState() instanceof CommandBlock) { + event.getBlock().getState().update(); } else if (event.getBlock().isLiquid()) { final Block block = event.getBlock(); final World world = block.getWorld(); diff --git a/src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java b/src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java index d10754c..4ff52fa 100644 --- a/src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java +++ b/src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java @@ -69,21 +69,18 @@ class EntitySpawn implements Listener { @EventHandler void onBlockDispense(BlockDispenseEvent event) { - System.out.println("lol"); try { + /*BlockStateMeta stateMeta = (BlockStateMeta) event.getItem().getItemMeta(); + + /*if (stateMeta.getBlockState() instanceof ShulkerBox) { + ShulkerBox shulkerBox = (ShulkerBox) stateMeta.getBlockState(); + } + stateMeta.getBlockState();*/ event.getBlock().getState(); event.getItem().getItemMeta(); } catch (Exception exception) { event.setCancelled(true); } - - /*try { - BlockStateMeta state = (BlockStateMeta) event.getItem().getItemMeta(); - state.getBlockState(); - } catch (UnsupportedOperationException exception) { - System.out.println("I caught: " + exception); - event.setCancelled(true); - }*/ } @EventHandler