From 2353fb17e74a3cdb2a10a8f9084dd409bf6aa7c4 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 9 Apr 2021 16:24:47 +0200 Subject: [PATCH 1/8] Add initial Region.protect --- .../bausystem/world/regions/Region.java | 54 ++++++++++++------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java index a02edfb..723587d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java @@ -29,6 +29,7 @@ import de.steamwar.bausystem.world.Color; import de.steamwar.bausystem.world.SizedStack; import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; +import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.configuration.ConfigurationSection; @@ -133,10 +134,19 @@ public class Region { private JsonObject regionOptions = new JsonObject(); + @Getter private TNTMode tntMode = Region.buildAreaEnabled() ? TNTMode.ONLY_TB : TNTMode.OFF; + + @Getter private boolean freeze = false; + + @Getter private boolean fire = false; + @Getter + private boolean protect = false; + + @Getter private Color color = Color.YELLOW; private Region(ConfigurationSection config) { @@ -178,6 +188,10 @@ public class Region { freeze = regionOptions.getAsJsonPrimitive("freeze").getAsBoolean(); } + if (regionOptions.has("protect")) { + protect = regionOptions.getAsJsonPrimitive("protect").getAsBoolean(); + } + if (regionOptions.has("color")) { String colorName = regionOptions.getAsJsonPrimitive("color").getAsString(); try { @@ -191,10 +205,6 @@ public class Region { } } - public Color getColor() { - return color; - } - public void setColor(Color color) { this.color = color; regionOptions.add("color", new JsonPrimitive(color.name())); @@ -217,36 +227,42 @@ public class Region { } } - public TNTMode getTntMode() { - return tntMode; - } - public void setTntMode(TNTMode tntMode) { this.tntMode = tntMode; - setLinkedRegion(region -> region.tntMode = tntMode); + setLinkedRegion(region -> { + region.tntMode = tntMode; + region.regionOptions.add("tnt", new JsonPrimitive(tntMode.name())); + }); regionOptions.add("tnt", new JsonPrimitive(tntMode.name())); } - public boolean isFreeze() { - return freeze; - } - public void setFreeze(boolean freeze) { this.freeze = freeze; - setLinkedRegion(region -> region.freeze = freeze); + setLinkedRegion(region -> { + region.freeze = freeze; + region.regionOptions.add("freeze", new JsonPrimitive(freeze)); + }); regionOptions.add("freeze", new JsonPrimitive(freeze)); } - public boolean isFire() { - return fire; - } - public void setFire(boolean fire) { this.fire = fire; - setLinkedRegion(region -> region.fire = fire); + setLinkedRegion(region -> { + region.fire = fire; + region.regionOptions.add("fire", new JsonPrimitive(fire)); + }); regionOptions.add("fire", new JsonPrimitive(fire)); } + public void setProtect(boolean protect) { + this.protect = protect; + setLinkedRegion(region -> { + region.protect = protect; + region.regionOptions.add("protect", new JsonPrimitive(protect)); + }); + regionOptions.add("protect", new JsonPrimitive(protect)); + } + public Point getMinPoint(RegionType regionType, RegionExtensionType regionExtensionType) { switch (regionType) { case BUILD: -- 2.39.5 From 010bac9741013d2b10a37a12f6378055a4892982 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 9 Apr 2021 16:51:52 +0200 Subject: [PATCH 2/8] Add initial CommandProtect usability --- .../steamwar/bausystem/commands/CommandProtect.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java index 5917041..259fe14 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java @@ -48,6 +48,15 @@ public class CommandProtect extends SWCommand { if (!permissionCheck(p)) return; Region region = regionCheck(p); if (region == null) return; + if (Region.buildAreaEnabled()) { + region.setProtect(!region.isProtect()); + if (region.isProtect()) { + p.sendMessage(BauSystem.PREFIX + "§7Boden geschützt"); + } else { + p.sendMessage(BauSystem.PREFIX + "§7Boden Schutz aufgehoben"); + } + return; + } try { region.protect(null); p.sendMessage(BauSystem.PREFIX + "§7Boden geschützt"); @@ -60,6 +69,10 @@ public class CommandProtect extends SWCommand { @Register public void schematicProtectCommand(Player p, String s) { if (!permissionCheck(p)) return; + if (Region.buildAreaEnabled()) { + genericHelp(p); + return; + } Region region = regionCheck(p); if (region == null) return; Schematic schem = Schematic.getSchemFromDB(s, p.getUniqueId()); -- 2.39.5 From 4098d70a2395147f7fd3d32b1328e3d86531b0e4 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 9 Apr 2021 18:11:17 +0200 Subject: [PATCH 3/8] Add CommandProtect capabilities Add Region.getProtectYLevel --- .../bausystem/commands/CommandProtect.java | 24 ++++++++++++++++++- .../bausystem/world/regions/Region.java | 4 ++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java index 259fe14..117e8d7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java @@ -23,18 +23,26 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.Welt; import de.steamwar.bausystem.world.regions.Region; +import de.steamwar.bausystem.world.regions.RegionExtensionType; +import de.steamwar.bausystem.world.regions.RegionType; import de.steamwar.command.SWCommand; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityExplodeEvent; import java.io.IOException; import java.util.logging.Level; -public class CommandProtect extends SWCommand { +public class CommandProtect extends SWCommand implements Listener { public CommandProtect() { super("protect"); + if (Region.buildAreaEnabled()) { + Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); + } } @Register(help = true) @@ -105,4 +113,18 @@ public class CommandProtect extends SWCommand { } return region; } + + @EventHandler + public void onExplode(EntityExplodeEvent event) { + event.blockList().removeIf(block -> { + Region region = Region.getRegion(block.getLocation()); + if (!region.isProtect()) { + return false; + } + if (!region.hasProtection()) { + return false; + } + return block.getY() < region.getProtectYLevel(); + }); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java index 723587d..065f020 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/regions/Region.java @@ -326,6 +326,10 @@ public class Region { undosessions.push(prototype.protect(this, schem)); } + public int getProtectYLevel() { + return getMinPoint(RegionType.TESTBLOCK, RegionExtensionType.NORMAL).getY(); + } + public boolean hasExtensionArea(RegionType regionType) { switch (regionType) { case BUILD: -- 2.39.5 From bcc972ab6b2cf8f32d43e15f2e0b31e6193b4a0b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 9 Apr 2021 18:16:19 +0200 Subject: [PATCH 4/8] Add BauScoreboard Protect section --- .../src/de/steamwar/bausystem/world/BauScoreboard.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java index 5ba1eb3..f01e67c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/BauScoreboard.java @@ -66,6 +66,9 @@ public class BauScoreboard implements Listener { strings.add("§eFire§8: " + (region.isFire() ? "§aaus" : "§can")); strings.add("§eTrace§8: " + RecordStateMachine.getRecordStatus().getName()); strings.add("§eLoader§8: " + (AutoLoader.hasLoader(p) ? "§aan" : "§caus")); + if (region.hasProtection()) { + strings.add("§eProtect§8: " + (region.isProtect() ? "§aan" : "§caus")); + } if (RecordStateMachine.getRecordStatus().isTracing()) { strings.add("§3"); -- 2.39.5 From f95fb01eb12cdaa4c671f107b67585ebb79259ff Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 9 Apr 2021 18:43:53 +0200 Subject: [PATCH 5/8] Update CommandProtect message sending Add CommandInfo protect status --- .../de/steamwar/bausystem/commands/CommandInfo.java | 12 +++++++++--- .../steamwar/bausystem/commands/CommandProtect.java | 6 ++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index c6b245d..f3c9b31 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -20,8 +20,8 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.world.regions.Region; import de.steamwar.bausystem.world.TPSUtils; +import de.steamwar.bausystem.world.regions.Region; import de.steamwar.command.SWCommand; import de.steamwar.core.TPSWatcher; import de.steamwar.sql.BauweltMember; @@ -52,11 +52,15 @@ public class CommandInfo extends SWCommand { p.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName()); Region region = Region.getRegion(p.getLocation()); p.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + region.getTntMode().getName() + " §eFire§8: " + (region.isFire() ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (region.isFreeze() ? "§aAN" : "§cAUS")); + if (region.hasProtection()) { + p.sendMessage(BauSystem.PREFIX + "§eProtect§8: " + (region.isProtect() ? "§aAN" : "§cAUS")); + } List members = BauweltMember.getMembers(BauSystem.getOwnerID()); StringBuilder membermessage = new StringBuilder().append(BauSystem.PREFIX).append("Mitglieder: "); - for (BauweltMember member : members) { + for ( + BauweltMember member : members) { membermessage.append("§e").append(SteamwarUser.get(member.getMemberID()).getUserName()).append("§8["); membermessage.append(member.isWorldEdit() ? "§a" : "§c").append("WE").append("§8,"); membermessage.append(member.isWorld() ? "§a" : "§c").append("W").append("§8]").append(" "); @@ -64,7 +68,9 @@ public class CommandInfo extends SWCommand { p.sendMessage(membermessage.toString()); StringBuilder tpsMessage = new StringBuilder(); - tpsMessage.append(BauSystem.PREFIX).append("TPS:§e"); + tpsMessage.append(BauSystem.PREFIX). + + append("TPS:§e"); tpsMessage.append(" ").append(getTps(TPSWatcher.TPSType.ONE_SECOND)); tpsMessage.append(" ").append(getTps(TPSWatcher.TPSType.TEN_SECONDS)); if (!TPSUtils.isWarping()) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java index 117e8d7..249d512 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java @@ -23,8 +23,6 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.Welt; import de.steamwar.bausystem.world.regions.Region; -import de.steamwar.bausystem.world.regions.RegionExtensionType; -import de.steamwar.bausystem.world.regions.RegionType; import de.steamwar.command.SWCommand; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; @@ -59,9 +57,9 @@ public class CommandProtect extends SWCommand implements Listener { if (Region.buildAreaEnabled()) { region.setProtect(!region.isProtect()); if (region.isProtect()) { - p.sendMessage(BauSystem.PREFIX + "§7Boden geschützt"); + RegionUtils.actionBar(region, "§aBoden geschützt"); } else { - p.sendMessage(BauSystem.PREFIX + "§7Boden Schutz aufgehoben"); + RegionUtils.actionBar(region, "§cBoden Schutz aufgehoben"); } return; } -- 2.39.5 From f3f3fb36258767659cdbd071e2fc3c2708f6527a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 9 Apr 2021 20:36:19 +0200 Subject: [PATCH 6/8] Update CommandProtect message sending Add CommandInfo protect status --- .../src/de/steamwar/bausystem/commands/CommandInfo.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index f3c9b31..c8de3ad 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -68,9 +68,7 @@ public class CommandInfo extends SWCommand { p.sendMessage(membermessage.toString()); StringBuilder tpsMessage = new StringBuilder(); - tpsMessage.append(BauSystem.PREFIX). - - append("TPS:§e"); + tpsMessage.append(BauSystem.PREFIX).append("TPS:§e"); tpsMessage.append(" ").append(getTps(TPSWatcher.TPSType.ONE_SECOND)); tpsMessage.append(" ").append(getTps(TPSWatcher.TPSType.TEN_SECONDS)); if (!TPSUtils.isWarping()) { -- 2.39.5 From 364267ae3c2997f2412cc9c6d33abb879fa73189 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 9 Apr 2021 20:36:34 +0200 Subject: [PATCH 7/8] Update CommandProtect message sending Add CommandInfo protect status --- .../src/de/steamwar/bausystem/commands/CommandInfo.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index c8de3ad..b183140 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java @@ -59,8 +59,7 @@ public class CommandInfo extends SWCommand { List members = BauweltMember.getMembers(BauSystem.getOwnerID()); StringBuilder membermessage = new StringBuilder().append(BauSystem.PREFIX).append("Mitglieder: "); - for ( - BauweltMember member : members) { + for (BauweltMember member : members) { membermessage.append("§e").append(SteamwarUser.get(member.getMemberID()).getUserName()).append("§8["); membermessage.append(member.isWorldEdit() ? "§a" : "§c").append("WE").append("§8,"); membermessage.append(member.isWorld() ? "§a" : "§c").append("W").append("§8]").append(" "); -- 2.39.5 From a6e32e08cfd3ff3198875f205a0751273b97db5a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 10 Apr 2021 18:40:11 +0200 Subject: [PATCH 8/8] Simplify CommandProtect --- .../steamwar/bausystem/commands/CommandProtect.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java index 249d512..1ac7468 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java @@ -114,14 +114,11 @@ public class CommandProtect extends SWCommand implements Listener { @EventHandler public void onExplode(EntityExplodeEvent event) { + Region region = Region.getRegion(event.getLocation()); + if (!region.isProtect() && !region.hasProtection()) { + return; + } event.blockList().removeIf(block -> { - Region region = Region.getRegion(block.getLocation()); - if (!region.isProtect()) { - return false; - } - if (!region.hasProtection()) { - return false; - } return block.getY() < region.getProtectYLevel(); }); } -- 2.39.5