diff --git a/src/main/java/pw/kaboom/extras/Events.java b/src/main/java/pw/kaboom/extras/Events.java index f3984e8..40e3c13 100644 --- a/src/main/java/pw/kaboom/extras/Events.java +++ b/src/main/java/pw/kaboom/extras/Events.java @@ -24,6 +24,7 @@ import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; import org.bukkit.block.Container; import org.bukkit.block.CreatureSpawner; @@ -166,35 +167,71 @@ class Events implements Listener { @EventHandler void onBlockPhysics(BlockPhysicsEvent event) { Block block = event.getBlock(); - World world = event.getBlock().getWorld(); - int radius = 5; - int blockCount = 0; - for (int x = -radius; x < radius; x++) { - for (int y = -radius; y < radius; y++) { - for (int z = -radius; z < radius; z++) { - if (blockCount < 50) { - Location blockLocation = new Location(world, block.getX() + x, block.getY() + y, block.getZ() + z); - Block coordBlock = world.getBlockAt(blockLocation); + if (main.fallingBlockList.contains(block.getType())) { + main.fallingBlockCount++; - if ((coordBlock.getType() == Material.CACTUS || - coordBlock.getType() == Material.LADDER || - coordBlock.getType() == Material.SOIL) && - coordBlock.getType() == block.getType()) { - blockCount++; + if (main.fallingBlockCount == 10) { + event.setCancelled(true); + main.fallingBlockCount = 0; + } + } else if (block.getType() == Material.SOIL) { + event.setCancelled(true); + } else if (main.nonSolidWallMountedBlockList.contains(block.getType())) { + World world = event.getBlock().getWorld(); + int radius = 5; + int blockCount = 0; + + for (int x = -radius; x <= radius; x++) { + for (int y = -radius; y <= radius; y++) { + for (int z = -radius; z <= radius; z++) { + if (blockCount < 42) { + Location blockLocation = new Location(world, block.getX() + x, block.getY() + y, block.getZ() + z); + Block coordBlock = world.getBlockAt(blockLocation); + + if (coordBlock.getType() == block.getType() || + main.nonSolidWallMountedBlockList.contains(coordBlock.getType())) { + blockCount++; + } + + continue; } - - continue; + break; } - break; } } - } - if (blockCount == 50) { - event.setCancelled(true); - } + if (blockCount == 42) { + event.setCancelled(true); + } + } else if (main.nonSolidDoubleBlockList.contains(block.getType())) { + /*if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR || + (main.nonSolidBlockList.contains(block.getRelative(BlockFace.DOWN).getType()) && block.getRelative(BlockFace.DOWN).getType() != block.getType())) { + for (int y = block.getRelative(BlockFace.UP).getY(); y <= 128; y++) { + World world = event.getBlock().getWorld(); + Block coordBlock = world.getBlockAt(new Location(world, block.getX(), y, block.getZ())); + if (coordBlock.getType() == block.getType()) { + coordBlock.setType(Material.AIR, false); + continue; + } + + break; + } + + block.setType(Material.AIR, false);*/ + /*} else */if (block.getRelative(BlockFace.DOWN).getType() == block.getType()) { + event.setCancelled(true); + } + } else if (main.nonSolidSingularBlockList.contains(block.getType())) { + /*if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR || + main.nonSolidBlockList.contains(block.getRelative(BlockFace.DOWN).getType())) { + block.setType(Material.AIR, false); + BlockState state = block.getState(); + state.setType(Material.AIR); + state.update(true, false); + }*/ + } } @EventHandler @@ -480,9 +517,9 @@ class Events implements Listener { event.disallow(Result.KICK_OTHER, "The server is throttled due to bot attacks. Please try logging in again."); main.onlineCount++; } - } else if (!(event.getHostname().startsWith("play.kaboom.pw") && + /*} else if (!(event.getHostname().startsWith("play.kaboom.pw") && event.getHostname().endsWith(":64518"))) { - event.disallow(Result.KICK_OTHER, "You connected to the server using an outdated server address/IP.\nPlease use the following address/IP:\n\nkaboom.pw"); + event.disallow(Result.KICK_OTHER, "You connected to the server using an outdated server address/IP.\nPlease use the following address/IP:\n\nkaboom.pw");*/ } else { event.allow(); } diff --git a/src/main/java/pw/kaboom/extras/Main.java b/src/main/java/pw/kaboom/extras/Main.java index fc8a7c7..118c5d1 100644 --- a/src/main/java/pw/kaboom/extras/Main.java +++ b/src/main/java/pw/kaboom/extras/Main.java @@ -25,6 +25,7 @@ import org.bukkit.plugin.java.JavaPlugin; public class Main extends JavaPlugin { int onlineCount = 0; + int fallingBlockCount = 0; HashMap commandMillisList = new HashMap(); HashMap interactMillisList = new HashMap(); HashSet consoleCommandBlacklist = new HashSet(Arrays.asList(new String[] { @@ -353,8 +354,86 @@ public class Main extends JavaPlugin { "warps", "whisper", })); + HashSet fallingBlockList = new HashSet(Arrays.asList(new Material[] { + Material.ANVIL, + Material.GRAVEL, + Material.SAND, + })); + HashSet nonSolidDoubleBlockList = new HashSet(Arrays.asList(new Material[] { + Material.LONG_GRASS, + Material.SIGN_POST, + Material.WOODEN_DOOR, + Material.IRON_DOOR_BLOCK, + Material.CACTUS, + Material.SUGAR_CANE_BLOCK, + Material.CAKE_BLOCK, + Material.DAYLIGHT_DETECTOR, + Material.CARPET, + Material.DOUBLE_PLANT, + Material.STANDING_BANNER, + Material.DAYLIGHT_DETECTOR_INVERTED, + Material.SPRUCE_DOOR, + Material.BIRCH_DOOR, + Material.JUNGLE_DOOR, + Material.ACACIA_DOOR, + Material.DARK_OAK_DOOR, + })); + HashSet nonSolidSingularBlockList = new HashSet(Arrays.asList(new Material[] { + Material.SAPLING, + Material.BED_BLOCK, + Material.POWERED_RAIL, + Material.DETECTOR_RAIL, + Material.DEAD_BUSH, + Material.YELLOW_FLOWER, + Material.RED_ROSE, + Material.BROWN_MUSHROOM, + Material.RED_MUSHROOM, + Material.FIRE, + /*Material.REDSTONE_WIRE,*/ + Material.CROPS, + Material.RAILS, + Material.STONE_PLATE, + Material.WOOD_PLATE, + Material.SNOW, + Material.DIODE_BLOCK_OFF, + Material.DIODE_BLOCK_ON, + Material.PUMPKIN_STEM, + Material.MELON_STEM, + Material.WATER_LILY, + Material.FLOWER_POT, + Material.CARROT, + Material.POTATO, + Material.GOLD_PLATE, + Material.IRON_PLATE, + Material.REDSTONE_COMPARATOR_OFF, + Material.REDSTONE_COMPARATOR_ON, + Material.ACTIVATOR_RAIL, + Material.BEETROOT_BLOCK, + Material.NETHER_WART_BLOCK, + })); + HashSet nonSolidWallMountedBlockList = new HashSet(Arrays.asList(new Material[] { + Material.TORCH, + Material.LADDER, + Material.WALL_SIGN, + Material.LEVER, + Material.REDSTONE_TORCH_OFF, + Material.REDSTONE_TORCH_ON, + Material.STONE_BUTTON, + Material.TRAP_DOOR, + Material.VINE, + Material.COCOA, + Material.TRIPWIRE_HOOK, + Material.WOOD_BUTTON, + Material.IRON_TRAPDOOR, + Material.WALL_BANNER, + })); + HashSet nonSolidBlockList = new HashSet(); public void onEnable() { + this.nonSolidBlockList.addAll(nonSolidDoubleBlockList); + this.nonSolidBlockList.addAll(nonSolidSingularBlockList); + this.nonSolidBlockList.addAll(nonSolidWallMountedBlockList); + this.getCommand("clearchat").setExecutor(new CommandClearChat()); this.getCommand("console").setExecutor(new CommandConsole()); this.getCommand("destroyentities").setExecutor(new CommandDestroyEntities());