forked from SteamWar/SteamWar
Add DynamicRegion
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.region;
|
package de.steamwar.bausystem.region;
|
||||||
|
|
||||||
|
import de.steamwar.core.Core;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
@@ -39,11 +40,6 @@ public interface RegionSystem {
|
|||||||
*/
|
*/
|
||||||
void load();
|
void load();
|
||||||
|
|
||||||
/**
|
|
||||||
* Saves anything that should be written to file on either CRIUSleepEvent or plugin disable.
|
|
||||||
*/
|
|
||||||
void save();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Location to teleport players to when they first join or Warp to "WorldSpawn"
|
* Returns the Location to teleport players to when they first join or Warp to "WorldSpawn"
|
||||||
*/
|
*/
|
||||||
@@ -77,52 +73,51 @@ public interface RegionSystem {
|
|||||||
Stream<Region> getRegions();
|
Stream<Region> getRegions();
|
||||||
|
|
||||||
private static RegionSystem init() {
|
private static RegionSystem init() {
|
||||||
try {
|
if (Core.getVersion() >= 21) {
|
||||||
return (RegionSystem) Class.forName("de.steamwar.bausystem.region.DynamicRegionSystem").getConstructor().newInstance();
|
// TODO: Add some kind of detection if the DynamicRegionSystem should be used!
|
||||||
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException |
|
try {
|
||||||
InvocationTargetException e) {
|
return (RegionSystem) Class.forName("de.steamwar.bausystem.region.DynamicRegionSystem").getConstructor().newInstance();
|
||||||
// Ignore
|
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException |
|
||||||
|
InvocationTargetException e) {
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return (RegionSystem) Class.forName("de.steamwar.bausystem.region.FixedRegionSystem").getConstructor().newInstance();
|
return (RegionSystem) Class.forName("de.steamwar.bausystem.region.FixedRegionSystem").getConstructor().newInstance();
|
||||||
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException |
|
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException |
|
||||||
InvocationTargetException e) {
|
InvocationTargetException e) {
|
||||||
return new RegionSystem() {
|
// Ignore
|
||||||
@Override
|
|
||||||
public void load() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void save() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NonNull Location getWorldSpawn() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Region getGlobalRegion() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Region get(Location location) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<Region> getRegion(UUID id) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Stream<Region> getRegions() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
return new RegionSystem() {
|
||||||
|
@Override
|
||||||
|
public void load() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull Location getWorldSpawn() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Region getGlobalRegion() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Region get(Location location) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Region> getRegion(UUID id) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream<Region> getRegions() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ java {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
compileOnly(libs.classindex)
|
||||||
|
|
||||||
compileOnly(project(":BauSystem:BauSystem_Main", "default"))
|
compileOnly(project(":BauSystem:BauSystem_Main", "default"))
|
||||||
compileOnly(project(":SpigotCore", "default"))
|
compileOnly(project(":SpigotCore", "default"))
|
||||||
|
|
||||||
|
|||||||
+32
-7
@@ -19,20 +19,22 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.region;
|
package de.steamwar.bausystem.region;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.bausystem.region.dynamic.DynamicRegion;
|
||||||
|
import de.steamwar.bausystem.region.dynamic.RegionConstructorData;
|
||||||
import de.steamwar.bausystem.region.dynamic.Tile;
|
import de.steamwar.bausystem.region.dynamic.Tile;
|
||||||
import de.steamwar.bausystem.region.dynamic.global.GlobalRegion;
|
import de.steamwar.bausystem.region.dynamic.global.GlobalRegion;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
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 final Map<Long, Region> regionCache = new LinkedHashMap<>(16, 0.75f, true) {
|
private static final Map<Long, Region> regionCache = new LinkedHashMap<>(16, 0.75f, true) {
|
||||||
@Override
|
@Override
|
||||||
@@ -43,13 +45,36 @@ public class DynamicRegionSystem implements RegionSystem {
|
|||||||
private static final Map<UUID, Region> regionMap = new HashMap<>();
|
private static final Map<UUID, Region> regionMap = new HashMap<>();
|
||||||
private static final Map<RegionType, Set<Region>> regionTypeMap = new EnumMap<>(RegionType.class);
|
private static final Map<RegionType, Set<Region>> regionTypeMap = new EnumMap<>(RegionType.class);
|
||||||
|
|
||||||
@Override
|
public void add(DynamicRegion region) {
|
||||||
public void load() {
|
regionCache.clear();
|
||||||
INSTANCE = this;
|
regionMap.put(region.getID(), region);
|
||||||
|
regionTypeMap.computeIfAbsent(region.getType(), __ -> new HashSet<>()).add(region);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(DynamicRegion region) {
|
||||||
|
regionCache.clear();
|
||||||
|
regionMap.remove(region.getId());
|
||||||
|
regionTypeMap.getOrDefault(region.getType(), Collections.emptySet()).remove(region);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save() {
|
public void load() {
|
||||||
|
INSTANCE = this;
|
||||||
|
|
||||||
|
new BufferedReader(new InputStreamReader(BauSystem.getInstance().getClass().getResourceAsStream("/META-INF/annotations/de.steamwar.bausystem.region.dynamic.RegionConstructorData")))
|
||||||
|
.lines()
|
||||||
|
.map(s -> {
|
||||||
|
try {
|
||||||
|
return Class.forName(s, false, BauSystem.getInstance().getClass().getClassLoader());
|
||||||
|
} catch (ClassNotFoundException | NoClassDefFoundError e) {
|
||||||
|
throw new SecurityException(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.forEach(clazz -> {
|
||||||
|
RegionConstructorData regionConstructorData = clazz.getAnnotation(RegionConstructorData.class);
|
||||||
|
if (regionConstructorData == null) return;
|
||||||
|
// TODO: Save regionConstructorData together with clazz
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2025 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 de.steamwar.bausystem.region.DynamicRegionSystem;
|
||||||
|
import de.steamwar.bausystem.region.Region;
|
||||||
|
import de.steamwar.bausystem.region.RegionData;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NonNull;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public abstract class DynamicRegion implements Region {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
protected final UUID id;
|
||||||
|
protected final int minX;
|
||||||
|
protected final int minZ;
|
||||||
|
|
||||||
|
protected DynamicRegion(UUID id, int minX, int minZ) {
|
||||||
|
this.id = id;
|
||||||
|
this.minX = minX;
|
||||||
|
this.minZ = minZ;
|
||||||
|
DynamicRegionSystem.INSTANCE.add(this);
|
||||||
|
// TODO: Implement further
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(DynamicRegion updateFrom) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void setRegionData(@NonNull RegionData regionData);
|
||||||
|
|
||||||
|
public void delete() {
|
||||||
|
if (getType().isCannotDelete()) return;
|
||||||
|
DynamicRegionSystem.INSTANCE.remove(this);
|
||||||
|
// TODO: Implement!
|
||||||
|
}
|
||||||
|
}
|
||||||
+17
-5
@@ -17,10 +17,22 @@
|
|||||||
* 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;
|
package de.steamwar.bausystem.region.dynamic;
|
||||||
|
|
||||||
public abstract class RegionConstructor<T extends Region> {
|
import de.steamwar.bausystem.region.RegionData;
|
||||||
public abstract int getWidthX();
|
import org.atteo.classindex.IndexAnnotated;
|
||||||
public abstract int getWidthZ();
|
|
||||||
public abstract T create(int tileX, int tileZ);
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@IndexAnnotated
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
public @interface RegionConstructorData {
|
||||||
|
int widthX();
|
||||||
|
int widthZ();
|
||||||
|
boolean placeable() default true;
|
||||||
|
Class<? extends RegionData> regionDataClass();
|
||||||
}
|
}
|
||||||
+4
@@ -33,6 +33,10 @@ public class GlobalRegionData extends RegionData {
|
|||||||
|
|
||||||
public GlobalRegionData() {
|
public GlobalRegionData() {
|
||||||
super(new YAPIONObject(), () -> {}); // TODO: Implement loading of data and saving!
|
super(new YAPIONObject(), () -> {}); // TODO: Implement loading of data and saving!
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initialize() {
|
||||||
flagMap.put(Flag.TNT, TNTMode.DENY);
|
flagMap.put(Flag.TNT, TNTMode.DENY);
|
||||||
flagMap.put(Flag.COLOR, ColorMode.YELLOW);
|
flagMap.put(Flag.COLOR, ColorMode.YELLOW);
|
||||||
flagMap.put(Flag.PROTECT, ProtectMode.INACTIVE);
|
flagMap.put(Flag.PROTECT, ProtectMode.INACTIVE);
|
||||||
|
|||||||
-4
@@ -74,10 +74,6 @@ public class DynamicRegionSystem implements RegionSystem {
|
|||||||
regionMap.remove(region.getID());
|
regionMap.remove(region.getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void save() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull Location getWorldSpawn() {
|
public @NonNull Location getWorldSpawn() {
|
||||||
if (SpawnResetter.isBigSpawn()) {
|
if (SpawnResetter.isBigSpawn()) {
|
||||||
|
|||||||
-4
@@ -46,10 +46,6 @@ public class FixedRegionSystem implements RegionSystem {
|
|||||||
RegionLoader.load();
|
RegionLoader.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void save() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull Location getWorldSpawn() {
|
public @NonNull Location getWorldSpawn() {
|
||||||
Location spawnLocation = Bukkit.getWorlds().get(0).getSpawnLocation();
|
Location spawnLocation = Bukkit.getWorlds().get(0).getSpawnLocation();
|
||||||
|
|||||||
@@ -40,3 +40,12 @@ tasks.register<DevServer>("DevBau21") {
|
|||||||
dependsOn(":SchematicSystem:shadowJar")
|
dependsOn(":SchematicSystem:shadowJar")
|
||||||
template = "Bau21"
|
template = "Bau21"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.register<DevServer>("DevBau21Dynamic") {
|
||||||
|
group = "run"
|
||||||
|
description = "Run a 1.21 Dynamic Dev Bau"
|
||||||
|
dependsOn(":BauSystem:shadowJar")
|
||||||
|
dependsOn(":SchematicSystem:shadowJar")
|
||||||
|
template = "Bau21-Dynamic"
|
||||||
|
jar = "/jars/paper-1.21.6.jar"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user