Mitigate command block bugs

This commit is contained in:
mathiascode 2019-11-15 17:30:36 +02:00
parent b5046d8325
commit ddd6fa76f4
3 changed files with 12 additions and 32 deletions

View file

@ -1,16 +1,11 @@
package pw.kaboom.extras; package pw.kaboom.extras;
import org.bukkit.block.BlockState;
import org.bukkit.block.CommandBlock;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.world.ChunkLoadEvent;
class BlockCheck implements Listener { class BlockCheck implements Listener {
@EventHandler @EventHandler
void onBlockPlace(BlockPlaceEvent event) { 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 @EventHandler
void onSignChange(SignChangeEvent event) { void onSignChange(SignChangeEvent event) {
try { try {

View file

@ -9,6 +9,8 @@ import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.CommandBlock;
import org.bukkit.block.ShulkerBox;
import org.bukkit.block.data.Levelled; import org.bukkit.block.data.Levelled;
@ -74,6 +76,10 @@ class BlockPhysics implements Listener {
if (material == Material.FARMLAND) { if (material == Material.FARMLAND) {
event.setCancelled(true); 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()) { } else if (event.getBlock().isLiquid()) {
final Block block = event.getBlock(); final Block block = event.getBlock();
final World world = block.getWorld(); final World world = block.getWorld();

View file

@ -69,21 +69,18 @@ class EntitySpawn implements Listener {
@EventHandler @EventHandler
void onBlockDispense(BlockDispenseEvent event) { void onBlockDispense(BlockDispenseEvent event) {
System.out.println("lol");
try { try {
/*BlockStateMeta stateMeta = (BlockStateMeta) event.getItem().getItemMeta();
/*if (stateMeta.getBlockState() instanceof ShulkerBox) {
ShulkerBox shulkerBox = (ShulkerBox) stateMeta.getBlockState();
}
stateMeta.getBlockState();*/
event.getBlock().getState(); event.getBlock().getState();
event.getItem().getItemMeta(); event.getItem().getItemMeta();
} catch (Exception exception) { } catch (Exception exception) {
event.setCancelled(true); 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 @EventHandler