From 23fba7074d4f60f8406dd4661f197665eba2ef78 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 17 Sep 2023 16:37:20 +0200 Subject: [PATCH] Add TNTMode.ONLY_BUILD Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 7 +++- BauSystem_Main/src/BauSystem_de.properties | 6 +++- .../bausystem/features/region/TNTCommand.java | 9 +++++ .../features/region/TNTListener.java | 33 ++++++++++--------- .../features/region/items/TntBauGuiItem.java | 20 ++++++++--- .../features/script/lua/libs/RegionLib.java | 1 + .../region/flags/flagvalues/TNTMode.java | 3 +- SCRIPT.md | 11 ++++--- sw.def.lua | 3 ++ 9 files changed, 66 insertions(+), 27 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 667879e3..01684b52 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -60,6 +60,7 @@ FLAG_PROTECT_INACTIVE = §coff FLAG_TNT_ALLOW = §aon FLAG_TNT_DENY = §coff FLAG_TNT_ONLY_TB = §7no §ebuild area +FLAG_TNT_ONLY_BUILD = §7no §etestblock area FLAG_ITEMS_ACTIVE = §aon FLAG_ITEMS_INACTIVE = §coff @@ -790,10 +791,12 @@ REGION_ITEM_RESET=§eReset REGION_ITEM_TESTBLOCK=§eDummy REGION_ITEM_TNT_OFF=§7TNT: §eDeactivated REGION_ITEM_TNT_ONLY_TB=§7TNT: §eonly dummy +REGION_ITEM_TNT_ONLY_BUILD=§7TNT: §eonly build REGION_ITEM_TNT_ON=§7TNT: §eActivated REGION_ITEM_SELECTOR_TITLE=Tnt Mode REGION_ITEM_SELECTOR_ON=§eActivate REGION_ITEM_SELECTOR_ONLY_TB=§eonly dummy +REGION_ITEM_SELECTOR_ONLY_BUILD=§eonly build REGION_ITEM_SELECTOR_OFF=§eDeactivate #Region REGION_COLOR_HELP_COLOR=§8/§ecolor §8[§7Color§8] §8- §7Sets the color of the region @@ -877,8 +880,10 @@ REGION_TNT_HELP_MODE=§8/§etnt §8[§7Mode§8] §8- §7Set TNT behaviour to a g REGION_TNT_ON=§aTNT-Damage activated REGION_TNT_OFF=§cTNT-Damage deactivated REGION_TNT_TB=§aTNT-Damage activated outside the building area +REGION_TNT_BUILD=§aTNT-Damage activated outside the testblok area REGION_TNT_NO_PERMS=§cYou are not allowed to toggle tnt damage here -REGION_TNT_BUILD=§cAn explosion would have destroyed blocks in the building area +REGION_TNT_BUILD_DESTROY=§cAn explosion would have destroyed blocks in the building area +REGION_TNT_TB_DESTROY=§cAn explosion would have destroyed blocks in the testblock area AFK_KICK_MESSAGE=§cNothing happened on this server for 5 minutes. AFK_WARNING_MESSAGE=§cThis server will stop in one minute if you remain inactive diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 7d16c0d7..540edc2f 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -60,6 +60,7 @@ FLAG_PROTECT_INACTIVE = §caus FLAG_TNT_ALLOW = §aan FLAG_TNT_DENY = §caus FLAG_TNT_ONLY_TB = §7Kein §eBaurahmen +FLAG_TNT_ONLY_BUILD = §7Kein §eTestblock FLAG_ITEMS_ACTIVE = §aan FLAG_ITEMS_INACTIVE = §caus @@ -754,10 +755,12 @@ REGION_ITEM_RESET=§eReset REGION_ITEM_TESTBLOCK=§eTestblock REGION_ITEM_TNT_OFF=§7TNT: §eAusgeschaltet REGION_ITEM_TNT_ONLY_TB=§7TNT: §enur Testblock +REGION_ITEM_TNT_ONLY_BUILD=§7TNT: §enur Baubereich REGION_ITEM_TNT_ON=§7TNT: §eEingeschaltet REGION_ITEM_SELECTOR_TITLE=Tnt Modus REGION_ITEM_SELECTOR_ON=§eEinschalten REGION_ITEM_SELECTOR_ONLY_TB=§enur Testblock +REGION_ITEM_SELECTOR_ONLY_BUILD=§enur Baubereich REGION_ITEM_SELECTOR_OFF=§eAusschalten #Region REGION_COLOR_HELP_COLOR=§8/§ecolor §8[§7Color§8] §8- §7Setze die Farbe der Region @@ -842,7 +845,8 @@ REGION_TNT_ON=§aTNT-Schaden aktiviert REGION_TNT_OFF=§cTNT-Schaden deaktiviert REGION_TNT_TB=§aTNT-Schaden außerhalb Baurahmen aktiviert REGION_TNT_NO_PERMS=§cDu darfst hier nicht TNT-Schaden (de-)aktivieren -REGION_TNT_BUILD=§cEine Explosion hätte Blöcke im Baubereich zerstört +REGION_TNT_BUILD_DESTROY=§cEine Explosion hätte Blöcke im Baubereich zerstört +REGION_TNT_TB_DESTROY=§cEine Explosion hätte Blöcke im Testblockbereich zerstört AFK_KICK_MESSAGE=§cAuf diesem Server ist seit 5 Minuten nichts passiert. AFK_WARNING_MESSAGE=§cDieser Server wird bei weiterer Inaktivität in einer Minute gestoppt diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTCommand.java index f8d6fd40..af9f3837 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTCommand.java @@ -74,6 +74,9 @@ public class TNTCommand extends SWCommand { case ONLY_TB: requestedMessage = getTestblockEnableMessage(); break; + case ONLY_BUILD: + requestedMessage = getBuildEnableMessage(); + break; } tntToggle(region, tntMode, requestedMessage); } @@ -89,6 +92,7 @@ public class TNTCommand extends SWCommand { Map tntModeMap = new HashMap<>(tntModeMapReduced); tntModeMap.put("testblock", TNTMode.ONLY_TB); tntModeMap.put("tb", TNTMode.ONLY_TB); + tntModeMap.put("build", TNTMode.ONLY_BUILD); return new TypeMapper() { @Override @@ -125,6 +129,10 @@ public class TNTCommand extends SWCommand { return "REGION_TNT_TB"; } + private String getBuildEnableMessage() { + return "REGION_TNT_BUILD"; + } + private void tntToggle(Region region, TNTMode requestedMode, String requestedMessage) { if (requestedMode != null && region.hasType(RegionType.TESTBLOCK) && region.hasType(RegionType.BUILD)) { region.set(Flag.TNT, requestedMode); @@ -134,6 +142,7 @@ public class TNTCommand extends SWCommand { switch (region.getPlain(Flag.TNT, TNTMode.class)) { case ALLOW: case ONLY_TB: + case ONLY_BUILD: region.set(Flag.TNT, TNTMode.DENY); RegionUtils.actionBar(region, getDisableMessage()); break; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java index d65a8750..a8d34de5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java @@ -28,12 +28,8 @@ import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.linkage.Linked; -import de.steamwar.linkage.LinkedInstance; -import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Player; -import org.bukkit.event.Event; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -47,22 +43,29 @@ import java.util.concurrent.atomic.AtomicBoolean; public class TNTListener implements Listener, ScoreboardElement { private void explode(List blockList) { - AtomicBoolean inBuild = new AtomicBoolean(); blockList.removeIf(block -> { Region region = Region.getRegion(block.getLocation()); TNTMode value = region.getPlain(Flag.TNT); if (value == TNTMode.ALLOW) { return false; - } - if (region.hasType(RegionType.BUILD) && region.inRegion(block.getLocation(), RegionType.BUILD, RegionExtensionType.NORMAL)) { - RegionUtils.actionBar(region, "REGION_TNT_BUILD"); - inBuild.set(true); - return true; - } - if (region.hasType(RegionType.BUILD) && region.inRegion(block.getLocation(), RegionType.BUILD, RegionExtensionType.EXTENSION)) { - RegionUtils.actionBar(region, "REGION_TNT_BUILD"); - inBuild.set(true); - return true; + } else if (value == TNTMode.ONLY_TB) { + if (region.hasType(RegionType.BUILD) && region.inRegion(block.getLocation(), RegionType.BUILD, RegionExtensionType.NORMAL)) { + RegionUtils.actionBar(region, "REGION_TNT_BUILD_DESTROY"); + return true; + } + if (region.hasType(RegionType.BUILD) && region.inRegion(block.getLocation(), RegionType.BUILD, RegionExtensionType.EXTENSION)) { + RegionUtils.actionBar(region, "REGION_TNT_BUILD_DESTROY"); + return true; + } + } else if (value == TNTMode.ONLY_BUILD) { + if (region.hasType(RegionType.TESTBLOCK) && region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.NORMAL)) { + RegionUtils.actionBar(region, "REGION_TNT_TB_DESTROY"); + return true; + } + if (region.hasType(RegionType.TESTBLOCK) && region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)) { + RegionUtils.actionBar(region, "REGION_TNT_TB_DESTROY"); + return true; + } } return value == TNTMode.DENY; }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TntBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TntBauGuiItem.java index f4626cce..673a9295 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TntBauGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TntBauGuiItem.java @@ -25,6 +25,7 @@ import de.steamwar.bausystem.linkage.specific.BauGuiItem; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.flagvalues.TNTMode; +import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import de.steamwar.linkage.Linked; @@ -47,6 +48,8 @@ public class TntBauGuiItem extends BauGuiItem { return new SWItem(Material.MINECART, BauSystem.MESSAGE.parse("REGION_ITEM_TNT_OFF", player)).getItemStack(); case ONLY_TB: return new SWItem(Material.TNT_MINECART, BauSystem.MESSAGE.parse("REGION_ITEM_TNT_ONLY_TB", player)).getItemStack(); + case ONLY_BUILD: + return new SWItem(Material.OBSIDIAN, BauSystem.MESSAGE.parse("REGION_ITEM_TNT_ONLY_BUILD", player)).getItemStack(); default: return new SWItem(Material.TNT, BauSystem.MESSAGE.parse("REGION_ITEM_TNT_ON", player)).getItemStack(); } @@ -60,8 +63,10 @@ public class TntBauGuiItem extends BauGuiItem { updateTntMode(TNTMode.ALLOW, p); break; case ALLOW: - updateTntMode(TNTMode.ONLY_TB, p); - break; + if (Region.getRegion(p.getLocation()).hasType(RegionType.BUILD) && Region.getRegion(p.getLocation()).hasType(RegionType.TESTBLOCK)) { + updateTntMode(TNTMode.ONLY_TB, p); + break; + } default: updateTntMode(TNTMode.DENY, p); } @@ -72,11 +77,15 @@ public class TntBauGuiItem extends BauGuiItem { updateTntMode(TNTMode.ALLOW, p); p.closeInventory(); })); - if (!Region.getRegion(p.getLocation()).isGlobal()) { - selector.setItem(4, new SWItem(Material.TNT_MINECART, BauSystem.MESSAGE.parse("REGION_ITEM_SELECTOR_ONLY_TB", p), clickType -> { + if (Region.getRegion(p.getLocation()).hasType(RegionType.BUILD) && Region.getRegion(p.getLocation()).hasType(RegionType.TESTBLOCK)) { + selector.setItem(3, new SWItem(Material.TNT_MINECART, BauSystem.MESSAGE.parse("REGION_ITEM_SELECTOR_ONLY_TB", p), clickType -> { updateTntMode(TNTMode.ONLY_TB, p); p.closeInventory(); })); + selector.setItem(5, new SWItem(Material.OBSIDIAN, BauSystem.MESSAGE.parse("REGION_ITEM_SELECTOR_ONLY_BUILD", p), clickType -> { + updateTntMode(TNTMode.ONLY_BUILD, p); + p.closeInventory(); + })); } selector.setItem(7, new SWItem(Material.MINECART, BauSystem.MESSAGE.parse("REGION_ITEM_SELECTOR_OFF", p), clickType -> { updateTntMode(TNTMode.DENY, p); @@ -92,6 +101,9 @@ public class TntBauGuiItem extends BauGuiItem { case ONLY_TB: p.performCommand("tnt tb"); break; + case ONLY_BUILD: + p.performCommand("tnt build"); + break; case ALLOW: p.performCommand("tnt on"); break; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java index 0f3104cf..626e6510 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java @@ -55,6 +55,7 @@ public class RegionLib implements LuaLib { tntLib.set("mode", getter(() -> region.get().getPlain(Flag.TNT, TNTMode.class).name())); tntLib.set("enabled", getter(() -> region.get().getPlain(Flag.TNT, TNTMode.class) != TNTMode.DENY)); tntLib.set("onlyTb", getter(() -> region.get().getPlain(Flag.TNT, TNTMode.class) == TNTMode.ONLY_TB)); + tntLib.set("onlyBuild", getter(() -> region.get().getPlain(Flag.TNT, TNTMode.class) == TNTMode.ONLY_BUILD)); table.set("tnt", tntLib); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/TNTMode.java b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/TNTMode.java index f6f2706d..9b05d6b5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/TNTMode.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/TNTMode.java @@ -29,7 +29,8 @@ public enum TNTMode implements Flag.Value { ALLOW("FLAG_TNT_ALLOW"), DENY("FLAG_TNT_DENY"), - ONLY_TB("FLAG_TNT_ONLY_TB"); + ONLY_TB("FLAG_TNT_ONLY_TB"), + ONLY_BUILD("FLAG_TNT_ONLY_BUILD"); private static TNTMode[] values; private final String chatValue; diff --git a/SCRIPT.md b/SCRIPT.md index bd4edd7c..ae9cb181 100644 --- a/SCRIPT.md +++ b/SCRIPT.md @@ -144,11 +144,12 @@ Es gibt folgende weitere Module: Das `tnt`-Modul stellt Funktionen zur Verfügung, die den TNT-Modus in der Region des Spielers betreffen. Es gibt folgende Funktionen: -| Name | Signature | Beschreibung | -|-----------|--------------------|-------------------------------------------------------------------------------------| -| `mode` | mode(): String | Gibt den Aktuellen TNT-Modus zurück, die werte sind: `ALLOW`, `DENY` oder `ONLY_TB` | -| `enabled` | enabled(): Boolean | Gibt zurück, ob der TNT-Modus in der Region des Spielers aktiviert ist oder nicht | -| `onlyTb` | onlyTb(): Boolean | Gibt zurück, ob der TNT-Modus auf Only-Tb ist | +| Name | Signature | Beschreibung | +|-------------|----------------------|-------------------------------------------------------------------------------------| +| `mode` | mode(): String | Gibt den Aktuellen TNT-Modus zurück, die werte sind: `ALLOW`, `DENY` oder `ONLY_TB` | +| `enabled` | enabled(): Boolean | Gibt zurück, ob der TNT-Modus in der Region des Spielers aktiviert ist oder nicht | +| `onlyTb` | onlyTb(): Boolean | Gibt zurück, ob der TNT-Modus auf Only-Tb ist | +| `onlyBuild` | onlyBuild(): Boolean | Gibt zurück, ob der TNT-Modus auf Only-Build ist | #### trace diff --git a/sw.def.lua b/sw.def.lua index d1570fd8..cf343c4e 100644 --- a/sw.def.lua +++ b/sw.def.lua @@ -167,6 +167,9 @@ function tnt.enabled() return nil end ---@return boolean function tnt.onlyTb() return nil end +---@return boolean +function tnt.onlyBuild() return nil end + ---@class trace local trace = {}