From 4d4d01893aeddf90b7b8e478bf82af88822147cd Mon Sep 17 00:00:00 2001 From: mathiascode Date: Sun, 13 Oct 2019 16:14:25 +0300 Subject: [PATCH] Push WIP physics code --- src/main/java/pw/kaboom/extras/Main.java | 6 +- .../extras/modules/block/BlockCheck.java | 25 +------- .../extras/modules/block/BlockPhysics.java | 59 +++++++++---------- .../extras/modules/entity/EntitySpawn.java | 2 + .../modules/player/PlayerConnection.java | 10 +++- 5 files changed, 44 insertions(+), 58 deletions(-) diff --git a/src/main/java/pw/kaboom/extras/Main.java b/src/main/java/pw/kaboom/extras/Main.java index 840fa89..62407f5 100644 --- a/src/main/java/pw/kaboom/extras/Main.java +++ b/src/main/java/pw/kaboom/extras/Main.java @@ -479,7 +479,6 @@ public class Main extends JavaPlugin { Material.OXEYE_DAISY, Material.BROWN_MUSHROOM, Material.RED_MUSHROOM, - Material.FIRE, Material.WHEAT, Material.RAIL, Material.STONE_PRESSURE_PLATE, @@ -541,6 +540,7 @@ public class Main extends JavaPlugin { Collections.addAll( nonSolidWallMountedBlockList, + Material.FIRE, Material.TORCH, Material.WALL_TORCH, Material.LADDER, @@ -603,7 +603,9 @@ public class Main extends JavaPlugin { Material.HORN_CORAL_FAN, Material.HORN_CORAL_WALL_FAN, Material.TUBE_CORAL_FAN, - Material.TUBE_CORAL_WALL_FAN + Material.TUBE_CORAL_WALL_FAN, + Material.CHORUS_FLOWER, + Material.CHORUS_PLANT ); Collections.addAll( 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 d02386b..2217727 100644 --- a/src/main/java/pw/kaboom/extras/modules/block/BlockCheck.java +++ b/src/main/java/pw/kaboom/extras/modules/block/BlockCheck.java @@ -51,27 +51,4 @@ class BlockCheck implements Listener { event.setCancelled(true); } } -} - -/*class TileEntityCheck extends BukkitRunnable { - private Main main; - public TileEntityCheck(Main main) { - this.main = main; - } - - public void run() { - for (final World world : Bukkit.getServer().getWorlds()) { - for (final Chunk chunk : world.getLoadedChunks()) { - try { - chunk.getTileEntities(); - } catch (Exception e) { - new BukkitRunnable() { - public void run() { - world.regenerateChunk(chunk.getX(), chunk.getZ()); - } - }.runTask(main); - } - } - } - } -}*/ +} \ No newline at end of file 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 b49549b..f92d2bd 100644 --- a/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java +++ b/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java @@ -60,29 +60,28 @@ class BlockPhysics implements Listener { } continue; + } else { + event.setCancelled(true); + return; } - break; } } } - - if (blockCount == 300) { - event.setCancelled(true); - } } @EventHandler void onBlockPhysics(BlockPhysicsEvent event) { - final Material material = event.getChangedType(); + final Material material = event.getSourceBlock().getType(); if (material == Material.FARMLAND) { event.setCancelled(true); } else if (material == Material.LAVA || material == Material.WATER) { - final Block block = event.getBlock(); + final Block block = event.getSourceBlock(); final World world = block.getWorld(); final 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++) { @@ -98,17 +97,17 @@ class BlockPhysics implements Listener { } continue; + } else { + event.setCancelled(true); + return; } - break; } } } - - if (blockCount == 300) { - block.setType(Material.AIR, false); - } - } else if (Main.nonSolidWallMountedBlockList.contains(material)) { - final Block block = event.getBlock(); + } else if (Main.nonSolidBlockList.contains(material) || + material == Material.AIR || + material == Material.CAVE_AIR) { + final Block block = event.getSourceBlock(); final World world = block.getWorld(); final int radius = 5; int blockCount = 0; @@ -120,29 +119,25 @@ class BlockPhysics implements Listener { final Location blockLocation = new Location(world, block.getX() + x, block.getY() + y, block.getZ() + z); final Block coordBlock = world.getBlockAt(blockLocation); - if (coordBlock.getType() == material || - Main.nonSolidWallMountedBlockList.contains(coordBlock.getType())) { + if (Main.nonSolidBlockList.contains(coordBlock.getType())) { blockCount++; } continue; + } else { + for (BlockFace face : BlockFace.values()) { + if (Main.nonSolidBlockList.contains(block.getRelative(face).getType())) { + event.setCancelled(true); + return; + } + } + return; } - break; } } } - - if (blockCount == 42) { - Material materialReplacement = Material.AIR; - - if (Main.nonSolidWaterBlockList.contains(material)) { - materialReplacement = Material.WATER; - } - - block.setType(materialReplacement, false); - } - } else if (Main.nonSolidDoubleBlockList.contains(material)) { - final Block block = event.getBlock(); + } /*else if (Main.nonSolidDoubleBlockList.contains(material)) { + final Block block = event.getSourceBlock(); if (Main.nonSolidDoubleBlockList.contains(block.getRelative(BlockFace.DOWN).getType())) { event.setCancelled(true); @@ -171,10 +166,11 @@ class BlockPhysics implements Listener { break; } + event.setCancelled(true); block.setType(materialReplacement, false); } } else if (Main.nonSolidSingularBlockList.contains(material)) { - final Block block = event.getBlock(); + final Block block = event.getSourceBlock(); if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR || (Main.nonSolidWaterBlockList.contains(material) && @@ -191,9 +187,10 @@ class BlockPhysics implements Listener { materialReplacement = Material.WATER; } + event.setCancelled(true); block.setType(materialReplacement, false); } - } + }*/ } @EventHandler 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 f3bf4dd..e190744 100644 --- a/src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java +++ b/src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java @@ -69,7 +69,9 @@ class EntitySpawn implements Listener { @EventHandler void onBlockDispense(BlockDispenseEvent event) { + System.out.println("lol"); try { + event.getBlock().getState(); event.getItem().getItemMeta(); } catch (Exception exception) { event.setCancelled(true); diff --git a/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java b/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java index b49434f..b74a3e6 100644 --- a/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java +++ b/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java @@ -13,6 +13,7 @@ import org.bukkit.ChatColor; import org.bukkit.Chunk; import org.bukkit.World; +import org.bukkit.block.BlockState; import org.bukkit.block.banner.Pattern; import org.bukkit.entity.Player; @@ -149,7 +150,14 @@ class PlayerConnection implements Listener { for (final Chunk chunk : world.getLoadedChunks()) { try { - if (chunk.getTileEntities(false).length == 0); + int data = 0; + for (BlockState block : chunk.getTileEntities()) { + data = data + block.getBlockData().getAsString().length(); + } + + if (data > 1285579) { + world.regenerateChunk(chunk.getX(), chunk.getZ()); + } } catch (Exception exception) { world.regenerateChunk(chunk.getX(), chunk.getZ()); }