forked from SteamWar/SteamWar
Add name to RegionConstructorData
This commit is contained in:
+12
-6
@@ -22,6 +22,7 @@ package de.steamwar.bausystem.region;
|
||||
import de.steamwar.bausystem.features.region.RegionCommand;
|
||||
import de.steamwar.bausystem.region.dynamic.DynamicRegion;
|
||||
import de.steamwar.bausystem.region.dynamic.DynamicRegionRepository;
|
||||
import de.steamwar.bausystem.region.dynamic.RegionConstructorData;
|
||||
import de.steamwar.bausystem.region.dynamic.Tile;
|
||||
import de.steamwar.bausystem.utils.PasteBuilder;
|
||||
import de.steamwar.command.AbstractSWCommand;
|
||||
@@ -32,7 +33,9 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@AbstractSWCommand.PartOf(RegionCommand.class)
|
||||
public class DynamicRegionCommand extends SWCommand {
|
||||
@@ -50,7 +53,7 @@ public class DynamicRegionCommand extends SWCommand {
|
||||
|
||||
// Check location!
|
||||
|
||||
Class<? extends DynamicRegion> regionClass = DynamicRegionSystem.getRegionClassByIdentifier(regionType);
|
||||
Class<? extends DynamicRegion> regionClass = DynamicRegionSystem.identifierDataMap.get(regionType);
|
||||
DynamicRegion dynamicRegion = DynamicRegionRepository.constructRegion(regionClass, UUID.randomUUID(), tile.getMinX(), tile.getMinZ());
|
||||
if (dynamicRegion == null) {
|
||||
// TODO: Give error to user
|
||||
@@ -73,16 +76,19 @@ public class DynamicRegionCommand extends SWCommand {
|
||||
return new TypeMapper<>() {
|
||||
@Override
|
||||
public String map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||
if (DynamicRegionSystem.hasRegionClassForIdentifier(s)) {
|
||||
return s;
|
||||
} else {
|
||||
return null;
|
||||
for (Map.Entry<Class<? extends DynamicRegion>, RegionConstructorData> entry : DynamicRegionSystem.constructorDataMap.entrySet()) {
|
||||
if (entry.getValue().name().equalsIgnoreCase(s)) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
|
||||
return DynamicRegionSystem.allRegionIdentifiers();
|
||||
return DynamicRegionSystem.constructorDataMap.values()
|
||||
.stream().map(RegionConstructorData::name)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
+2
-18
@@ -62,24 +62,8 @@ public class DynamicRegionSystem implements RegionSystem {
|
||||
regionTypeMap.getOrDefault(region.getType(), Collections.emptySet()).remove(region);
|
||||
}
|
||||
|
||||
private static Map<Class<? extends DynamicRegion>, RegionConstructorData> constructorDataMap = new HashMap<>();
|
||||
private static Map<String, Class<? extends DynamicRegion>> identifierDataMap = new HashMap<>();
|
||||
|
||||
public static RegionConstructorData getRegionConstructorByRegionClass(Class<?> regionClass) {
|
||||
return constructorDataMap.get(regionClass);
|
||||
}
|
||||
|
||||
public static Class<? extends DynamicRegion> getRegionClassByIdentifier(String identifier) {
|
||||
return identifierDataMap.get(identifier);
|
||||
}
|
||||
|
||||
public static boolean hasRegionClassForIdentifier(String identifier) {
|
||||
return identifierDataMap.containsKey(identifier);
|
||||
}
|
||||
|
||||
public static Set<String> allRegionIdentifiers() {
|
||||
return Collections.unmodifiableSet(identifierDataMap.keySet());
|
||||
}
|
||||
public static Map<Class<? extends DynamicRegion>, RegionConstructorData> constructorDataMap = new HashMap<>();
|
||||
public static Map<String, Class<? extends DynamicRegion>> identifierDataMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
|
||||
+2
-2
@@ -132,7 +132,7 @@ public class DynamicRegionRepository {
|
||||
}
|
||||
|
||||
// TODO: Maybe add static method to DynamicRegionSystem
|
||||
Class<? extends DynamicRegion> regionClass = DynamicRegionSystem.getRegionClassByIdentifier(identifier);
|
||||
Class<? extends DynamicRegion> regionClass = DynamicRegionSystem.identifierDataMap.get(identifier);
|
||||
if (regionClass == null) {
|
||||
RegionSystem.LOGGER.log(Level.SEVERE, "Failed to read region metadata file (region no longer exists)");
|
||||
continue;
|
||||
@@ -242,7 +242,7 @@ public class DynamicRegionRepository {
|
||||
}
|
||||
|
||||
if (!region.getType().isGlobal()) {
|
||||
RegionConstructorData constructorData = DynamicRegionSystem.getRegionConstructorByRegionClass(region.getClass());
|
||||
RegionConstructorData constructorData = DynamicRegionSystem.constructorDataMap.get(region.getClass());
|
||||
Point point = region.getArea().getMinPoint(false);
|
||||
Tile tile = Tile.fromPoint(point).get();
|
||||
|
||||
|
||||
+1
@@ -31,6 +31,7 @@ import java.lang.annotation.Target;
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface RegionConstructorData {
|
||||
String identifier();
|
||||
String name();
|
||||
int widthX();
|
||||
int widthZ();
|
||||
boolean placeable() default true;
|
||||
|
||||
+1
@@ -37,6 +37,7 @@ import java.util.UUID;
|
||||
|
||||
@RegionConstructorData(
|
||||
identifier = "microwargear_display",
|
||||
name = "MicoWarGearDisplay",
|
||||
widthX = Tile.tileSize,
|
||||
widthZ = Tile.tileSize
|
||||
)
|
||||
|
||||
+1
@@ -30,6 +30,7 @@ import java.util.UUID;
|
||||
|
||||
@RegionConstructorData(
|
||||
identifier = "path",
|
||||
name = "Path",
|
||||
widthX = Tile.tileSize,
|
||||
widthZ = Tile.tileSize
|
||||
)
|
||||
|
||||
+1
@@ -37,6 +37,7 @@ import static de.steamwar.bausystem.region.dynamic.special.SpecialArea.SPECIAL_P
|
||||
|
||||
@RegionConstructorData(
|
||||
identifier = "special_dry",
|
||||
name = "Dry",
|
||||
widthX = Tile.tileSize,
|
||||
widthZ = Tile.tileSize
|
||||
)
|
||||
|
||||
+1
@@ -36,6 +36,7 @@ import static de.steamwar.bausystem.region.dynamic.special.SpecialArea.SPECIAL_P
|
||||
|
||||
@RegionConstructorData(
|
||||
identifier = "special_wet",
|
||||
name = "Wet",
|
||||
widthX = Tile.tileSize,
|
||||
widthZ = Tile.tileSize
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user