From 01d9532aa66dab0d4ce82324ad3cb1c185fcae75 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 31 Jul 2025 14:31:16 +0200 Subject: [PATCH] Pot impl a FixedGlobalRegion --- .../bausystem/region/RegionBackups.java | 18 +++ .../bausystem/region/RegionHistory.java | 16 +++ .../bausystem/region/RegionSkins.java | 35 +++++ .../steamwar/bausystem/region/flags/Flag.java | 10 +- .../bausystem/region/FixedFlagStorage.java | 32 +++-- .../bausystem/region/FixedGlobalRegion.java | 132 ++++++++++-------- .../bausystem/region/FixedRegion.java | 111 --------------- .../bausystem/region/FixedRegionSystem.java | 10 +- 8 files changed, 171 insertions(+), 193 deletions(-) delete mode 100644 BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedRegion.java diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionBackups.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionBackups.java index 53b3b8a7..b49e949a 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionBackups.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionBackups.java @@ -65,4 +65,22 @@ public interface RegionBackups { @Nullable Backup get(String name); + + RegionBackups EMPTY = new RegionBackups() { + @Override + public Optional create(BackupType backupType) { + return Optional.empty(); + } + + @Override + public @NonNull List list() { + return List.of(); + } + + @Nullable + @Override + public Backup get(String name) { + return null; + } + }; } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionHistory.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionHistory.java index 9732b325..2eb79247 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionHistory.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionHistory.java @@ -29,4 +29,20 @@ public interface RegionHistory { boolean undo(); boolean redo(); + + RegionHistory EMPTY = new RegionHistory() { + @Override + public void remember(@NonNull EditSession editSession) { + } + + @Override + public boolean undo() { + return false; + } + + @Override + public boolean redo() { + return false; + } + }; } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionSkins.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionSkins.java index e12f2221..b9413d9f 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionSkins.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionSkins.java @@ -40,6 +40,13 @@ public interface RegionSkins { @CheckReturnValue public abstract boolean apply(); + + public static final Skin GLOBAL = new Skin("Global", "§eSteam§8War") { + @Override + public boolean apply() { + return false; + } + }; } @NonNull @@ -52,4 +59,32 @@ public interface RegionSkins { @Nullable Skin get(@NonNull String name); + + RegionSkins GLOBAL = new RegionSkins() { + + @Override + public @NonNull Skin getCurrentSkin() { + return Skin.GLOBAL; + } + + @Override + public @NonNull List list() { + return List.of(Skin.GLOBAL); + } + + @Override + public boolean has(@NonNull String name) { + return Skin.GLOBAL.name.equals(name); + } + + @Nullable + @Override + public Skin get(@NonNull String name) { + if (Skin.GLOBAL.name.equals(name)) { + return Skin.GLOBAL; + } else { + return null; + } + } + }; } 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 e9eb963b..c62e0748 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 @@ -29,6 +29,11 @@ import java.util.concurrent.atomic.AtomicInteger; public final class Flag & Flag.Value> implements EnumDisplay { + @Getter + private static final Set flags = new HashSet<>(); + + private static AtomicInteger counter = new AtomicInteger(0); + 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); @@ -39,11 +44,6 @@ public final class Flag & Flag.Value> implements EnumDispla public static final Flag TESTBLOCK = new Flag<>("TESTBLOCK", "FLAG_TESTBLOCK", TestblockMode.class, TestblockMode.NO_VALUE); public static final Flag CHANGED = new Flag<>("CHANGED", "FLAG_CHANGED", ChangedMode.class, ChangedMode.NO_CHANGE); - @Getter - private static final Set flags = new HashSet<>(); - - private static AtomicInteger counter = new AtomicInteger(0); - private String name; private int ordinal; 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 af44866a..7f083084 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 lombok.NonNull; import java.io.File; import java.util.HashMap; @@ -29,27 +30,28 @@ public class FixedFlagStorage implements FlagStorage { private Map, Flag.Value> flagMap = new HashMap<>(); - public static FlagStorage createFromRegion(Region region) { - FlagStorage flagStorage = new FixedFlagStorage(); - Flag.getFlags().forEach(flag -> { - if (region.hasFlag(flag).isReadable()) { - flagStorage.set(flag, flag.getDefaultValue()); - } - }); - return flagStorage; - } - public static FlagStorage createFromFile(File file) { - throw new IllegalStateException("Not implemented yet"); + // throw new IllegalStateException("Not implemented yet"); + return new FixedFlagStorage(); } @Override - public & Flag.Value> boolean set(Flag flag, T value) { - return flagMap.put(flag, value) != value; + public @NonNull & Flag.Value> RegionFlagPolicy has(@NonNull Flag flag) { + return RegionFlagPolicy.NOT_APPLICABLE; } @Override - public & Flag.Value> T get(Flag flag) { - return (T) flagMap.get(flag); + public & Flag.Value> boolean set(@NonNull Flag flag, @NonNull T value) { + return false; + } + + @Override + public @NonNull & Flag.Value> FlagOptional get(@NonNull Flag flag) { + return FlagOptional.of(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 b36ddecb..b1545d48 100644 --- a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedGlobalRegion.java +++ b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedGlobalRegion.java @@ -20,12 +20,14 @@ package de.steamwar.bausystem.region; import com.sk89q.worldedit.EditSession; -import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.utils.PasteBuilder; import lombok.NonNull; import org.bukkit.Location; +import javax.annotation.Nullable; import java.io.File; -import java.util.Optional; +import java.util.UUID; +import java.util.function.BiConsumer; public final class FixedGlobalRegion implements Region { @@ -34,7 +36,58 @@ 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 final FlagStorage FLAG_STORAGE = FixedFlagStorage.createFromRegion(this); // TODO: Update to either File or Region creation! + private static final FlagStorage FLAG_STORAGE = FixedFlagStorage.createFromFile(null); // TODO: Update to either File or Region creation! + + private static final UUID GLOBAL_REGION_ID = new UUID(0, 0); + + private static final Area GLOBAL_AREA = new Area() { + @Override + public @NonNull Point getMinPoint(boolean extension) { + return MIN_POINT; + } + + @Override + public @NonNull Point getMaxPoint(boolean extension) { + return MAX_POINT; + } + + @Override + public @NonNull Point getCopyPoint() { + return Point.ZERO; + } + + @Override + public boolean inRegion(Location location, boolean extension) { + return true; + } + + @Nullable + @Override + public EditSession copy(boolean extension) { + return null; + } + + @Nullable + @Override + public File getResetFile() { + return null; + } + + @Override + public void reset(PasteBuilder pasteBuilder, boolean extension) { + } + + @Override + public void forEachChunk(BiConsumer executor) { + } + + @Override + public boolean isChunkOutside(int chunkX, int chunkZ) { + return false; + } + }; + + private static final RegionConfig GLOBAL_CONFIG = new RegionConfig(null); private FixedGlobalRegion() { } @@ -45,84 +98,47 @@ public final class FixedGlobalRegion implements Region { } @Override - public & Flag.Value> RegionFlagPolicy hasFlag(@NonNull Flag flag) { - if (flag.oneOf(Flag.TNT, Flag.FIRE, Flag.FREEZE, Flag.ITEMS, Flag.NO_GRAVITY)) { - return RegionFlagPolicy.WRITABLE; - } - return RegionFlagPolicy.NOT_APPLICABLE; + public @NonNull UUID getID() { + return GLOBAL_REGION_ID; } @Override - public & Flag.Value> boolean setFlag(@NonNull Flag flag, T value) { - return hasFlag(flag).isWritable() && FLAG_STORAGE.set(flag, value); + public @NonNull FlagStorage getFlags() { + return FLAG_STORAGE; } @Override - public & Flag.Value> Optional getFlag(@NonNull Flag flag) { - if (hasFlag(flag).isReadable()) { - return Optional.ofNullable(FLAG_STORAGE.get(flag)); - } else { - return Optional.empty(); - } + public @NonNull Area getArea() { + return GLOBAL_AREA; } @Override - public Point getMinPoint() { - return MIN_POINT; + public @NonNull Area getBuildArea() { + return Area.EMPTY; } @Override - public Point getMaxPoint() { - return MAX_POINT; + public @NonNull Area getTestblockArea() { + return Area.EMPTY; } @Override - public boolean inRegion(Location location) { - return true; + public @NonNull RegionConfig getGameModeConfig() { + return GLOBAL_CONFIG; } @Override - public Inner getBuildArea() { - return Inner.EMPTY; + public @NonNull RegionHistory getHistory() { + return RegionHistory.EMPTY; } @Override - public Inner getTestblockArea() { - return Inner.EMPTY; + public @NonNull RegionBackups getBackups() { + return RegionBackups.EMPTY; } @Override - public Optional getGameModeConfig() { - return Optional.empty(); - } - - @Override - public Optional copy() { - return Optional.empty(); - } - - @Override - public boolean backup(boolean automatic) { - return false; - } - - @Override - public void reset() { - - } - - @Override - public void remember(EditSession editSession) { - - } - - @Override - public boolean undo() { - return false; - } - - @Override - public boolean redo() { - return false; + public @NonNull RegionSkins getSkins() { + return RegionSkins.GLOBAL; } } diff --git a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedRegion.java b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedRegion.java deleted file mode 100644 index 0023060d..00000000 --- a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedRegion.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2024 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 com.sk89q.worldedit.EditSession; -import de.steamwar.bausystem.region.flags.Flag; -import lombok.NonNull; -import org.bukkit.Location; - -import java.io.File; -import java.util.Optional; - -public class FixedRegion implements Region { // TODO: Implement! - - @Override - public RegionType getType() { - return RegionType.NORMAL; - } - - @Override - public & Flag.Value> RegionFlagPolicy hasFlag(@NonNull Flag flag) { - return null; - } - - @Override - public & Flag.Value> boolean setFlag(@NonNull Flag flag, T value) { - return false; - } - - @Override - public & Flag.Value> Optional getFlag(@NonNull Flag flag) { - return Optional.empty(); - } - - @Override - public Point getMinPoint() { - return null; - } - - @Override - public Point getMaxPoint() { - return null; - } - - @Override - public boolean inRegion(Location location) { - return false; - } - - @Override - public Inner getBuildArea() { - return Inner.EMPTY; - } - - @Override - public Inner getTestblockArea() { - return Inner.EMPTY; - } - - @Override - public Optional getGameModeConfig() { - return Optional.empty(); - } - - @Override - public boolean backup(boolean automatic) { - return false; - } - - @Override - public Optional copy() { - return Optional.empty(); - } - - @Override - public void reset() { - - } - - @Override - public void remember(EditSession editSession) { - - } - - @Override - public boolean undo() { - return false; - } - - @Override - public boolean redo() { - return false; - } -} diff --git a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedRegionSystem.java b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedRegionSystem.java index dfdaf3f3..473ec0d3 100644 --- a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedRegionSystem.java +++ b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedRegionSystem.java @@ -19,16 +19,18 @@ package de.steamwar.bausystem.region; +import lombok.NonNull; import org.bukkit.Location; import java.util.HashMap; import java.util.Map; import java.util.Optional; +import java.util.UUID; import java.util.stream.Stream; public class FixedRegionSystem implements RegionSystem { - private static final Map REGION_MAP = new HashMap<>(); + private static final Map REGION_MAP = new HashMap<>(); @Override public void load() { @@ -48,14 +50,14 @@ public class FixedRegionSystem implements RegionSystem { @Override public Region get(Location location) { return REGION_MAP.values().stream() - .filter(region -> region.inRegion(location)) + .filter(region -> region.getArea().inRegion(location, false)) .findFirst() .orElse(FixedGlobalRegion.INSTANCE); } @Override - public Optional getRegion(String name) { - return Optional.ofNullable(REGION_MAP.get(name)); + public Optional getRegion(@NonNull UUID id) { + return Optional.ofNullable(REGION_MAP.get(id)); } @Override