diff --git a/BauSystem/BauSystem_Main/src/BauSystem.properties b/BauSystem/BauSystem_Main/src/BauSystem.properties index e7bf15eb..7ae8298b 100644 --- a/BauSystem/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem/BauSystem_Main/src/BauSystem.properties @@ -738,12 +738,10 @@ 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 diff --git a/BauSystem/BauSystem_Main/src/BauSystem_de.properties b/BauSystem/BauSystem_Main/src/BauSystem_de.properties index 101eba76..1bcce497 100644 --- a/BauSystem/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem/BauSystem_Main/src/BauSystem_de.properties @@ -681,12 +681,10 @@ 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 diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTCommand.java index df5bd796..97abf0bc 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTCommand.java @@ -72,9 +72,6 @@ public class TNTCommand extends SWCommand { case ONLY_TB: requestedMessage = getTestblockEnableMessage(); break; - case ONLY_BUILD: - requestedMessage = getBuildEnableMessage(); - break; } tntToggle(region, tntMode, requestedMessage); } @@ -90,9 +87,8 @@ 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() { + return new TypeMapper<>() { @Override public List tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { Region region = Region.getRegion(((Player) sender).getLocation()); @@ -140,7 +136,6 @@ public class TNTCommand extends SWCommand { switch (region.getFlags().get(Flag.TNT).getWithDefault()) { case ALLOW: case ONLY_TB: - case ONLY_BUILD: region.getFlags().set(Flag.TNT, TNTMode.DENY); RegionUtils.actionBar(region, getDisableMessage()); break; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java index 791a9cb1..285b2a7f 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java @@ -50,11 +50,6 @@ public class TNTListener implements Listener, ScoreboardElement { RegionUtils.actionBar(region, "REGION_TNT_BUILD_DESTROY"); return true; } - } else if (value == TNTMode.ONLY_BUILD) { - if (region.getTestblockArea().inRegion(block.getLocation(), true)) { - RegionUtils.actionBar(region, "REGION_TNT_TB_DESTROY"); - return true; - } } return value == TNTMode.DENY; }); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TntBauGuiItem.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TntBauGuiItem.java index c633c569..2205cf10 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TntBauGuiItem.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TntBauGuiItem.java @@ -25,7 +25,6 @@ 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.TNTMode; -import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import de.steamwar.linkage.Linked; @@ -48,8 +47,6 @@ 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(); } @@ -82,10 +79,6 @@ public class TntBauGuiItem extends BauGuiItem { 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); @@ -101,9 +94,6 @@ 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/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java index 52c97c21..474a5b1f 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java @@ -57,7 +57,6 @@ public class RegionLib implements LuaLib { tntLib.set("mode", getter(() -> region.get().getFlags().get(Flag.TNT).nameWithDefault())); tntLib.set("enabled", getter(() -> region.get().getFlags().get(Flag.TNT).orElse(null) != TNTMode.DENY)); tntLib.set("onlyTb", getter(() -> region.get().getFlags().get(Flag.TNT).orElse(null) == TNTMode.ONLY_TB)); - tntLib.set("onlyBuild", getter(() -> region.get().getFlags().get(Flag.TNT).orElse(null) == TNTMode.ONLY_BUILD)); table.set("tnt", tntLib); table.set("fire", getter(() -> region.get().getFlags().get(Flag.FIRE).orElse(null) == FireMode.ALLOW)); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index 76dfeee1..bad3b0ef 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -136,7 +136,14 @@ public interface Region { @NonNull Point getCopyPoint(); - boolean inRegion(Location location, boolean extension); + default boolean inRegion(Location location, boolean extension) { + Point minPoint = getMinPoint(extension); + Point maxPoint = getMaxPoint(extension); + if (location.getBlockX() < minPoint.getX() || location.getBlockX() > maxPoint.getX()) return false; + if (location.getBlockY() < minPoint.getY() || location.getBlockY() > maxPoint.getY()) return false; + if (location.getBlockZ() < minPoint.getZ() || location.getBlockZ() > maxPoint.getZ()) return false; + return true; + } @Nullable EditSession copy(boolean extension); @@ -146,8 +153,21 @@ public interface Region { void reset(PasteBuilder pasteBuilder, boolean extension); - void forEachChunk(BiConsumer executor); + default void forEachChunk(BiConsumer executor) { + Point minPoint = getMinPoint(false); + Point maxPoint = getMaxPoint(false); + for (int x = (int) Math.floor(minPoint.getX() / 16.0); x <= (int) Math.ceil(maxPoint.getX() / 16.0); x++) { + for (int z = (int) Math.floor(minPoint.getZ() / 16.0); z <= (int) Math.ceil(maxPoint.getZ() / 16.0); z++) { + executor.accept(x, z); + } + } + } - boolean isChunkOutside(int chunkX, int chunkZ); + default boolean isChunkOutside(int chunkX, int chunkZ) { + Point minPoint = getMinPoint(true); + Point maxPoint = getMaxPoint(true); + return Math.floor(minPoint.getX() / 16.0) > chunkX || chunkX >= Math.ceil(maxPoint.getX() / 16.0) || + Math.floor(minPoint.getZ() / 16.0) > chunkZ || chunkZ >= Math.ceil(maxPoint.getZ() / 16.0); + } } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/TNTMode.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/TNTMode.java index 0f73f81b..fe343707 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/TNTMode.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/TNTMode.java @@ -28,8 +28,7 @@ public enum TNTMode implements Flag.Value { ALLOW("FLAG_TNT_ALLOW"), DENY("FLAG_TNT_DENY"), - ONLY_TB("FLAG_TNT_ONLY_TB"), - ONLY_BUILD("FLAG_TNT_ONLY_BUILD"); + ONLY_TB("FLAG_TNT_ONLY_TB"); private static TNTMode[] values; private final String chatValue; diff --git a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedFlagStorage.java b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedFlagStorage.java index 3de70483..6893f904 100644 --- a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedFlagStorage.java +++ b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedFlagStorage.java @@ -23,20 +23,20 @@ import de.steamwar.bausystem.region.FlagOptional; import de.steamwar.bausystem.region.FlagStorage; import de.steamwar.bausystem.region.RegionFlagPolicy; import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.TestblockMode; import de.steamwar.core.Core; import lombok.NonNull; -import java.io.File; import java.util.HashMap; import java.util.Map; public class FixedFlagStorage implements FlagStorage { + private TestblockMode testBlockMode; private Map, Flag.Value> flagMap = new HashMap<>(); - public static FlagStorage createFromFile(File file) { - // throw new IllegalStateException("Not implemented yet"); - return new FixedFlagStorage(); + public FixedFlagStorage(TestblockMode testblockMode) { + this.testBlockMode = testblockMode; } @Override @@ -44,16 +44,26 @@ public class FixedFlagStorage implements FlagStorage { if (flag.oneOf(Flag.ITEMS) && Core.getVersion() < 20) { return RegionFlagPolicy.NOT_APPLICABLE; } + if (flag.oneOf(Flag.TESTBLOCK)) { + return RegionFlagPolicy.READ_ONLY; + } return RegionFlagPolicy.WRITABLE; } @Override public & Flag.Value> boolean set(@NonNull Flag flag, @NonNull T value) { - return flagMap.put(flag, value) != value; + if (has(flag).isWritable()) { + return flagMap.put(flag, value) != value; + } else { + return false; + } } @Override public @NonNull & Flag.Value> FlagOptional get(@NonNull Flag flag) { + if (flag.oneOf(Flag.TESTBLOCK)) { + return FlagOptional.of((Flag) flag, testBlockMode); + } return FlagOptional.of(flag, (T) flagMap.get(flag)); } diff --git a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedRegion.java b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedRegion.java new file mode 100644 index 00000000..e008fab7 --- /dev/null +++ b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedRegion.java @@ -0,0 +1,80 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.region.fixed; + +import de.steamwar.bausystem.region.*; +import lombok.NonNull; + +import java.nio.charset.StandardCharsets; +import java.util.UUID; + +public class FixedRegion implements Region { + + private UUID uuid; + + public FixedRegion(String name) { + uuid = UUID.nameUUIDFromBytes(name.getBytes(StandardCharsets.UTF_8)); + } + + @Override + public @NonNull UUID getID() { + return uuid; + } + + @Override + public @NonNull RegionType getType() { + return RegionType.NORMAL; + } + + @Override + public @NonNull FlagStorage getFlags() { + return null; + } + + @Override + public @NonNull Area getArea() { + return null; + } + + @Override + public @NonNull Area getBuildArea() { + return null; + } + + @Override + public @NonNull Area getTestblockArea() { + return null; + } + + @Override + public @NonNull RegionConfig getGameModeConfig() { + return null; + } + + @Override + public @NonNull RegionHistory getHistory() { + return null; + } + + @Override + public @NonNull RegionBackups getBackups() { + return null; + } +}