From ddcbec834e9fdd03f20ef85ff52cd43664b09e65 Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 25 Jan 2021 17:37:21 +0100 Subject: [PATCH] Fix last stuff --- .../bausystem/commands/CommandInfo.java | 2 +- .../bausystem/commands/CommandProtect.java | 2 +- .../bausystem/commands/CommandReset.java | 2 +- .../bausystem/commands/CommandTestblock.java | 2 +- .../commands/RegionToggleCommand.java | 2 +- .../bausystem/world/BauScoreboard.java | 2 +- .../de/steamwar/bausystem/world/Region.java | 64 ++++++------------- .../bausystem/world/ScriptListener.java | 2 +- 8 files changed, 25 insertions(+), 53 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index fa3ea86..fd8fc56 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -41,7 +41,7 @@ public class CommandInfo implements CommandExecutor { Player player = (Player) sender; sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName()); - Region region = Region.getRegion(player); + 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 { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java index 6adcd6b..b6a34d0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java @@ -45,7 +45,7 @@ public class CommandProtect implements CommandExecutor { return false; } - Region region = Region.getRegion(player); + Region region = Region.getRegion(player.getLocation()); if (region == null || !region.hasProtection()) { player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner (M)WG-Region"); return false; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java index a75be05..934a383 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java @@ -45,7 +45,7 @@ public class CommandReset implements CommandExecutor { return false; } - Region region = Region.getRegion(player); + Region region = Region.getRegion(player.getLocation()); if (region == null) { player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region"); return false; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java index e44d889..87ffbf3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java @@ -45,7 +45,7 @@ public class CommandTestblock implements CommandExecutor { return false; } - Region region = Region.getRegion(player); + Region region = Region.getRegion(player.getLocation()); if (region == null || !region.hasTestblock()) { player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region"); return false; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java index 5661ec5..49e36b8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java @@ -51,7 +51,7 @@ public abstract class RegionToggleCommand implements CommandExecutor, Listener { return false; } - Region region = Region.getRegion(player); + Region region = Region.getRegion(player.getLocation()); if (region == null) { if (toggleGlobal()) { actionBar(player, getEnableMessage()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index 3a9ae2a..316cf00 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -59,7 +59,7 @@ public class BauScoreboard implements Listener { strings.add("§1"); strings.add("§eUhrzeit§8: §7" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())); strings.add("§2"); - Region region = Region.getRegion(p); + Region region = Region.getRegion(p.getLocation()); if (region != null) { strings.add("§eTNT§8: " + region.getTntMode().getName()); strings.add("§eFreeze§8: " + (region.isFreeze() ? "§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 6388c0b..590e033 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -29,7 +29,6 @@ import org.bukkit.Location; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; import java.io.File; import java.io.IOException; @@ -74,10 +73,6 @@ public class Region { return buildArea; } - public static Region getRegion(Player player) { - return getRegion(player.getLocation()); - } - public static Region getRegion(Location location) { for (Region region : regions) { if (region.inRegion(location)) return region; @@ -93,20 +88,7 @@ public class Region { b = false; } } - if (b) { - noRegion.run(); - } - } - - public static List getRegions(){ - return regions; - } - - private static Region getRegionByName(String name) { - for (Region region : regions) { - if (region.name.equals(name)) return region; - } - return null; + if (b) noRegion.run(); } private final String name; @@ -131,9 +113,20 @@ public class Region { regions.add(this); } - private void link() { - if (optionsLinkedWith != null && linkedRegion == null) { - linkedRegion = getRegionByName(optionsLinkedWith); + private void setLinkedRegion(Consumer regionConsumer) { + if (optionsLinkedWith == null) { + return; + } + if (linkedRegion != null) { + regionConsumer.accept(linkedRegion); + return; + } + for (Region region : regions) { + if (region.name.equals(name)) { + linkedRegion = region; + regionConsumer.accept(linkedRegion); + return; + } } } @@ -143,14 +136,7 @@ public class Region { public void setTntMode(TNTMode tntMode) { this.tntMode = tntMode; - link(); - if (linkedRegion != null) { - linkedRegion.setTntModeOther(tntMode); - } - } - - private void setTntModeOther(TNTMode tntMode) { - this.tntMode = tntMode; + setLinkedRegion(region -> region.tntMode = tntMode); } public boolean isFreeze() { @@ -159,14 +145,7 @@ public class Region { public void setFreeze(boolean freeze) { this.freeze = freeze; - link(); - if (linkedRegion != null) { - linkedRegion.setFreezeOther(freeze); - } - } - - public void setFreezeOther(boolean freeze) { - this.freeze = freeze; + setLinkedRegion(region -> region.freeze = freeze); } public boolean isFire() { @@ -175,14 +154,7 @@ public class Region { public void setFire(boolean fire) { this.fire = fire; - link(); - if (linkedRegion != null) { - linkedRegion.setFireOther(fire); - } - } - - public void setFireOther(boolean fire) { - this.fire = fire; + setLinkedRegion(region -> region.fire = fire); } public boolean inRegion(Location l){ diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java index 0bc9897..60c3121 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -282,7 +282,7 @@ public class ScriptListener implements Listener { } private static int getValue(ScriptExecutor scriptExecutor, String key) { - Region region = Region.getRegion(scriptExecutor.player); + Region region = Region.getRegion(scriptExecutor.player.getLocation()); switch (key) { case "trace": return RecordStateMachine.getRecordStatus().isTracing() ? 1 : 0;