From 6e958d7eb931f2ed73712a6cc70a97effbf5e0f8 Mon Sep 17 00:00:00 2001 From: david <89749147+davight@users.noreply.github.com> Date: Mon, 20 Jan 2025 19:26:38 +0100 Subject: [PATCH 01/11] fix while not having citizens installed --- .../bukkit/bridges/WorldGuardBridge.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/bridges/WorldGuardBridge.java b/src/main/java/com/denizenscript/depenizen/bukkit/bridges/WorldGuardBridge.java index 4a5536348..48ca18e01 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/bridges/WorldGuardBridge.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/bridges/WorldGuardBridge.java @@ -1,9 +1,7 @@ package com.denizenscript.depenizen.bukkit.bridges; -import com.denizenscript.denizen.objects.CuboidTag; -import com.denizenscript.denizen.objects.LocationTag; import com.denizenscript.denizen.objects.PlayerTag; -import com.denizenscript.denizen.objects.WorldTag; +import com.denizenscript.denizen.utilities.depends.Depends; import com.denizenscript.denizencore.DenizenCore; import com.denizenscript.denizencore.objects.ObjectFetcher; import com.denizenscript.denizencore.objects.properties.PropertyParser; @@ -11,11 +9,7 @@ import com.denizenscript.depenizen.bukkit.Bridge; import com.denizenscript.depenizen.bukkit.commands.worldguard.RegionCommand; import com.denizenscript.depenizen.bukkit.objects.worldguard.WorldGuardRegionTag; -import com.denizenscript.depenizen.bukkit.properties.worldguard.WorldGuardCuboidProperties; -import com.denizenscript.depenizen.bukkit.properties.worldguard.WorldGuardLocationProperties; -import com.denizenscript.depenizen.bukkit.properties.worldguard.WorldGuardNPCExtensions; -import com.denizenscript.depenizen.bukkit.properties.worldguard.WorldGuardPlayerProperties; -import com.denizenscript.depenizen.bukkit.properties.worldguard.WorldGuardWorldProperties; +import com.denizenscript.depenizen.bukkit.properties.worldguard.*; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldguard.WorldGuard; import com.sk89q.worldguard.protection.managers.RegionManager; @@ -29,11 +23,14 @@ public class WorldGuardBridge extends Bridge { public void init() { instance = this; ObjectFetcher.registerWithObjectFetcher(WorldGuardRegionTag.class, WorldGuardRegionTag.tagProcessor); - PropertyParser.registerProperty(WorldGuardLocationProperties.class, LocationTag.class); + WorldGuardLocationExtensions.register(); + WorldGuardPlayerExtensions.register(); PropertyParser.registerProperty(WorldGuardPlayerProperties.class, PlayerTag.class); - PropertyParser.registerProperty(WorldGuardCuboidProperties.class, CuboidTag.class); - PropertyParser.registerProperty(WorldGuardWorldProperties.class, WorldTag.class); - WorldGuardNPCExtensions.register(); + WorldGuardCuboidExtensions.register(); + WorldGuardWorldExtensions.register(); + if (Depends.citizens != null) { + WorldGuardNPCExtensions.register(); + } DenizenCore.commandRegistry.registerCommand(RegionCommand.class); // <--[tag] From 0b291436886f9c50f0a9d7f2305669bfc99d417b Mon Sep 17 00:00:00 2001 From: david <89749147+davight@users.noreply.github.com> Date: Mon, 20 Jan 2025 19:27:57 +0100 Subject: [PATCH 02/11] convert to extensions --- .../WorldGuardCuboidExtensions.java | 73 +++++++++++ .../WorldGuardCuboidProperties.java | 114 ------------------ 2 files changed, 73 insertions(+), 114 deletions(-) create mode 100644 src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardCuboidExtensions.java delete mode 100644 src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardCuboidProperties.java diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardCuboidExtensions.java b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardCuboidExtensions.java new file mode 100644 index 000000000..eab1f8815 --- /dev/null +++ b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardCuboidExtensions.java @@ -0,0 +1,73 @@ +package com.denizenscript.depenizen.bukkit.properties.worldguard; + +import com.denizenscript.denizen.objects.CuboidTag; +import com.denizenscript.denizen.objects.LocationTag; +import com.denizenscript.denizencore.objects.core.ElementTag; +import com.denizenscript.denizencore.objects.core.ListTag; +import com.denizenscript.depenizen.bukkit.objects.worldguard.WorldGuardRegionTag; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.protection.ApplicableRegionSet; +import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; + +public class WorldGuardCuboidExtensions { + + public static ApplicableRegionSet getApplicableRegions(CuboidTag cuboid) { + LocationTag low = cuboid.getLow(0); + LocationTag high = cuboid.getHigh(0); + BlockVector3 vecLow = BlockVector3.at(low.getX(), low.getY(), low.getZ()); + BlockVector3 vecHigh = BlockVector3.at(high.getX(), high.getY(), high.getZ()); + ProtectedCuboidRegion region = new ProtectedCuboidRegion("FAKE_REGION", vecLow, vecHigh); + return WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(cuboid.getWorld().getWorld())).getApplicableRegions(region); + } + + public static void register() { + + // <--[tag] + // @attribute + // @returns ElementTag(Boolean) + // @plugin Depenizen, WorldGuard + // @deprecated Use 'CuboidTag.worldguard_has_region' + // @description + // Deprecated in favor of <@link tag CuboidTag.worldguard_has_region>. + // --> + + // <--[tag] + // @attribute + // @returns ElementTag(Boolean) + // @plugin Depenizen, WorldGuard + // @description + // Returns whether the cuboid contains any region. + // --> + CuboidTag.tagProcessor.registerTag(ElementTag.class, "worldguard_has_region", (attribute, area) -> { + return new ElementTag(getApplicableRegions(area).size() > 0); + }, "has_region"); + + // <--[tag] + // @attribute + // @returns ListTag(WorldGuardRegionTag) + // @plugin Depenizen, WorldGuard + // @deprecated Use 'CuboidTag.worldguard_regions' + // @description + // Deprecated in favor of <@link tag CuboidTag.worldguard_regions>. + // --> + + // <--[tag] + // @attribute + // @returns ListTag(WorldGuardRegionTag) + // @plugin Depenizen, WorldGuard + // @description + // Returns a list of regions that are in this cuboid. + // --> + CuboidTag.tagProcessor.registerTag(ListTag.class, "worldguard_regions", (attribute, area) -> { + ListTag regionList = new ListTag(); + for (ProtectedRegion protectedRegion : getApplicableRegions(area)) { + regionList.addObject(new WorldGuardRegionTag(protectedRegion, area.getWorld().getWorld())); + } + return regionList; + }, "regions"); + } + +} diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardCuboidProperties.java b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardCuboidProperties.java deleted file mode 100644 index bd3187184..000000000 --- a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardCuboidProperties.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.denizenscript.depenizen.bukkit.properties.worldguard; - -import com.denizenscript.denizencore.objects.properties.Property; -import com.denizenscript.denizencore.objects.Mechanism; -import com.denizenscript.depenizen.bukkit.objects.worldguard.WorldGuardRegionTag; -import com.denizenscript.depenizen.bukkit.bridges.WorldGuardBridge; -import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldguard.WorldGuard; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.protection.ApplicableRegionSet; -import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import com.denizenscript.denizen.objects.CuboidTag; -import com.denizenscript.denizen.objects.LocationTag; -import com.denizenscript.denizencore.objects.core.ElementTag; -import com.denizenscript.denizencore.objects.core.ListTag; -import com.denizenscript.denizencore.objects.ObjectTag; -import com.denizenscript.denizencore.tags.Attribute; -import org.bukkit.World; - -public class WorldGuardCuboidProperties implements Property { - - @Override - public String getPropertyString() { - return null; - } - - @Override - public String getPropertyId() { - return "WorldGuardCuboid"; - } - - @Override - public void adjust(Mechanism mechanism) { - // None - } - - public static boolean describes(ObjectTag cuboid) { - return cuboid instanceof CuboidTag; - } - - public static WorldGuardCuboidProperties getFrom(ObjectTag cuboid) { - if (!describes(cuboid)) { - return null; - } - else { - return new WorldGuardCuboidProperties((CuboidTag) cuboid); - } - } - - public static final String[] handledTags = new String[] { - "has_region", "regions" - }; - - public static final String[] handledMechs = new String[] { - }; // None - - public WorldGuardCuboidProperties(CuboidTag cuboid) { - this.cuboid = cuboid; - } - - CuboidTag cuboid; - - public ApplicableRegionSet getApplicableRegions() { - WorldGuardPlugin worldGuard = (WorldGuardPlugin) WorldGuardBridge.instance.plugin; - LocationTag low = cuboid.getLow(0); - LocationTag high = cuboid.getHigh(0); - BlockVector3 vecLow = BlockVector3.at(low.getX(), low.getY(), low.getZ()); - BlockVector3 vecHigh = BlockVector3.at(high.getX(), high.getY(), high.getZ()); - ProtectedCuboidRegion region = new ProtectedCuboidRegion("FAKE_REGION", vecLow, vecHigh); - return WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(cuboid.getWorld().getWorld())).getApplicableRegions(region); - } - - public boolean hasRegion() { - return getApplicableRegions().size() > 0; - } - - public ListTag getRegions(World world) { - ListTag regionList = new ListTag(); - for (ProtectedRegion protectedRegion : getApplicableRegions()) { - regionList.addObject(new WorldGuardRegionTag(protectedRegion, world)); - } - return regionList; - } - - @Override - public ObjectTag getObjectAttribute(Attribute attribute) { - - // <--[tag] - // @attribute - // @returns ElementTag(Boolean) - // @plugin Depenizen, WorldGuard - // @description - // Returns whether the cuboid contains any region. - // --> - if (attribute.startsWith("has_region")) { - return new ElementTag(hasRegion()).getObjectAttribute(attribute.fulfill(1)); - } - - // <--[tag] - // @attribute - // @returns ListTag(WorldGuardRegionTag) - // @plugin Depenizen, WorldGuard - // @description - // Returns a list of regions that are in this cuboid. - // --> - if (attribute.startsWith("regions")) { - return getRegions(cuboid.getWorld().getWorld()).getObjectAttribute(attribute.fulfill(1)); - } - - return null; - } -} From 5bfe7d90cd04e41c46e2ba90600c7f57ccec3b1d Mon Sep 17 00:00:00 2001 From: david <89749147+davight@users.noreply.github.com> Date: Mon, 20 Jan 2025 19:28:22 +0100 Subject: [PATCH 03/11] convert to extensions (location) --- .../WorldGuardLocationExtensions.java | 81 +++++++++++ .../WorldGuardLocationProperties.java | 130 ------------------ 2 files changed, 81 insertions(+), 130 deletions(-) create mode 100644 src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardLocationExtensions.java delete mode 100644 src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardLocationProperties.java diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardLocationExtensions.java b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardLocationExtensions.java new file mode 100644 index 000000000..c8e60c1f1 --- /dev/null +++ b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardLocationExtensions.java @@ -0,0 +1,81 @@ +package com.denizenscript.depenizen.bukkit.properties.worldguard; + +import com.denizenscript.denizen.objects.LocationTag; +import com.denizenscript.denizencore.objects.core.ElementTag; +import com.denizenscript.denizencore.objects.core.ListTag; +import com.denizenscript.depenizen.bukkit.objects.worldguard.WorldGuardRegionTag; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; + +import java.util.Set; + +public class WorldGuardLocationExtensions { + + public static Set getApplicableRegions(LocationTag loc) { + return WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(loc)).getRegions(); + } + + public static void register() { + + // <--[tag] + // @attribute |...)]> + // @returns ListTag(WorldGuardRegionTag) + // @plugin Depenizen, WorldGuard + // @deprecated Use 'LocationTag.worldguard_in_region[(|...)]' + // @description + // Deprecated in favor of <@link tag LocationTag.worldguard_in_region[(|...)]>. + // --> + + // <--[tag] + // @attribute |...)]> + // @returns ElementTag(Boolean) + // @plugin Depenizen, WorldGuard + // @description + // If a region name or list of names is specified, returns whether the + // location is in one of the listed regions, otherwise returns whether + // the location is in any region. + // --> + LocationTag.tagProcessor.registerTag(ElementTag.class, "worldguard_in_region", (attribute, loc) -> { + Set queryRegions = getApplicableRegions(loc); + if (attribute.hasParam()) { + ListTag regions = attribute.paramAsType(ListTag.class); + for (ProtectedRegion region : queryRegions) { + for (String id : regions) { + if (id.equalsIgnoreCase(region.getId())) { + return new ElementTag(true); + } + } + } + return new ElementTag(false); + } + return new ElementTag(!queryRegions.isEmpty()); + }, "in_region"); + + // <--[tag] + // @attribute + // @returns ListTag(WorldGuardRegionTag) + // @plugin Depenizen, WorldGuard + // @deprecated Use 'LocationTag.worldguard_regions' + // @description + // Deprecated in favor of <@link tag LocationTag.worldguard_regions>. + // --> + + // <--[tag] + // @attribute + // @returns ListTag(WorldGuardRegionTag) + // @plugin Depenizen, WorldGuard + // @description + // Returns a list of regions that the location is in. + // --> + LocationTag.tagProcessor.registerTag(ListTag.class, "worldguard_regions", (attribute, loc) -> { + Set queryRegions = getApplicableRegions(loc); + ListTag regions = new ListTag(queryRegions.size()); + for (ProtectedRegion region : queryRegions) { + regions.addObject(new WorldGuardRegionTag(region, loc.getWorld())); + } + return regions; + }, "regions"); + } + +} diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardLocationProperties.java b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardLocationProperties.java deleted file mode 100644 index 79faafc58..000000000 --- a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardLocationProperties.java +++ /dev/null @@ -1,130 +0,0 @@ -package com.denizenscript.depenizen.bukkit.properties.worldguard; - -import com.denizenscript.denizencore.objects.properties.Property; -import com.denizenscript.denizencore.objects.Mechanism; -import com.denizenscript.depenizen.bukkit.objects.worldguard.WorldGuardRegionTag; -import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldguard.WorldGuard; -import com.sk89q.worldguard.protection.ApplicableRegionSet; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import com.denizenscript.denizen.objects.LocationTag; -import com.denizenscript.denizencore.objects.core.ElementTag; -import com.denizenscript.denizencore.objects.core.ListTag; -import com.denizenscript.denizencore.objects.ObjectTag; -import com.denizenscript.denizencore.tags.Attribute; -import org.bukkit.World; - -public class WorldGuardLocationProperties implements Property { - - @Override - public String getPropertyString() { - return null; - } - - @Override - public String getPropertyId() { - return "WorldGuardLocation"; - } - - @Override - public void adjust(Mechanism mechanism) { - // None - } - - public static boolean describes(ObjectTag loc) { - return loc instanceof LocationTag; - } - - public static WorldGuardLocationProperties getFrom(ObjectTag loc) { - if (!describes(loc)) { - return null; - } - else { - return new WorldGuardLocationProperties((LocationTag) loc); - } - } - - public static final String[] handledTags = new String[] { - "in_region", "regions" - }; - - public static final String[] handledMechs = new String[] { - }; // None - - public WorldGuardLocationProperties(LocationTag loc) { - location = loc; - } - - LocationTag location; - - public ApplicableRegionSet getApplicableRegions() { - return WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(location.getWorld())) - .getApplicableRegions(BukkitAdapter.asBlockVector(location)); - } - - public boolean inRegion() { - return getApplicableRegions().size() > 0; - } - - public boolean inRegion(String region) { - for (ProtectedRegion protectedRegion : getApplicableRegions()) { - if (protectedRegion.getId().equalsIgnoreCase(region)) { - return true; - } - } - return false; - } - - public ListTag getRegions(World world) { - ListTag regionList = new ListTag(); - for (ProtectedRegion protectedRegion : getApplicableRegions()) { - regionList.addObject(new WorldGuardRegionTag(protectedRegion, world)); - } - return regionList; - } - - @Override - public ObjectTag getObjectAttribute(Attribute attribute) { - - // <--[tag] - // @attribute |...)]> - // @returns ElementTag(Boolean) - // @plugin Depenizen, WorldGuard - // @description - // If a region name or list of names is specified, returns whether the - // location is in one of the listed regions, otherwise returns whether - // the location is in any region. - // --> - if (attribute.startsWith("in_region")) { - // Check if the location is in the specified region - if (attribute.hasParam()) { - ListTag region_list = attribute.paramAsType(ListTag.class); - for (String region : region_list) { - if (inRegion(region)) { - return new ElementTag(true).getObjectAttribute(attribute.fulfill(1)); - } - } - return new ElementTag(false).getObjectAttribute(attribute.fulfill(1)); - } - - // Check if the location is in any region - else { - return new ElementTag(inRegion()).getObjectAttribute(attribute.fulfill(1)); - } - } - - // <--[tag] - // @attribute - // @returns ListTag(WorldGuardRegionTag) - // @plugin Depenizen, WorldGuard - // @description - // Returns a list of regions that the location is in. - // --> - if (attribute.startsWith("regions")) { - return getRegions(location.getWorld()).getObjectAttribute(attribute.fulfill(1)); - } - - return null; - - } -} From ffe1d97b277ef488616891238381a758e40d16ec Mon Sep 17 00:00:00 2001 From: david <89749147+davight@users.noreply.github.com> Date: Mon, 20 Jan 2025 19:28:29 +0100 Subject: [PATCH 04/11] convert to extensions (world) --- .../worldguard/WorldGuardWorldExtensions.java | 59 ++++++++++++ .../worldguard/WorldGuardWorldProperties.java | 92 ------------------- 2 files changed, 59 insertions(+), 92 deletions(-) create mode 100644 src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardWorldExtensions.java delete mode 100644 src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardWorldProperties.java diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardWorldExtensions.java b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardWorldExtensions.java new file mode 100644 index 000000000..662417a39 --- /dev/null +++ b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardWorldExtensions.java @@ -0,0 +1,59 @@ +package com.denizenscript.depenizen.bukkit.properties.worldguard; + +import com.denizenscript.denizen.objects.WorldTag; +import com.denizenscript.denizencore.objects.core.ElementTag; +import com.denizenscript.denizencore.objects.core.ListTag; +import com.denizenscript.depenizen.bukkit.bridges.WorldGuardBridge; +import com.denizenscript.depenizen.bukkit.objects.worldguard.WorldGuardRegionTag; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; + +public class WorldGuardWorldExtensions { + + public static void register() { + + // <--[tag] + // @attribute + // @returns ListTag(WorldGuardRegionTag) + // @plugin Depenizen, WorldGuard + // @deprecated Use 'WorldTag.worldguard_list_regions' + // @description + // Deprecated in favor of <@link tag WorldTag.worldguard_list_regions>. + // --> + + // <--[tag] + // @attribute + // @returns ListTag(WorldGuardRegionTag) + // @plugin Depenizen, WorldGuard + // @description + // Returns a list of WorldGuard regions in this world. + // --> + WorldTag.tagProcessor.registerTag(ListTag.class, "worldguard_list_regions", (attribute, world) -> { + ListTag listRegions = new ListTag(); + for (ProtectedRegion region : WorldGuardBridge.getManager(world.getWorld()).getRegions().values()) { + listRegions.addObject(new WorldGuardRegionTag(region, world.getWorld())); + } + return listRegions; + }, "list_regions"); + + // <--[tag] + // @attribute ]> + // @returns ListTag(WorldGuardRegionTag) + // @plugin Depenizen, WorldGuard + // @deprecated Use 'WorldTag.worldguard_has_region[]' + // @description + // Deprecated in favor of <@link tag WorldTag.worldguard_has_region[]>. + // --> + + // <--[tag] + // @attribute ]> + // @returns ElementTag(Boolean) + // @plugin Depenizen, WorldGuard + // @description + // Returns whether a region exists in this world for the given name. + // --> + WorldTag.tagProcessor.registerTag(ElementTag.class, ElementTag.class, "worldguard_has_region", (attribute, world, name) -> { + return new ElementTag(WorldGuardBridge.getManager(world.getWorld()).hasRegion(name.asString())); + }, "has_region"); + } + +} diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardWorldProperties.java b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardWorldProperties.java deleted file mode 100644 index 8462bbc84..000000000 --- a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardWorldProperties.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.denizenscript.depenizen.bukkit.properties.worldguard; - -import com.denizenscript.denizencore.objects.core.ElementTag; -import com.denizenscript.denizencore.objects.properties.Property; -import com.denizenscript.denizencore.objects.Mechanism; -import com.denizenscript.depenizen.bukkit.objects.worldguard.WorldGuardRegionTag; -import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldguard.WorldGuard; -import com.sk89q.worldguard.protection.managers.RegionManager; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import com.denizenscript.denizen.objects.WorldTag; -import com.denizenscript.denizencore.objects.core.ListTag; -import com.denizenscript.denizencore.objects.ObjectTag; -import com.denizenscript.denizencore.tags.Attribute; -import org.bukkit.World; - -public class WorldGuardWorldProperties implements Property { - - @Override - public String getPropertyString() { - return null; - } - - @Override - public String getPropertyId() { - return "WorldGuardWorld"; - } - - public static boolean describes(ObjectTag object) { - return object instanceof WorldTag; - } - - public static WorldGuardWorldProperties getFrom(ObjectTag object) { - if (!describes(object)) { - return null; - } - else { - return new WorldGuardWorldProperties((WorldTag) object); - } - } - - public static final String[] handledTags = new String[] { - "list_regions", "has_region" - }; - - public static final String[] handledMechs = new String[] { - }; // None - - public WorldGuardWorldProperties(WorldTag world) { - this.world = world.getWorld(); - this.manager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(this.world)); - } - - World world; - RegionManager manager; - - @Override - public ObjectTag getObjectAttribute(Attribute attribute) { - - // <--[tag] - // @attribute - // @returns ListTag(WorldGuardRegionTag) - // @plugin Depenizen, WorldGuard - // @description - // Returns a list of WorldGuard regions in this world. - // --> - if (attribute.startsWith("list_regions")) { - ListTag regions = new ListTag(); - for (ProtectedRegion r : manager.getRegions().values()) { - regions.addObject(new WorldGuardRegionTag(r, world)); - } - return regions.getObjectAttribute(attribute.fulfill(1)); - } - - // <--[tag] - // @attribute ]> - // @returns ElementTag(Boolean) - // @plugin Depenizen, WorldGuard - // @description - // Returns whether a region exists in this world for the given name. - // --> - if (attribute.startsWith("has_region") && attribute.hasParam()) { - return new ElementTag(manager.hasRegion(attribute.getParam())).getObjectAttribute(attribute.fulfill(1)); - } - - return null; - } - - @Override - public void adjust(Mechanism mechanism) { - } -} From e6d9184826fc448a60859c3de8c124a4dfe00d99 Mon Sep 17 00:00:00 2001 From: david <89749147+davight@users.noreply.github.com> Date: Mon, 20 Jan 2025 19:28:52 +0100 Subject: [PATCH 05/11] add extension (player) --- .../WorldGuardPlayerExtensions.java | 81 +++++++++++++++++++ .../WorldGuardPlayerProperties.java | 5 ++ 2 files changed, 86 insertions(+) create mode 100644 src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardPlayerExtensions.java diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardPlayerExtensions.java b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardPlayerExtensions.java new file mode 100644 index 000000000..c3980f58a --- /dev/null +++ b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardPlayerExtensions.java @@ -0,0 +1,81 @@ +package com.denizenscript.depenizen.bukkit.properties.worldguard; + +import com.denizenscript.denizen.objects.LocationTag; +import com.denizenscript.denizen.objects.PlayerTag; +import com.denizenscript.denizencore.objects.core.ElementTag; +import com.denizenscript.denizencore.utilities.CoreUtilities; +import com.denizenscript.denizencore.utilities.debugging.Debug; +import com.denizenscript.depenizen.bukkit.bridges.WorldGuardBridge; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.flags.Flag; +import com.sk89q.worldguard.protection.flags.Flags; +import com.sk89q.worldguard.protection.flags.StateFlag; +import com.sk89q.worldguard.protection.regions.RegionQuery; + +public class WorldGuardPlayerExtensions { + + public static void register() { + + // <--[tag] + // @attribute ]> + // @returns ElementTag(Boolean) + // @plugin Depenizen, WorldGuard + // @description + // Whether WorldGuard allows to build at a location. + // --> + PlayerTag.tagProcessor.registerTag(ElementTag.class, LocationTag.class, "worldguard_can_build", (attribute, player, loc) -> { + WorldGuardPlugin worldGuard = (WorldGuardPlugin) WorldGuardBridge.instance.plugin; + return new ElementTag(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().testBuild(BukkitAdapter.adapt(loc), worldGuard.wrapPlayer(player.getPlayerEntity()))); + }); + + // <--[tag] + // @attribute ]> + // @returns ElementTag + // @plugin Depenizen, WorldGuard + // @description + // Returns the boolean state of a flag for that player at their location. + // For non-state tags, returns the current value of the flag. + // @example + // # Returns 'true' if the player can be attacked (according to WG) or 'false' if not. + // - narrate + // --> + PlayerTag.tagProcessor.registerTag(ElementTag.class, ElementTag.class, "worldguard_test_flag", (attribute, player, name) -> { + WorldGuardPlugin worldGuard = (WorldGuardPlugin) WorldGuardBridge.instance.plugin; + Flag flag = Flags.fuzzyMatchFlag(WorldGuard.getInstance().getFlagRegistry(), name.asString()); + if (flag == null) { + Debug.echoError("The tag PlayerTag.worlduard_test_flag[...] has an invalid value: " + attribute.getParam()); + return null; + } + LocationTag loc = player.getLocation(); + + // <--[tag] + // @attribute ].at[]> + // @returns ElementTag + // @plugin Depenizen, WorldGuard + // @description + // Returns the boolean state of a flag for that player at the specified location. + // For non-state tags, returns the current value of the flag. + // --> + if (attribute.startsWith("at", 2) && attribute.hasContext(2)) { + loc = attribute.contextAsType(2, LocationTag.class); + if (loc == null) { + return null; + } + attribute.fulfill(1); + } + + RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery(); + if (flag instanceof StateFlag) { + return new ElementTag(query.testState(BukkitAdapter.adapt(loc), worldGuard.wrapPlayer(player.getPlayerEntity()), (StateFlag) flag)); + } + else { + return CoreUtilities.objectToTagForm(query.queryValue(BukkitAdapter.adapt(loc), worldGuard.wrapPlayer(player.getPlayerEntity()), flag), attribute.context).asElement(); + } + }); + + } + + +} diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardPlayerProperties.java b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardPlayerProperties.java index 9b1ae267c..521cf760f 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardPlayerProperties.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardPlayerProperties.java @@ -3,6 +3,7 @@ import com.denizenscript.denizencore.objects.properties.Property; import com.denizenscript.denizencore.objects.Mechanism; import com.denizenscript.denizencore.utilities.CoreUtilities; +import com.denizenscript.denizencore.utilities.debugging.Warning; import com.denizenscript.depenizen.bukkit.bridges.WorldGuardBridge; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldguard.WorldGuard; @@ -22,6 +23,8 @@ public class WorldGuardPlayerProperties implements Property { + public static Warning oldWgPlayerProperty = new Warning("", ""); + @Override public String getPropertyString() { return null; @@ -82,6 +85,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) { // Whether WorldGuard allows to build at a location. // --> if (attribute.startsWith("can_build") && attribute.hasParam()) { + oldWgPlayerProperty.warn(); LocationTag location = attribute.paramAsType(LocationTag.class); if (location == null) { return null; @@ -103,6 +107,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) { // - narrate // --> if (attribute.startsWith("test_flag")) { + oldWgPlayerProperty.warn(); if (!attribute.hasParam()) { Debug.echoError("The tag PlayerTag.worlduard.test_flag[...] must have a value."); return null; From d50ed4f0f45baebf7762af2c80bc7c46c485443a Mon Sep 17 00:00:00 2001 From: david <89749147+davight@users.noreply.github.com> Date: Sun, 26 Jan 2025 23:45:58 +0100 Subject: [PATCH 06/11] convert to extensions (player) --- .../WorldGuardPlayerExtensions.java | 126 ++++++++++---- .../WorldGuardPlayerProperties.java | 154 ------------------ 2 files changed, 94 insertions(+), 186 deletions(-) delete mode 100644 src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardPlayerProperties.java diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardPlayerExtensions.java b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardPlayerExtensions.java index c3980f58a..35cd75d9b 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardPlayerExtensions.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardPlayerExtensions.java @@ -2,9 +2,14 @@ import com.denizenscript.denizen.objects.LocationTag; import com.denizenscript.denizen.objects.PlayerTag; +import com.denizenscript.denizencore.objects.ObjectTag; import com.denizenscript.denizencore.objects.core.ElementTag; +import com.denizenscript.denizencore.objects.core.MapTag; +import com.denizenscript.denizencore.tags.TagRunnable; import com.denizenscript.denizencore.utilities.CoreUtilities; import com.denizenscript.denizencore.utilities.debugging.Debug; +import com.denizenscript.denizencore.utilities.debugging.SlowWarning; +import com.denizenscript.denizencore.utilities.debugging.Warning; import com.denizenscript.depenizen.bukkit.bridges.WorldGuardBridge; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldguard.WorldGuard; @@ -16,8 +21,84 @@ public class WorldGuardPlayerExtensions { + public static Warning worldguardCanBuild = new SlowWarning("worldguardCanBuild", "The tag 'PlayerTag.worldguard.can_build' from Depenizen/Worldguard is deprecated: use 'PlayerTag.worldguard_can_build'"); + public static Warning worldguardTestFlag = new SlowWarning("worldguardTestFlag", "The tag 'PlayerTag.worldguard.test_flag' from Depenizen/Worldguard is deprecated: use 'PlayerTag.worldguard_flag'"); + public static void register() { + TagRunnable.ObjectInterface runnable = (attribute, player) -> { + + // <--[tag] + // @attribute ]> + // @returns ElementTag(Boolean) + // @plugin Depenizen, WorldGuard + // @description + // Whether WorldGuard allows to build at a location. + // --> + if (attribute.startsWith("can_build", 2) && attribute.hasContext(2)) { + worldguardCanBuild.warn(attribute.context); + LocationTag loc = attribute.contextAsType(2, LocationTag.class); + attribute.fulfill(1); + if (loc == null) { + return null; + } + WorldGuardPlugin worldGuard = (WorldGuardPlugin) WorldGuardBridge.instance.plugin; + return new ElementTag(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().testBuild(BukkitAdapter.adapt(loc), worldGuard.wrapPlayer(player.getPlayerEntity()))); + } + + // <--[tag] + // @attribute ]> + // @returns ElementTag + // @plugin Depenizen, WorldGuard + // @description + // Returns the boolean state of a flag for that player at their location. + // For non-state tags, returns the current value of the flag. + // @example + // # Returns 'true' if the player can be attacked (according to WG) or 'false' if not. + // - narrate + // --> + if (attribute.startsWith("test_flag", 2) && attribute.hasContext(2)) { + worldguardTestFlag.warn(attribute.context); + ElementTag name = attribute.contextAsType(2, ElementTag.class); + attribute.fulfill(1); + Flag flag = Flags.fuzzyMatchFlag(WorldGuard.getInstance().getFlagRegistry(), name.asString()); + if (flag == null) { + Debug.echoError("The tag PlayerTag.worldguard.test_flag[...] has an invalid value: " + name.asString()); + return null; + } + LocationTag loc = player.getLocation(); + + // <--[tag] + // @attribute ].at[]> + // @returns ElementTag + // @plugin Depenizen, WorldGuard + // @description + // Returns the boolean state of a flag for that player at the specified location. + // For non-state tags, returns the current value of the flag. + // --> + if (attribute.startsWith("at", 2) && attribute.hasContext(2)) { + loc = attribute.contextAsType(2, LocationTag.class); + attribute.fulfill(1); + if (loc == null) { + return null; + } + } + WorldGuardPlugin worldGuard = (WorldGuardPlugin) WorldGuardBridge.instance.plugin; + RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery(); + if (flag instanceof StateFlag stateFlag) { + return new ElementTag(query.testState(BukkitAdapter.adapt(loc), worldGuard.wrapPlayer(player.getPlayerEntity()), stateFlag)); + } + else { + return CoreUtilities.objectToTagForm(query.queryValue(BukkitAdapter.adapt(loc), worldGuard.wrapPlayer(player.getPlayerEntity()), flag), attribute.context).asElement(); + } + } + + return null; + }; + + PlayerTag.tagProcessor.registerTag(ObjectTag.class, "worldguard", runnable); + PlayerTag.tagProcessor.registerTag(ObjectTag.class, "wg", runnable); + // <--[tag] // @attribute ]> // @returns ElementTag(Boolean) @@ -31,51 +112,32 @@ public static void register() { }); // <--[tag] - // @attribute ]> - // @returns ElementTag + // @attribute (;location=)]> + // @returns ObjectTag // @plugin Depenizen, WorldGuard // @description - // Returns the boolean state of a flag for that player at their location. + // Returns the boolean state of a flag for that player at the specified location. // For non-state tags, returns the current value of the flag. - // @example - // # Returns 'true' if the player can be attacked (according to WG) or 'false' if not. - // - narrate // --> - PlayerTag.tagProcessor.registerTag(ElementTag.class, ElementTag.class, "worldguard_test_flag", (attribute, player, name) -> { - WorldGuardPlugin worldGuard = (WorldGuardPlugin) WorldGuardBridge.instance.plugin; + PlayerTag.tagProcessor.registerTag(ObjectTag.class, MapTag.class, "worldguard_flag", (attribute, player, map) -> { + ElementTag name = map.getRequiredObjectAs("flag", ElementTag.class, attribute); Flag flag = Flags.fuzzyMatchFlag(WorldGuard.getInstance().getFlagRegistry(), name.asString()); if (flag == null) { - Debug.echoError("The tag PlayerTag.worlduard_test_flag[...] has an invalid value: " + attribute.getParam()); + Debug.echoError("The tag PlayerTag.worldguard_flag[...] has an invalid flag: " + name.asString()); return null; } - LocationTag loc = player.getLocation(); - - // <--[tag] - // @attribute ].at[]> - // @returns ElementTag - // @plugin Depenizen, WorldGuard - // @description - // Returns the boolean state of a flag for that player at the specified location. - // For non-state tags, returns the current value of the flag. - // --> - if (attribute.startsWith("at", 2) && attribute.hasContext(2)) { - loc = attribute.contextAsType(2, LocationTag.class); - if (loc == null) { - return null; - } - attribute.fulfill(1); + LocationTag loc = map.getObjectAs("location", LocationTag.class, attribute.context); + if (loc == null) { + loc = player.getLocation(); } - + WorldGuardPlugin worldGuard = (WorldGuardPlugin) WorldGuardBridge.instance.plugin; RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery(); - if (flag instanceof StateFlag) { - return new ElementTag(query.testState(BukkitAdapter.adapt(loc), worldGuard.wrapPlayer(player.getPlayerEntity()), (StateFlag) flag)); + if (flag instanceof StateFlag stateFlag) { + return new ElementTag(query.testState(BukkitAdapter.adapt(loc), worldGuard.wrapPlayer(player.getPlayerEntity()), stateFlag)); } else { - return CoreUtilities.objectToTagForm(query.queryValue(BukkitAdapter.adapt(loc), worldGuard.wrapPlayer(player.getPlayerEntity()), flag), attribute.context).asElement(); + return CoreUtilities.objectToTagForm(query.queryValue(BukkitAdapter.adapt(loc), worldGuard.wrapPlayer(player.getPlayerEntity()), flag), attribute.context); } }); - } - - } diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardPlayerProperties.java b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardPlayerProperties.java deleted file mode 100644 index 521cf760f..000000000 --- a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardPlayerProperties.java +++ /dev/null @@ -1,154 +0,0 @@ -package com.denizenscript.depenizen.bukkit.properties.worldguard; - -import com.denizenscript.denizencore.objects.properties.Property; -import com.denizenscript.denizencore.objects.Mechanism; -import com.denizenscript.denizencore.utilities.CoreUtilities; -import com.denizenscript.denizencore.utilities.debugging.Warning; -import com.denizenscript.depenizen.bukkit.bridges.WorldGuardBridge; -import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldguard.WorldGuard; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.protection.flags.Flag; -import com.sk89q.worldguard.protection.flags.Flags; -import com.sk89q.worldguard.protection.flags.StateFlag; -import com.sk89q.worldguard.protection.regions.RegionQuery; -import com.denizenscript.denizen.objects.LocationTag; -import com.denizenscript.denizen.objects.PlayerTag; -import com.denizenscript.denizencore.objects.core.ElementTag; -import com.denizenscript.denizencore.objects.ObjectTag; -import com.denizenscript.denizencore.tags.Attribute; -import com.denizenscript.denizencore.utilities.debugging.Debug; -import org.bukkit.Location; -import org.bukkit.entity.Player; - -public class WorldGuardPlayerProperties implements Property { - - public static Warning oldWgPlayerProperty = new Warning("", ""); - - @Override - public String getPropertyString() { - return null; - } - - @Override - public String getPropertyId() { - return "WorldGuardPlayer"; - } - - @Override - public void adjust(Mechanism mechanism) { - // None - } - - public static boolean describes(ObjectTag object) { - return object instanceof PlayerTag - && ((PlayerTag) object).isOnline(); - } - - public static WorldGuardPlayerProperties getFrom(ObjectTag object) { - if (!describes(object)) { - return null; - } - return new WorldGuardPlayerProperties((PlayerTag) object); - } - - public static final String[] handledTags = new String[] { - "worldguard" - }; - - public static final String[] handledMechs = new String[] { - }; // None - - public WorldGuardPlayerProperties(PlayerTag player) { - this.player = player.getPlayerEntity(); - } - - Player player; - - public Flag getFlag(String s) { - return Flags.fuzzyMatchFlag(WorldGuard.getInstance().getFlagRegistry(), s); - } - - @Override - public ObjectTag getObjectAttribute(Attribute attribute) { - - if (!attribute.startsWith("worldguard") && !attribute.startsWith("wg")) { - return null; - } - attribute = attribute.fulfill(1); - - // <--[tag] - // @attribute ]> - // @returns ElementTag(Boolean) - // @plugin Depenizen, WorldGuard - // @description - // Whether WorldGuard allows to build at a location. - // --> - if (attribute.startsWith("can_build") && attribute.hasParam()) { - oldWgPlayerProperty.warn(); - LocationTag location = attribute.paramAsType(LocationTag.class); - if (location == null) { - return null; - } - WorldGuardPlugin worldGuard = (WorldGuardPlugin) WorldGuardBridge.instance.plugin; - return new ElementTag(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().testBuild(BukkitAdapter.adapt(location), worldGuard.wrapPlayer(player))) - .getObjectAttribute(attribute.fulfill(1)); - } - - // <--[tag] - // @attribute ]> - // @returns ElementTag - // @plugin Depenizen, WorldGuard - // @description - // Returns the boolean state of a flag for that player at their location. - // For non-state tags, returns the current value of the flag. - // @example - // # Returns 'true' if the player can be attacked (according to WG) or 'false' if not. - // - narrate - // --> - if (attribute.startsWith("test_flag")) { - oldWgPlayerProperty.warn(); - if (!attribute.hasParam()) { - Debug.echoError("The tag PlayerTag.worlduard.test_flag[...] must have a value."); - return null; - } - Flag flag = getFlag(attribute.getParam()); - if (flag == null) { - Debug.echoError("The tag PlayerTag.worlduard.test_flag[...] has an invalid value: " + attribute.getParam()); - return null; - } - - RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery(); - Location loc = player.getLocation(); - int args = 1; - - // <--[tag] - // @attribute ].at[]> - // @returns ElementTag - // @plugin Depenizen, WorldGuard - // @description - // Returns the boolean state of a flag for that player at the specified location. - // For non-state tags, returns the current value of the flag. - // --> - if (attribute.getAttribute(2).startsWith("at") && attribute.hasContext(2)) { - loc = attribute.contextAsType(2, LocationTag.class); - args = 2; - if (loc == null) { - return null; - } - } - WorldGuardPlugin worldGuard = (WorldGuardPlugin) WorldGuardBridge.instance.plugin; - ObjectTag result; - if (flag instanceof StateFlag) { - result = new ElementTag(query.testState(BukkitAdapter.adapt(loc), worldGuard.wrapPlayer(player), (StateFlag) flag)); - } - else { - result = CoreUtilities.objectToTagForm(query.queryValue(BukkitAdapter.adapt(loc), worldGuard.wrapPlayer(player), flag), attribute.context); - } - return result.getObjectAttribute(attribute.fulfill(args)); - } - - return null; - - } -} From 7ebf0f3e0294501fc742a0c623d7dfce2f76c499 Mon Sep 17 00:00:00 2001 From: david <89749147+davight@users.noreply.github.com> Date: Sun, 26 Jan 2025 23:46:14 +0100 Subject: [PATCH 07/11] update --- .../depenizen/bukkit/bridges/WorldGuardBridge.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/bridges/WorldGuardBridge.java b/src/main/java/com/denizenscript/depenizen/bukkit/bridges/WorldGuardBridge.java index 48ca18e01..0d2c70abd 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/bridges/WorldGuardBridge.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/bridges/WorldGuardBridge.java @@ -1,10 +1,8 @@ package com.denizenscript.depenizen.bukkit.bridges; -import com.denizenscript.denizen.objects.PlayerTag; import com.denizenscript.denizen.utilities.depends.Depends; import com.denizenscript.denizencore.DenizenCore; import com.denizenscript.denizencore.objects.ObjectFetcher; -import com.denizenscript.denizencore.objects.properties.PropertyParser; import com.denizenscript.denizencore.tags.TagManager; import com.denizenscript.depenizen.bukkit.Bridge; import com.denizenscript.depenizen.bukkit.commands.worldguard.RegionCommand; @@ -25,7 +23,6 @@ public void init() { ObjectFetcher.registerWithObjectFetcher(WorldGuardRegionTag.class, WorldGuardRegionTag.tagProcessor); WorldGuardLocationExtensions.register(); WorldGuardPlayerExtensions.register(); - PropertyParser.registerProperty(WorldGuardPlayerProperties.class, PlayerTag.class); WorldGuardCuboidExtensions.register(); WorldGuardWorldExtensions.register(); if (Depends.citizens != null) { From d0e087be700ace5c5827d20e360d81534a70c07b Mon Sep 17 00:00:00 2001 From: david <89749147+davight@users.noreply.github.com> Date: Sat, 8 Feb 2025 23:04:25 +0100 Subject: [PATCH 08/11] meta fixes --- .../properties/worldguard/WorldGuardCuboidExtensions.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardCuboidExtensions.java b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardCuboidExtensions.java index eab1f8815..680b1b44e 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardCuboidExtensions.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardCuboidExtensions.java @@ -26,7 +26,7 @@ public static ApplicableRegionSet getApplicableRegions(CuboidTag cuboid) { public static void register() { // <--[tag] - // @attribute + // @attribute // @returns ElementTag(Boolean) // @plugin Depenizen, WorldGuard // @deprecated Use 'CuboidTag.worldguard_has_region' @@ -46,7 +46,7 @@ public static void register() { }, "has_region"); // <--[tag] - // @attribute + // @attribute // @returns ListTag(WorldGuardRegionTag) // @plugin Depenizen, WorldGuard // @deprecated Use 'CuboidTag.worldguard_regions' From 62f2a9ff663b2c16f6419fbd488a5133efc6a49e Mon Sep 17 00:00:00 2001 From: david <89749147+davight@users.noreply.github.com> Date: Sat, 8 Feb 2025 23:27:47 +0100 Subject: [PATCH 09/11] more meta fixes --- .../WorldGuardPlayerExtensions.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardPlayerExtensions.java b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardPlayerExtensions.java index 35cd75d9b..be97b2abe 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardPlayerExtensions.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardPlayerExtensions.java @@ -32,8 +32,9 @@ public static void register() { // @attribute ]> // @returns ElementTag(Boolean) // @plugin Depenizen, WorldGuard + // @deprecated Use 'PlayerTag.worldguard_can_build' // @description - // Whether WorldGuard allows to build at a location. + // Deprecated in favor of <@link tag PlayerTag.worldguard_can_build> // --> if (attribute.startsWith("can_build", 2) && attribute.hasContext(2)) { worldguardCanBuild.warn(attribute.context); @@ -48,14 +49,11 @@ public static void register() { // <--[tag] // @attribute ]> - // @returns ElementTag + // @returns ObjectTag // @plugin Depenizen, WorldGuard + // @deprecated Use 'PlayerTag.worldguard_flag' // @description - // Returns the boolean state of a flag for that player at their location. - // For non-state tags, returns the current value of the flag. - // @example - // # Returns 'true' if the player can be attacked (according to WG) or 'false' if not. - // - narrate + // Deprecated in favor of <@link tag PlayerTag.worldguard_flag> // --> if (attribute.startsWith("test_flag", 2) && attribute.hasContext(2)) { worldguardTestFlag.warn(attribute.context); @@ -69,12 +67,12 @@ public static void register() { LocationTag loc = player.getLocation(); // <--[tag] - // @attribute ].at[]> - // @returns ElementTag + // @attribute ].at[]> + // @returns ObjectTag // @plugin Depenizen, WorldGuard + // @deprecated Use 'PlayerTag.worldguard_flag' // @description - // Returns the boolean state of a flag for that player at the specified location. - // For non-state tags, returns the current value of the flag. + // Deprecated in favor of <@link tag PlayerTag.worldguard_flag> // --> if (attribute.startsWith("at", 2) && attribute.hasContext(2)) { loc = attribute.contextAsType(2, LocationTag.class); @@ -118,6 +116,9 @@ public static void register() { // @description // Returns the boolean state of a flag for that player at the specified location. // For non-state tags, returns the current value of the flag. + // @example + // # Returns 'true' if the player can be attacked (according to WG) or 'false' if not. + // - narrate // --> PlayerTag.tagProcessor.registerTag(ObjectTag.class, MapTag.class, "worldguard_flag", (attribute, player, map) -> { ElementTag name = map.getRequiredObjectAs("flag", ElementTag.class, attribute); From 5850ea4f7fefaf2ec1dca51261446e31aabe7fc3 Mon Sep 17 00:00:00 2001 From: david <89749147+davight@users.noreply.github.com> Date: Sun, 9 Feb 2025 13:37:07 +0100 Subject: [PATCH 10/11] remove pointless deprecations --- .../WorldGuardCuboidExtensions.java | 26 +++---------------- .../WorldGuardLocationExtensions.java | 26 +++---------------- .../worldguard/WorldGuardWorldExtensions.java | 26 +++---------------- 3 files changed, 12 insertions(+), 66 deletions(-) diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardCuboidExtensions.java b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardCuboidExtensions.java index 680b1b44e..d1ee8342f 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardCuboidExtensions.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardCuboidExtensions.java @@ -29,45 +29,27 @@ public static void register() { // @attribute // @returns ElementTag(Boolean) // @plugin Depenizen, WorldGuard - // @deprecated Use 'CuboidTag.worldguard_has_region' - // @description - // Deprecated in favor of <@link tag CuboidTag.worldguard_has_region>. - // --> - - // <--[tag] - // @attribute - // @returns ElementTag(Boolean) - // @plugin Depenizen, WorldGuard // @description // Returns whether the cuboid contains any region. // --> - CuboidTag.tagProcessor.registerTag(ElementTag.class, "worldguard_has_region", (attribute, area) -> { + CuboidTag.tagProcessor.registerTag(ElementTag.class, "has_region", (attribute, area) -> { return new ElementTag(getApplicableRegions(area).size() > 0); - }, "has_region"); + }); // <--[tag] // @attribute // @returns ListTag(WorldGuardRegionTag) // @plugin Depenizen, WorldGuard - // @deprecated Use 'CuboidTag.worldguard_regions' - // @description - // Deprecated in favor of <@link tag CuboidTag.worldguard_regions>. - // --> - - // <--[tag] - // @attribute - // @returns ListTag(WorldGuardRegionTag) - // @plugin Depenizen, WorldGuard // @description // Returns a list of regions that are in this cuboid. // --> - CuboidTag.tagProcessor.registerTag(ListTag.class, "worldguard_regions", (attribute, area) -> { + CuboidTag.tagProcessor.registerTag(ListTag.class, "regions", (attribute, area) -> { ListTag regionList = new ListTag(); for (ProtectedRegion protectedRegion : getApplicableRegions(area)) { regionList.addObject(new WorldGuardRegionTag(protectedRegion, area.getWorld().getWorld())); } return regionList; - }, "regions"); + }); } } diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardLocationExtensions.java b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardLocationExtensions.java index c8e60c1f1..b8774415b 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardLocationExtensions.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardLocationExtensions.java @@ -20,15 +20,6 @@ public static void register() { // <--[tag] // @attribute |...)]> - // @returns ListTag(WorldGuardRegionTag) - // @plugin Depenizen, WorldGuard - // @deprecated Use 'LocationTag.worldguard_in_region[(|...)]' - // @description - // Deprecated in favor of <@link tag LocationTag.worldguard_in_region[(|...)]>. - // --> - - // <--[tag] - // @attribute |...)]> // @returns ElementTag(Boolean) // @plugin Depenizen, WorldGuard // @description @@ -36,7 +27,7 @@ public static void register() { // location is in one of the listed regions, otherwise returns whether // the location is in any region. // --> - LocationTag.tagProcessor.registerTag(ElementTag.class, "worldguard_in_region", (attribute, loc) -> { + LocationTag.tagProcessor.registerTag(ElementTag.class, "in_region", (attribute, loc) -> { Set queryRegions = getApplicableRegions(loc); if (attribute.hasParam()) { ListTag regions = attribute.paramAsType(ListTag.class); @@ -50,32 +41,23 @@ public static void register() { return new ElementTag(false); } return new ElementTag(!queryRegions.isEmpty()); - }, "in_region"); + }); // <--[tag] // @attribute // @returns ListTag(WorldGuardRegionTag) // @plugin Depenizen, WorldGuard - // @deprecated Use 'LocationTag.worldguard_regions' - // @description - // Deprecated in favor of <@link tag LocationTag.worldguard_regions>. - // --> - - // <--[tag] - // @attribute - // @returns ListTag(WorldGuardRegionTag) - // @plugin Depenizen, WorldGuard // @description // Returns a list of regions that the location is in. // --> - LocationTag.tagProcessor.registerTag(ListTag.class, "worldguard_regions", (attribute, loc) -> { + LocationTag.tagProcessor.registerTag(ListTag.class, "regions", (attribute, loc) -> { Set queryRegions = getApplicableRegions(loc); ListTag regions = new ListTag(queryRegions.size()); for (ProtectedRegion region : queryRegions) { regions.addObject(new WorldGuardRegionTag(region, loc.getWorld())); } return regions; - }, "regions"); + }); } } diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardWorldExtensions.java b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardWorldExtensions.java index 662417a39..851aee9db 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardWorldExtensions.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardWorldExtensions.java @@ -15,45 +15,27 @@ public static void register() { // @attribute // @returns ListTag(WorldGuardRegionTag) // @plugin Depenizen, WorldGuard - // @deprecated Use 'WorldTag.worldguard_list_regions' - // @description - // Deprecated in favor of <@link tag WorldTag.worldguard_list_regions>. - // --> - - // <--[tag] - // @attribute - // @returns ListTag(WorldGuardRegionTag) - // @plugin Depenizen, WorldGuard // @description // Returns a list of WorldGuard regions in this world. // --> - WorldTag.tagProcessor.registerTag(ListTag.class, "worldguard_list_regions", (attribute, world) -> { + WorldTag.tagProcessor.registerTag(ListTag.class, "list_regions", (attribute, world) -> { ListTag listRegions = new ListTag(); for (ProtectedRegion region : WorldGuardBridge.getManager(world.getWorld()).getRegions().values()) { listRegions.addObject(new WorldGuardRegionTag(region, world.getWorld())); } return listRegions; - }, "list_regions"); + }); // <--[tag] // @attribute ]> - // @returns ListTag(WorldGuardRegionTag) - // @plugin Depenizen, WorldGuard - // @deprecated Use 'WorldTag.worldguard_has_region[]' - // @description - // Deprecated in favor of <@link tag WorldTag.worldguard_has_region[]>. - // --> - - // <--[tag] - // @attribute ]> // @returns ElementTag(Boolean) // @plugin Depenizen, WorldGuard // @description // Returns whether a region exists in this world for the given name. // --> - WorldTag.tagProcessor.registerTag(ElementTag.class, ElementTag.class, "worldguard_has_region", (attribute, world, name) -> { + WorldTag.tagProcessor.registerTag(ElementTag.class, ElementTag.class, "has_region", (attribute, world, name) -> { return new ElementTag(WorldGuardBridge.getManager(world.getWorld()).hasRegion(name.asString())); - }, "has_region"); + }); } } From 24ec669e22c994589aca8990d302813fdcbe9ad2 Mon Sep 17 00:00:00 2001 From: david <89749147+davight@users.noreply.github.com> Date: Sun, 9 Feb 2025 18:02:59 +0100 Subject: [PATCH 11/11] fixes --- .../worldguard/WorldGuardPlayerExtensions.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardPlayerExtensions.java b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardPlayerExtensions.java index be97b2abe..d5b75129e 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardPlayerExtensions.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/properties/worldguard/WorldGuardPlayerExtensions.java @@ -5,7 +5,6 @@ import com.denizenscript.denizencore.objects.ObjectTag; import com.denizenscript.denizencore.objects.core.ElementTag; import com.denizenscript.denizencore.objects.core.MapTag; -import com.denizenscript.denizencore.tags.TagRunnable; import com.denizenscript.denizencore.utilities.CoreUtilities; import com.denizenscript.denizencore.utilities.debugging.Debug; import com.denizenscript.denizencore.utilities.debugging.SlowWarning; @@ -19,14 +18,16 @@ import com.sk89q.worldguard.protection.flags.StateFlag; import com.sk89q.worldguard.protection.regions.RegionQuery; +import static com.denizenscript.denizencore.utilities.Deprecations.pointlessSubtagPrefix; + public class WorldGuardPlayerExtensions { - public static Warning worldguardCanBuild = new SlowWarning("worldguardCanBuild", "The tag 'PlayerTag.worldguard.can_build' from Depenizen/Worldguard is deprecated: use 'PlayerTag.worldguard_can_build'"); - public static Warning worldguardTestFlag = new SlowWarning("worldguardTestFlag", "The tag 'PlayerTag.worldguard.test_flag' from Depenizen/Worldguard is deprecated: use 'PlayerTag.worldguard_flag'"); + public static Warning worldguardCanBuild = new SlowWarning("worldguardCanBuild", pointlessSubtagPrefix + "The tag 'PlayerTag.worldguard.can_build[...]' from Depenizen/Worldguard is deprecated: use 'PlayerTag.worldguard_can_build[...]'"); + public static Warning worldguardTestFlag = new SlowWarning("worldguardTestFlag", pointlessSubtagPrefix + "The tag 'PlayerTag.worldguard.test_flag[...]' from Depenizen/Worldguard is deprecated: use 'PlayerTag.worldguard_flag[...]'"); public static void register() { - TagRunnable.ObjectInterface runnable = (attribute, player) -> { + PlayerTag.tagProcessor.registerTag(ObjectTag.class, "worldguard", (attribute, player) -> { // <--[tag] // @attribute ]> @@ -92,10 +93,7 @@ public static void register() { } return null; - }; - - PlayerTag.tagProcessor.registerTag(ObjectTag.class, "worldguard", runnable); - PlayerTag.tagProcessor.registerTag(ObjectTag.class, "wg", runnable); + }); // <--[tag] // @attribute ]> @@ -114,7 +112,7 @@ public static void register() { // @returns ObjectTag // @plugin Depenizen, WorldGuard // @description - // Returns the boolean state of a flag for that player at the specified location. + // Returns the boolean state of a flag for that player at the specified location, defaults to player location. // For non-state tags, returns the current value of the flag. // @example // # Returns 'true' if the player can be attacked (according to WG) or 'false' if not.