From 015c015b67acb5ac7566e9ebf1473173b78bf088 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Fri, 29 May 2020 20:07:11 +0200 Subject: [PATCH] Update v7 implementation, bump version --- api/pom.xml | 2 +- implementation/legacy/pom.xml | 4 +- implementation/pom.xml | 5 +- implementation/v6/pom.xml | 4 +- implementation/v7/pom.xml | 12 +- implementation/v7fawe/pom.xml | 66 ------ .../v7fawe/WorldGuardImplementation.java | 196 ------------------ .../v7fawe/event/EventListener.java | 100 --------- .../v7fawe/flag/AbstractWrappedFlag.java | 30 --- .../v7fawe/flag/WrappedPrimitiveFlag.java | 40 ---- .../v7fawe/flag/WrappedStatusFlag.java | 28 --- .../v7fawe/region/WrappedRegion.java | 187 ----------------- .../utility/WorldGuardFlagUtilities.java | 68 ------ library/pom.xml | 17 +- pom.xml | 4 +- 15 files changed, 19 insertions(+), 744 deletions(-) delete mode 100644 implementation/v7fawe/pom.xml delete mode 100644 implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/WorldGuardImplementation.java delete mode 100644 implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/event/EventListener.java delete mode 100644 implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/flag/AbstractWrappedFlag.java delete mode 100644 implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/flag/WrappedPrimitiveFlag.java delete mode 100644 implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/flag/WrappedStatusFlag.java delete mode 100644 implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/region/WrappedRegion.java delete mode 100644 implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/utility/WorldGuardFlagUtilities.java diff --git a/api/pom.xml b/api/pom.xml index 92d2062..1930f1a 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -7,7 +7,7 @@ org.codemc.worldguardwrapper worldguardwrapper-parent - 1.1.6-SNAPSHOT + 1.1.7-SNAPSHOT worldguardwrapper-api diff --git a/implementation/legacy/pom.xml b/implementation/legacy/pom.xml index cdb8dd7..ecfb0c3 100644 --- a/implementation/legacy/pom.xml +++ b/implementation/legacy/pom.xml @@ -7,7 +7,7 @@ org.codemc.worldguardwrapper worldguardwrapper-implementation - 1.1.6-SNAPSHOT + 1.1.7-SNAPSHOT worldguardwrapper-implementation-legacy @@ -28,7 +28,7 @@ ${project.groupId} worldguardwrapper-api - 1.1.6-SNAPSHOT + 1.1.7-SNAPSHOT provided diff --git a/implementation/pom.xml b/implementation/pom.xml index 509b48e..ba2e6d6 100644 --- a/implementation/pom.xml +++ b/implementation/pom.xml @@ -7,7 +7,7 @@ org.codemc.worldguardwrapper worldguardwrapper-parent - 1.1.6-SNAPSHOT + 1.1.7-SNAPSHOT worldguardwrapper-implementation @@ -17,9 +17,6 @@ legacy v6 v7 - WorldGuardWrapper-Implementation diff --git a/implementation/v6/pom.xml b/implementation/v6/pom.xml index 0ee5342..c442c6d 100644 --- a/implementation/v6/pom.xml +++ b/implementation/v6/pom.xml @@ -7,7 +7,7 @@ org.codemc.worldguardwrapper worldguardwrapper-implementation - 1.1.6-SNAPSHOT + 1.1.7-SNAPSHOT worldguardwrapper-implementation-v6 @@ -28,7 +28,7 @@ ${project.groupId} worldguardwrapper-api - 1.1.6-SNAPSHOT + 1.1.7-SNAPSHOT provided diff --git a/implementation/v7/pom.xml b/implementation/v7/pom.xml index 394442e..2a02f51 100644 --- a/implementation/v7/pom.xml +++ b/implementation/v7/pom.xml @@ -7,7 +7,7 @@ org.codemc.worldguardwrapper worldguardwrapper-implementation - 1.1.6-SNAPSHOT + 1.1.7-SNAPSHOT worldguardwrapper-implementation-v7 @@ -16,8 +16,8 @@ - sk89q-repo - http://maven.sk89q.com/repo/ + enginehub-repo + https://maven.enginehub.org/repo/ always @@ -28,13 +28,13 @@ ${project.groupId} worldguardwrapper-api - 1.1.6-SNAPSHOT + 1.1.7-SNAPSHOT provided com.sk89q.worldguard - worldguard-legacy - 7.0.0-SNAPSHOT + worldguard-bukkit + 7.0.3-SNAPSHOT provided diff --git a/implementation/v7fawe/pom.xml b/implementation/v7fawe/pom.xml deleted file mode 100644 index 1c8a0e8..0000000 --- a/implementation/v7fawe/pom.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - 4.0.0 - - - org.codemc.worldguardwrapper - worldguardwrapper-implementation - 1.1.4-SNAPSHOT - - - worldguardwrapper-implementation-v7-fawe - - WorldGuardWrapper-Implementation-V7-FAWE - - - - fawe-repo - http://ci.athion.net/job/FAWE-1.13/ws/mvn/ - - always - - - - worldguard-repo - http://ci.athion.net/job/FAWE-WorldGuard-1.13/ws/mvn/ - - always - - - - - - - ${project.groupId} - worldguardwrapper-api - 1.1.4-SNAPSHOT - provided - - - com.boydti - fawe-api - latest - provided - - - com.boydti - fawe-bukkit - latest - provided - - - com.sk89q - worldguard-core - latest - provided - - - com.sk89q - worldguard-legacy - latest - provided - - - diff --git a/implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/WorldGuardImplementation.java b/implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/WorldGuardImplementation.java deleted file mode 100644 index 278d35c..0000000 --- a/implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/WorldGuardImplementation.java +++ /dev/null @@ -1,196 +0,0 @@ -package org.codemc.worldguardwrapper.implementation.v7fawe; - -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.BlockVector2D; -import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldedit.bukkit.BukkitWorld; -import com.sk89q.worldguard.LocalPlayer; -import com.sk89q.worldguard.WorldGuard; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.protection.ApplicableRegionSet; -import com.sk89q.worldguard.protection.flags.*; -import com.sk89q.worldguard.protection.flags.registry.FlagConflictException; -import com.sk89q.worldguard.protection.flags.registry.FlagRegistry; -import com.sk89q.worldguard.protection.managers.RegionManager; -import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; -import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import lombok.NoArgsConstructor; -import lombok.NonNull; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.util.Vector; -import org.codemc.worldguardwrapper.flag.IWrappedFlag; -import org.codemc.worldguardwrapper.flag.WrappedState; -import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation; -import org.codemc.worldguardwrapper.implementation.v7fawe.flag.AbstractWrappedFlag; -import org.codemc.worldguardwrapper.implementation.v7fawe.region.WrappedRegion; -import org.codemc.worldguardwrapper.implementation.v7fawe.utility.WorldGuardFlagUtilities; -import org.codemc.worldguardwrapper.region.IWrappedRegion; - -import java.util.*; -import java.util.stream.Collectors; - -@NoArgsConstructor -public class WorldGuardImplementation implements IWorldGuardImplementation { - - private final WorldGuard core = WorldGuard.getInstance(); - private final FlagRegistry flagRegistry = core.getFlagRegistry(); - private final WorldGuardPlugin plugin = WorldGuardPlugin.inst(); - - public static BlockVector asBlockVector(@NonNull Location location) { - return new BlockVector(BukkitAdapter.asVector(location)); - } - - private Optional wrapPlayer(Player player) { - return Optional.ofNullable(player).map(bukkitPlayer -> plugin.wrapPlayer(player)); - } - - private Optional getWorldManager(@NonNull World world) { - return Optional.ofNullable(core.getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world))); - } - - private Optional getApplicableRegions(@NonNull Location location) { - return getWorldManager(location.getWorld()).map(manager -> manager.getApplicableRegions(asBlockVector(location))); - } - - private Optional getApplicableRegions(@NonNull Location minimum, @NonNull Location maximum) { - return getWorldManager(minimum.getWorld()).map(manager -> manager.getApplicableRegions( - new ProtectedCuboidRegion("temp", asBlockVector(minimum), asBlockVector(maximum)))); - } - - private Optional queryValue(Player player, @NonNull Location location, @NonNull Flag flag) { - return getApplicableRegions(location).map(applicableRegions -> applicableRegions.queryValue(wrapPlayer(player) - .orElse(null), flag)); - } - - @Override - public JavaPlugin getWorldGuardPlugin() { - return WorldGuardPlugin.inst(); - } - - @Override - public int getApiVersion() { - return 7; - } - - @Override - public Optional> getFlag(String name, Class type) { - return Optional.ofNullable(flagRegistry.get(name)) - .map(flag -> WorldGuardFlagUtilities.wrap(flag, type)); - } - - @Override - public Optional queryFlag(Player player, Location location, IWrappedFlag flag) { - AbstractWrappedFlag wrappedFlag = (AbstractWrappedFlag) flag; - return queryValue(player, location, wrappedFlag.getHandle()).flatMap(value -> wrappedFlag.fromWGValue(value)); - } - - @SuppressWarnings("unchecked") - @Override - public Optional> registerFlag(String name, Class type, T defaultValue) { - final Flag flag; - if (type.equals(WrappedState.class)) { - flag = new StateFlag(name, defaultValue == WrappedState.ALLOW); - } else if (type.equals(Boolean.class) || type.equals(boolean.class)) { - flag = new BooleanFlag(name); - } else if (type.equals(Double.class) || type.equals(double.class)) { - flag = new DoubleFlag(name); - } else if (type.equals(Enum.class)) { - flag = new EnumFlag(name, type); - } else if (type.equals(Integer.class) || type.equals(int.class)) { - flag = new IntegerFlag(name); - } else if (type.equals(Location.class)) { - flag = new LocationFlag(name); - } else if (type.equals(String.class)) { - flag = new StringFlag(name, (String) defaultValue); - } else if (type.equals(Vector.class)) { - flag = new VectorFlag(name); - } else { - throw new IllegalArgumentException("Unsupported flag type " + type.getName()); - } - try { - flagRegistry.register(flag); - return Optional.of(WorldGuardFlagUtilities.wrap(flag, type)); - } catch (FlagConflictException ignored) { - } - return Optional.empty(); - } - - @Override - public Optional getRegion(World world, String id) { - return getWorldManager(world) - .map(regionManager -> regionManager.getRegion(id)) - .map(region -> new WrappedRegion(world, region)); - } - - @Override - public Map getRegions(World world) { - RegionManager regionManager = core.getPlatform().getRegionContainer().get(new BukkitWorld(world)); - if (regionManager == null) { - return Collections.emptyMap(); - } - - Map regions = regionManager.getRegions(); - Map map = new HashMap<>(); - regions.forEach((name, region) -> map.put(name, new WrappedRegion(world, region))); - return map; - } - - @Override - public Set getRegions(Location location) { - ApplicableRegionSet regionSet = getApplicableRegions(location).orElse(null); - if (regionSet == null) { - return Collections.emptySet(); - } - - return regionSet.getRegions().stream() - .map(region -> new WrappedRegion(location.getWorld(), region)) - .collect(Collectors.toSet()); - } - - @Override - public Set getRegions(Location minimum, Location maximum) { - ApplicableRegionSet regionSet = getApplicableRegions(minimum, maximum).orElse(null); - if (regionSet == null) { - return Collections.emptySet(); - } - - return regionSet.getRegions().stream() - .map(region -> new WrappedRegion(minimum.getWorld(), region)) - .collect(Collectors.toSet()); - } - - @Override - public Optional addRegion(String id, List points, int minY, int maxY) { - ProtectedRegion region; - World world = points.get(0).getWorld(); - if (points.size() == 2) { - region = new ProtectedCuboidRegion(id, asBlockVector(points.get(0)), - asBlockVector(points.get(1))); - } else { - List vectorPoints = points.stream() - .map(location -> asBlockVector(location).toBlockVector2D()) - .collect(Collectors.toList()); - - region = new ProtectedPolygonalRegion(id, vectorPoints, minY, maxY); - } - - Optional manager = getWorldManager(world); - if (manager.isPresent()) { - manager.get().addRegion(region); - return Optional.of(new WrappedRegion(world, region)); - } else { - return Optional.empty(); - } - } - - @Override - public Optional> removeRegion(World world, String id) { - Optional> set = getWorldManager(world).map(manager -> manager.removeRegion(id)); - return set.map(protectedRegions -> protectedRegions.stream() - .map(region -> new WrappedRegion(world, region)).collect(Collectors.toSet())); - } -} diff --git a/implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/event/EventListener.java b/implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/event/EventListener.java deleted file mode 100644 index 71f52b2..0000000 --- a/implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/event/EventListener.java +++ /dev/null @@ -1,100 +0,0 @@ -package org.codemc.worldguardwrapper.implementation.v7fawe.event; - -import com.sk89q.worldguard.bukkit.event.block.UseBlockEvent; -import com.sk89q.worldguard.bukkit.event.entity.DamageEntityEvent; -import com.sk89q.worldguard.bukkit.event.entity.UseEntityEvent; -import com.sk89q.worldguard.bukkit.protection.events.DisallowedPVPEvent; -import lombok.NoArgsConstructor; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.Event.Result; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.codemc.worldguardwrapper.event.*; - -@NoArgsConstructor -public class EventListener implements Listener { - - @EventHandler(priority = EventPriority.LOW) - public void onUseBlock(UseBlockEvent worldGuardEvent) { - Player player = worldGuardEvent.getCause().getFirstPlayer(); - if (player == null) { - // Only forward player events for now - return; - } - - AbstractWrappedEvent event = new WrappedUseBlockEvent( - worldGuardEvent.getOriginalEvent(), - player, worldGuardEvent.getWorld(), - worldGuardEvent.getBlocks(), - worldGuardEvent.getEffectiveMaterial()); - Bukkit.getServer().getPluginManager().callEvent(event); - - if (event.getResult() != Result.DEFAULT) { - // DEFAULT = Result probably has not been touched by the handler, - // so don't touch the original result either. - worldGuardEvent.setResult(event.getResult()); - } - } - - @EventHandler(priority = EventPriority.LOW) - public void onUseEntity(UseEntityEvent worldGuardEvent) { - Player player = worldGuardEvent.getCause().getFirstPlayer(); - if (player == null) { - // Only forward player events for now - return; - } - - AbstractWrappedEvent event = new WrappedUseEntityEvent( - worldGuardEvent.getOriginalEvent(), - player, - worldGuardEvent.getTarget(), - worldGuardEvent.getEntity()); - Bukkit.getServer().getPluginManager().callEvent(event); - - if (event.getResult() != Result.DEFAULT) { - // DEFAULT = Result probably has not been touched by the handler, - // so don't touch the original result either. - worldGuardEvent.setResult(event.getResult()); - } - } - - @EventHandler(priority = EventPriority.LOW) - public void onDamageEntity(DamageEntityEvent worldGuardEvent) { - Player player = worldGuardEvent.getCause().getFirstPlayer(); - if (player == null) { - // Only forward player events for now - return; - } - - AbstractWrappedEvent event = new WrappedDamageEntityEvent( - worldGuardEvent.getOriginalEvent(), - player, - worldGuardEvent.getTarget(), - worldGuardEvent.getEntity()); - Bukkit.getServer().getPluginManager().callEvent(event); - - if (event.getResult() != Result.DEFAULT) { - // DEFAULT = Result probably has not been touched by the handler, - // so don't touch the original result either. - worldGuardEvent.setResult(event.getResult()); - } - } - - @EventHandler(priority = EventPriority.LOW) - public void onDisallowedPVP(DisallowedPVPEvent worldGuardEvent) { - AbstractWrappedEvent event = new WrappedDisallowedPVPEvent( - worldGuardEvent.getAttacker(), - worldGuardEvent.getDefender(), - worldGuardEvent.getCause()); - Bukkit.getServer().getPluginManager().callEvent(event); - - if (event.getResult() != Result.DEFAULT) { - // DEFAULT = Result probably has not been touched by the handler, - // so don't touch the original result either. - worldGuardEvent.setCancelled(event.getResult() == Result.DENY); - } - } - -} diff --git a/implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/flag/AbstractWrappedFlag.java b/implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/flag/AbstractWrappedFlag.java deleted file mode 100644 index 7b819c4..0000000 --- a/implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/flag/AbstractWrappedFlag.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.codemc.worldguardwrapper.implementation.v7fawe.flag; - -import com.sk89q.worldguard.protection.flags.Flag; -import lombok.AllArgsConstructor; -import lombok.Getter; -import org.codemc.worldguardwrapper.flag.IWrappedFlag; - -import java.util.Optional; - -@AllArgsConstructor -@Getter -public abstract class AbstractWrappedFlag implements IWrappedFlag { - - private final Flag handle; - - @Override - public String getName() { - return handle.getName(); - } - - public abstract Optional fromWGValue(Object value); - - public abstract Optional fromWrapperValue(T value); - - @Override - public Optional getDefaultValue() { - return fromWGValue(handle.getDefault()); - } - -} diff --git a/implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/flag/WrappedPrimitiveFlag.java b/implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/flag/WrappedPrimitiveFlag.java deleted file mode 100644 index 5d0cbd3..0000000 --- a/implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/flag/WrappedPrimitiveFlag.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.codemc.worldguardwrapper.implementation.v7fawe.flag; - -import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldedit.math.Vector3; -import com.sk89q.worldguard.protection.flags.Flag; - -import org.bukkit.Location; -import org.bukkit.util.Vector; -import org.codemc.worldguardwrapper.implementation.v7.utility.WorldGuardFlagUtilities; - -import java.util.Optional; - -public class WrappedPrimitiveFlag extends AbstractWrappedFlag { - - public WrappedPrimitiveFlag(Flag handle) { - super(handle); - } - - @SuppressWarnings("unchecked") - @Override - public Optional fromWGValue(Object value) { - if (value instanceof com.sk89q.worldedit.util.Location) { - return Optional.of((T) BukkitAdapter.adapt((com.sk89q.worldedit.util.Location) value)); - } else if (value instanceof Vector3) { - return Optional.of((T) WorldGuardFlagUtilities.adaptVector((Vector3) value)); - } - return Optional.ofNullable((T) value); - } - - @Override - public Optional fromWrapperValue(T value) { - if (value instanceof Location) { - return Optional.of(BukkitAdapter.adapt((Location) value)); - } else if (value instanceof Vector) { - return Optional.of(WorldGuardFlagUtilities.adaptVector((Vector) value)); - } - return Optional.ofNullable(value); - } - -} diff --git a/implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/flag/WrappedStatusFlag.java b/implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/flag/WrappedStatusFlag.java deleted file mode 100644 index def467c..0000000 --- a/implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/flag/WrappedStatusFlag.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.codemc.worldguardwrapper.implementation.v7fawe.flag; - -import com.sk89q.worldguard.protection.flags.Flag; -import com.sk89q.worldguard.protection.flags.StateFlag; -import org.codemc.worldguardwrapper.flag.IWrappedStatusFlag; -import org.codemc.worldguardwrapper.flag.WrappedState; - -import java.util.Optional; - -public class WrappedStatusFlag extends AbstractWrappedFlag implements IWrappedStatusFlag { - - public WrappedStatusFlag(Flag handle) { - super(handle); - } - - @Override - public Optional fromWGValue(Object value) { - return Optional.ofNullable(value) - .map(state -> state == StateFlag.State.ALLOW ? WrappedState.ALLOW : WrappedState.DENY); - } - - @Override - public Optional fromWrapperValue(WrappedState value) { - return Optional.ofNullable(value) - .map(state -> state == WrappedState.ALLOW ? StateFlag.State.ALLOW : StateFlag.State.DENY); - } - -} diff --git a/implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/region/WrappedRegion.java b/implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/region/WrappedRegion.java deleted file mode 100644 index 4952f7e..0000000 --- a/implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/region/WrappedRegion.java +++ /dev/null @@ -1,187 +0,0 @@ -package org.codemc.worldguardwrapper.implementation.v7fawe.region; - -import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldguard.protection.flags.Flag; -import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import lombok.AllArgsConstructor; -import lombok.Getter; -import org.bukkit.Location; -import org.bukkit.World; -import org.codemc.worldguardwrapper.flag.IWrappedFlag; -import org.codemc.worldguardwrapper.implementation.v7fawe.WorldGuardImplementation; -import org.codemc.worldguardwrapper.implementation.v7fawe.flag.AbstractWrappedFlag; -import org.codemc.worldguardwrapper.implementation.v7fawe.utility.WorldGuardFlagUtilities; -import org.codemc.worldguardwrapper.region.IWrappedDomain; -import org.codemc.worldguardwrapper.region.IWrappedRegion; -import org.codemc.worldguardwrapper.selection.ICuboidSelection; -import org.codemc.worldguardwrapper.selection.IPolygonalSelection; -import org.codemc.worldguardwrapper.selection.ISelection; - -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; -import java.util.stream.Collectors; - -@AllArgsConstructor -@Getter -public class WrappedRegion implements IWrappedRegion { - - private final World world; - private final ProtectedRegion handle; - - @Override - public ISelection getSelection() { - if (handle instanceof ProtectedPolygonalRegion) { - return new IPolygonalSelection() { - @Override - public Set getPoints() { - return handle.getPoints().stream() - .map(blockVector2D -> blockVector2D.toVector(0)) - .map(vector -> BukkitAdapter.adapt(world, vector)) - .collect(Collectors.toSet()); - } - - @Override - public int getMinimumY() { - return handle.getMinimumPoint().getBlockY(); - } - - @Override - public int getMaximumY() { - return handle.getMaximumPoint().getBlockY(); - } - }; - } - - return new ICuboidSelection() { - @Override - public Location getMinimumPoint() { - return BukkitAdapter.adapt(world, handle.getMinimumPoint()); - } - - @Override - public Location getMaximumPoint() { - return BukkitAdapter.adapt(world, handle.getMaximumPoint()); - } - }; - } - - @Override - public String getId() { - return handle.getId(); - } - - @Override - public Map, Object> getFlags() { - Map, Object> result = new HashMap<>(); - handle.getFlags().forEach((flag, value) -> { - if (value != null) { - try { - IWrappedFlag wrappedFlag = WorldGuardFlagUtilities.wrapFixType(flag, value.getClass()); - Optional wrappedValue = ((AbstractWrappedFlag) wrappedFlag).fromWGValue(value); - wrappedValue.ifPresent(val -> result.put(wrappedFlag, val)); - } catch (IllegalArgumentException ignored) {/* Unsupported flag type */} - } - }); - return result; - } - - @SuppressWarnings("unchecked") - @Override - public Optional getFlag(IWrappedFlag flag) { - AbstractWrappedFlag wrappedFlag = (AbstractWrappedFlag) flag; - return Optional.ofNullable(handle.getFlag(wrappedFlag.getHandle())) - .map(value -> (T) wrappedFlag.fromWGValue(value)); - } - - @SuppressWarnings("unchecked") - @Override - public void setFlag(IWrappedFlag flag, T value) { - AbstractWrappedFlag wrappedFlag = (AbstractWrappedFlag) flag; - handle.setFlag((Flag) wrappedFlag.getHandle(), wrappedFlag.fromWrapperValue(value).orElse(null)); - } - - @Override - public int getPriority() { - return handle.getPriority(); - } - - @Override - public IWrappedDomain getOwners() { - return new IWrappedDomain() { - @Override - public Set getPlayers() { - return handle.getOwners().getUniqueIds(); - } - - @Override - public void addPlayer(UUID uuid) { - handle.getOwners().addPlayer(uuid); - } - - @Override - public void removePlayer(UUID uuid) { - handle.getOwners().removePlayer(uuid); - } - - @Override - public Set getGroups() { - return handle.getOwners().getGroups(); - } - - @Override - public void addGroup(String name) { - handle.getOwners().addGroup(name); - } - - @Override - public void removeGroup(String name) { - handle.getOwners().removeGroup(name); - } - }; - } - - @Override - public IWrappedDomain getMembers() { - return new IWrappedDomain() { - @Override - public Set getPlayers() { - return handle.getMembers().getUniqueIds(); - } - - @Override - public void addPlayer(UUID uuid) { - handle.getMembers().addPlayer(uuid); - } - - @Override - public void removePlayer(UUID uuid) { - handle.getMembers().removePlayer(uuid); - } - - @Override - public Set getGroups() { - return handle.getMembers().getGroups(); - } - - @Override - public void addGroup(String name) { - handle.getMembers().addGroup(name); - } - - @Override - public void removeGroup(String name) { - handle.getMembers().removeGroup(name); - } - }; - } - - @Override - public boolean contains(Location location) { - return handle.contains(WorldGuardImplementation.asBlockVector(location)); - } - -} diff --git a/implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/utility/WorldGuardFlagUtilities.java b/implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/utility/WorldGuardFlagUtilities.java deleted file mode 100644 index f2642bc..0000000 --- a/implementation/v7fawe/src/main/java/org/codemc/worldguardwrapper/implementation/v7fawe/utility/WorldGuardFlagUtilities.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.codemc.worldguardwrapper.implementation.v7fawe.utility; - -import com.sk89q.worldguard.protection.flags.Flag; -import com.sk89q.worldguard.protection.flags.StateFlag; - -import org.bukkit.Location; -import org.bukkit.util.Vector; -import org.codemc.worldguardwrapper.flag.IWrappedFlag; -import org.codemc.worldguardwrapper.flag.WrappedState; -import org.codemc.worldguardwrapper.implementation.v7fawe.flag.WrappedPrimitiveFlag; -import org.codemc.worldguardwrapper.implementation.v7fawe.flag.WrappedStatusFlag; - -import lombok.experimental.UtilityClass; - -@UtilityClass -public class WorldGuardFlagUtilities { - - // TODO: find a better way to define wrapper mappings and register mappings - @SuppressWarnings({"unchecked", "rawtypes"}) - public IWrappedFlag wrap(Flag flag, Class type) { - final IWrappedFlag wrappedFlag; - if (type.equals(WrappedState.class)) { - wrappedFlag = (IWrappedFlag) new WrappedStatusFlag((Flag) flag); - } else if (type.equals(Boolean.class) || type.equals(boolean.class)) { - wrappedFlag = new WrappedPrimitiveFlag(flag); - } else if (type.equals(Double.class) || type.equals(double.class)) { - wrappedFlag = new WrappedPrimitiveFlag(flag); - } else if (type.equals(Enum.class)) { - wrappedFlag = new WrappedPrimitiveFlag(flag); - } else if (type.equals(Integer.class) || type.equals(int.class)) { - wrappedFlag = new WrappedPrimitiveFlag(flag); - } else if (type.equals(Location.class)) { - wrappedFlag = new WrappedPrimitiveFlag(flag); - } else if (type.equals(String.class)) { - wrappedFlag = new WrappedPrimitiveFlag(flag); - } else if (type.equals(Vector.class)) { - wrappedFlag = new WrappedPrimitiveFlag(flag); - } else { - throw new IllegalArgumentException("Unsupported flag type " + type.getName()); - } - return wrappedFlag; - } - - // Used when the flag's type is not known, so it has to be derived from a sample value's class - public IWrappedFlag wrapFixType(Flag flag, Class type) { - if (StateFlag.State.class.isAssignableFrom(type)) { - // StateFlag - type = WrappedState.class; - } else if (com.sk89q.worldedit.util.Location.class.isAssignableFrom(type)) { - // LocationFlag - type = org.bukkit.Location.class; - } else if (Vector3.class.isAssignableFrom(type)) { - // VectorFlag - type = Vector.class; - } - - return wrap(flag, type); - } - - public Vector adaptVector(Vector3 vector) { - return new Vector(vector.getX(), vector.getY(), vector.getZ()); - } - - public Vector3 adaptVector(Vector vector) { - return Vector3.at(vector.getX(), vector.getY(), vector.getZ()); - } - -} \ No newline at end of file diff --git a/library/pom.xml b/library/pom.xml index f7df969..d054ba9 100644 --- a/library/pom.xml +++ b/library/pom.xml @@ -7,7 +7,7 @@ org.codemc.worldguardwrapper worldguardwrapper-parent - 1.1.6-SNAPSHOT + 1.1.7-SNAPSHOT worldguardwrapper @@ -18,30 +18,23 @@ ${project.groupId} worldguardwrapper-api - 1.1.6-SNAPSHOT + 1.1.7-SNAPSHOT ${project.groupId} worldguardwrapper-implementation-legacy - 1.1.6-SNAPSHOT + 1.1.7-SNAPSHOT ${project.groupId} worldguardwrapper-implementation-v6 - 1.1.6-SNAPSHOT + 1.1.7-SNAPSHOT ${project.groupId} worldguardwrapper-implementation-v7 - 1.1.6-SNAPSHOT + 1.1.7-SNAPSHOT - diff --git a/pom.xml b/pom.xml index 38e2869..a3c00cb 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.codemc.worldguardwrapper worldguardwrapper-parent - 1.1.6-SNAPSHOT + 1.1.7-SNAPSHOT pom @@ -51,7 +51,7 @@ UTF-8 UTF-8 1.8 - 1.14-R0.1-SNAPSHOT + 1.15.2-R0.1-SNAPSHOT