diff --git a/BauSystem_15/src/de/steamwar/bausystem/features/.gitkeep b/BauSystem_15/src/de/steamwar/bausystem/features/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/BauSystem_15/src/de/steamwar/bausystem/features/util/SelectCommand_15.java b/BauSystem_15/src/de/steamwar/bausystem/features/util/SelectCommand_15.java new file mode 100644 index 00000000..7ac89890 --- /dev/null +++ b/BauSystem_15/src/de/steamwar/bausystem/features/util/SelectCommand_15.java @@ -0,0 +1,21 @@ +package de.steamwar.bausystem.features.util; + +import com.sk89q.worldedit.bukkit.BukkitWorld; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; +import com.sk89q.worldedit.world.World; +import de.steamwar.bausystem.region.Point; +import de.steamwar.bausystem.region.RegionUtils_15; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class SelectCommand_15 { + + static final WorldEditPlugin WORLDEDIT_PLUGIN = ((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit")); + static final World BUKKITWORLD = new BukkitWorld(Bukkit.getWorlds().get(0)); + + static void setSelection(Player p, Point minPoint, Point maxPoint) { + WORLDEDIT_PLUGIN.getSession(p).setRegionSelector(BUKKITWORLD, new CuboidRegionSelector(BUKKITWORLD, RegionUtils_15.toBlockVector3(minPoint), RegionUtils_15.toBlockVector3(maxPoint))); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java new file mode 100644 index 00000000..97004bfe --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java @@ -0,0 +1,72 @@ +package de.steamwar.bausystem.features.region; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.config.BauServer; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.linkage.LinkedInstance; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.flagvalues.ColorMode; +import de.steamwar.command.SWCommand; +import org.bukkit.entity.Player; + +@Linked(LinkageType.COMMAND) +public class ColorCommand extends SWCommand { + + @LinkedInstance(BauServer.class) + private BauServer bauServer; + + public ColorCommand() { + super("color"); + } + + @Register(help = true) + public void genericHelp(Player p, String... args) { + p.sendMessage("§8/§ecolor §8[§7Color§8] §8- §7Setze die Farbe der Region"); + p.sendMessage("§8/§ecolor §8[§7Color§8] §8[§7Type§8] §8- §7Setze die Farbe der Region oder Global"); + } + + @Register + public void genericColor(Player p, ColorMode color) { + genericColorSet(p, color, ColorizationType.LOCAL); + } + + @Register + public void genericColorSet(Player p, ColorMode color, ColorizationType colorizationType) { + if (!permissionCheck(p)) { + return; + } + if (colorizationType == ColorizationType.GLOBAL) { + Region.setGlobal(Flag.COLOR, color); + p.sendMessage(BauSystem.PREFIX + "Alle Regions farben auf §e" + color.name().toLowerCase() + "§7 gesetzt"); + return; + } + Region region = Region.getRegion(p.getLocation()); + if (region.isGlobal()) { + p.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region"); + return; + } + region.set(Flag.COLOR, color); + p.sendMessage(BauSystem.PREFIX + "Regions farben auf §e" + color.name().toLowerCase() + "§7 gesetzt"); + } + + @Register + public void genericColorSet(Player p, ColorizationType colorizationType, ColorMode color) { + genericColorSet(p, color, colorizationType); + } + + private boolean permissionCheck(Player p) { + if (bauServer.getOwner().equals(p.getUniqueId())) { + return true; + } + p.sendMessage(BauSystem.PREFIX + "§cDies ist nicht deine Welt!"); + return false; + } + + public enum ColorizationType { + LOCAL, + GLOBAL + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/SelectCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SelectCommand.java new file mode 100644 index 00000000..0af7429f --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SelectCommand.java @@ -0,0 +1,91 @@ +package de.steamwar.bausystem.features.util; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.region.Point; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.utils.RegionExtensionType; +import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.command.SWCommand; +import de.steamwar.core.VersionedRunnable; +import org.bukkit.entity.Player; + +@Linked(LinkageType.COMMAND) +public class SelectCommand extends SWCommand { + + public SelectCommand() { + super("select"); + } + + @Register(help = true) + public void genericHelp(Player p, String... args) { + p.sendMessage("§8/§eselect §8[§7RegionsTyp§8] §8- §7Wähle einen RegionsTyp aus"); + p.sendMessage("§8/§eselect §8[§7RegionsTyp§8] §8[§7Extension§8] §8- §7Wähle einen RegionsTyp aus mit oder ohne Extension"); + } + + @Register + public void baurahmenCommand(Player p, RegionType regionType) { + if (!permissionCheck(p)) { + return; + } + + Region region = Region.getRegion(p.getLocation()); + + if (region.isGlobal()) { + p.sendMessage(BauSystem.PREFIX + "§cDie globale Region kannst du nicht auswählen"); + return; + } + + if (!region.hasType(regionType)) { + p.sendMessage(BauSystem.PREFIX + "§cDiese Region hat keinen " + regionType.getChatValue()); + return; + } + + setSelection(regionType, RegionExtensionType.NORMAL, region, p); + } + + @Register + public void baurahmenCommand(Player p, RegionType regionType, RegionExtensionType regionExtensionType) { + if (!permissionCheck(p)) { + return; + } + + Region region = Region.getRegion(p.getLocation()); + + if (region.isGlobal()) { + p.sendMessage(BauSystem.PREFIX + "§cDie globale Region kannst du nicht auswählen"); + return; + } + + if (!region.hasType(regionType)) { + p.sendMessage(BauSystem.PREFIX + "§cDiese Region hat keinen " + regionType.getChatValue()); + return; + } + if (regionExtensionType == RegionExtensionType.EXTENSION && !region.hasExtensionType(regionType)) { + p.sendMessage(BauSystem.PREFIX + "§cDiese Region hat keine Ausfahrmaße"); + return; + } + + setSelection(regionType, regionExtensionType, region, p); + } + + + private boolean permissionCheck(Player player) { + if (Permission.hasPermission(player, Permission.WORLDEDIT)) { + return true; + } + player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den Select Befehl verwenden"); + return false; + } + + private void setSelection(RegionType regionType, RegionExtensionType regionExtensionType, Region region, Player p) { + Point minPoint = region.getMinPoint(regionType, regionExtensionType); + Point maxPoint = region.getMaxPoint(regionType, regionExtensionType); + + VersionedRunnable.call(new VersionedRunnable(() -> SelectCommand_15.setSelection(p, minPoint, maxPoint), 15)); + p.sendMessage(BauSystem.PREFIX + "WorldEdit auswahl auf " + minPoint.getX() + ", " + minPoint.getY() + ", " + minPoint.getZ() + " und " + maxPoint.getX() + ", " + maxPoint.getY() + ", " + maxPoint.getZ() + " gesetzt"); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java index 7821c886..0a2973ba 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Prototype.java @@ -96,6 +96,8 @@ public class Prototype { private final int extensionNegativeZ; private final int extensionPositiveZ; + private boolean extensionRegistered; + private SubPrototype(YAPIONObject yapionObject) { offsetX = yapionObject.getPlainValueOrDefault("offsetX", 0); offsetY = yapionObject.getPlainValueOrDefault("offsetY", 0); @@ -134,6 +136,8 @@ public class Prototype { extensionNegativeZ = yapionObject.getPlainValueOrDefault("extensionNegativeZ", 0); extensionPositiveZ = yapionObject.getPlainValueOrDefault("extensionPositiveZ", 0); } + + extensionRegistered = extensionNegativeX != 0 || extensionPositiveX != 0 || extensionNegativeY != 0 || extensionPositiveY != 0 || extensionNegativeZ != 0 || extensionPositiveZ != 0; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index 432a8f64..f26916c7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -37,7 +37,6 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.function.Consumer; import java.util.function.Predicate; @Getter @@ -54,6 +53,12 @@ public class Region { return GlobalRegion.instance; } + public static void setGlobal(Flag flagType, Flag.Value value) { + for (Region region : REGION_LIST) { + region.set(flagType, value); + } + } + private YAPIONObject regionData; private String name; @@ -194,6 +199,18 @@ public class Region { } } + public boolean hasExtensionType(RegionType regionType) { + switch (regionType) { + case BUILD: + return prototype != null && prototype.getBuild() != null && prototype.getBuild().isExtensionRegistered(); + case TESTBLOCK: + return prototype != null && prototype.getTestblock() != null && prototype.getTestblock().isExtensionRegistered(); + default: + case NORMAL: + return false; + } + } + public String getDisplayName() { return prototype != null ? prototype.getDisplayName() : ""; } @@ -257,6 +274,30 @@ public class Region { return (T) flagStorage.get(flagType).getValue(); } + public Point getMinPoint(RegionType regionType, RegionExtensionType regionExtensionType) { + switch (regionType) { + case TESTBLOCK: + return (regionExtensionType == null || regionExtensionType == RegionExtensionType.NORMAL) ? minPointTestblock : minPointTestblockExtension; + case BUILD: + return (regionExtensionType == null || regionExtensionType == RegionExtensionType.NORMAL) ? minPointBuild : minPointBuildExtension; + default: + case NORMAL: + return minPoint; + } + } + + public Point getMaxPoint(RegionType regionType, RegionExtensionType regionExtensionType) { + switch (regionType) { + case TESTBLOCK: + return (regionExtensionType == null || regionExtensionType == RegionExtensionType.NORMAL) ? maxPointTestblock : maxPointTestblockExtension; + case BUILD: + return (regionExtensionType == null || regionExtensionType == RegionExtensionType.NORMAL) ? maxPointBuild : maxPointBuildExtension; + default: + case NORMAL: + return maxPoint; + } + } + public void reset(RegionType regionType) { if (!hasType(regionType)) { return; @@ -270,4 +311,8 @@ public class Region { } } + public boolean isGlobal() { + return this == GlobalRegion.getInstance(); + } + } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/utils/RegionType.java b/BauSystem_Main/src/de/steamwar/bausystem/region/utils/RegionType.java index e3b45030..f81fe9ad 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/utils/RegionType.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/utils/RegionType.java @@ -19,8 +19,17 @@ package de.steamwar.bausystem.region.utils; -public enum RegionType { - NORMAL, - BUILD, - TESTBLOCK +import de.steamwar.bausystem.shared.EnumDisplay; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +public enum RegionType implements EnumDisplay { + NORMAL("Normal"), + BUILD("Baubereich"), + TESTBLOCK("Testblock"); + + + @Getter + private String chatValue; }