forked from SteamWar/SteamWar
Add RegionData
Improve TestblockCommand with remembering the TB
This commit is contained in:
@@ -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);
|
||||
|
||||
+26
-2
@@ -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)
|
||||
|
||||
@@ -72,6 +72,9 @@ public interface Region {
|
||||
@NonNull
|
||||
RegionBackups getBackups();
|
||||
|
||||
@NonNull
|
||||
RegionData getRegionData();
|
||||
|
||||
interface Area {
|
||||
|
||||
Area EMPTY = new Area() {
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+8
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user