mirror of
https://github.com/CodeMC/WorldGuardWrapper.git
synced 2024-11-10 05:05:20 +01:00
commit
7c6f9e0f34
8
.travis.yml
Normal file
8
.travis.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
sudo: false
|
||||
dist: trusty
|
||||
language: java
|
||||
jdk:
|
||||
- oraclejdk8
|
||||
cache:
|
||||
directories:
|
||||
- '$HOME/.m2/repository'
|
|
@ -21,7 +21,7 @@ How to include WorldEditWrapper into your maven project:
|
|||
<dependency>
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper</artifactId>
|
||||
<version>1.0.3-SNAPSHOT</version>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
```
|
||||
|
@ -34,7 +34,7 @@ Remember to include/relocate the library into your final jar, example:
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<version>3.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper-parent</artifactId>
|
||||
<version>1.0.4-SNAPSHOT</version>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>worldguardwrapper-api</artifactId>
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.bukkit.event.HandlerList;
|
|||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class DamageEntityEvent extends AbstractWrappedEvent {
|
||||
public class WrappedDamageEntityEvent extends AbstractWrappedEvent {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
|
@ -8,7 +8,7 @@ import org.bukkit.event.HandlerList;
|
|||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class DisallowedPVPEvent extends AbstractWrappedEvent {
|
||||
public class WrappedDisallowedPVPEvent extends AbstractWrappedEvent {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
|
@ -13,7 +13,7 @@ import java.util.List;
|
|||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class UseBlockEvent extends AbstractWrappedEvent {
|
||||
public class WrappedUseBlockEvent extends AbstractWrappedEvent {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
|
@ -10,7 +10,7 @@ import org.bukkit.event.HandlerList;
|
|||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class UseEntityEvent extends AbstractWrappedEvent {
|
||||
public class WrappedUseEntityEvent extends AbstractWrappedEvent {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package org.codemc.worldguardwrapper.flag;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface IWrappedFlag<T> {
|
||||
|
||||
String getName();
|
||||
|
||||
Optional<T> getDefaultValue();
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package org.codemc.worldguardwrapper.flag;
|
||||
|
||||
public enum WrappedState {
|
||||
ALLOW,
|
||||
DENY;
|
||||
|
||||
WrappedState() {
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
package org.codemc.worldguardwrapper.flags;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
public abstract class AbstractWrappedFlag<T> {
|
||||
@NonNull
|
||||
private String name;
|
||||
@NonNull
|
||||
private Class<T> type;
|
||||
private T defaultValue;
|
||||
|
||||
/**
|
||||
* Get the name of this flag.
|
||||
*
|
||||
* @return The name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of this flag's value.
|
||||
*
|
||||
* @return The type
|
||||
*/
|
||||
public Class<T> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default value of this flag.
|
||||
*
|
||||
* @return The default value (may be {@code null})
|
||||
*/
|
||||
public T getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the value stored in this flag into a type that can be
|
||||
* serialized into YAML.
|
||||
*
|
||||
* @param value The value
|
||||
* @return The serialized type
|
||||
*/
|
||||
public abstract Object serialize(T value);
|
||||
|
||||
/**
|
||||
* Convert a raw object that was loaded (from a YAML file, for example) into the
|
||||
* type that this flag uses.
|
||||
*
|
||||
* @param serialized The raw object
|
||||
* @return The deserialized type
|
||||
*/
|
||||
public abstract T deserialize(Object serialized);
|
||||
|
||||
/**
|
||||
* Parse a given input to force it to a type compatible with the flag.
|
||||
*
|
||||
* @param player Player who entered the string.
|
||||
* @param userInput Input string (e.g. a player input)
|
||||
* @return A type compatible with the flag
|
||||
*/
|
||||
public abstract T parse(Player player, String userInput);
|
||||
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package org.codemc.worldguardwrapper.flags;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* A flag that stores a boolean.
|
||||
*/
|
||||
public class BooleanFlag extends AbstractWrappedFlag<Boolean> {
|
||||
|
||||
public BooleanFlag(String name) {
|
||||
this(name, false);
|
||||
}
|
||||
|
||||
public BooleanFlag(String name, boolean defaultValue) {
|
||||
super(name, boolean.class, defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object serialize(Boolean value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deserialize(Object serialized) {
|
||||
return (Boolean) serialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean parse(Player player, String userInput) {
|
||||
if (userInput.equalsIgnoreCase("true") || userInput.equalsIgnoreCase("yes")
|
||||
|| userInput.equalsIgnoreCase("on")
|
||||
|| userInput.equalsIgnoreCase("1")) {
|
||||
return true;
|
||||
} else if (userInput.equalsIgnoreCase("false") || userInput.equalsIgnoreCase("no")
|
||||
|| userInput.equalsIgnoreCase("off")
|
||||
|| userInput.equalsIgnoreCase("0")) {
|
||||
return false;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package org.codemc.worldguardwrapper.flags;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* A flag that stores a double.
|
||||
*/
|
||||
public class DoubleFlag extends AbstractWrappedFlag<Double> {
|
||||
|
||||
public DoubleFlag(String name) {
|
||||
this(name, 0d);
|
||||
}
|
||||
|
||||
public DoubleFlag(String name, double defaultValue) {
|
||||
super(name, double.class, defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object serialize(Double value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double deserialize(Object serialized) {
|
||||
if (serialized instanceof Number) {
|
||||
return ((Number) serialized).doubleValue();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double parse(Player player, String userInput) {
|
||||
return Double.parseDouble(userInput);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
package org.codemc.worldguardwrapper.flags;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* A flag that stores an enum value.
|
||||
*/
|
||||
public class EnumFlag<T extends Enum<T>> extends AbstractWrappedFlag<T> {
|
||||
|
||||
public EnumFlag(String name, Class<T> enumClass) {
|
||||
this(name, enumClass, null);
|
||||
}
|
||||
|
||||
public EnumFlag(String name, Class<T> enumClass, T defaultValue) {
|
||||
super(name, enumClass, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the enum class.
|
||||
* TODO: really needed? we already have getType() -Gab
|
||||
*
|
||||
* @return The enum class
|
||||
*/
|
||||
public Class<T> getEnumClass() {
|
||||
return getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object serialize(T value) {
|
||||
return value.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T deserialize(Object serialized) {
|
||||
if (serialized instanceof String) {
|
||||
return Enum.valueOf(getEnumClass(), (String) serialized);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T parse(Player player, String userInput) {
|
||||
return Enum.valueOf(getEnumClass(), userInput);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package org.codemc.worldguardwrapper.flags;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* A flag that stores an integer.
|
||||
*/
|
||||
public class IntegerFlag extends AbstractWrappedFlag<Integer> {
|
||||
|
||||
public IntegerFlag(String name) {
|
||||
this(name, 0);
|
||||
}
|
||||
|
||||
public IntegerFlag(String name, int defaultValue) {
|
||||
super(name, int.class, defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object serialize(Integer value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deserialize(Object serialized) {
|
||||
if (serialized instanceof Number) {
|
||||
return ((Number) serialized).intValue();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer parse(Player player, String userInput) {
|
||||
return Integer.parseInt(userInput);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
package org.codemc.worldguardwrapper.flags;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A flag that stores a bukkit location.
|
||||
*/
|
||||
public class LocationFlag extends AbstractWrappedFlag<Location> {
|
||||
|
||||
public LocationFlag(String name) {
|
||||
this(name, null);
|
||||
}
|
||||
|
||||
public LocationFlag(String name, Location defaultValue) {
|
||||
super(name, Location.class, defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object serialize(Location value) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
|
||||
map.put("world", value.getWorld().getName());
|
||||
map.put("x", value.getX());
|
||||
map.put("y", value.getY());
|
||||
map.put("z", value.getZ());
|
||||
map.put("yaw", value.getYaw());
|
||||
map.put("pitch", value.getPitch());
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location deserialize(Object serialized) {
|
||||
if (serialized instanceof Map) {
|
||||
Map<?, ?> map = (Map<?, ?>) serialized;
|
||||
|
||||
Object worldName = map.get("world");
|
||||
if (worldName == null) return null;
|
||||
|
||||
Object x = map.get("x");
|
||||
if (x == null) return null;
|
||||
|
||||
Object y = map.get("y");
|
||||
if (y == null) return null;
|
||||
|
||||
Object z = map.get("z");
|
||||
if (z == null) return null;
|
||||
|
||||
Object yaw = map.get("yaw");
|
||||
if (yaw == null) return null;
|
||||
|
||||
Object pitch = map.get("pitch");
|
||||
if (pitch == null) return null;
|
||||
|
||||
World world = Bukkit.getWorld(String.valueOf(worldName));
|
||||
if (world == null) return null;
|
||||
|
||||
return new Location(world, toNumber(x), toNumber(y), toNumber(z),
|
||||
(float) toNumber(yaw), (float) toNumber(pitch));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location parse(Player player, String userInput) {
|
||||
if ("here".equalsIgnoreCase(userInput)) {
|
||||
return player.getLocation();
|
||||
} else if ("none".equalsIgnoreCase(userInput)) {
|
||||
return null;
|
||||
} else {
|
||||
String[] split = userInput.split(",");
|
||||
if (split.length >= 3) {
|
||||
final World world = player.getWorld();
|
||||
final double x = Double.parseDouble(split[0]);
|
||||
final double y = Double.parseDouble(split[1]);
|
||||
final double z = Double.parseDouble(split[2]);
|
||||
final float yaw = split.length < 4 ? 0 : Float.parseFloat(split[3]);
|
||||
final float pitch = split.length < 5 ? 0 : Float.parseFloat(split[4]);
|
||||
|
||||
return new Location(world, x, y, z, yaw, pitch);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private double toNumber(Object o) {
|
||||
if (o instanceof Number) {
|
||||
return ((Number) o).doubleValue();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
package org.codemc.worldguardwrapper.flags;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* A flag that stores a set of values of the sub flag's type.
|
||||
*/
|
||||
public class SetFlag<T> extends AbstractWrappedFlag<Set<T>> {
|
||||
|
||||
private AbstractWrappedFlag<T> subFlag;
|
||||
|
||||
public SetFlag(String name, AbstractWrappedFlag<T> subFlag) {
|
||||
this(name, new HashSet<>(), subFlag);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public SetFlag(String name, Set<T> defaultValue, AbstractWrappedFlag<T> subFlag) {
|
||||
super(name, (Class<Set<T>>) defaultValue.getClass(), defaultValue);
|
||||
this.subFlag = subFlag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of values stored in this flag.
|
||||
*
|
||||
* @return The stored flag type.
|
||||
*/
|
||||
public AbstractWrappedFlag<T> getSubType() {
|
||||
return subFlag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<T> deserialize(Object o) {
|
||||
if (o instanceof Collection<?>) {
|
||||
Collection<?> collection = (Collection<?>) o;
|
||||
Set<T> items = new HashSet<T>();
|
||||
|
||||
for (Object sub : collection) {
|
||||
T item = subFlag.deserialize(sub);
|
||||
if (item != null) {
|
||||
items.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
return items;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object serialize(Set<T> o) {
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
for (T item : o) {
|
||||
list.add(subFlag.serialize(item));
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<T> parse(Player player, String userInput) {
|
||||
if (userInput.isEmpty()) {
|
||||
return new HashSet<>();
|
||||
} else {
|
||||
Set<T> items = new HashSet<>();
|
||||
|
||||
for (String str : userInput.split(",")) {
|
||||
items.add(subFlag.parse(player, str));
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package org.codemc.worldguardwrapper.flags;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* A flag that stores a string.
|
||||
*/
|
||||
public class StringFlag extends AbstractWrappedFlag<String> {
|
||||
|
||||
public StringFlag(String name) {
|
||||
this(name, "");
|
||||
}
|
||||
|
||||
public StringFlag(String name, String defaultValue) {
|
||||
super(name, String.class, defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object serialize(String value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String deserialize(Object serialized) {
|
||||
return (String) serialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parse(Player player, String userInput) {
|
||||
return userInput;
|
||||
}
|
||||
|
||||
}
|
|
@ -5,8 +5,8 @@ import org.bukkit.Location;
|
|||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.codemc.worldguardwrapper.flags.AbstractWrappedFlag;
|
||||
import org.codemc.worldguardwrapper.region.WrappedRegion;
|
||||
import org.codemc.worldguardwrapper.flag.IWrappedFlag;
|
||||
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
@ -26,36 +26,6 @@ public interface IWorldGuardImplementation {
|
|||
*/
|
||||
int getApiVersion();
|
||||
|
||||
/**
|
||||
* Query a StateFlag's value for a given player at a given location.
|
||||
*
|
||||
* @param player The player
|
||||
* @param location The location
|
||||
* @param flagName The flag's name
|
||||
* @return The flag's value
|
||||
*/
|
||||
Optional<Boolean> queryStateFlag(Player player, @NonNull Location location, @NonNull String flagName);
|
||||
|
||||
/**
|
||||
* Register a {@code StateFlag}.
|
||||
*
|
||||
* @param flagName The name of the flag
|
||||
* @param defaultValue The flag's default value
|
||||
* @return Whether the flag has been registered
|
||||
*/
|
||||
boolean registerStateFlag(@NonNull String flagName, @NonNull Boolean defaultValue);
|
||||
|
||||
/**
|
||||
* Query a flag's value for a given player at a given location.
|
||||
*
|
||||
* @param player The player
|
||||
* @param location The location
|
||||
* @param flagName The name of the flag
|
||||
* @param type The type of the flag's value
|
||||
* @return The flag's value
|
||||
*/
|
||||
<T> Optional<T> queryFlag(Player player, @NonNull Location location, @NonNull String flagName, Class<T> type);
|
||||
|
||||
/**
|
||||
* Query a flag's value for a given player at a given location.
|
||||
*
|
||||
|
@ -64,17 +34,36 @@ public interface IWorldGuardImplementation {
|
|||
* @param flag The flag
|
||||
* @return The flag's value
|
||||
*/
|
||||
default <T> Optional<T> queryFlag(Player player, @NonNull Location location, @NonNull AbstractWrappedFlag<T> flag) {
|
||||
return queryFlag(player, location, flag.getName(), flag.getType());
|
||||
}
|
||||
<T> Optional<T> queryFlag(Player player, @NonNull Location location, @NonNull IWrappedFlag<T> flag);
|
||||
|
||||
/**
|
||||
* Register a flag to WorldGuard's flag registry.
|
||||
* Returns the flag with the given name.
|
||||
*
|
||||
* @param flag The flag to register
|
||||
* @return Whether the flag has been registered
|
||||
* @param name The flag name
|
||||
* @return The flag, empty if it doesn't exists
|
||||
*/
|
||||
<T> boolean registerFlag(@NonNull AbstractWrappedFlag<T> flag);
|
||||
Optional<IWrappedFlag<?>> getFlag(@NonNull String name);
|
||||
|
||||
/**
|
||||
* Registers a flag to WorldGuard's flag registry.
|
||||
*
|
||||
* @param name The flag name
|
||||
* @param type The flag type
|
||||
* @param defaultValue the flag default value (if supported by the type), can be null
|
||||
* @return The created flag, empty if a name conflict occurred
|
||||
*/
|
||||
<T> Optional<IWrappedFlag<T>> registerFlag(@NonNull String name, @NonNull Class<T> type, T defaultValue);
|
||||
|
||||
/**
|
||||
* Registers a flag to WorldGuard's flag registry.
|
||||
*
|
||||
* @param name The flag name
|
||||
* @param type The flag type
|
||||
* @return The created flag, empty if a name conflict occurred
|
||||
*/
|
||||
default <T> Optional<IWrappedFlag<T>> registerFlag(@NonNull String name, @NonNull Class<T> type) {
|
||||
return registerFlag(name, type, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a region by its ID.
|
||||
|
@ -83,7 +72,7 @@ public interface IWorldGuardImplementation {
|
|||
* @param id ID of the region
|
||||
* @return The region
|
||||
*/
|
||||
Optional<WrappedRegion> getRegion(@NonNull World world, @NonNull String id);
|
||||
Optional<IWrappedRegion> getRegion(@NonNull World world, @NonNull String id);
|
||||
|
||||
/**
|
||||
* Get an unmodifiable map of regions containing the state of the
|
||||
|
@ -95,7 +84,7 @@ public interface IWorldGuardImplementation {
|
|||
* @param world The world
|
||||
* @return A map of regions
|
||||
*/
|
||||
Map<String, WrappedRegion> getRegions(@NonNull World world);
|
||||
Map<String, IWrappedRegion> getRegions(@NonNull World world);
|
||||
|
||||
/**
|
||||
* Get a set of regions at the given location.
|
||||
|
@ -103,7 +92,7 @@ public interface IWorldGuardImplementation {
|
|||
* @param location The location
|
||||
* @return A set of regions
|
||||
*/
|
||||
Set<WrappedRegion> getRegions(@NonNull Location location);
|
||||
Set<IWrappedRegion> getRegions(@NonNull Location location);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -113,7 +102,7 @@ public interface IWorldGuardImplementation {
|
|||
* @param maximum The maximum location of the area
|
||||
* @return A set of regions
|
||||
*/
|
||||
Set<WrappedRegion> getRegions(@NonNull Location minimum, @NonNull Location maximum);
|
||||
Set<IWrappedRegion> getRegions(@NonNull Location minimum, @NonNull Location maximum);
|
||||
|
||||
/**
|
||||
* Add a region. If only two points are given, a cuboid region will be created.
|
||||
|
@ -124,7 +113,7 @@ public interface IWorldGuardImplementation {
|
|||
* @param maxY The maximum y coordinate
|
||||
* @return The added region
|
||||
*/
|
||||
Optional<WrappedRegion> addRegion(@NonNull String id, @NonNull List<Location> points, int minY, int maxY);
|
||||
Optional<IWrappedRegion> addRegion(@NonNull String id, @NonNull List<Location> points, int minY, int maxY);
|
||||
|
||||
/**
|
||||
* Add a cuboid region.
|
||||
|
@ -134,7 +123,7 @@ public interface IWorldGuardImplementation {
|
|||
* @param point2 The second point of the region
|
||||
* @return The added region
|
||||
*/
|
||||
default Optional<WrappedRegion> addCuboidRegion(@NonNull String id, @NonNull Location point1, @NonNull Location point2) {
|
||||
default Optional<IWrappedRegion> addCuboidRegion(@NonNull String id, @NonNull Location point1, @NonNull Location point2) {
|
||||
return addRegion(id, Arrays.asList(point1, point2), 0, 0);
|
||||
}
|
||||
|
||||
|
@ -145,6 +134,6 @@ public interface IWorldGuardImplementation {
|
|||
* @param id The region ID
|
||||
* @return A list of removed regions where the first entry is the region specified by {@code id}
|
||||
*/
|
||||
Optional<Set<WrappedRegion>> removeRegion(@NonNull World world, @NonNull String id);
|
||||
Optional<Set<IWrappedRegion>> removeRegion(@NonNull World world, @NonNull String id);
|
||||
|
||||
}
|
|
@ -3,7 +3,7 @@ package org.codemc.worldguardwrapper.region;
|
|||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface PlayerDomain {
|
||||
public interface IWrappedDomain {
|
||||
|
||||
Set<UUID> getPlayers();
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package org.codemc.worldguardwrapper.region;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.codemc.worldguardwrapper.flag.IWrappedFlag;
|
||||
import org.codemc.worldguardwrapper.selection.ISelection;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface IWrappedRegion {
|
||||
|
||||
ISelection getSelection();
|
||||
|
||||
String getId();
|
||||
|
||||
<T> Optional<T> getFlag(IWrappedFlag<T> flag);
|
||||
|
||||
<T> void setFlag(IWrappedFlag<T> flag, T value);
|
||||
|
||||
Map<IWrappedFlag<?>, Object> getFlags();
|
||||
|
||||
int getPriority();
|
||||
|
||||
IWrappedDomain getOwners();
|
||||
|
||||
IWrappedDomain getMembers();
|
||||
|
||||
boolean contains(Location location);
|
||||
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package org.codemc.worldguardwrapper.region;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.codemc.worldguardwrapper.selection.Selection;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface WrappedRegion {
|
||||
|
||||
Selection getSelection();
|
||||
|
||||
String getId();
|
||||
|
||||
Optional<Object> getFlag(String name);
|
||||
|
||||
Map<String, Object> getFlags();
|
||||
|
||||
int getPriority();
|
||||
|
||||
PlayerDomain getOwners();
|
||||
|
||||
PlayerDomain getMembers();
|
||||
|
||||
boolean contains(Location location);
|
||||
|
||||
}
|
|
@ -2,7 +2,7 @@ package org.codemc.worldguardwrapper.selection;
|
|||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public interface CuboidSelection extends Selection {
|
||||
public interface ICuboidSelection extends ISelection {
|
||||
|
||||
Location getMinimumPoint();
|
||||
|
|
@ -4,7 +4,7 @@ import org.bukkit.Location;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
public interface PolygonalSelection extends Selection {
|
||||
public interface IPolygonalSelection extends ISelection {
|
||||
|
||||
Set<Location> getPoints();
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.codemc.worldguardwrapper.selection;
|
||||
|
||||
public interface Selection {
|
||||
public interface ISelection {
|
||||
}
|
|
@ -1,24 +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.0.4-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>worldguardwrapper-implementation-interface</artifactId>
|
||||
|
||||
<name>WorldGuardWrapper-Implementation-Interface</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-api</artifactId>
|
||||
<version>1.0.4-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -7,14 +7,13 @@
|
|||
<parent>
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper-parent</artifactId>
|
||||
<version>1.0.4-SNAPSHOT</version>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>worldguardwrapper-implementation</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>interface</module>
|
||||
<module>v6</module>
|
||||
<module>v7</module>
|
||||
</modules>
|
||||
|
@ -29,6 +28,9 @@
|
|||
<repository>
|
||||
<id>sk89q-repo</id>
|
||||
<url>http://maven.sk89q.com/repo/</url>
|
||||
<snapshots>
|
||||
<updatePolicy>always</updatePolicy>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
</project>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper-implementation</artifactId>
|
||||
<version>1.0.4-SNAPSHOT</version>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>worldguardwrapper-implementation-v6</artifactId>
|
||||
|
@ -17,8 +17,9 @@
|
|||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-implementation-interface</artifactId>
|
||||
<version>1.0.4-SNAPSHOT</version>
|
||||
<artifactId>worldguardwrapper-api</artifactId>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
|
@ -48,10 +49,6 @@
|
|||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>jsr305</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.thoughtworks.paranamer</groupId>
|
||||
<artifactId>paranamer</artifactId>
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
package org.codemc.worldguardwrapper.implementation.v6;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.FlagContext;
|
||||
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
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;
|
||||
|
@ -21,13 +16,14 @@ import org.bukkit.Location;
|
|||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.codemc.worldguardwrapper.flags.AbstractWrappedFlag;
|
||||
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.region.PlayerDomain;
|
||||
import org.codemc.worldguardwrapper.region.WrappedRegion;
|
||||
import org.codemc.worldguardwrapper.selection.CuboidSelection;
|
||||
import org.codemc.worldguardwrapper.selection.PolygonalSelection;
|
||||
import org.codemc.worldguardwrapper.selection.Selection;
|
||||
import org.codemc.worldguardwrapper.implementation.v6.flag.WrappedFlag;
|
||||
import org.codemc.worldguardwrapper.implementation.v6.region.WrappedRegion;
|
||||
import org.codemc.worldguardwrapper.implementation.v6.utility.WorldGuardVectorUtilities;
|
||||
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -52,7 +48,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
|
||||
private Optional<ApplicableRegionSet> getApplicableRegions(@NonNull Location minimum, @NonNull Location maximum) {
|
||||
return getWorldManager(minimum.getWorld()).map(manager -> manager.getApplicableRegions(
|
||||
new ProtectedCuboidRegion("temp", toBlockVector(minimum), toBlockVector(maximum))));
|
||||
new ProtectedCuboidRegion("temp", WorldGuardVectorUtilities.toBlockVector(minimum), WorldGuardVectorUtilities.toBlockVector(maximum))));
|
||||
}
|
||||
|
||||
private <V> Optional<V> queryValue(Player player, @NonNull Location location, @NonNull Flag<V> flag) {
|
||||
|
@ -60,164 +56,6 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
.orElse(null), flag));
|
||||
}
|
||||
|
||||
private Optional<StateFlag.State> queryState(Player player, @NonNull Location location, @NonNull StateFlag... stateFlags) {
|
||||
return getApplicableRegions(location).map(applicableRegions -> applicableRegions.queryState(wrapPlayer(player)
|
||||
.orElse(null), stateFlags));
|
||||
}
|
||||
|
||||
private BlockVector toBlockVector(Location location) {
|
||||
return new BlockVector(location.getX(), location.getY(), location.getZ());
|
||||
}
|
||||
|
||||
private Location fromBlockVector(World world, BlockVector vector) {
|
||||
return new Location(world, vector.getX(), vector.getY(), vector.getZ());
|
||||
}
|
||||
|
||||
private List<BlockVector2D> toBlockVector2DList(List<Location> locations) {
|
||||
return locations.stream().map(location -> new BlockVector2D(location.getX(), location.getZ())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private WrappedRegion toRegion(World world, ProtectedRegion region) {
|
||||
return new WrappedRegion() {
|
||||
|
||||
@Override
|
||||
public Selection getSelection() {
|
||||
if (region instanceof PolygonalSelection) {
|
||||
return new PolygonalSelection() {
|
||||
|
||||
@Override
|
||||
public Set<Location> getPoints() {
|
||||
return region.getPoints().stream()
|
||||
.map(vector -> new BlockVector(vector.toVector()))
|
||||
.map(vector -> fromBlockVector(world, vector))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumY() {
|
||||
return ((PolygonalSelection) region).getMinimumY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaximumY() {
|
||||
return ((PolygonalSelection) region).getMaximumY();
|
||||
}
|
||||
};
|
||||
}
|
||||
return new CuboidSelection() {
|
||||
|
||||
@Override
|
||||
public Location getMinimumPoint() {
|
||||
return fromBlockVector(world, region.getMinimumPoint());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getMaximumPoint() {
|
||||
return fromBlockVector(world, region.getMaximumPoint());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return region.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getFlags() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
region.getFlags().forEach((flag, value) -> map.put(flag.getName(), value));
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Object> getFlag(String name) {
|
||||
return Optional.ofNullable(flagRegistry.get(name))
|
||||
.map(region::getFlag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return region.getPriority();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDomain getOwners() {
|
||||
return new PlayerDomain() {
|
||||
@Override
|
||||
public Set<UUID> getPlayers() {
|
||||
return region.getOwners().getUniqueIds();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPlayer(UUID uuid) {
|
||||
region.getOwners().addPlayer(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePlayer(UUID uuid) {
|
||||
region.getOwners().removePlayer(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getGroups() {
|
||||
return region.getOwners().getGroups();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGroup(String name) {
|
||||
region.getOwners().addGroup(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeGroup(String name) {
|
||||
region.getOwners().removeGroup(name);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDomain getMembers() {
|
||||
return new PlayerDomain() {
|
||||
@Override
|
||||
public Set<UUID> getPlayers() {
|
||||
return region.getMembers().getUniqueIds();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPlayer(UUID uuid) {
|
||||
region.getMembers().addPlayer(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePlayer(UUID uuid) {
|
||||
region.getMembers().removePlayer(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getGroups() {
|
||||
return region.getMembers().getGroups();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGroup(String name) {
|
||||
region.getMembers().addGroup(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeGroup(String name) {
|
||||
region.getMembers().removeGroup(name);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Location location) {
|
||||
return region.contains(toBlockVector(location));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaPlugin getWorldGuardPlugin() {
|
||||
return WorldGuardPlugin.inst();
|
||||
|
@ -229,132 +67,113 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Optional<Boolean> queryStateFlag(Player player, @NonNull Location location, @NonNull String flagId) {
|
||||
Flag<?> flag = flagRegistry.get(flagId);
|
||||
if (!(flag instanceof StateFlag)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return queryState(player, location, (StateFlag) flag).map(state -> state == StateFlag.State.ALLOW);
|
||||
public <T> Optional<T> queryFlag(Player player, Location location, IWrappedFlag<T> flag) {
|
||||
Flag<T> wrappedFlag = ((WrappedFlag<T>) flag).getHandle();
|
||||
return queryValue(player, location, wrappedFlag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerStateFlag(@NonNull String flagId, @NonNull Boolean defaultValue) {
|
||||
try {
|
||||
flagRegistry.register(new StateFlag(flagId, defaultValue));
|
||||
return true;
|
||||
} catch (FlagConflictException ignored) {
|
||||
}
|
||||
return false;
|
||||
public Optional<IWrappedFlag<?>> getFlag(String name) {
|
||||
return Optional.ofNullable(flagRegistry.get(name))
|
||||
.map(WrappedFlag::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Optional<T> queryFlag(Player player, Location location, String flagName, Class<T> type) {
|
||||
Flag<?> flag = flagRegistry.get(flagName);
|
||||
Object value = queryValue(player, location, flag).orElse(null);
|
||||
if (type.isInstance(value)) {
|
||||
return Optional.of((T) value);
|
||||
@Override
|
||||
public <T> Optional<IWrappedFlag<T>> registerFlag(String name, Class<T> type, T defaultValue) {
|
||||
final Flag<T> wrappedFlag;
|
||||
if (type.equals(Boolean.class) || type.equals(boolean.class)) {
|
||||
wrappedFlag = (Flag<T>) new BooleanFlag(name);
|
||||
} else if (type.equals(Double.class) || type.equals(double.class)) {
|
||||
wrappedFlag = (Flag<T>) new DoubleFlag(name);
|
||||
} else if (type.equals(Enum.class)) {
|
||||
wrappedFlag = new EnumFlag(name, type);
|
||||
} else if (type.equals(Integer.class) || type.equals(int.class)) {
|
||||
wrappedFlag = (Flag<T>) new IntegerFlag(name);
|
||||
} else if (type.equals(Location.class)) {
|
||||
wrappedFlag = (Flag<T>) new LocationFlag(name);
|
||||
} else if (type.equals(WrappedState.class)) {
|
||||
wrappedFlag = (Flag<T>) new StateFlag(name, defaultValue == WrappedState.ALLOW);
|
||||
} else if (type.equals(String.class)) {
|
||||
wrappedFlag = (Flag<T>) new StringFlag(name, (String) defaultValue);
|
||||
} else if (type.equals(Vector.class)) {
|
||||
wrappedFlag = (Flag<T>) new VectorFlag(name);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported flag type " + type.getName());
|
||||
}
|
||||
try {
|
||||
flagRegistry.register(wrappedFlag);
|
||||
return Optional.of(new WrappedFlag<>(wrappedFlag));
|
||||
} catch (FlagConflictException ignored) {
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> boolean registerFlag(AbstractWrappedFlag<T> flag) {
|
||||
Flag<T> wgFlag = new Flag<T>(flag.getName()) {
|
||||
@Override
|
||||
public T getDefault() {
|
||||
return flag.getDefaultValue();
|
||||
public Optional<IWrappedRegion> getRegion(World world, String id) {
|
||||
return getWorldManager(world).map(regionManager -> new WrappedRegion(world, regionManager.getRegion(id)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object marshal(T o) {
|
||||
return flag.serialize(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T unmarshal(Object o) {
|
||||
return flag.deserialize(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T parseInput(FlagContext context) throws InvalidFlagFormat {
|
||||
return flag.parse(context.getPlayerSender(), context.getUserInput());
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
flagRegistry.register(wgFlag);
|
||||
return true;
|
||||
} catch (FlagConflictException ignored) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<WrappedRegion> getRegion(World world, String id) {
|
||||
return getWorldManager(world).map(regionManager -> toRegion(world, regionManager.getRegion(id)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, WrappedRegion> getRegions(World world) {
|
||||
public Map<String, IWrappedRegion> getRegions(World world) {
|
||||
RegionManager regionManager = plugin.getRegionManager(world);
|
||||
Map<String, ProtectedRegion> regions = regionManager.getRegions();
|
||||
|
||||
Map<String, WrappedRegion> map = new HashMap<>();
|
||||
regions.forEach((name, region) -> map.put(name, toRegion(world, region)));
|
||||
Map<String, IWrappedRegion> map = new HashMap<>();
|
||||
regions.forEach((name, region) -> map.put(name, new WrappedRegion(world, region)));
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<WrappedRegion> getRegions(Location location) {
|
||||
public Set<IWrappedRegion> getRegions(Location location) {
|
||||
ApplicableRegionSet regionSet = getApplicableRegions(location).orElse(null);
|
||||
Set<WrappedRegion> set = new HashSet<>();
|
||||
Set<IWrappedRegion> set = new HashSet<>();
|
||||
|
||||
if (regionSet == null) {
|
||||
return set;
|
||||
}
|
||||
|
||||
regionSet.forEach(region -> set.add(toRegion(location.getWorld(), region)));
|
||||
regionSet.forEach(region -> set.add(new WrappedRegion(location.getWorld(), region)));
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<WrappedRegion> getRegions(Location minimum, Location maximum) {
|
||||
public Set<IWrappedRegion> getRegions(Location minimum, Location maximum) {
|
||||
ApplicableRegionSet regionSet = getApplicableRegions(minimum, maximum).orElse(null);
|
||||
Set<WrappedRegion> set = new HashSet<>();
|
||||
Set<IWrappedRegion> set = new HashSet<>();
|
||||
|
||||
if (regionSet == null) {
|
||||
return set;
|
||||
}
|
||||
|
||||
regionSet.forEach(region -> set.add(toRegion(minimum.getWorld(), region)));
|
||||
regionSet.forEach(region -> set.add(new WrappedRegion(minimum.getWorld(), region)));
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<WrappedRegion> addRegion(String id, List<Location> points, int minY, int maxY) {
|
||||
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, toBlockVector(points.get(0)), toBlockVector(points.get(1)));
|
||||
region = new ProtectedCuboidRegion(id, WorldGuardVectorUtilities.toBlockVector(points.get(0)), WorldGuardVectorUtilities.toBlockVector(points.get(1)));
|
||||
} else {
|
||||
region = new ProtectedPolygonalRegion(id, toBlockVector2DList(points), minY, maxY);
|
||||
region = new ProtectedPolygonalRegion(id, WorldGuardVectorUtilities.toBlockVector2DList(points), minY, maxY);
|
||||
}
|
||||
|
||||
Optional<RegionManager> manager = getWorldManager(world);
|
||||
if (manager.isPresent()) {
|
||||
manager.get().addRegion(region);
|
||||
return Optional.of(toRegion(world, region));
|
||||
return Optional.of(new WrappedRegion(world, region));
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Set<WrappedRegion>> removeRegion(World world, String id) {
|
||||
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 -> toRegion(world, region))
|
||||
return set.map(protectedRegions -> protectedRegions.stream().map(region -> new WrappedRegion(world, region))
|
||||
.collect(Collectors.toSet()));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.codemc.worldguardwrapper.implementation.v6;
|
||||
package org.codemc.worldguardwrapper.implementation.v6.event;
|
||||
|
||||
import com.sk89q.worldguard.bukkit.event.block.UseBlockEvent;
|
||||
import com.sk89q.worldguard.bukkit.event.entity.DamageEntityEvent;
|
||||
|
@ -7,11 +7,11 @@ import com.sk89q.worldguard.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.bukkit.event.Event.Result;
|
||||
import org.codemc.worldguardwrapper.event.AbstractWrappedEvent;
|
||||
import org.codemc.worldguardwrapper.event.*;
|
||||
|
||||
@NoArgsConstructor
|
||||
public class EventListener implements Listener {
|
||||
|
@ -24,7 +24,7 @@ public class EventListener implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
AbstractWrappedEvent event = new org.codemc.worldguardwrapper.event.UseBlockEvent(
|
||||
AbstractWrappedEvent event = new WrappedUseBlockEvent(
|
||||
worldGuardEvent.getOriginalEvent(),
|
||||
player, worldGuardEvent.getWorld(),
|
||||
worldGuardEvent.getBlocks(),
|
||||
|
@ -46,7 +46,7 @@ public class EventListener implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
AbstractWrappedEvent event = new org.codemc.worldguardwrapper.event.UseEntityEvent(
|
||||
AbstractWrappedEvent event = new WrappedUseEntityEvent(
|
||||
worldGuardEvent.getOriginalEvent(),
|
||||
player,
|
||||
worldGuardEvent.getTarget(),
|
||||
|
@ -68,7 +68,7 @@ public class EventListener implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
AbstractWrappedEvent event = new org.codemc.worldguardwrapper.event.DamageEntityEvent(
|
||||
AbstractWrappedEvent event = new WrappedDamageEntityEvent(
|
||||
worldGuardEvent.getOriginalEvent(),
|
||||
player,
|
||||
worldGuardEvent.getTarget(),
|
||||
|
@ -84,7 +84,7 @@ public class EventListener implements Listener {
|
|||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onDisallowedPVP(DisallowedPVPEvent worldGuardEvent) {
|
||||
AbstractWrappedEvent event = new org.codemc.worldguardwrapper.event.DisallowedPVPEvent(
|
||||
AbstractWrappedEvent event = new WrappedDisallowedPVPEvent(
|
||||
worldGuardEvent.getAttacker(),
|
||||
worldGuardEvent.getDefender(),
|
||||
worldGuardEvent.getCause());
|
|
@ -0,0 +1,26 @@
|
|||
package org.codemc.worldguardwrapper.implementation.v6.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 class WrappedFlag<T> implements IWrappedFlag<T> {
|
||||
|
||||
private final Flag<T> handle;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return handle.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<T> getDefaultValue() {
|
||||
return Optional.ofNullable(handle.getDefault());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,174 @@
|
|||
package org.codemc.worldguardwrapper.implementation.v6.region;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
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.v6.flag.WrappedFlag;
|
||||
import org.codemc.worldguardwrapper.implementation.v6.utility.WorldGuardVectorUtilities;
|
||||
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.*;
|
||||
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(vector -> new BlockVector(vector.toVector()))
|
||||
.map(vector -> WorldGuardVectorUtilities.fromBlockVector(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 WorldGuardVectorUtilities.fromBlockVector(world, handle.getMinimumPoint());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getMaximumPoint() {
|
||||
return WorldGuardVectorUtilities.fromBlockVector(world, handle.getMaximumPoint());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return handle.getId();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> Optional<T> getFlag(IWrappedFlag<T> flag) {
|
||||
Flag wrappedFlag = ((WrappedFlag) flag).getHandle();
|
||||
return Optional.ofNullable(handle.getFlag(wrappedFlag))
|
||||
.map(value -> (T) value);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> void setFlag(IWrappedFlag<T> flag, T value) {
|
||||
Flag wrappedFlag = ((WrappedFlag) flag).getHandle();
|
||||
handle.setFlag(wrappedFlag, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<IWrappedFlag<?>, Object> getFlags() {
|
||||
Map<IWrappedFlag<?>, Object> map = new HashMap<>();
|
||||
handle.getFlags().forEach((flag, value) -> map.put(new WrappedFlag<>(flag), value));
|
||||
return map;
|
||||
}
|
||||
|
||||
@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(WorldGuardVectorUtilities.toBlockVector(location));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package org.codemc.worldguardwrapper.implementation.v6.utility;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@UtilityClass
|
||||
public class WorldGuardVectorUtilities {
|
||||
|
||||
public BlockVector toBlockVector(Location location) {
|
||||
return new BlockVector(location.getX(), location.getY(), location.getZ());
|
||||
}
|
||||
|
||||
public Location fromBlockVector(World world, BlockVector vector) {
|
||||
return new Location(world, vector.getX(), vector.getY(), vector.getZ());
|
||||
}
|
||||
|
||||
public List<BlockVector2D> toBlockVector2DList(List<Location> locations) {
|
||||
return locations.stream().map(location -> new BlockVector2D(location.getX(), location.getZ())).collect(Collectors.toList());
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper-implementation</artifactId>
|
||||
<version>1.0.4-SNAPSHOT</version>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>worldguardwrapper-implementation-v7</artifactId>
|
||||
|
@ -17,13 +17,14 @@
|
|||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-implementation-interface</artifactId>
|
||||
<version>1.0.4-SNAPSHOT</version>
|
||||
<artifactId>worldguardwrapper-api</artifactId>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
<artifactId>worldguard-legacy</artifactId>
|
||||
<version>7.0.0-20181117.063337-9</version> <!-- Manually set version -->
|
||||
<version>7.0.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
|
@ -34,14 +35,10 @@
|
|||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>commandbook</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency> <!-- Override worldguard-core to manually set version -->
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
<artifactId>worldguard-core</artifactId>
|
||||
<version>7.0.0-20181117.063337-9</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>dummypermscompat</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.sk89q.intake</groupId>
|
||||
<artifactId>intake</artifactId>
|
||||
|
@ -50,10 +47,6 @@
|
|||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>squirrelid</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.flywaydb</groupId>
|
||||
<artifactId>flyway-core</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.khelekore</groupId>
|
||||
<artifactId>prtree</artifactId>
|
||||
|
@ -67,88 +60,20 @@
|
|||
<artifactId>json-simple</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>jsr305</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency> <!-- Override worldedit-bukkit to manually set version -->
|
||||
<groupId>com.sk89q.worldedit</groupId>
|
||||
<artifactId>worldedit-bukkit</artifactId>
|
||||
<version>7.0.0-20181118.055910-28</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>dummypermscompat</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<groupId>org.flywaydb</groupId>
|
||||
<artifactId>flyway-core</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.papermc</groupId>
|
||||
<artifactId>paperlib</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<groupId>org.bstats.bStats-Metrics</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency> <!-- Override worldedit-core to manually set version -->
|
||||
<groupId>com.sk89q.worldedit</groupId>
|
||||
<artifactId>worldedit-core</artifactId>
|
||||
<version>7.0.0-20181118.055910-28</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>de.schlichtherle</groupId>
|
||||
<artifactId>truezip</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>rhino</groupId>
|
||||
<artifactId>js</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>jchronic</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>jsr305</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.thoughtworks.paranamer</groupId>
|
||||
<artifactId>paranamer</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.sk89q.lib</groupId>
|
||||
<artifactId>jlibnoise</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
|
|
@ -7,53 +7,41 @@ 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.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.FlagContext;
|
||||
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
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.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.codemc.worldguardwrapper.flags.AbstractWrappedFlag;
|
||||
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.region.PlayerDomain;
|
||||
import org.codemc.worldguardwrapper.region.WrappedRegion;
|
||||
import org.codemc.worldguardwrapper.selection.CuboidSelection;
|
||||
import org.codemc.worldguardwrapper.selection.PolygonalSelection;
|
||||
import org.codemc.worldguardwrapper.selection.Selection;
|
||||
import org.codemc.worldguardwrapper.implementation.v7.flag.WrappedFlag;
|
||||
import org.codemc.worldguardwrapper.implementation.v7.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;
|
||||
private final FlagRegistry flagRegistry;
|
||||
private final WorldGuardPlugin plugin;
|
||||
|
||||
public WorldGuardImplementation() {
|
||||
core = WorldGuard.getInstance();
|
||||
flagRegistry = core.getFlagRegistry();
|
||||
plugin = WorldGuardPlugin.inst();
|
||||
}
|
||||
private final WorldGuard core = WorldGuard.getInstance();
|
||||
private final FlagRegistry flagRegistry = core.getFlagRegistry();
|
||||
private final WorldGuardPlugin plugin = WorldGuardPlugin.inst();
|
||||
|
||||
private Optional<LocalPlayer> wrapPlayer(Player player) {
|
||||
return Optional.ofNullable(player).map(bukkitPlayer -> plugin.wrapPlayer(player));
|
||||
}
|
||||
|
||||
private Optional<Player> getPlayer(LocalPlayer player) {
|
||||
return Optional.ofNullable(Bukkit.getPlayer(player.getUniqueId()));
|
||||
}
|
||||
|
||||
private Optional<RegionManager> getWorldManager(@NonNull World world) {
|
||||
return Optional.ofNullable(core.getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world)));
|
||||
}
|
||||
|
@ -72,152 +60,6 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
.orElse(null), flag));
|
||||
}
|
||||
|
||||
private Optional<StateFlag.State> queryState(Player player, @NonNull Location location, @NonNull StateFlag... stateFlags) {
|
||||
return getApplicableRegions(location).map(applicableRegions -> applicableRegions.queryState(wrapPlayer(player)
|
||||
.orElse(null), stateFlags));
|
||||
}
|
||||
|
||||
private WrappedRegion toRegion(World world, ProtectedRegion region) {
|
||||
return new WrappedRegion() {
|
||||
|
||||
@Override
|
||||
public Selection getSelection() {
|
||||
if (region instanceof PolygonalSelection) {
|
||||
return new PolygonalSelection() {
|
||||
|
||||
@Override
|
||||
public Set<Location> getPoints() {
|
||||
return region.getPoints().stream()
|
||||
.map(BlockVector2::toBlockVector3)
|
||||
.map(vector -> BukkitAdapter.adapt(world, vector))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumY() {
|
||||
return ((PolygonalSelection) region).getMinimumY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaximumY() {
|
||||
return ((PolygonalSelection) region).getMaximumY();
|
||||
}
|
||||
};
|
||||
}
|
||||
return new CuboidSelection() {
|
||||
|
||||
@Override
|
||||
public Location getMinimumPoint() {
|
||||
return BukkitAdapter.adapt(world, region.getMinimumPoint());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getMaximumPoint() {
|
||||
return BukkitAdapter.adapt(world, region.getMaximumPoint());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return region.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getFlags() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
region.getFlags().forEach((flag, value) -> map.put(flag.getName(), value));
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Object> getFlag(String name) {
|
||||
return Optional.ofNullable(flagRegistry.get(name))
|
||||
.map(region::getFlag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return region.getPriority();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDomain getOwners() {
|
||||
return new PlayerDomain() {
|
||||
@Override
|
||||
public Set<UUID> getPlayers() {
|
||||
return region.getOwners().getUniqueIds();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPlayer(UUID uuid) {
|
||||
region.getOwners().addPlayer(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePlayer(UUID uuid) {
|
||||
region.getOwners().removePlayer(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getGroups() {
|
||||
return region.getOwners().getGroups();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGroup(String name) {
|
||||
region.getOwners().addGroup(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeGroup(String name) {
|
||||
region.getOwners().removeGroup(name);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDomain getMembers() {
|
||||
return new PlayerDomain() {
|
||||
@Override
|
||||
public Set<UUID> getPlayers() {
|
||||
return region.getMembers().getUniqueIds();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPlayer(UUID uuid) {
|
||||
region.getMembers().addPlayer(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePlayer(UUID uuid) {
|
||||
region.getMembers().removePlayer(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getGroups() {
|
||||
return region.getMembers().getGroups();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGroup(String name) {
|
||||
region.getMembers().addGroup(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeGroup(String name) {
|
||||
region.getMembers().removeGroup(name);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Location location) {
|
||||
return region.contains(BukkitAdapter.asBlockVector(location));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaPlugin getWorldGuardPlugin() {
|
||||
return WorldGuardPlugin.inst();
|
||||
|
@ -229,113 +71,94 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Optional<Boolean> queryStateFlag(Player player, @NonNull Location location, @NonNull String flagId) {
|
||||
Flag<?> flag = flagRegistry.get(flagId);
|
||||
if (!(flag instanceof StateFlag)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return queryState(player, location, (StateFlag) flag).map(state -> state == StateFlag.State.ALLOW);
|
||||
public <T> Optional<T> queryFlag(Player player, Location location, IWrappedFlag<T> flag) {
|
||||
Flag<T> wrappedFlag = ((WrappedFlag<T>) flag).getHandle();
|
||||
return queryValue(player, location, wrappedFlag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerStateFlag(@NonNull String flagId, @NonNull Boolean defaultValue) {
|
||||
try {
|
||||
flagRegistry.register(new StateFlag(flagId, defaultValue));
|
||||
return true;
|
||||
} catch (FlagConflictException ignored) {
|
||||
}
|
||||
return false;
|
||||
public Optional<IWrappedFlag<?>> getFlag(String name) {
|
||||
return Optional.ofNullable(flagRegistry.get(name))
|
||||
.map(WrappedFlag::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Optional<T> queryFlag(Player player, Location location, String flagName, Class<T> type) {
|
||||
Flag<?> flag = flagRegistry.get(flagName);
|
||||
Object value = queryValue(player, location, flag).orElse(null);
|
||||
if (type.isInstance(value)) {
|
||||
return Optional.of((T) value);
|
||||
@Override
|
||||
public <T> Optional<IWrappedFlag<T>> registerFlag(String name, Class<T> type, T defaultValue) {
|
||||
final Flag<T> wrappedFlag;
|
||||
if (type.equals(Boolean.class) || type.equals(boolean.class)) {
|
||||
wrappedFlag = (Flag<T>) new BooleanFlag(name);
|
||||
} else if (type.equals(Double.class) || type.equals(double.class)) {
|
||||
wrappedFlag = (Flag<T>) new DoubleFlag(name);
|
||||
} else if (type.equals(Enum.class)) {
|
||||
wrappedFlag = new EnumFlag(name, type);
|
||||
} else if (type.equals(Integer.class) || type.equals(int.class)) {
|
||||
wrappedFlag = (Flag<T>) new IntegerFlag(name);
|
||||
} else if (type.equals(Location.class)) {
|
||||
wrappedFlag = (Flag<T>) new LocationFlag(name);
|
||||
} else if (type.equals(WrappedState.class)) {
|
||||
wrappedFlag = (Flag<T>) new StateFlag(name, defaultValue == WrappedState.ALLOW);
|
||||
} else if (type.equals(String.class)) {
|
||||
wrappedFlag = (Flag<T>) new StringFlag(name, (String) defaultValue);
|
||||
} else if (type.equals(Vector.class)) {
|
||||
wrappedFlag = (Flag<T>) new VectorFlag(name);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported flag type " + type.getName());
|
||||
}
|
||||
try {
|
||||
flagRegistry.register(wrappedFlag);
|
||||
return Optional.of(new WrappedFlag<>(wrappedFlag));
|
||||
} catch (FlagConflictException ignored) {
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> boolean registerFlag(AbstractWrappedFlag<T> flag) {
|
||||
Flag<T> wgFlag = new Flag<T>(flag.getName()) {
|
||||
@Override
|
||||
public T getDefault() {
|
||||
return flag.getDefaultValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object marshal(T o) {
|
||||
return flag.serialize(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T unmarshal(Object o) {
|
||||
return flag.deserialize(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T parseInput(FlagContext context) throws InvalidFlagFormat {
|
||||
return flag.parse(getPlayer(context.getPlayerSender()).orElse(null), context.getUserInput());
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
flagRegistry.register(wgFlag);
|
||||
return true;
|
||||
} catch (FlagConflictException ignored) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<WrappedRegion> getRegion(World world, String id) {
|
||||
public Optional<IWrappedRegion> getRegion(World world, String id) {
|
||||
return getWorldManager(world)
|
||||
.map(regionManager -> regionManager.getRegion(id))
|
||||
.map(region -> toRegion(world, region));
|
||||
.map(region -> new WrappedRegion(world, region));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, WrappedRegion> getRegions(World world) {
|
||||
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, WrappedRegion> map = new HashMap<>();
|
||||
regions.forEach((name, region) -> map.put(name, toRegion(world, region)));
|
||||
Map<String, IWrappedRegion> map = new HashMap<>();
|
||||
regions.forEach((name, region) -> map.put(name, new WrappedRegion(world, region)));
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<WrappedRegion> getRegions(Location location) {
|
||||
public Set<IWrappedRegion> getRegions(Location location) {
|
||||
ApplicableRegionSet regionSet = getApplicableRegions(location).orElse(null);
|
||||
if (regionSet == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
return regionSet.getRegions().stream()
|
||||
.map(region -> toRegion(location.getWorld(), region))
|
||||
.map(region -> new WrappedRegion(location.getWorld(), region))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<WrappedRegion> getRegions(Location minimum, Location maximum) {
|
||||
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 -> toRegion(minimum.getWorld(), region))
|
||||
.map(region -> new WrappedRegion(minimum.getWorld(), region))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<WrappedRegion> addRegion(String id, List<Location> points, int minY, int maxY) {
|
||||
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) {
|
||||
|
@ -352,16 +175,16 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
Optional<RegionManager> manager = getWorldManager(world);
|
||||
if (manager.isPresent()) {
|
||||
manager.get().addRegion(region);
|
||||
return Optional.of(toRegion(world, region));
|
||||
return Optional.of(new WrappedRegion(world, region));
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Set<WrappedRegion>> removeRegion(World world, String id) {
|
||||
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 -> toRegion(world, region)).collect(Collectors.toSet()));
|
||||
.map(region -> new WrappedRegion(world, region)).collect(Collectors.toSet()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.codemc.worldguardwrapper.implementation.v7;
|
||||
package org.codemc.worldguardwrapper.implementation.v7.event;
|
||||
|
||||
import com.sk89q.worldguard.bukkit.event.block.UseBlockEvent;
|
||||
import com.sk89q.worldguard.bukkit.event.entity.DamageEntityEvent;
|
||||
|
@ -11,7 +11,7 @@ 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.AbstractWrappedEvent;
|
||||
import org.codemc.worldguardwrapper.event.*;
|
||||
|
||||
@NoArgsConstructor
|
||||
public class EventListener implements Listener {
|
||||
|
@ -24,7 +24,7 @@ public class EventListener implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
AbstractWrappedEvent event = new org.codemc.worldguardwrapper.event.UseBlockEvent(
|
||||
AbstractWrappedEvent event = new WrappedUseBlockEvent(
|
||||
worldGuardEvent.getOriginalEvent(),
|
||||
player, worldGuardEvent.getWorld(),
|
||||
worldGuardEvent.getBlocks(),
|
||||
|
@ -46,7 +46,7 @@ public class EventListener implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
AbstractWrappedEvent event = new org.codemc.worldguardwrapper.event.UseEntityEvent(
|
||||
AbstractWrappedEvent event = new WrappedUseEntityEvent(
|
||||
worldGuardEvent.getOriginalEvent(),
|
||||
player,
|
||||
worldGuardEvent.getTarget(),
|
||||
|
@ -68,7 +68,7 @@ public class EventListener implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
AbstractWrappedEvent event = new org.codemc.worldguardwrapper.event.DamageEntityEvent(
|
||||
AbstractWrappedEvent event = new WrappedDamageEntityEvent(
|
||||
worldGuardEvent.getOriginalEvent(),
|
||||
player,
|
||||
worldGuardEvent.getTarget(),
|
||||
|
@ -84,7 +84,7 @@ public class EventListener implements Listener {
|
|||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onDisallowedPVP(DisallowedPVPEvent worldGuardEvent) {
|
||||
AbstractWrappedEvent event = new org.codemc.worldguardwrapper.event.DisallowedPVPEvent(
|
||||
AbstractWrappedEvent event = new WrappedDisallowedPVPEvent(
|
||||
worldGuardEvent.getAttacker(),
|
||||
worldGuardEvent.getDefender(),
|
||||
worldGuardEvent.getCause());
|
|
@ -0,0 +1,26 @@
|
|||
package org.codemc.worldguardwrapper.implementation.v7.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 class WrappedFlag<T> implements IWrappedFlag<T> {
|
||||
|
||||
private final Flag<T> handle;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return handle.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<T> getDefaultValue() {
|
||||
return Optional.ofNullable(handle.getDefault());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,174 @@
|
|||
package org.codemc.worldguardwrapper.implementation.v7.region;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
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.v7.flag.WrappedFlag;
|
||||
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.*;
|
||||
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(BlockVector2::toBlockVector3)
|
||||
.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) {
|
||||
Flag wrappedFlag = ((WrappedFlag) flag).getHandle();
|
||||
return Optional.ofNullable(handle.getFlag(wrappedFlag))
|
||||
.map(value -> (T) value);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> void setFlag(IWrappedFlag<T> flag, T value) {
|
||||
Flag wrappedFlag = ((WrappedFlag) flag).getHandle();
|
||||
handle.setFlag(wrappedFlag, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<IWrappedFlag<?>, Object> getFlags() {
|
||||
Map<IWrappedFlag<?>, Object> map = new HashMap<>();
|
||||
handle.getFlags().forEach((flag, value) -> map.put(new WrappedFlag<>(flag), value));
|
||||
return map;
|
||||
}
|
||||
|
||||
@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(BukkitAdapter.asBlockVector(location));
|
||||
}
|
||||
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper-parent</artifactId>
|
||||
<version>1.0.4-SNAPSHOT</version>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>worldguardwrapper</artifactId>
|
||||
|
@ -15,17 +15,22 @@
|
|||
<name>WorldGuardWrapper-Library</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-api</artifactId>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-implementation-v6</artifactId>
|
||||
<version>1.0.4-SNAPSHOT</version>
|
||||
<optional>true</optional>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-implementation-v7</artifactId>
|
||||
<version>1.0.4-SNAPSHOT</version>
|
||||
<optional>true</optional>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -27,13 +27,20 @@ public class WorldGuardWrapper implements IWorldGuardImplementation {
|
|||
private Listener eventListener;
|
||||
|
||||
private WorldGuardWrapper() {
|
||||
String version;
|
||||
try {
|
||||
Class.forName("com.sk89q.worldguard.WorldGuard");
|
||||
delegate = new org.codemc.worldguardwrapper.implementation.v7.WorldGuardImplementation();
|
||||
eventListener = new org.codemc.worldguardwrapper.implementation.v7.EventListener();
|
||||
version = "v7";
|
||||
} catch (ClassNotFoundException e) {
|
||||
delegate = new org.codemc.worldguardwrapper.implementation.v6.WorldGuardImplementation();
|
||||
eventListener = new org.codemc.worldguardwrapper.implementation.v6.EventListener();
|
||||
version = "v6";
|
||||
}
|
||||
try {
|
||||
delegate = (IWorldGuardImplementation) Class.forName("org.codemc.worldguardwrapper.implementation."
|
||||
+ version + ".WorldGuardImplementation").newInstance();
|
||||
eventListener = (Listener) Class.forName("new org.codemc.worldguardwrapper.implementation."
|
||||
+ version + ".event.EventListener").newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
|
||||
throw new RuntimeException("Unable to initialize WorldGuard implementation " + version, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
7
pom.xml
7
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper-parent</artifactId>
|
||||
<version>1.0.4-SNAPSHOT</version>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
|
@ -149,10 +149,7 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<configuration>
|
||||
<minimizeJar>false</minimizeJar>
|
||||
</configuration>
|
||||
<version>3.2.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
|
Loading…
Reference in New Issue
Block a user