forked from SteamWar/SteamWar
Fix RegionConfig
Implement FixedRegion Add RegionHistory.Impl
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.bausystem.region;
|
||||
|
||||
import de.steamwar.core.FlatteningWrapper;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -117,7 +118,7 @@ public class RegionConfig {
|
||||
private void load(ConfigurationSection section) {
|
||||
Active = section.getBoolean("Active", false);
|
||||
ObfuscateWith = Material.getMaterial(section.getString("ObfuscateWith", "END_STONE"));
|
||||
HiddenBlocks = section.getStringList("HiddenBlocks").stream().map(Material::getMaterial).collect(Collectors.toUnmodifiableSet());
|
||||
HiddenBlocks = section.getStringList("HiddenBlocks").stream().map(FlatteningWrapper.impl::getMaterial).filter(Objects::nonNull).collect(Collectors.toUnmodifiableSet());
|
||||
HiddenBlockEntities = Collections.unmodifiableSet(new HashSet<>(section.getStringList("HiddenBlockEntities")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,11 @@
|
||||
package de.steamwar.bausystem.region;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import de.steamwar.bausystem.shared.SizedStack;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public interface RegionHistory {
|
||||
|
||||
@@ -45,4 +49,44 @@ public interface RegionHistory {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class Impl implements RegionHistory {
|
||||
|
||||
private SizedStack<EditSession> undoSessions;
|
||||
private SizedStack<EditSession> redoSessions;
|
||||
|
||||
public Impl(int size) {
|
||||
this.undoSessions = new SizedStack<>(size);
|
||||
this.redoSessions = new SizedStack<>(size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remember(@NonNull EditSession editSession) {
|
||||
undoSessions.push(editSession);
|
||||
if (redoSessions.empty()) return;
|
||||
redoSessions.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean undo() {
|
||||
EditSession session = undoSessions.pop();
|
||||
if (session == null) return false;
|
||||
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
|
||||
session.undo(e);
|
||||
redoSessions.push(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean redo() {
|
||||
EditSession session = redoSessions.pop();
|
||||
if (session == null) return false;
|
||||
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
|
||||
session.redo(e);
|
||||
undoSessions.push(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,6 +130,12 @@ public class SizedStack<T> {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.data = (T[]) new Object[this.maxSize];
|
||||
this.head = 0;
|
||||
this.size = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder result = new StringBuilder("[");
|
||||
|
||||
+4
@@ -36,6 +36,10 @@ public class FixedRegionSystem implements RegionSystem {
|
||||
|
||||
private static final Map<UUID, Region> REGION_MAP = new HashMap<>();
|
||||
|
||||
public static void addRegion(Region region) {
|
||||
REGION_MAP.put(region.getID(), region);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
PrototypeLoader.load();
|
||||
|
||||
+1
-7
@@ -23,7 +23,6 @@ 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.bausystem.worlddata.WorldData;
|
||||
import de.steamwar.core.Core;
|
||||
import lombok.NonNull;
|
||||
@@ -34,12 +33,10 @@ import java.util.Map;
|
||||
|
||||
public class FixedFlagStorage implements FlagStorage {
|
||||
|
||||
private TestblockMode testBlockMode;
|
||||
private Map<Flag<?>, Flag.Value<?>> flagMap = new HashMap<>();
|
||||
private YAPIONObject data;
|
||||
|
||||
public FixedFlagStorage(TestblockMode testblockMode, YAPIONObject data) {
|
||||
this.testBlockMode = testblockMode;
|
||||
public FixedFlagStorage(YAPIONObject data) {
|
||||
this.data = data;
|
||||
for (final Flag flag : Flag.getFlags()) {
|
||||
if (!has(flag).isWritable()) continue;
|
||||
@@ -79,9 +76,6 @@ public class FixedFlagStorage implements FlagStorage {
|
||||
|
||||
@Override
|
||||
public @NonNull <T extends Enum<T> & Flag.Value<T>> FlagOptional<T> get(@NonNull Flag<T> flag) {
|
||||
if (flag.oneOf(Flag.TESTBLOCK)) {
|
||||
return FlagOptional.of((Flag) flag, testBlockMode);
|
||||
}
|
||||
return FlagOptional.of(flag, (T) flagMap.get(flag));
|
||||
}
|
||||
|
||||
|
||||
+197
-7
@@ -19,9 +19,18 @@
|
||||
|
||||
package de.steamwar.bausystem.region.fixed;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.region.*;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import de.steamwar.bausystem.region.flags.TestblockMode;
|
||||
import de.steamwar.bausystem.utils.PasteBuilder;
|
||||
import de.steamwar.core.Core;
|
||||
import lombok.NonNull;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -31,10 +40,191 @@ public class FixedRegion implements Region {
|
||||
private FixedFlagStorage flagStorage;
|
||||
private Prototype prototype;
|
||||
|
||||
public FixedRegion(String name, FixedFlagStorage flagStorage, Prototype prototype) {
|
||||
private final Area area;
|
||||
private final Area build;
|
||||
private final Area testblock;
|
||||
private final int floorLevel;
|
||||
private final int waterLevel;
|
||||
private final RegionConfig regionConfig;
|
||||
private final RegionHistory regionHistory = new RegionHistory.Impl(20);
|
||||
|
||||
public FixedRegion(String name, FixedFlagStorage flagStorage, Prototype prototype, YAPIONObject regionConfig, YAPIONObject regionData) {
|
||||
uuid = UUID.nameUUIDFromBytes(name.getBytes(StandardCharsets.UTF_8));
|
||||
this.flagStorage = flagStorage;
|
||||
this.prototype = prototype;
|
||||
System.out.println(name + " " + prototype + " " + flagStorage);
|
||||
|
||||
Point minPoint;
|
||||
if (regionConfig.containsKey("minX", Integer.class) && regionConfig.containsKey("minY", Integer.class) && regionConfig.containsKey("minZ", Integer.class)) {
|
||||
minPoint = new Point(regionConfig.getInt("minX"), regionConfig.getInt("minY"), regionConfig.getInt("minZ"));
|
||||
} else {
|
||||
throw new IllegalArgumentException("minX and minY and minZ are required");
|
||||
}
|
||||
Point maxPoint = minPoint.add(prototype.getSizeX() - 1, prototype.getSizeY() - 1, prototype.getSizeZ() - 1);
|
||||
|
||||
area = new Area() {
|
||||
@Override
|
||||
public @NonNull Point getMinPoint(boolean extension) {
|
||||
return minPoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Point getMaxPoint(boolean extension) {
|
||||
return maxPoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Point getCopyPoint() {
|
||||
return minPoint;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public EditSession copy(boolean extension) {
|
||||
return null; // TODO: Implement
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public File getResetFile() {
|
||||
return null; // TODO: Implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset(PasteBuilder pasteBuilder, boolean extension) {
|
||||
// TODO: Implement
|
||||
}
|
||||
};
|
||||
|
||||
if (prototype.getBuild() != null) {
|
||||
Point minPointBuild = minPoint.add(prototype.getBuild().getOffsetX(), prototype.getBuild().getOffsetY(), prototype.getBuild().getOffsetZ());
|
||||
Point maxPointBuild = minPointBuild.add(prototype.getBuild().getSizeX() - 1, prototype.getBuild().getSizeY() - 1, prototype.getBuild().getSizeZ() - 1);
|
||||
|
||||
Point minPointBuildExtension = minPointBuild.subtract(prototype.getBuild().getExtensionNegativeX(), prototype.getBuild().getExtensionNegativeY(), prototype.getBuild().getExtensionNegativeZ());
|
||||
Point maxPointBuildExtension = maxPointBuild.add(prototype.getBuild().getExtensionPositiveX(), prototype.getBuild().getExtensionPositiveY(), prototype.getBuild().getExtensionPositiveZ());
|
||||
|
||||
Point copyPoint;
|
||||
if (!prototype.getBuild().isHasCopyPoint() && (prototype.getCopyPointOffsetX() != 0 || prototype.getCopyPointOffsetY() != 0 || prototype.getCopyPointOffsetZ() != 0)) {
|
||||
copyPoint = minPoint.add(prototype.getCopyPointOffsetX(), prototype.getCopyPointOffsetY(), prototype.getCopyPointOffsetZ());
|
||||
} else if (prototype.getBuild().getCopyOffsetX() != 0 || prototype.getBuild().getCopyOffsetY() != 0 || prototype.getBuild().getCopyOffsetZ() != 0) {
|
||||
copyPoint = minPointBuild.add(prototype.getBuild().getCopyOffsetX(), prototype.getBuild().getCopyOffsetY(), prototype.getBuild().getCopyOffsetZ());
|
||||
} else {
|
||||
copyPoint = minPointBuild.add(prototype.getBuild().getSizeX() / 2, 0, prototype.getBuild().getSizeZ());
|
||||
}
|
||||
|
||||
build = new Area() {
|
||||
@Override
|
||||
public @NonNull Point getMinPoint(boolean extension) {
|
||||
return extension ? minPointBuildExtension : minPointBuild;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Point getMaxPoint(boolean extension) {
|
||||
return extension ? maxPointBuildExtension : maxPointBuild;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Point getCopyPoint() {
|
||||
return copyPoint;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public EditSession copy(boolean extension) {
|
||||
return null; // TODO: Implement
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public File getResetFile() {
|
||||
return null; // TODO: Implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset(PasteBuilder pasteBuilder, boolean extension) {
|
||||
// TODO: Implement
|
||||
}
|
||||
};
|
||||
} else {
|
||||
build = Area.EMPTY;
|
||||
}
|
||||
|
||||
if (prototype.getTestblock() != null) {
|
||||
Point minPointTestblock = minPoint.add(prototype.getTestblock().getOffsetX(), prototype.getTestblock().getOffsetY(), prototype.getTestblock().getOffsetZ());
|
||||
Point maxPointTestblock = minPointTestblock.add(prototype.getTestblock().getSizeX() - 1, prototype.getTestblock().getSizeY() - 1, prototype.getTestblock().getSizeZ() - 1);
|
||||
|
||||
Point minPointTestblockExtension = minPointTestblock.subtract(prototype.getTestblock().getExtensionNegativeX(), prototype.getTestblock().getExtensionNegativeY(), prototype.getTestblock().getExtensionNegativeZ());
|
||||
Point maxPointTestblockExtension = maxPointTestblock.add(prototype.getTestblock().getExtensionPositiveX(), prototype.getTestblock().getExtensionPositiveY(), prototype.getTestblock().getExtensionPositiveZ());
|
||||
|
||||
Point copyPoint;
|
||||
if (!prototype.getTestblock().isHasCopyPoint() && (prototype.getCopyPointOffsetX() != 0 || prototype.getCopyPointOffsetY() != 0 || prototype.getCopyPointOffsetZ() != 0)) {
|
||||
copyPoint = minPoint.add(prototype.getCopyPointOffsetX(), prototype.getCopyPointOffsetY(), prototype.getCopyPointOffsetZ());
|
||||
} else if (prototype.getTestblock().getCopyOffsetX() != 0 || prototype.getTestblock().getCopyOffsetY() != 0 || prototype.getTestblock().getCopyOffsetZ() != 0) {
|
||||
copyPoint = minPointTestblock.add(prototype.getTestblock().getCopyOffsetX(), prototype.getTestblock().getCopyOffsetY(), prototype.getTestblock().getCopyOffsetZ());
|
||||
} else {
|
||||
copyPoint = minPointTestblock.add(prototype.getTestblock().getSizeX() / 2, 0, prototype.getTestblock().getSizeZ());
|
||||
}
|
||||
|
||||
testblock = new Area() {
|
||||
@Override
|
||||
public @NonNull Point getMinPoint(boolean extension) {
|
||||
return extension ? minPointTestblockExtension : minPointTestblock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Point getMaxPoint(boolean extension) {
|
||||
return extension ? maxPointTestblockExtension : maxPointTestblock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Point getCopyPoint() {
|
||||
return copyPoint;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public EditSession copy(boolean extension) {
|
||||
return null; // TODO: Implement
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public File getResetFile() {
|
||||
return null; // TODO: Implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset(PasteBuilder pasteBuilder, boolean extension) {
|
||||
// TODO: Implement
|
||||
}
|
||||
};
|
||||
} else {
|
||||
testblock = Area.EMPTY;
|
||||
}
|
||||
|
||||
if (!testblock.isEmpty() && !build.isEmpty()) {
|
||||
if (testblock.getMinPoint(false).getZ() > build.getMinPoint(false).getZ()) {
|
||||
flagStorage.getBackedMap().put(Flag.TESTBLOCK, TestblockMode.SOUTH);
|
||||
} else {
|
||||
flagStorage.getBackedMap().put(Flag.TESTBLOCK, TestblockMode.NORTH);
|
||||
}
|
||||
} else {
|
||||
flagStorage.getBackedMap().put(Flag.TESTBLOCK, TestblockMode.NO_VALUE);
|
||||
}
|
||||
|
||||
floorLevel = prototype.getFloorOffset() != 0 ? minPoint.getY() + prototype.getFloorOffset() : 0;
|
||||
waterLevel = prototype.getWaterOffset() != 0 ? minPoint.getX() + prototype.getWaterOffset() : 0;
|
||||
|
||||
File found = null;
|
||||
File baseFile = new File(BauSystem.getInstance().getDataFolder().getParentFile(), "FightSystem");
|
||||
for (int version = Core.getVersion(); version >= 15; version--) {
|
||||
File specific = new File(baseFile, prototype.getDisplayName() + version + ".yml");
|
||||
if (specific.exists()) {
|
||||
found = specific;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.regionConfig = new RegionConfig(found);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,31 +244,31 @@ public class FixedRegion implements Region {
|
||||
|
||||
@Override
|
||||
public @NonNull Area getArea() {
|
||||
return null;
|
||||
return area;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Area getBuildArea() {
|
||||
return null;
|
||||
return build;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Area getTestblockArea() {
|
||||
return null;
|
||||
return testblock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull RegionConfig getGameModeConfig() {
|
||||
return null;
|
||||
return regionConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull RegionHistory getHistory() {
|
||||
return null;
|
||||
return regionHistory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull RegionBackups getBackups() {
|
||||
return null;
|
||||
return RegionBackups.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-5
@@ -19,8 +19,7 @@
|
||||
|
||||
package de.steamwar.bausystem.region.fixed;
|
||||
|
||||
import de.steamwar.bausystem.region.FlagStorage;
|
||||
import de.steamwar.bausystem.region.flags.TestblockMode;
|
||||
import de.steamwar.bausystem.region.FixedRegionSystem;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
@@ -217,8 +216,7 @@ public class Prototype {
|
||||
} else {
|
||||
prototype = PROTOTYPE_MAP.get(regionConfig.getPlainValue("prototype"));
|
||||
}
|
||||
FlagStorage flagStorage = new FixedFlagStorage(TestblockMode.NO_VALUE, regionData.getObjectOrSetDefault("flagStorage", new YAPIONObject()));
|
||||
System.out.println(name + " " + prototype + " " + flagStorage);
|
||||
// return new Region(name, prototype, regionConfig, flagStorage, regionData);
|
||||
FixedFlagStorage flagStorage = new FixedFlagStorage(regionData.getObjectOrSetDefault("flagStorage", new YAPIONObject()));
|
||||
FixedRegionSystem.addRegion(new FixedRegion(name, flagStorage, prototype, regionConfig, regionData));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user