Update, add FAWE support

This commit is contained in:
Gabriele C 2019-01-13 12:33:47 +01:00
parent 62ab411dd3
commit 379433ea35
18 changed files with 690 additions and 29 deletions

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.codemc.worldguardwrapper</groupId> <groupId>org.codemc.worldguardwrapper</groupId>
<artifactId>worldguardwrapper-parent</artifactId> <artifactId>worldguardwrapper-parent</artifactId>
<version>1.1.2-SNAPSHOT</version> <version>1.1.3-SNAPSHOT</version>
</parent> </parent>
<artifactId>worldguardwrapper-api</artifactId> <artifactId>worldguardwrapper-api</artifactId>

View File

@ -4,7 +4,6 @@ import org.bukkit.Location;
import org.codemc.worldguardwrapper.flag.IWrappedFlag; import org.codemc.worldguardwrapper.flag.IWrappedFlag;
import org.codemc.worldguardwrapper.selection.ISelection; import org.codemc.worldguardwrapper.selection.ISelection;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
public interface IWrappedRegion { public interface IWrappedRegion {

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.codemc.worldguardwrapper</groupId> <groupId>org.codemc.worldguardwrapper</groupId>
<artifactId>worldguardwrapper-parent</artifactId> <artifactId>worldguardwrapper-parent</artifactId>
<version>1.1.2-SNAPSHOT</version> <version>1.1.3-SNAPSHOT</version>
</parent> </parent>
<artifactId>worldguardwrapper-implementation</artifactId> <artifactId>worldguardwrapper-implementation</artifactId>
@ -16,6 +16,7 @@
<modules> <modules>
<module>v6</module> <module>v6</module>
<module>v7</module> <module>v7</module>
<module>v7fawe</module>
</modules> </modules>
<name>WorldGuardWrapper-Implementation</name> <name>WorldGuardWrapper-Implementation</name>
@ -23,14 +24,4 @@
<properties> <properties>
<maven.deploy.skip>true</maven.deploy.skip> <maven.deploy.skip>true</maven.deploy.skip>
</properties> </properties>
<repositories>
<repository>
<id>sk89q-repo</id>
<url>http://maven.sk89q.com/repo/</url>
<snapshots>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</project> </project>

View File

@ -7,18 +7,28 @@
<parent> <parent>
<groupId>org.codemc.worldguardwrapper</groupId> <groupId>org.codemc.worldguardwrapper</groupId>
<artifactId>worldguardwrapper-implementation</artifactId> <artifactId>worldguardwrapper-implementation</artifactId>
<version>1.1.2-SNAPSHOT</version> <version>1.1.3-SNAPSHOT</version>
</parent> </parent>
<artifactId>worldguardwrapper-implementation-v6</artifactId> <artifactId>worldguardwrapper-implementation-v6</artifactId>
<name>WorldGuardWrapper-Implementation-V6</name> <name>WorldGuardWrapper-Implementation-V6</name>
<repositories>
<repository>
<id>sk89q-repo</id>
<url>http://maven.sk89q.com/repo/</url>
<snapshots>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>worldguardwrapper-api</artifactId> <artifactId>worldguardwrapper-api</artifactId>
<version>1.1.2-SNAPSHOT</version> <version>1.1.3-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -20,8 +20,8 @@ import org.bukkit.util.Vector;
import org.codemc.worldguardwrapper.flag.IWrappedFlag; import org.codemc.worldguardwrapper.flag.IWrappedFlag;
import org.codemc.worldguardwrapper.flag.WrappedState; import org.codemc.worldguardwrapper.flag.WrappedState;
import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation; import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation;
import org.codemc.worldguardwrapper.implementation.v6.flag.WrappedPrimitiveFlag;
import org.codemc.worldguardwrapper.implementation.v6.flag.AbstractWrappedFlag; import org.codemc.worldguardwrapper.implementation.v6.flag.AbstractWrappedFlag;
import org.codemc.worldguardwrapper.implementation.v6.flag.WrappedPrimitiveFlag;
import org.codemc.worldguardwrapper.implementation.v6.flag.WrappedStatusFlag; import org.codemc.worldguardwrapper.implementation.v6.flag.WrappedStatusFlag;
import org.codemc.worldguardwrapper.implementation.v6.region.WrappedRegion; import org.codemc.worldguardwrapper.implementation.v6.region.WrappedRegion;
import org.codemc.worldguardwrapper.implementation.v6.utility.WorldGuardVectorUtilities; import org.codemc.worldguardwrapper.implementation.v6.utility.WorldGuardVectorUtilities;

View File

@ -16,7 +16,9 @@ import org.codemc.worldguardwrapper.selection.ICuboidSelection;
import org.codemc.worldguardwrapper.selection.IPolygonalSelection; import org.codemc.worldguardwrapper.selection.IPolygonalSelection;
import org.codemc.worldguardwrapper.selection.ISelection; import org.codemc.worldguardwrapper.selection.ISelection;
import java.util.*; import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@AllArgsConstructor @AllArgsConstructor

View File

@ -7,18 +7,28 @@
<parent> <parent>
<groupId>org.codemc.worldguardwrapper</groupId> <groupId>org.codemc.worldguardwrapper</groupId>
<artifactId>worldguardwrapper-implementation</artifactId> <artifactId>worldguardwrapper-implementation</artifactId>
<version>1.1.2-SNAPSHOT</version> <version>1.1.3-SNAPSHOT</version>
</parent> </parent>
<artifactId>worldguardwrapper-implementation-v7</artifactId> <artifactId>worldguardwrapper-implementation-v7</artifactId>
<name>WorldGuardWrapper-Implementation-V7</name> <name>WorldGuardWrapper-Implementation-V7</name>
<repositories>
<repository>
<id>sk89q-repo</id>
<url>http://maven.sk89q.com/repo/</url>
<snapshots>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>worldguardwrapper-api</artifactId> <artifactId>worldguardwrapper-api</artifactId>
<version>1.1.2-SNAPSHOT</version> <version>1.1.3-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.codemc.worldguardwrapper</groupId>
<artifactId>worldguardwrapper-implementation</artifactId>
<version>1.1.3-SNAPSHOT</version>
</parent>
<artifactId>worldguardwrapper-implementation-v7-fawe</artifactId>
<name>WorldGuardWrapper-Implementation-V7-FAWE</name>
<repositories>
<repository>
<id>fawe-repo</id>
<url>http://ci.athion.net/job/FAWE-1.13/ws/mvn/</url>
<releases>
<updatePolicy>always</updatePolicy>
</releases>
</repository>
<repository>
<id>worldguard-repo</id>
<url>http://ci.athion.net/job/FAWE-WorldGuard-1.13/ws/mvn/</url>
<releases>
<updatePolicy>always</updatePolicy>
</releases>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>worldguardwrapper-api</artifactId>
<version>1.1.3-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.boydti</groupId>
<artifactId>fawe-api</artifactId>
<version>latest</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.boydti</groupId>
<artifactId>fawe-bukkit</artifactId>
<version>latest</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldguard-core</artifactId>
<version>latest</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldguard-legacy</artifactId>
<version>latest</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,223 @@
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.flag.WrappedPrimitiveFlag;
import org.codemc.worldguardwrapper.implementation.v7fawe.flag.WrappedStatusFlag;
import org.codemc.worldguardwrapper.implementation.v7fawe.region.WrappedRegion;
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<LocalPlayer> wrapPlayer(Player player) {
return Optional.ofNullable(player).map(bukkitPlayer -> plugin.wrapPlayer(player));
}
private Optional<RegionManager> getWorldManager(@NonNull World world) {
return Optional.ofNullable(core.getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world)));
}
private Optional<ApplicableRegionSet> getApplicableRegions(@NonNull Location location) {
return getWorldManager(location.getWorld()).map(manager -> manager.getApplicableRegions(asBlockVector(location)));
}
private Optional<ApplicableRegionSet> getApplicableRegions(@NonNull Location minimum, @NonNull Location maximum) {
return getWorldManager(minimum.getWorld()).map(manager -> manager.getApplicableRegions(
new ProtectedCuboidRegion("temp", asBlockVector(minimum), asBlockVector(maximum))));
}
private <V> Optional<V> queryValue(Player player, @NonNull Location location, @NonNull Flag<V> flag) {
return getApplicableRegions(location).map(applicableRegions -> applicableRegions.queryValue(wrapPlayer(player)
.orElse(null), flag));
}
// TODO: find a better way to define wrapper mappings and register mappings
@SuppressWarnings("unchecked")
private <T> IWrappedFlag<T> wrap(Flag<?> flag, Class<T> type) {
final IWrappedFlag<T> wrappedFlag;
if (type.equals(WrappedState.class)) {
wrappedFlag = (IWrappedFlag<T>) new WrappedStatusFlag((Flag<StateFlag.State>) 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;
}
@Override
public JavaPlugin getWorldGuardPlugin() {
return WorldGuardPlugin.inst();
}
@Override
public int getApiVersion() {
return 7;
}
@Override
public <T> Optional<IWrappedFlag<T>> getFlag(String name, Class<T> type) {
return Optional.ofNullable(flagRegistry.get(name))
.map(flag -> wrap(flag, type));
}
@Override
public <T> Optional<T> queryFlag(Player player, Location location, IWrappedFlag<T> flag) {
AbstractWrappedFlag<T> wrappedFlag = (AbstractWrappedFlag<T>) flag;
return wrappedFlag.fromWGValue(queryValue(player, location, wrappedFlag.getHandle()));
}
@SuppressWarnings("unchecked")
@Override
public <T> Optional<IWrappedFlag<T>> registerFlag(String name, Class<T> 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(wrap(flag, type));
} catch (FlagConflictException ignored) {
}
return Optional.empty();
}
@Override
public Optional<IWrappedRegion> getRegion(World world, String id) {
return getWorldManager(world)
.map(regionManager -> regionManager.getRegion(id))
.map(region -> new WrappedRegion(world, region));
}
@Override
public Map<String, IWrappedRegion> getRegions(World world) {
RegionManager regionManager = core.getPlatform().getRegionContainer().get(new BukkitWorld(world));
if (regionManager == null) {
return Collections.emptyMap();
}
Map<String, ProtectedRegion> regions = regionManager.getRegions();
Map<String, IWrappedRegion> map = new HashMap<>();
regions.forEach((name, region) -> map.put(name, new WrappedRegion(world, region)));
return map;
}
@Override
public Set<IWrappedRegion> 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<IWrappedRegion> 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<IWrappedRegion> addRegion(String id, List<Location> 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<BlockVector2D> vectorPoints = points.stream()
.map(location -> asBlockVector(location).toBlockVector2D())
.collect(Collectors.toList());
region = new ProtectedPolygonalRegion(id, vectorPoints, minY, maxY);
}
Optional<RegionManager> manager = getWorldManager(world);
if (manager.isPresent()) {
manager.get().addRegion(region);
return Optional.of(new WrappedRegion(world, region));
} else {
return Optional.empty();
}
}
@Override
public Optional<Set<IWrappedRegion>> removeRegion(World world, String id) {
Optional<Set<ProtectedRegion>> set = getWorldManager(world).map(manager -> manager.removeRegion(id));
return set.map(protectedRegions -> protectedRegions.stream()
.map(region -> new WrappedRegion(world, region)).collect(Collectors.toSet()));
}
}

View File

@ -0,0 +1,100 @@
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);
}
}
}

View File

@ -0,0 +1,30 @@
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<T> implements IWrappedFlag<T> {
private final Flag<?> handle;
@Override
public String getName() {
return handle.getName();
}
public abstract Optional<T> fromWGValue(Object value);
public abstract Optional<Object> fromWrapperValue(T value);
@Override
public Optional<T> getDefaultValue() {
return fromWGValue(handle.getDefault());
}
}

View File

@ -0,0 +1,23 @@
package org.codemc.worldguardwrapper.implementation.v7fawe.flag;
import com.sk89q.worldguard.protection.flags.Flag;
import java.util.Optional;
public class WrappedPrimitiveFlag<T> extends AbstractWrappedFlag<T> {
public WrappedPrimitiveFlag(Flag<T> handle) {
super(handle);
}
@Override
public Optional<T> fromWGValue(Object value) {
return Optional.ofNullable((T) value);
}
@Override
public Optional<Object> fromWrapperValue(T value) {
return Optional.ofNullable(value);
}
}

View File

@ -0,0 +1,28 @@
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<WrappedState> implements IWrappedStatusFlag {
public WrappedStatusFlag(Flag<StateFlag.State> handle) {
super(handle);
}
@Override
public Optional<WrappedState> fromWGValue(Object value) {
return Optional.ofNullable(value)
.map(state -> state == StateFlag.State.ALLOW ? WrappedState.ALLOW : WrappedState.DENY);
}
@Override
public Optional<Object> fromWrapperValue(WrappedState value) {
return Optional.ofNullable(value)
.map(state -> state == WrappedState.ALLOW ? StateFlag.State.ALLOW : StateFlag.State.DENY);
}
}

View File

@ -0,0 +1,169 @@
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.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.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.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 IPolygonalSelection) {
return new IPolygonalSelection() {
@Override
public Set<Location> getPoints() {
return handle.getPoints().stream()
.map(blockVector2D -> blockVector2D.toVector(0))
.map(vector -> BukkitAdapter.adapt(world, vector))
.collect(Collectors.toSet());
}
@Override
public int getMinimumY() {
return ((IPolygonalSelection) handle).getMinimumY();
}
@Override
public int getMaximumY() {
return ((IPolygonalSelection) handle).getMaximumY();
}
};
}
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();
}
@SuppressWarnings("unchecked")
@Override
public <T> Optional<T> getFlag(IWrappedFlag<T> flag) {
AbstractWrappedFlag<T> wrappedFlag = (AbstractWrappedFlag<T>) flag;
return Optional.ofNullable(handle.getFlag(wrappedFlag.getHandle()))
.map(value -> (T) wrappedFlag.fromWGValue(value));
}
@SuppressWarnings("unchecked")
@Override
public <T> void setFlag(IWrappedFlag<T> flag, T value) {
AbstractWrappedFlag<T> wrappedFlag = (AbstractWrappedFlag<T>) flag;
handle.setFlag((Flag<Object>) wrappedFlag.getHandle(), wrappedFlag.fromWrapperValue(value).orElse(null));
}
@Override
public int getPriority() {
return handle.getPriority();
}
@Override
public IWrappedDomain getOwners() {
return new IWrappedDomain() {
@Override
public Set<UUID> 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<String> 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<UUID> 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<String> 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));
}
}

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.codemc.worldguardwrapper</groupId> <groupId>org.codemc.worldguardwrapper</groupId>
<artifactId>worldguardwrapper-parent</artifactId> <artifactId>worldguardwrapper-parent</artifactId>
<version>1.1.2-SNAPSHOT</version> <version>1.1.3-SNAPSHOT</version>
</parent> </parent>
<artifactId>worldguardwrapper</artifactId> <artifactId>worldguardwrapper</artifactId>
@ -18,17 +18,22 @@
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>worldguardwrapper-api</artifactId> <artifactId>worldguardwrapper-api</artifactId>
<version>1.1.2-SNAPSHOT</version> <version>1.1.3-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>worldguardwrapper-implementation-v6</artifactId> <artifactId>worldguardwrapper-implementation-v6</artifactId>
<version>1.1.2-SNAPSHOT</version> <version>1.1.3-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>worldguardwrapper-implementation-v7</artifactId> <artifactId>worldguardwrapper-implementation-v7</artifactId>
<version>1.1.2-SNAPSHOT</version> <version>1.1.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>worldguardwrapper-implementation-v7-fawe</artifactId>
<version>1.1.3-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -37,11 +37,16 @@ public class WorldGuardWrapper implements IWorldGuardImplementation {
if (legacy) { if (legacy) {
implementation = new org.codemc.worldguardwrapper.implementation.v6.WorldGuardImplementation(); implementation = new org.codemc.worldguardwrapper.implementation.v6.WorldGuardImplementation();
listener = new org.codemc.worldguardwrapper.implementation.v6.event.EventListener(); listener = new org.codemc.worldguardwrapper.implementation.v6.event.EventListener();
} else {
if (Bukkit.getPluginManager().isPluginEnabled("FastAsyncWorldEdit")) {
implementation = new org.codemc.worldguardwrapper.implementation.v7fawe.WorldGuardImplementation();
listener = new org.codemc.worldguardwrapper.implementation.v7fawe.event.EventListener();
} else { } else {
implementation = new org.codemc.worldguardwrapper.implementation.v7.WorldGuardImplementation(); implementation = new org.codemc.worldguardwrapper.implementation.v7.WorldGuardImplementation();
listener = new org.codemc.worldguardwrapper.implementation.v7.event.EventListener(); listener = new org.codemc.worldguardwrapper.implementation.v7.event.EventListener();
} }
} }
}
/** /**
* Forward WorldGuard event calls to wrapped events to allow listening to them * Forward WorldGuard event calls to wrapped events to allow listening to them

View File

@ -6,7 +6,7 @@
<groupId>org.codemc.worldguardwrapper</groupId> <groupId>org.codemc.worldguardwrapper</groupId>
<artifactId>worldguardwrapper-parent</artifactId> <artifactId>worldguardwrapper-parent</artifactId>
<version>1.1.2-SNAPSHOT</version> <version>1.1.3-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<modules> <modules>