forked from SteamWar/SteamWar
Add DynamicRegion
This commit is contained in:
+32
-7
@@ -19,20 +19,22 @@
|
||||
|
||||
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.global.GlobalRegion;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class DynamicRegionSystem implements RegionSystem {
|
||||
|
||||
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) {
|
||||
@Override
|
||||
@@ -43,13 +45,36 @@ public class DynamicRegionSystem implements RegionSystem {
|
||||
private static final Map<UUID, Region> regionMap = new HashMap<>();
|
||||
private static final Map<RegionType, Set<Region>> regionTypeMap = new EnumMap<>(RegionType.class);
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
INSTANCE = this;
|
||||
public void add(DynamicRegion region) {
|
||||
regionCache.clear();
|
||||
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
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user