forked from SteamWar/SteamWar
Add DynamicRegionVisualizer
This commit is contained in:
+1
-62
@@ -20,24 +20,12 @@
|
||||
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;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.TypeMapper;
|
||||
import de.steamwar.core.SWPlayer;
|
||||
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 {
|
||||
|
||||
@@ -45,7 +33,7 @@ public class DynamicRegionCommand extends SWCommand {
|
||||
super("");
|
||||
}
|
||||
|
||||
@Register({"dynamic", "visualize"})
|
||||
@Register({"dynamic"})
|
||||
public void visualizeRegions(Player player) {
|
||||
Tile tile = Tile.fromLocation(player.getLocation()).orElse(null);
|
||||
if (tile == null) return;
|
||||
@@ -56,53 +44,4 @@ public class DynamicRegionCommand extends SWCommand {
|
||||
swPlayer.setComponent(new DynamicRegionVisualizer());
|
||||
}
|
||||
}
|
||||
|
||||
@Register({"dynamic", "place"})
|
||||
public void placeRegion(Player player, @Mapper("regionType") String regionType) {
|
||||
Region region = DynamicRegionSystem.INSTANCE.get(player.getLocation());
|
||||
if (!region.getType().isGlobal()) return;
|
||||
Tile tile = Tile.fromLocation(player.getLocation()).orElse(null);
|
||||
if (tile == null) return;
|
||||
|
||||
// Check location!
|
||||
|
||||
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
|
||||
return;
|
||||
}
|
||||
|
||||
dynamicRegion.getArea().place(new PasteBuilder(new PasteBuilder.FileProvider(dynamicRegion.getArea().getResetFile())), false);
|
||||
dynamicRegion.updateNeighbours();
|
||||
}
|
||||
|
||||
@Register({"dynamic", "delete"})
|
||||
public void deleteRegion(Player player) {
|
||||
Region region = DynamicRegionSystem.INSTANCE.get(player.getLocation());
|
||||
if (!region.getType().isDeletable()) return;
|
||||
region.delete();
|
||||
}
|
||||
|
||||
@Mapper("regionType")
|
||||
private TypeMapper<String> regionType() {
|
||||
return new TypeMapper<>() {
|
||||
@Override
|
||||
public String map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||
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.constructorDataMap.values()
|
||||
.stream().map(RegionConstructorData::name)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user