diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java index 9c341d0..1b6f158 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java @@ -45,28 +45,14 @@ public class CommandFire extends RegionToggleCommand { return region.isFire(); } - @Override - boolean toggleGlobal() { - Region.NoRegion.fire = !Region.NoRegion.fire; - return Region.NoRegion.fire; - } - @EventHandler public void onFireDamage(BlockBurnEvent e) { - Region.getRegion(e.getBlock().getLocation(), region -> { - if (region.isFire()) e.setCancelled(true); - }, () -> { - if (Region.NoRegion.fire) 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.NoRegion.fire) 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 6e6247d..5a6857b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -48,112 +48,58 @@ public class CommandFreeze extends RegionToggleCommand { return region.isFreeze(); } - @Override - boolean toggleGlobal() { - Region.NoRegion.freeze = !Region.NoRegion.freeze; - return Region.NoRegion.freeze; - } - @EventHandler public void onEntitySpawn(EntitySpawnEvent e) { - Region.getRegion(e.getLocation(), region -> { - if (region.isFreeze()) e.setCancelled(true); - }, () -> { - if (Region.NoRegion.freeze) 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.NoRegion.freeze) { - 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.NoRegion.freeze) 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.NoRegion.freeze) 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.NoRegion.freeze) 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.NoRegion.freeze) 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.NoRegion.freeze) 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.NoRegion.freeze) 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.NoRegion.freeze) 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.NoRegion.freeze) e.setCancelled(true); - }); + if (Region.getRegion(e.getDestination().getLocation()).isFreeze()) e.setCancelled(true); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index fd8fc56..980133b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -42,11 +42,7 @@ public class CommandInfo implements CommandExecutor { sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName()); Region region = Region.getRegion(player.getLocation()); - if (region == null) { - sender.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + Region.NoRegion.tnt.getName() + " §eFire§8: " + (Region.NoRegion.fire ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (Region.NoRegion.freeze ? "§aAN" : "§cAUS")); - } else { - sender.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + region.getTntMode().getName() + " §eFire§8: " + (region.isFire() ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (region.isFreeze() ? "§aAN" : "§cAUS")); - } + sender.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + region.getTntMode().getName() + " §eFire§8: " + (region.isFire() ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (region.isFreeze() ? "§aAN" : "§cAUS")); List members = BauweltMember.getMembers(BauSystem.getOwnerID()); StringBuilder membermessage = new StringBuilder().append(BauSystem.PREFIX).append("Mitglieder: "); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 252973f..caecbb6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -117,33 +117,10 @@ public class CommandTNT implements CommandExecutor, Listener { } Region region = Region.getRegion(player.getLocation()); - if (region == null) { - tntGlobalToggle(requestedMode, requestedMessage); - return false; - } tntToggle(region, requestedMode, requestedMessage); return false; } - private void tntGlobalToggle(TNTMode requestedMode, String requestedMessage) { - if (requestedMode != null && requestedMode != TNTMode.ONLY_TB) { - Region.NoRegion.tnt = requestedMode; - RegionToggleCommand.actionBar(requestedMessage); - return; - } - switch (Region.NoRegion.tnt) { - case ON: - case ONLY_TB: - Region.NoRegion.tnt = TNTMode.OFF; - RegionToggleCommand.actionBar(getDisableMessage()); - break; - case OFF: - Region.NoRegion.tnt = TNTMode.ON; - RegionToggleCommand.actionBar(getEnableMessage()); - break; - } - } - private void tntToggle(Region region, TNTMode requestedMode, String requestedMessage) { if (requestedMode != null && region.hasTestblock()) { region.setTntMode(requestedMode); @@ -172,9 +149,6 @@ public class CommandTNT implements CommandExecutor, Listener { public void onExplode(EntityExplodeEvent event) { event.blockList().removeIf(block -> { Region region = Region.getRegion(block.getLocation()); - if (region == null) { - return Region.NoRegion.tnt == TNTMode.OFF; - } if (region.getTntMode() == TNTMode.OFF) return true; if (region.getTntMode() == TNTMode.ON) return false; if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java index 6eba349..d07e013 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java @@ -52,14 +52,6 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener { } Region region = Region.getRegion(player.getLocation()); - if (region == null) { - if (toggleGlobal()) { - actionBar(getEnableMessage()); - } else { - actionBar(getDisableMessage()); - } - return false; - } if (toggle(region)) { actionBar(region, getEnableMessage()); } else { @@ -69,11 +61,11 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener { } public static void actionBar(Region region, String s) { - Bukkit.getOnlinePlayers().stream().filter(player -> region.inRegion(player.getLocation())).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s))); - } - - public static void actionBar(String s) { - Bukkit.getOnlinePlayers().stream().filter(player -> Region.getRegion(player.getLocation()) == null).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s))); + if (Region.GlobalRegion.isGlobalRegion(region)) { + Bukkit.getOnlinePlayers().stream().filter(player -> Region.getRegion(player.getLocation()) == null).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s))); + } else { + Bukkit.getOnlinePlayers().stream().filter(player -> region.inRegion(player.getLocation())).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s))); + } } abstract String getNoPermMessage(); @@ -84,6 +76,5 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener { * {@code true} for {@link #getEnableMessage()}, {@code false} for {@link #getDisableMessage()} */ abstract boolean toggle(Region region); - abstract boolean toggleGlobal(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index 316cf00..17873b7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -60,15 +60,9 @@ public class BauScoreboard implements Listener { strings.add("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())); strings.add("§2"); Region region = Region.getRegion(p.getLocation()); - if (region != null) { - strings.add("§eTNT§8: " + region.getTntMode().getName()); - strings.add("§eFreeze§8: " + (region.isFreeze() ? "§aan" : "§caus")); - strings.add("§eFire§8: " + (region.isFire() ? "§aaus" : "§can")); - } else { - strings.add("§eTNT§8: " + Region.NoRegion.tnt.getName()); - strings.add("§eFreeze§8: " + (Region.NoRegion.freeze ? "§aan" : "§caus")); - strings.add("§eFire§8: " + (Region.NoRegion.fire ? "§aaus" : "§can")); - } + strings.add("§eTNT§8: " + region.getTntMode().getName()); + strings.add("§eFreeze§8: " + (region.isFreeze() ? "§aan" : "§caus")); + strings.add("§eFire§8: " + (region.isFire() ? "§aaus" : "§can")); strings.add("§eTrace§8: " + RecordStateMachine.getRecordStatus().getName()); strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus")); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 781a0b7..28552ac 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -41,13 +41,6 @@ public class Region { private static final List regions = new ArrayList<>(); private static boolean buildArea = false; - public static class NoRegion { - private NoRegion() {} - public static TNTMode tnt = TNTMode.OFF; - public static boolean fire = false; - public static boolean freeze = false; - } - static{ YamlConfiguration config = new YamlConfiguration(); try { @@ -77,18 +70,7 @@ public class Region { for (Region region : regions) { if (region.inRegion(location)) return region; } - return null; - } - - public static void getRegion(Location location, Consumer regionConsumer, Runnable noRegion) { - boolean b = true; - for (Region region : regions) { - if (region.inRegion(location)) { - regionConsumer.accept(region); - b = false; - } - } - if (b) noRegion.run(); + return GlobalRegion.getInstance(); } private final String name; @@ -114,6 +96,16 @@ public class Region { regions.add(this); } + public Region(String name) { + this.name = name; + this.minX = 0; + this.minY = 0; + this.minZ = 0; + this.prototype = null; + this.optionsLinkedWith = null; + tntMode = TNTMode.OFF; + } + private void setLinkedRegion(Consumer regionConsumer) { if (optionsLinkedWith == null) { return; @@ -194,6 +186,49 @@ public class Region { prototype.protect(this, schem); } + public static class GlobalRegion extends Region { + + private static final GlobalRegion GLOBAL_REGION = new GlobalRegion(); + + public static GlobalRegion getInstance() { + return GLOBAL_REGION; + } + + public static boolean isGlobalRegion(Region region) { + return region == GLOBAL_REGION; + } + + public GlobalRegion() { + super("Global"); + } + + @Override + public boolean inRegion(Location l) { + return true; + } + + @Override + public boolean hasBuildRegion() { + return false; + } + + @Override + public boolean inBuildRegion(Location l) { + return false; + } + + @Override + public boolean hasTestblock() { + return false; + } + + @Override + public boolean hasProtection() { + return false; + } + + } + public static class Prototype{ private static final Map prototypes = new HashMap<>();