From 97d626fcb3ef23eaaabf7e21fec2eda3f6c76132 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 21:08:59 +0100 Subject: [PATCH] Simplify RegionSystem --- .../bausystem/commands/CommandFire.java | 8 +-- .../bausystem/commands/CommandFreeze.java | 52 ++++++------------- .../de/steamwar/bausystem/world/Region.java | 26 ---------- 3 files changed, 18 insertions(+), 68 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java index 8dcf312..1b6f158 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java @@ -47,16 +47,12 @@ public class CommandFire extends RegionToggleCommand { @EventHandler public void onFireDamage(BlockBurnEvent e) { - Region.getRegion(e.getBlock().getLocation(), region -> { - if (region.isFire()) e.setCancelled(true); - }); + if (Region.getRegion(e.getBlock().getLocation()).isFire()) e.setCancelled(true); } @EventHandler public void onFireSpread(BlockSpreadEvent e){ - Region.getRegion(e.getBlock().getLocation(), region -> { - if (region.isFire()) e.setCancelled(true); - }); + if (Region.getRegion(e.getBlock().getLocation()).isFire()) e.setCancelled(true); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 37c7a60..2835e7c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -27,6 +27,8 @@ import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.inventory.InventoryMoveItemEvent; +import java.sql.Ref; + public class CommandFreeze extends RegionToggleCommand { @Override @@ -50,78 +52,56 @@ public class CommandFreeze extends RegionToggleCommand { @EventHandler public void onEntitySpawn(EntitySpawnEvent e) { - Region.getRegion(e.getLocation(), region -> { - if (region.isFreeze()) e.setCancelled(true); - }); + if (Region.getRegion(e.getLocation()).isFreeze()) e.setCancelled(true); } @EventHandler public void onBlockCanBuild(BlockCanBuildEvent e) { if (!e.isBuildable()) return; - Region.getRegion(e.getBlock().getLocation(), region -> { - if (!region.isFreeze()) { - return; - } - if (e.getMaterial() == Material.TNT) { - e.setBuildable(false); - e.getBlock().setType(Material.TNT, false); - } - }); + if (!Region.getRegion(e.getBlock().getLocation()).isFreeze()) return; + if (e.getMaterial() == Material.TNT) { + e.setBuildable(false); + e.getBlock().setType(Material.TNT, false); + } } @EventHandler public void onEntityChangeBlock(EntityChangeBlockEvent e) { - Region.getRegion(e.getBlock().getLocation(), region -> { - if (region.isFreeze()) e.setCancelled(true); - }); + if (Region.getRegion(e.getBlock().getLocation()).isFreeze()) e.setCancelled(true); } @EventHandler public void onPhysicsEvent(BlockPhysicsEvent e){ - Region.getRegion(e.getBlock().getLocation(), region -> { - if (region.isFreeze()) e.setCancelled(true); - }); + if (Region.getRegion(e.getBlock().getLocation()).isFreeze()) e.setCancelled(true); } @EventHandler public void onPistonExtend(BlockPistonExtendEvent e){ - Region.getRegion(e.getBlock().getLocation(), region -> { - if (region.isFreeze()) e.setCancelled(true); - }); + if (Region.getRegion(e.getBlock().getLocation()).isFreeze()) e.setCancelled(true); } @EventHandler public void onPistonRetract(BlockPistonRetractEvent e){ - Region.getRegion(e.getBlock().getLocation(), region -> { - if (region.isFreeze()) e.setCancelled(true); - }); + if (Region.getRegion(e.getBlock().getLocation()).isFreeze()) e.setCancelled(true); } @EventHandler public void onBlockGrow(BlockGrowEvent e){ - Region.getRegion(e.getBlock().getLocation(), region -> { - if (region.isFreeze()) e.setCancelled(true); - }); + if (Region.getRegion(e.getBlock().getLocation()).isFreeze()) e.setCancelled(true); } @EventHandler public void onRedstoneEvent(BlockRedstoneEvent e){ - Region.getRegion(e.getBlock().getLocation(), region -> { - if (region.isFreeze()) e.setNewCurrent(e.getOldCurrent()); - }); + if (Region.getRegion(e.getBlock().getLocation()).isFreeze()) e.setNewCurrent(e.getOldCurrent()); } @EventHandler public void onBlockDispense(BlockDispenseEvent e){ - Region.getRegion(e.getBlock().getLocation(), region -> { - if (region.isFreeze()) e.setCancelled(true); - }); + if (Region.getRegion(e.getBlock().getLocation()).isFreeze()) e.setCancelled(true); } @EventHandler public void onInventoryMoveEvent(InventoryMoveItemEvent e){ - Region.getRegion(e.getDestination().getLocation(), region -> { - if (region.isFreeze()) e.setCancelled(true); - }); + if (Region.getRegion(e.getDestination().getLocation()).isFreeze()) e.setCancelled(true); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index ff9f130..28552ac 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -73,17 +73,6 @@ public class Region { return GlobalRegion.getInstance(); } - public static void getRegion(Location location, Consumer regionConsumer) { - boolean b = true; - for (Region region : regions) { - if (region.inRegion(location)) { - regionConsumer.accept(region); - b = false; - } - } - if (b) regionConsumer.accept(GlobalRegion.getInstance()); - } - private final String name; private final int minX; private final int minY; @@ -228,31 +217,16 @@ public class Region { return false; } - @Override - public void fastreset() { - - } - @Override public boolean hasTestblock() { return false; } - @Override - public void resetTestblock(Schematic schem) throws IOException, NoClipboardException { - - } - @Override public boolean hasProtection() { return false; } - @Override - public void protect(Schematic schem) throws IOException, NoClipboardException { - - } - } public static class Prototype{