diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 82c3be09..9daa3388 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -430,6 +430,10 @@ REGION_REGION_NO_SCHEM=§cSchematic nicht gefunden REGION_REGION_TP_COPY=§7Zum Kopierpunkt teleportiert REGION_REGION_NO_REGION=§cDu bist in keiner Region REGION_REGION_NO_PERMS=§cDu darfst hier nicht die Region verändern +REGION_REGION_CHANGETYPE_INFO=§7Regions Type ist {0} +REGION_REGION_CHANGETYPE_UNKNOWN=§cRegions Type ist nicht valide +REGION_REGION_CHANGETYPE_INVALID=§cRegions Type ist nicht erlaubt hier +REGION_REGION_CHANGETYPE_CHANGE=§aRegions Type ist auf {0} geändert REGION_RESET_HELP_1=§8/§ereset §8- §7Setzte die Region zurück REGION_RESET_HELP_2=§8/§ereset §8[§7Schematic§8] §8- §7Setzte die Region mit einer Schematic zurück REGION_RESET_RESETED=§7Region zurückgesetzt diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java index ccdd9fe4..e5f4237f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java @@ -25,19 +25,26 @@ import de.steamwar.bausystem.features.util.SelectCommand; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.linkage.LinkedInstance; +import de.steamwar.bausystem.region.Prototype; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.flags.flagvalues.ColorMode; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeMapper; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerTeleportEvent; import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.logging.Level; +import java.util.stream.Collectors; @Linked(LinkageType.COMMAND) public class RegionCommand extends SWCommand { @@ -167,6 +174,55 @@ public class RegionCommand extends SWCommand { BauSystem.MESSAGE.send("REGION_REGION_TP_COPY", p); } + @Register("changetype") + @Register("type") + public void changeTypeCommand(Player p) { + Region region = Region.getRegion(p.getLocation()); + if (checkGlobalRegion(region, p)) { + return; + } + BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_INFO", p, region.getPrototype().getDisplayName()); + } + + @Register("changetype") + @Register("type") + public void changeTypeCommand(Player p, @Mapper("regionTypeMapper") String s) { + Region region = Region.getRegion(p.getLocation()); + if (checkGlobalRegion(region, p)) { + return; + } + Prototype prototype = Prototype.getByDisplayName(s); + if (prototype == null) { + BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_UNKNOWN", p); + } else { + if (region.setPrototype(prototype)) { + BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_CHANGE", p, s); + } else { + BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_INVALID", p); + } + } + } + + @Mapper(value = "regionTypeMapper", local = true) + private TypeMapper regionTypeMapper() { + return new TypeMapper() { + @Override + public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + Player p = (Player) commandSender; + Region region = Region.getRegion(p.getLocation()); + if (checkGlobalRegion(region, p)) { + return Collections.emptyList(); + } + return region.getPrototypes().stream().map(Prototype::getByName).map(Prototype::getDisplayName).map(c -> c.replace(' ', '_')).collect(Collectors.toList()); + } + + @Override + public String map(CommandSender commandSender, String[] previousArguments, String s) { + return s.replace('_', ' '); + } + }; + } + private boolean permissionCheck(Player player) { if (Permission.hasPermission(player, Permission.WORLDEDIT)) { return true; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java index 119fb49e..c8cd7a4d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java @@ -31,6 +31,14 @@ import java.util.Map; public class Prototype { static final Map PROTOTYPE_MAP = new HashMap<>(); + + public static Prototype getByName(String name) { + return PROTOTYPE_MAP.get(name); + } + + public static Prototype getByDisplayName(String name) { + return PROTOTYPE_MAP.values().stream().filter(prototype -> prototype.getDisplayName().equals(name)).findFirst().orElse(null); + } private final String name; private final String displayName; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index 3233b284..5bce6af0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -262,9 +262,9 @@ public class Region { } } - public void setPrototype(@NonNull Prototype prototype) { + public boolean setPrototype(@NonNull Prototype prototype) { if (!prototypes.contains(prototype.getName()) && !prototypes.isEmpty()) { - return; + return false; } generatePrototypeData(prototype, minPoint); RegionUtils.save(this); @@ -272,6 +272,7 @@ public class Region { region.generatePrototypeData(prototype, region.minPoint); return true; }); + return true; } public void set(Flag flagType, Flag.Value value) {