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