From 6a5507321eb0b3c6733f9e96ae19e909531edeee Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 31 Jul 2025 18:17:38 +0200 Subject: [PATCH] Add FixedGlobalFlagStorage --- .../steamwar/bausystem/region/flags/Flag.java | 3 +- .../bausystem/region/FixedFlagStorage.java | 10 ++- .../region/FixedGlobalFlagStorage.java | 78 +++++++++++++++++++ .../bausystem/region/FixedGlobalRegion.java | 2 +- 4 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedGlobalFlagStorage.java diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java index c62e0748..ddee1806 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java @@ -20,7 +20,6 @@ package de.steamwar.bausystem.region.flags; import de.steamwar.bausystem.shared.EnumDisplay; -import lombok.AllArgsConstructor; import lombok.Getter; import java.util.HashSet; @@ -36,7 +35,7 @@ public final class Flag & Flag.Value> implements EnumDispla public static final Flag COLOR = new Flag<>("COLOR", "FLAG_COLOR", ColorMode.class, ColorMode.YELLOW); public static final Flag TNT = new Flag<>("TNT", "FLAG_TNT", TNTMode.class, TNTMode.ONLY_TB); - public static final Flag FIRE = new Flag<>("FIRE", "FLAG_FIRE", FireMode.class, FireMode.ALLOW); + public static final Flag FIRE = new Flag<>("FIRE", "FLAG_FIRE", FireMode.class, FireMode.DENY); public static final Flag FREEZE = new Flag<>("FREEZE", "FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE); public static final Flag PROTECT = new Flag<>("PROTECT", "FLAG_PROTECT", ProtectMode.class, ProtectMode.ACTIVE); public static final Flag ITEMS = new Flag<>("ITEMS", "FLAG_ITEMS", ItemMode.class, ItemMode.INACTIVE); diff --git a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedFlagStorage.java b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedFlagStorage.java index 7f083084..f2c05616 100644 --- a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedFlagStorage.java +++ b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedFlagStorage.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.region; import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.core.Core; import lombok.NonNull; import java.io.File; @@ -37,17 +38,20 @@ public class FixedFlagStorage implements FlagStorage { @Override public @NonNull & Flag.Value> RegionFlagPolicy has(@NonNull Flag flag) { - return RegionFlagPolicy.NOT_APPLICABLE; + if (flag.oneOf(Flag.ITEMS) && Core.getVersion() < 20) { + return RegionFlagPolicy.NOT_APPLICABLE; + } + return RegionFlagPolicy.WRITABLE; } @Override public & Flag.Value> boolean set(@NonNull Flag flag, @NonNull T value) { - return false; + return flagMap.put(flag, value) != value; } @Override public @NonNull & Flag.Value> FlagOptional get(@NonNull Flag flag) { - return FlagOptional.of(flag); + return FlagOptional.of(flag, (T) flagMap.get(flag)); } @Override diff --git a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedGlobalFlagStorage.java b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedGlobalFlagStorage.java new file mode 100644 index 00000000..f20f9a02 --- /dev/null +++ b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedGlobalFlagStorage.java @@ -0,0 +1,78 @@ +/* + * 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; + +import de.steamwar.bausystem.region.flags.ColorMode; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.ProtectMode; +import de.steamwar.bausystem.region.flags.TNTMode; +import de.steamwar.core.Core; +import lombok.NonNull; + +import java.util.HashMap; +import java.util.Map; + +public class FixedGlobalFlagStorage implements FlagStorage { + + private Map, Flag.Value> flagMap = new HashMap<>(); + + public FixedGlobalFlagStorage() { + flagMap.put(Flag.TNT, TNTMode.DENY); + } + + @Override + public @NonNull & Flag.Value> RegionFlagPolicy has(@NonNull Flag flag) { + if (flag.oneOf(Flag.PROTECT, Flag.TESTBLOCK, Flag.NO_GRAVITY, Flag.CHANGED)) { + return RegionFlagPolicy.NOT_APPLICABLE; + } + if (flag.oneOf(Flag.ITEMS) && Core.getVersion() < 20) { + return RegionFlagPolicy.NOT_APPLICABLE; + } + if (flag.oneOf(Flag.COLOR)) { + return RegionFlagPolicy.READ_ONLY; + } + return RegionFlagPolicy.WRITABLE; + } + + @Override + public & Flag.Value> boolean set(@NonNull Flag flag, @NonNull T 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.COLOR)) { + return FlagOptional.of((Flag) flag, ColorMode.YELLOW); + } + if (flag.oneOf(Flag.PROTECT)) { + return FlagOptional.of((Flag) flag, ProtectMode.INACTIVE); + } + return FlagOptional.of(flag, (T) flagMap.get(flag)); + } + + @Override + public void clear() { + flagMap.clear(); + } +} diff --git a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedGlobalRegion.java b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedGlobalRegion.java index b1545d48..ea9eb298 100644 --- a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedGlobalRegion.java +++ b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedGlobalRegion.java @@ -36,7 +36,7 @@ public final class FixedGlobalRegion implements Region { private static final Point MIN_POINT = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE); private static final Point MAX_POINT = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE); - private static final FlagStorage FLAG_STORAGE = FixedFlagStorage.createFromFile(null); // TODO: Update to either File or Region creation! + private static final FlagStorage FLAG_STORAGE = new FixedGlobalFlagStorage(); private static final UUID GLOBAL_REGION_ID = new UUID(0, 0);