forked from SteamWar/SteamWar
Add SpawnPathRegion
Add SpawnRegion
This commit is contained in:
@@ -57,6 +57,19 @@ public class PasteBuilder {
|
|||||||
this.clipboardProvider = clipboardProvider;
|
this.clipboardProvider = clipboardProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PasteBuilder with(ClipboardProvider clipboardProvider) {
|
||||||
|
return new PasteBuilder(clipboardProvider)
|
||||||
|
.pastePoint(pastPoint)
|
||||||
|
.rotate(rotate)
|
||||||
|
.ignoreAir(ignoreAir)
|
||||||
|
.reset(reset)
|
||||||
|
.minPoint(minPoint)
|
||||||
|
.maxPoint(maxPoint)
|
||||||
|
.waterLevel(waterLevel)
|
||||||
|
.predicates(predicates)
|
||||||
|
.mappers(mappers);
|
||||||
|
}
|
||||||
|
|
||||||
public PasteBuilder pastePoint(Point point) {
|
public PasteBuilder pastePoint(Point point) {
|
||||||
this.pastPoint = point;
|
this.pastPoint = point;
|
||||||
return this;
|
return this;
|
||||||
@@ -92,6 +105,16 @@ public class PasteBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PasteBuilder predicates(List<BiPredicate<BaseBlock, String>> predicates) {
|
||||||
|
this.predicates = predicates;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PasteBuilder mappers(List<BiConsumer<Clipboard, BlockVector3>> mappers) {
|
||||||
|
this.mappers = mappers;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public PasteBuilder only(BiPredicate<BaseBlock, String> predicate) {
|
public PasteBuilder only(BiPredicate<BaseBlock, String> predicate) {
|
||||||
predicates.add(predicate);
|
predicates.add(predicate);
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
+48
-11
@@ -20,30 +20,48 @@
|
|||||||
package de.steamwar.bausystem.region;
|
package de.steamwar.bausystem.region;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.bausystem.region.dynamic.DynamicRegion;
|
||||||
import de.steamwar.bausystem.region.dynamic.MovementListener;
|
import de.steamwar.bausystem.region.dynamic.MovementListener;
|
||||||
import de.steamwar.bausystem.region.dynamic.Tile;
|
import de.steamwar.bausystem.region.dynamic.RegionDataRepository;
|
||||||
import de.steamwar.bausystem.region.dynamic.global.GlobalRegion;
|
import de.steamwar.bausystem.region.dynamic.global.GlobalRegion;
|
||||||
|
import de.steamwar.bausystem.region.dynamic.spawn.SpawnPathRegion;
|
||||||
|
import de.steamwar.bausystem.region.dynamic.spawn.SpawnRegion;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class DynamicRegionSystem implements RegionSystem {
|
public class DynamicRegionSystem implements RegionSystem {
|
||||||
|
|
||||||
public static DynamicRegionSystem INSTANCE;
|
public static DynamicRegionSystem INSTANCE;
|
||||||
|
private static final World WORLD = Bukkit.getWorlds().get(0);
|
||||||
|
|
||||||
private static Map<Tile, UUID> tileMap = new HashMap<>();
|
|
||||||
private static Map<UUID, Region> regionMap = new HashMap<>();
|
private static Map<UUID, Region> regionMap = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load() {
|
public void load() {
|
||||||
INSTANCE = this;
|
INSTANCE = this;
|
||||||
|
RegionDataRepository.loadRegions();
|
||||||
Bukkit.getPluginManager().registerEvents(new MovementListener(), BauSystem.getInstance());
|
Bukkit.getPluginManager().registerEvents(new MovementListener(), BauSystem.getInstance());
|
||||||
|
|
||||||
|
if (regionMap.isEmpty()) {
|
||||||
|
new SpawnRegion(-9, -9);
|
||||||
|
new SpawnPathRegion(-9, -27);
|
||||||
|
new SpawnPathRegion(-9, 10);
|
||||||
|
new SpawnPathRegion(-27, -9);
|
||||||
|
new SpawnPathRegion(10, -9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(DynamicRegion region) {
|
||||||
|
regionMap.put(region.getID(), region);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(DynamicRegion region) {
|
||||||
|
regionMap.remove(region.getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -62,11 +80,10 @@ public class DynamicRegionSystem implements RegionSystem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull Region get(@NonNull Location location) {
|
public @NonNull Region get(@NonNull Location location) {
|
||||||
Optional<Tile> tile = Tile.fromLocation(location);
|
return regionMap.values().stream()
|
||||||
if (tile.isEmpty()) return GlobalRegion.INSTANCE;
|
.filter(region -> region.getArea().inRegion(location, false))
|
||||||
UUID uuid = tileMap.get(tile.get());
|
.findFirst()
|
||||||
if (uuid == null) return GlobalRegion.INSTANCE;
|
.orElse(GlobalRegion.INSTANCE);
|
||||||
return regionMap.getOrDefault(uuid, GlobalRegion.INSTANCE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -79,6 +96,26 @@ public class DynamicRegionSystem implements RegionSystem {
|
|||||||
return regionMap.values().stream();
|
return regionMap.values().stream();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Stream<Region> getNeighbours(Region region) {
|
||||||
|
Point minPoint = region.getArea().getMinPoint(false).subtract(19, 0, 19);
|
||||||
|
Point maxPoint = region.getArea().getMaxPoint(false).add(19, 0, 19);
|
||||||
|
Set<Region> neighbours = new HashSet<>();
|
||||||
|
for (int x = minPoint.getX(); x <= maxPoint.getX(); x += 19) {
|
||||||
|
int minZ = minPoint.getZ();
|
||||||
|
int maxZ = maxPoint.getZ();
|
||||||
|
neighbours.add(get(new Location(WORLD, x, 0, minZ)));
|
||||||
|
neighbours.add(get(new Location(WORLD, x, 0, maxZ)));
|
||||||
|
}
|
||||||
|
for (int z = minPoint.getZ() + 19; z <= maxPoint.getZ() - 19; z += 19) {
|
||||||
|
int minX = minPoint.getX();
|
||||||
|
int maxX = maxPoint.getX();
|
||||||
|
neighbours.add(get(new Location(WORLD, minX, 0, z)));
|
||||||
|
neighbours.add(get(new Location(WORLD, maxX, 0, z)));
|
||||||
|
}
|
||||||
|
neighbours.remove(GlobalRegion.INSTANCE);
|
||||||
|
return neighbours.stream();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isModular() {
|
public boolean isModular() {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
+59
-6
@@ -19,14 +19,67 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.region.dynamic;
|
package de.steamwar.bausystem.region.dynamic;
|
||||||
|
|
||||||
import de.steamwar.bausystem.region.FlagStorage;
|
import de.steamwar.bausystem.region.*;
|
||||||
import de.steamwar.bausystem.region.Region;
|
import lombok.NonNull;
|
||||||
|
|
||||||
public interface DynamicRegion extends Region {
|
import java.util.UUID;
|
||||||
|
|
||||||
default void update(Tile updateFrom) {
|
public abstract class DynamicRegion implements Region {
|
||||||
System.out.println("Updating from " + updateFrom);
|
|
||||||
|
protected final UUID id;
|
||||||
|
protected final int minX;
|
||||||
|
protected final int minZ;
|
||||||
|
|
||||||
|
protected final RegionHistory history = new RegionHistory.Impl(20);
|
||||||
|
protected final RegionBackups backups;
|
||||||
|
|
||||||
|
protected DynamicRegion(int minX, int minZ) {
|
||||||
|
this.id = UUID.randomUUID();
|
||||||
|
this.minX = minX;
|
||||||
|
this.minZ = minZ;
|
||||||
|
backups = RegionDataRepository.getBackups(this);
|
||||||
|
RegionDataRepository.saveRegion(this);
|
||||||
|
DynamicRegionSystem.INSTANCE.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setFlags(FlagStorage flags);
|
protected DynamicRegion(RegionConstructorData regionConstructorData) {
|
||||||
|
this.id = regionConstructorData.uuid;
|
||||||
|
this.minX = regionConstructorData.minX;
|
||||||
|
this.minZ = regionConstructorData.minZ;
|
||||||
|
backups = RegionDataRepository.getBackups(this);
|
||||||
|
DynamicRegionSystem.INSTANCE.add(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RegionConstructorData getRegionConstructorData() {
|
||||||
|
return new RegionConstructorData.RegionConstructorDataBuilder()
|
||||||
|
.regionClass(this.getClass().getSimpleName())
|
||||||
|
.uuid(id)
|
||||||
|
.minX(minX)
|
||||||
|
.minZ(minZ)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull UUID getID() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void update(DynamicRegion updateFrom);
|
||||||
|
|
||||||
|
public abstract void setFlags(FlagStorage flags);
|
||||||
|
|
||||||
|
public void delete() {
|
||||||
|
DynamicRegionSystem.INSTANCE.delete(this);
|
||||||
|
RegionDataRepository.deleteRegion(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull RegionHistory getHistory() {
|
||||||
|
return history;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull RegionBackups getBackups() {
|
||||||
|
return backups;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-4
@@ -20,8 +20,10 @@
|
|||||||
package de.steamwar.bausystem.region.dynamic;
|
package de.steamwar.bausystem.region.dynamic;
|
||||||
|
|
||||||
import de.steamwar.bausystem.region.Region;
|
import de.steamwar.bausystem.region.Region;
|
||||||
|
import de.steamwar.bausystem.shared.Pair;
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
@@ -30,14 +32,28 @@ import java.util.Optional;
|
|||||||
|
|
||||||
public class MovementListener implements Listener {
|
public class MovementListener implements Listener {
|
||||||
|
|
||||||
|
private static final int tileSize = 19;
|
||||||
|
private static final int minTile = -1023;
|
||||||
|
private static final int maxTile = 1023;
|
||||||
|
|
||||||
|
public static Pair<Integer, Integer> fromLocation(Location location) {
|
||||||
|
int x = (location.getBlockX() + 9) / tileSize;
|
||||||
|
int z = (location.getBlockZ() + 9) / tileSize;
|
||||||
|
if (location.getX() < -9) x--;
|
||||||
|
if (location.getZ() < -9) z--;
|
||||||
|
if (x < minTile || z < minTile) return null;
|
||||||
|
if (x > maxTile || z > maxTile) return null;
|
||||||
|
return new Pair<>(x, z);
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerMove(PlayerMoveEvent event) {
|
public void onPlayerMove(PlayerMoveEvent event) {
|
||||||
Optional<Tile> tile = Tile.fromLocation(event.getTo());
|
Pair<Integer, Integer> tile = fromLocation(event.getTo());
|
||||||
Region region = Region.getRegion(event.getTo());
|
Region region = Region.getRegion(event.getTo());
|
||||||
if (tile.isPresent()) {
|
if (tile != null) {
|
||||||
event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(region.getType() + " " + tile.get() + " " + region.getType()));
|
event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(tile.getKey() + " : " + tile.getValue() + " " + region.getType()));
|
||||||
} else {
|
} else {
|
||||||
event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(region.getType() + " NONE " + region.getType()));
|
event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("NONE " + region.getType()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-4
@@ -17,11 +17,10 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.region.dynamic.global;
|
package de.steamwar.bausystem.region.dynamic;
|
||||||
|
|
||||||
import de.steamwar.bausystem.region.FlagOptional;
|
import de.steamwar.bausystem.region.FlagOptional;
|
||||||
import de.steamwar.bausystem.region.RegionFlagPolicy;
|
import de.steamwar.bausystem.region.RegionFlagPolicy;
|
||||||
import de.steamwar.bausystem.region.dynamic.DefaultFlagStorage;
|
|
||||||
import de.steamwar.bausystem.region.flags.ColorMode;
|
import de.steamwar.bausystem.region.flags.ColorMode;
|
||||||
import de.steamwar.bausystem.region.flags.Flag;
|
import de.steamwar.bausystem.region.flags.Flag;
|
||||||
import de.steamwar.bausystem.region.flags.ProtectMode;
|
import de.steamwar.bausystem.region.flags.ProtectMode;
|
||||||
@@ -31,9 +30,9 @@ import lombok.NonNull;
|
|||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
@ToString
|
@ToString
|
||||||
public class GlobalFlagStorage extends DefaultFlagStorage {
|
public class NonNormalFlagStorage extends DefaultFlagStorage {
|
||||||
|
|
||||||
public GlobalFlagStorage() {
|
public NonNormalFlagStorage() {
|
||||||
flagMap.put(Flag.TNT, TNTMode.DENY);
|
flagMap.put(Flag.TNT, TNTMode.DENY);
|
||||||
}
|
}
|
||||||
|
|
||||||
+61
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* 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.dynamic;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.stream.JsonWriter;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Cleanup;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class RegionConstructorData {
|
||||||
|
|
||||||
|
public final String regionClass;
|
||||||
|
public final UUID uuid;
|
||||||
|
public final int minX;
|
||||||
|
public final int minZ;
|
||||||
|
|
||||||
|
public RegionConstructorData(JsonObject jsonObject) {
|
||||||
|
regionClass = jsonObject.get("regionClass").getAsString();
|
||||||
|
uuid = UUID.fromString(jsonObject.get("uuid").getAsString());
|
||||||
|
minX = jsonObject.get("minX").getAsInt();
|
||||||
|
minZ = jsonObject.get("minZ").getAsInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
public void write(File file) {
|
||||||
|
@Cleanup
|
||||||
|
JsonWriter writer = new JsonWriter(new FileWriter(file));
|
||||||
|
writer.setIndent(" ");
|
||||||
|
writer.beginObject();
|
||||||
|
writer.name("regionClass").value(regionClass);
|
||||||
|
writer.name("uuid").value(uuid.toString());
|
||||||
|
writer.name("minX").value(minX);
|
||||||
|
writer.name("minZ").value(minZ);
|
||||||
|
writer.endObject();
|
||||||
|
}
|
||||||
|
}
|
||||||
+44
-8
@@ -25,8 +25,11 @@ import com.google.gson.stream.JsonWriter;
|
|||||||
import com.sk89q.worldedit.EditSession;
|
import com.sk89q.worldedit.EditSession;
|
||||||
import de.steamwar.bausystem.region.FlagStorage;
|
import de.steamwar.bausystem.region.FlagStorage;
|
||||||
import de.steamwar.bausystem.region.Point;
|
import de.steamwar.bausystem.region.Point;
|
||||||
|
import de.steamwar.bausystem.region.Region;
|
||||||
import de.steamwar.bausystem.region.RegionBackups;
|
import de.steamwar.bausystem.region.RegionBackups;
|
||||||
import de.steamwar.bausystem.region.dynamic.normal.NormalFlagStorage;
|
import de.steamwar.bausystem.region.dynamic.normal.NormalFlagStorage;
|
||||||
|
import de.steamwar.bausystem.region.dynamic.spawn.SpawnPathRegion;
|
||||||
|
import de.steamwar.bausystem.region.dynamic.spawn.SpawnRegion;
|
||||||
import de.steamwar.bausystem.region.flags.Flag;
|
import de.steamwar.bausystem.region.flags.Flag;
|
||||||
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
||||||
import de.steamwar.bausystem.utils.PasteBuilder;
|
import de.steamwar.bausystem.utils.PasteBuilder;
|
||||||
@@ -48,29 +51,61 @@ import java.nio.file.SimpleFileVisitor;
|
|||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.function.Function;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class RegionDataRepository {
|
public class RegionDataRepository {
|
||||||
|
|
||||||
|
public static final String META_FILE_NAME = "meta.json";
|
||||||
public static final String FLAGS_FILE_NAME = "flags.json";
|
public static final String FLAGS_FILE_NAME = "flags.json";
|
||||||
public static final String REGION_SCHEM_FILE_NAME = "region.schem";
|
public static final String REGION_SCHEM_FILE_NAME = "region.schem";
|
||||||
|
public static final String BACKUP_DIRECTORY = "backup";
|
||||||
private static File regionDataFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions");
|
private static File regionDataFolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions");
|
||||||
|
private static Map<String, Function<RegionConstructorData, DynamicRegion>> regionCreators = new HashMap<>();
|
||||||
|
static {
|
||||||
|
regionCreators.put(SpawnRegion.class.getSimpleName(), SpawnRegion::new);
|
||||||
|
regionCreators.put(SpawnPathRegion.class.getSimpleName(), SpawnPathRegion::new);
|
||||||
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
regionDataFolder.mkdirs();
|
regionDataFolder.mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
private File getRegionDirectory(DynamicRegion region) {
|
private File getRegionDirectory(Region region) {
|
||||||
File file = new File(regionDataFolder, region.getID().toString());
|
File file = new File(regionDataFolder, region.getID().toString());
|
||||||
file.mkdirs();
|
file.mkdirs();
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadFlagStorage(DynamicRegion region, FlagStorage storage) {
|
@SneakyThrows
|
||||||
|
public List<DynamicRegion> loadRegions() {
|
||||||
|
File[] files = regionDataFolder.listFiles();
|
||||||
|
List<DynamicRegion> regions = new ArrayList<>();
|
||||||
|
for (File file : files) {
|
||||||
|
File metaFile = new File(file, META_FILE_NAME);
|
||||||
|
if (!metaFile.exists()) continue;
|
||||||
|
JsonObject jsonObject = JsonParser.parseReader(new FileReader(metaFile)).getAsJsonObject();
|
||||||
|
RegionConstructorData regionConstructorData = new RegionConstructorData(jsonObject);
|
||||||
|
Function<RegionConstructorData, DynamicRegion> constructor = regionCreators.get(regionConstructorData.regionClass);
|
||||||
|
if (constructor == null) continue;
|
||||||
|
regions.add(constructor.apply(regionConstructorData));
|
||||||
|
}
|
||||||
|
return regions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveRegion(DynamicRegion region) {
|
||||||
|
File file = getRegionDirectory(region);
|
||||||
|
file = new File(file, META_FILE_NAME);
|
||||||
|
region.getRegionConstructorData()
|
||||||
|
.write(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteRegion(DynamicRegion region) {
|
||||||
|
deleteDir(getRegionDirectory(region));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadFlagStorage(Region region, FlagStorage storage) {
|
||||||
File file = getRegionDirectory(region);
|
File file = getRegionDirectory(region);
|
||||||
file = new File(file, FLAGS_FILE_NAME);
|
file = new File(file, FLAGS_FILE_NAME);
|
||||||
loadFlagStorage(file, storage);
|
loadFlagStorage(file, storage);
|
||||||
@@ -84,6 +119,7 @@ public class RegionDataRepository {
|
|||||||
if (file == null || !file.exists()) return;
|
if (file == null || !file.exists()) return;
|
||||||
JsonObject jsonObject = JsonParser.parseReader(new FileReader(file)).getAsJsonObject();
|
JsonObject jsonObject = JsonParser.parseReader(new FileReader(file)).getAsJsonObject();
|
||||||
for (Flag flag : Flag.getFlags()) {
|
for (Flag flag : Flag.getFlags()) {
|
||||||
|
if (!jsonObject.has(flag.name())) continue;
|
||||||
Flag.Value<?> value;
|
Flag.Value<?> value;
|
||||||
try {
|
try {
|
||||||
value = flag.valueOfValue(jsonObject.get(flag.name()).getAsString());
|
value = flag.valueOfValue(jsonObject.get(flag.name()).getAsString());
|
||||||
@@ -94,7 +130,7 @@ public class RegionDataRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveFlagStorage(DynamicRegion region, FlagStorage storage) {
|
private void saveFlagStorage(Region region, FlagStorage storage) {
|
||||||
File file = getRegionDirectory(region);
|
File file = getRegionDirectory(region);
|
||||||
file = new File(file, FLAGS_FILE_NAME);
|
file = new File(file, FLAGS_FILE_NAME);
|
||||||
saveFlagStorage(file, storage);
|
saveFlagStorage(file, storage);
|
||||||
@@ -121,7 +157,7 @@ public class RegionDataRepository {
|
|||||||
return RegionBackups.EMPTY;
|
return RegionBackups.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
File directory = new File(getRegionDirectory(region), "backup");
|
File directory = new File(getRegionDirectory(region), BACKUP_DIRECTORY);
|
||||||
directory.mkdirs();
|
directory.mkdirs();
|
||||||
return new RegionBackups() {
|
return new RegionBackups() {
|
||||||
private List<Backup> backups = new ArrayList<>();
|
private List<Backup> backups = new ArrayList<>();
|
||||||
|
|||||||
@@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.dynamic;
|
|
||||||
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
|
||||||
public class Tile {
|
|
||||||
|
|
||||||
private static final int tileSize = 19;
|
|
||||||
private static final int minTile = -1023;
|
|
||||||
private static final int maxTile = 1023;
|
|
||||||
|
|
||||||
public static Optional<Tile> fromLocation(Location location) {
|
|
||||||
int x = (location.getBlockX() + 9) / tileSize;
|
|
||||||
int z = (location.getBlockZ() + 9) / tileSize;
|
|
||||||
if (location.getX() < -9) x--;
|
|
||||||
if (location.getZ() < -9) z--;
|
|
||||||
if (x < minTile || z < minTile) return Optional.empty();
|
|
||||||
if (x > maxTile || z > maxTile) return Optional.empty();
|
|
||||||
return Optional.of(new Tile(x, z));
|
|
||||||
}
|
|
||||||
|
|
||||||
private int x;
|
|
||||||
private int z;
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return x + " : " + z;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Tile> getNeighbors() {
|
|
||||||
List<Tile> neighbors = new ArrayList<>();
|
|
||||||
for (int x = -1; x <= 1; x++) {
|
|
||||||
for (int z = -1; z <= 1; z++) {
|
|
||||||
if (x == 0 && z == 0) continue;
|
|
||||||
if (this.x + x < minTile || this.z + z < minTile) continue;
|
|
||||||
if (this.x + x > maxTile || this.z + z > maxTile) continue;
|
|
||||||
neighbors.add(new Tile(this.x + x, this.z + z));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return neighbors;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+84
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* 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.dynamic;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
|
import de.steamwar.bausystem.region.Point;
|
||||||
|
import de.steamwar.bausystem.region.Region;
|
||||||
|
import de.steamwar.bausystem.region.RegionHistory;
|
||||||
|
import de.steamwar.bausystem.utils.PasteBuilder;
|
||||||
|
import lombok.NonNull;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class TileArea implements Region.Area {
|
||||||
|
|
||||||
|
private final int minX;
|
||||||
|
private final int minZ;
|
||||||
|
private final File resetFile;
|
||||||
|
private final Point minPoint;
|
||||||
|
private final Point maxPoint;
|
||||||
|
private final Point copyPoint;
|
||||||
|
private final RegionHistory regionHistory;
|
||||||
|
|
||||||
|
public TileArea(int minX, int minZ, File resetFile, RegionHistory regionHistory) {
|
||||||
|
this.minX = minX;
|
||||||
|
this.minZ = minZ;
|
||||||
|
this.resetFile = resetFile;
|
||||||
|
|
||||||
|
minPoint = new Point(minX, 0, minZ);
|
||||||
|
maxPoint = new Point(minX + 18, 255, minZ + 18);
|
||||||
|
copyPoint = new Point(minX + 9, 0, minZ + 9);
|
||||||
|
|
||||||
|
this.regionHistory = regionHistory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull Point getMinPoint(boolean extension) {
|
||||||
|
return minPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull Point getMaxPoint(boolean extension) {
|
||||||
|
return maxPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull Point getCopyPoint() {
|
||||||
|
return copyPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public File getResetFile() {
|
||||||
|
return resetFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reset(PasteBuilder pasteBuilder, boolean extension) {
|
||||||
|
EditSession editSession = pasteBuilder.with(new PasteBuilder.FileProvider(resetFile))
|
||||||
|
.minPoint(minPoint)
|
||||||
|
.maxPoint(maxPoint)
|
||||||
|
.pastePoint(minPoint)
|
||||||
|
.run();
|
||||||
|
regionHistory.remember(editSession);
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-7
@@ -22,6 +22,7 @@ package de.steamwar.bausystem.region.dynamic.global;
|
|||||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||||
import de.steamwar.bausystem.region.*;
|
import de.steamwar.bausystem.region.*;
|
||||||
import de.steamwar.bausystem.region.dynamic.DynamicRegion;
|
import de.steamwar.bausystem.region.dynamic.DynamicRegion;
|
||||||
|
import de.steamwar.bausystem.region.dynamic.NonNormalFlagStorage;
|
||||||
import de.steamwar.bausystem.region.dynamic.RegionDataRepository;
|
import de.steamwar.bausystem.region.dynamic.RegionDataRepository;
|
||||||
import de.steamwar.bausystem.utils.PasteBuilder;
|
import de.steamwar.bausystem.utils.PasteBuilder;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
@@ -32,7 +33,7 @@ import java.io.File;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
public class GlobalRegion implements DynamicRegion {
|
public class GlobalRegion implements Region {
|
||||||
|
|
||||||
public static final GlobalRegion INSTANCE = new GlobalRegion();
|
public static final GlobalRegion INSTANCE = new GlobalRegion();
|
||||||
|
|
||||||
@@ -90,7 +91,7 @@ public class GlobalRegion implements DynamicRegion {
|
|||||||
|
|
||||||
private static final RegionConfig GLOBAL_CONFIG = new RegionConfig(null);
|
private static final RegionConfig GLOBAL_CONFIG = new RegionConfig(null);
|
||||||
|
|
||||||
private static FlagStorage FLAG_STORAGE = new GlobalFlagStorage();
|
private static FlagStorage FLAG_STORAGE = new NonNormalFlagStorage();
|
||||||
static {
|
static {
|
||||||
RegionDataRepository.loadFlagStorage(INSTANCE, FLAG_STORAGE);
|
RegionDataRepository.loadFlagStorage(INSTANCE, FLAG_STORAGE);
|
||||||
}
|
}
|
||||||
@@ -113,11 +114,6 @@ public class GlobalRegion implements DynamicRegion {
|
|||||||
return FLAG_STORAGE;
|
return FLAG_STORAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setFlags(FlagStorage flags) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull Region.Area getArea() {
|
public @NonNull Region.Area getArea() {
|
||||||
return GLOBAL_AREA;
|
return GLOBAL_AREA;
|
||||||
|
|||||||
+84
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* 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.dynamic.spawn;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.region.FlagStorage;
|
||||||
|
import de.steamwar.bausystem.region.RegionConfig;
|
||||||
|
import de.steamwar.bausystem.region.RegionType;
|
||||||
|
import de.steamwar.bausystem.region.dynamic.*;
|
||||||
|
import lombok.NonNull;
|
||||||
|
|
||||||
|
public class SpawnPathRegion extends DynamicRegion {
|
||||||
|
|
||||||
|
private FlagStorage flagStorage = new NonNormalFlagStorage();
|
||||||
|
private final Area area;
|
||||||
|
private final RegionConfig config = new RegionConfig(null);
|
||||||
|
|
||||||
|
public SpawnPathRegion(int minX, int minZ) {
|
||||||
|
super(minX, minZ);
|
||||||
|
RegionDataRepository.loadFlagStorage(this, flagStorage);
|
||||||
|
area = new TileArea(minX, minZ, null, history);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SpawnPathRegion(RegionConstructorData regionConstructorData) {
|
||||||
|
super(regionConstructorData);
|
||||||
|
RegionDataRepository.loadFlagStorage(this, flagStorage);
|
||||||
|
area = new TileArea(minX, minZ, null, history);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(DynamicRegion updateFrom) {
|
||||||
|
// TODO: Implement
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFlags(FlagStorage flags) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull RegionType getType() {
|
||||||
|
return RegionType.SPAWN_PATH;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull FlagStorage getFlags() {
|
||||||
|
return flagStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull Area getArea() {
|
||||||
|
return area;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull Area getBuildArea() {
|
||||||
|
return Area.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull Area getTestblockArea() {
|
||||||
|
return Area.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull RegionConfig getGameModeConfig() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
||||||
+84
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* 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.dynamic.spawn;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.region.FlagStorage;
|
||||||
|
import de.steamwar.bausystem.region.RegionConfig;
|
||||||
|
import de.steamwar.bausystem.region.RegionType;
|
||||||
|
import de.steamwar.bausystem.region.dynamic.*;
|
||||||
|
import lombok.NonNull;
|
||||||
|
|
||||||
|
public class SpawnRegion extends DynamicRegion {
|
||||||
|
|
||||||
|
private FlagStorage flagStorage = new NonNormalFlagStorage();
|
||||||
|
private final Area area;
|
||||||
|
private final RegionConfig config = new RegionConfig(null);
|
||||||
|
|
||||||
|
public SpawnRegion(int minX, int minZ) {
|
||||||
|
super(minX, minZ);
|
||||||
|
RegionDataRepository.loadFlagStorage(this, flagStorage);
|
||||||
|
area = new TileArea(minX, minZ, null, history);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SpawnRegion(RegionConstructorData regionConstructorData) {
|
||||||
|
super(regionConstructorData);
|
||||||
|
RegionDataRepository.loadFlagStorage(this, flagStorage);
|
||||||
|
area = new TileArea(minX, minZ, null, history);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(DynamicRegion updateFrom) {
|
||||||
|
// TODO: Implement
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFlags(FlagStorage flags) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull RegionType getType() {
|
||||||
|
return RegionType.SPAWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull FlagStorage getFlags() {
|
||||||
|
return flagStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull Area getArea() {
|
||||||
|
return area;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull Area getBuildArea() {
|
||||||
|
return Area.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull Area getTestblockArea() {
|
||||||
|
return Area.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull RegionConfig getGameModeConfig() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user