diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java index c6b245d..b183140 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,6 +52,9 @@ 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: "); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java index 5917041..1ac7468 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java @@ -27,14 +27,20 @@ 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) @@ -48,6 +54,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()) { + RegionUtils.actionBar(region, "§aBoden geschützt"); + } else { + RegionUtils.actionBar(region, "§cBoden Schutz aufgehoben"); + } + return; + } try { region.protect(null); p.sendMessage(BauSystem.PREFIX + "§7Boden geschützt"); @@ -60,6 +75,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()); @@ -92,4 +111,15 @@ public class CommandProtect extends SWCommand { } return region; } + + @EventHandler + public void onExplode(EntityExplodeEvent event) { + Region region = Region.getRegion(event.getLocation()); + if (!region.isProtect() && !region.hasProtection()) { + return; + } + event.blockList().removeIf(block -> { + return block.getY() < region.getProtectYLevel(); + }); + } } 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"); 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 f762e02..d9860f3 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: @@ -310,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: