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());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user