mirror of
https://github.com/CodeMC/WorldGuardWrapper.git
synced 2024-11-10 05:05:20 +01:00
Update v7 implementation, bump version
This commit is contained in:
parent
1d1d4ab7d9
commit
015c015b67
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper-parent</artifactId>
|
||||
<version>1.1.6-SNAPSHOT</version>
|
||||
<version>1.1.7-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>worldguardwrapper-api</artifactId>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper-implementation</artifactId>
|
||||
<version>1.1.6-SNAPSHOT</version>
|
||||
<version>1.1.7-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>worldguardwrapper-implementation-legacy</artifactId>
|
||||
|
@ -28,7 +28,7 @@
|
|||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-api</artifactId>
|
||||
<version>1.1.6-SNAPSHOT</version>
|
||||
<version>1.1.7-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper-parent</artifactId>
|
||||
<version>1.1.6-SNAPSHOT</version>
|
||||
<version>1.1.7-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>worldguardwrapper-implementation</artifactId>
|
||||
|
@ -17,9 +17,6 @@
|
|||
<module>legacy</module>
|
||||
<module>v6</module>
|
||||
<module>v7</module>
|
||||
<!--
|
||||
<module>v7fawe</module>
|
||||
-->
|
||||
</modules>
|
||||
|
||||
<name>WorldGuardWrapper-Implementation</name>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper-implementation</artifactId>
|
||||
<version>1.1.6-SNAPSHOT</version>
|
||||
<version>1.1.7-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>worldguardwrapper-implementation-v6</artifactId>
|
||||
|
@ -28,7 +28,7 @@
|
|||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-api</artifactId>
|
||||
<version>1.1.6-SNAPSHOT</version>
|
||||
<version>1.1.7-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper-implementation</artifactId>
|
||||
<version>1.1.6-SNAPSHOT</version>
|
||||
<version>1.1.7-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>worldguardwrapper-implementation-v7</artifactId>
|
||||
|
@ -16,8 +16,8 @@
|
|||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>sk89q-repo</id>
|
||||
<url>http://maven.sk89q.com/repo/</url>
|
||||
<id>enginehub-repo</id>
|
||||
<url>https://maven.enginehub.org/repo/</url>
|
||||
<snapshots>
|
||||
<updatePolicy>always</updatePolicy>
|
||||
</snapshots>
|
||||
|
@ -28,13 +28,13 @@
|
|||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-api</artifactId>
|
||||
<version>1.1.6-SNAPSHOT</version>
|
||||
<version>1.1.7-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
<artifactId>worldguard-legacy</artifactId>
|
||||
<version>7.0.0-SNAPSHOT</version>
|
||||
<artifactId>worldguard-bukkit</artifactId>
|
||||
<version>7.0.3-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
<?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.4-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.4-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>
|
|
@ -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<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));
|
||||
}
|
||||
|
||||
@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 -> WorldGuardFlagUtilities.wrap(flag, type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> queryFlag(Player player, Location location, IWrappedFlag<T> flag) {
|
||||
AbstractWrappedFlag<T> wrappedFlag = (AbstractWrappedFlag<T>) flag;
|
||||
return queryValue(player, location, wrappedFlag.getHandle()).flatMap(value -> wrappedFlag.fromWGValue(value));
|
||||
}
|
||||
|
||||
@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(WorldGuardFlagUtilities.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()));
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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<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());
|
||||
}
|
||||
|
||||
}
|
|
@ -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<T> extends AbstractWrappedFlag<T> {
|
||||
|
||||
public WrappedPrimitiveFlag(Flag<T> handle) {
|
||||
super(handle);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Optional<T> 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<Object> 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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<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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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<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 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<IWrappedFlag<?>, Object> getFlags() {
|
||||
Map<IWrappedFlag<?>, 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 <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));
|
||||
}
|
||||
|
||||
}
|
|
@ -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 <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;
|
||||
}
|
||||
|
||||
// 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());
|
||||
}
|
||||
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper-parent</artifactId>
|
||||
<version>1.1.6-SNAPSHOT</version>
|
||||
<version>1.1.7-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>worldguardwrapper</artifactId>
|
||||
|
@ -18,30 +18,23 @@
|
|||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-api</artifactId>
|
||||
<version>1.1.6-SNAPSHOT</version>
|
||||
<version>1.1.7-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-implementation-legacy</artifactId>
|
||||
<version>1.1.6-SNAPSHOT</version>
|
||||
<version>1.1.7-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-implementation-v6</artifactId>
|
||||
<version>1.1.6-SNAPSHOT</version>
|
||||
<version>1.1.7-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-implementation-v7</artifactId>
|
||||
<version>1.1.6-SNAPSHOT</version>
|
||||
<version>1.1.7-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-implementation-v7-fawe</artifactId>
|
||||
<version>1.1.4-SNAPSHOT</version>
|
||||
</dependency>
|
||||
-->
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
4
pom.xml
4
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper-parent</artifactId>
|
||||
<version>1.1.6-SNAPSHOT</version>
|
||||
<version>1.1.7-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
|
@ -51,7 +51,7 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<spigot-api.version>1.14-R0.1-SNAPSHOT</spigot-api.version>
|
||||
<spigot-api.version>1.15.2-R0.1-SNAPSHOT</spigot-api.version>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
|
|
Loading…
Reference in New Issue
Block a user