From f9c320cb333871a7ea146592b4b11480374d59b5 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Fri, 17 Oct 2025 21:36:50 +0200 Subject: [PATCH] Add RegionData Improve TestblockCommand with remembering the TB --- .../features/region/ResetCommand.java | 1 + .../features/region/TestblockCommand.java | 28 +++++- .../de/steamwar/bausystem/region/Region.java | 3 + .../steamwar/bausystem/region/RegionData.java | 93 +++++++++++++++++++ .../region/fixed/FixedGlobalRegion.java | 5 + .../bausystem/region/fixed/FixedRegion.java | 8 ++ 6 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionData.java diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java index 49893d1d..097ec569 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java @@ -56,6 +56,7 @@ public class ResetCommand extends SWCommand { .color(region.getFlags().get(Flag.COLOR).getWithDefault()); region.getArea().reset(pasteBuilder, false); region.getFlags().clear(); + region.getRegionData().clear(); RegionUtils.message(region, "REGION_RESET_RESETED"); } catch (SecurityException e) { BauSystem.MESSAGE.send("REGION_RESET_ERROR", p); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java index 7e4abc4b..aaaef5a1 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java @@ -25,7 +25,6 @@ import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.utils.RegionExtensionType; -import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.bausystem.utils.PasteBuilder; import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; @@ -93,8 +92,33 @@ public class TestblockCommand extends SWCommand { } } + // Beta Tester enabled + switch (BauServer.getInstance().getOwnerID()) { + case 245: + case 403: + case 1898: + case 3320: + case 4603: + case 6032: + case 11888: + if (node == null) { + node = region.getRegionData().getTestblockSchematic(); + } else { + region.getRegionData().setTestblockSchematic(node); + } + break; + default: + break; + } + + PasteBuilder.ClipboardProvider clipboardProvider; + if (node == null) { + clipboardProvider = new PasteBuilder.FileProvider(region.getTestblockArea().getResetFile()); + } else { + clipboardProvider = new PasteBuilder.SchematicProvider(node); + } + try { - PasteBuilder.ClipboardProvider clipboardProvider = node == null ? new PasteBuilder.FileProvider(region.getTestblockArea().getResetFile()) : new PasteBuilder.SchematicProvider(node); PasteBuilder pasteBuilder = new PasteBuilder(clipboardProvider) .ignoreAir(ignoreAir) .onlyColors(onlyColors) 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 d00cb4e1..4b91f9fe 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -72,6 +72,9 @@ public interface Region { @NonNull RegionBackups getBackups(); + @NonNull + RegionData getRegionData(); + interface Area { Area EMPTY = new Area() { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionData.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionData.java new file mode 100644 index 00000000..615da706 --- /dev/null +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/region/RegionData.java @@ -0,0 +1,93 @@ +/* + * 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.sql.SchematicNode; +import yapion.hierarchy.types.YAPIONObject; + +import java.util.Objects; + +public interface RegionData { + + void clear(); + + SchematicNode getTestblockSchematic(); + + void setTestblockSchematic(SchematicNode schematic); + + RegionData EMPTY = new RegionData() { + + @Override + public void clear() { + } + + @Override + public SchematicNode getTestblockSchematic() { + return null; + } + + @Override + public void setTestblockSchematic(SchematicNode schematic) { + } + }; + + class RegionDataImpl implements RegionData { + + private final YAPIONObject yapionObject; + private final Runnable onChange; + + public RegionDataImpl(YAPIONObject yapionObject, Runnable onChange) { + this.yapionObject = yapionObject; + this.onChange = onChange; + + if (yapionObject.containsKey("testblockSchematic")) { + testblockSchematic = SchematicNode.getSchematicNode(yapionObject.getInt("testblockSchematic")); + } + } + + @Override + public void clear() { + testblockSchematic = null; + yapionObject.remove("testblockSchematic"); + onChange.run(); + } + + private SchematicNode testblockSchematic = null; + + @Override + public SchematicNode getTestblockSchematic() { + return testblockSchematic; + } + + @Override + public void setTestblockSchematic(SchematicNode schematic) { + if (Objects.equals(this.testblockSchematic, schematic)) { + return; + } + this.testblockSchematic = schematic; + if (schematic == null) { + yapionObject.remove("testblockSchematic"); + } else { + yapionObject.put("testblockSchematic", testblockSchematic.getId()); + } + onChange.run(); + } + } +} diff --git a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedGlobalRegion.java b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedGlobalRegion.java index 39e8ca1f..0eaaf87c 100644 --- a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedGlobalRegion.java +++ b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedGlobalRegion.java @@ -139,4 +139,9 @@ public final class FixedGlobalRegion implements Region { public @NonNull RegionBackups getBackups() { return RegionBackups.EMPTY; } + + @Override + public @NonNull RegionData getRegionData() { + return RegionData.EMPTY; + } } 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 index 256e1c00..c04a3ef7 100644 --- a/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedRegion.java +++ b/BauSystem/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/fixed/FixedRegion.java @@ -26,6 +26,7 @@ import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.TestblockMode; import de.steamwar.bausystem.utils.FlatteningWrapper; import de.steamwar.bausystem.utils.PasteBuilder; +import de.steamwar.bausystem.worlddata.WorldData; import de.steamwar.core.Core; import de.steamwar.sql.SchematicType; import lombok.NonNull; @@ -57,6 +58,7 @@ public class FixedRegion implements Region { private final int floorLevel; private final int waterLevel; private final GameModeConfig gameModeConfig; + private final RegionData regionData; private final RegionHistory regionHistory = new RegionHistory.Impl(20); private final RegionBackups regionBackups = new RegionBackups() { @@ -335,6 +337,7 @@ public class FixedRegion implements Region { } } this.gameModeConfig = new GameModeConfig(found); + this.regionData = new RegionData.RegionDataImpl(regionData, WorldData::write); } @Override @@ -381,4 +384,9 @@ public class FixedRegion implements Region { public @NonNull RegionBackups getBackups() { return regionBackups; } + + @Override + public @NonNull RegionData getRegionData() { + return regionData; + } }