mirror of
https://github.com/CodeMC/WorldGuardWrapper.git
synced 2025-01-18 04:02:38 +01:00
Bump version, enhance project structure, minor fixes
This commit is contained in:
parent
adc81ed1d6
commit
60d23d0364
31
api/pom.xml
31
api/pom.xml
|
@ -7,37 +7,10 @@
|
|||
<parent>
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper-parent</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>worldguardwrapper</artifactId>
|
||||
<artifactId>worldguardwrapper-api</artifactId>
|
||||
|
||||
<name>WorldGuardWrapper-API</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-implementation-aggregated</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>pom</type>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
package org.codemc.worldguardwrapper.implementation;
|
||||
package org.codemc.worldguardwrapper.event;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
public abstract class AbstractWrappedEvent extends Event implements Cancellable {
|
||||
|
||||
private Result result = Result.DEFAULT;
|
||||
|
||||
@Override
|
||||
|
@ -18,11 +19,22 @@ public abstract class AbstractWrappedEvent extends Event implements Cancellable
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the event result.
|
||||
*
|
||||
* @param result the new event result
|
||||
*/
|
||||
public void setResult(Result result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current event result.
|
||||
*
|
||||
* @return the event result
|
||||
*/
|
||||
public Result getResult() {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +1,15 @@
|
|||
package org.codemc.worldguardwrapper.event;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.codemc.worldguardwrapper.implementation.AbstractWrappedEvent;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class DamageEntityEvent extends AbstractWrappedEvent {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
@ -29,5 +27,4 @@ public class DamageEntityEvent extends AbstractWrappedEvent {
|
|||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,18 @@
|
|||
package org.codemc.worldguardwrapper.event;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.codemc.worldguardwrapper.implementation.AbstractWrappedEvent;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import java.util.List;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class UseBlockEvent extends AbstractWrappedEvent {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
@ -33,5 +31,5 @@ public class UseBlockEvent extends AbstractWrappedEvent {
|
|||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
package org.codemc.worldguardwrapper.event;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.codemc.worldguardwrapper.implementation.AbstractWrappedEvent;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class UseEntityEvent extends AbstractWrappedEvent {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
@ -29,5 +27,5 @@ public class UseEntityEvent extends AbstractWrappedEvent {
|
|||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
package org.codemc.worldguardwrapper.implementation;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
package org.codemc.worldguardwrapper.flags;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public abstract class AbstractFlag<T> {
|
||||
private @NonNull String name;
|
||||
private @NonNull Class<T> type;
|
||||
@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() {
|
||||
|
@ -24,7 +25,7 @@ public abstract class AbstractFlag<T> {
|
|||
|
||||
/**
|
||||
* Get the type of this flag's value.
|
||||
*
|
||||
*
|
||||
* @return The type
|
||||
*/
|
||||
public Class<T> getType() {
|
||||
|
@ -33,7 +34,7 @@ public abstract class AbstractFlag<T> {
|
|||
|
||||
/**
|
||||
* Get the default value of this flag.
|
||||
*
|
||||
*
|
||||
* @return The default value (may be {@code null})
|
||||
*/
|
||||
public T getDefaultValue() {
|
||||
|
@ -43,7 +44,7 @@ public abstract class AbstractFlag<T> {
|
|||
/**
|
||||
* Convert the value stored in this flag into a type that can be
|
||||
* serialized into YAML.
|
||||
*
|
||||
*
|
||||
* @param value The value
|
||||
* @return The serialized type
|
||||
*/
|
||||
|
@ -52,7 +53,7 @@ public abstract class AbstractFlag<T> {
|
|||
/**
|
||||
* 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
|
||||
*/
|
||||
|
@ -60,11 +61,11 @@ public abstract class AbstractFlag<T> {
|
|||
|
||||
/**
|
||||
* Parse a given input to force it to a type compatible with the flag.
|
||||
*
|
||||
* @param player Player who entered the string.
|
||||
*
|
||||
* @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,12 +1,11 @@
|
|||
package org.codemc.worldguardwrapper.flags;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.codemc.worldguardwrapper.implementation.AbstractFlag;
|
||||
|
||||
/**
|
||||
* A flag that stores a boolean.
|
||||
*/
|
||||
public class BooleanFlag extends AbstractFlag<Boolean> {
|
||||
public class BooleanFlag extends AbstractWrappedFlag<Boolean> {
|
||||
|
||||
public BooleanFlag(String name) {
|
||||
this(name, false);
|
||||
|
@ -27,7 +26,7 @@ public class BooleanFlag extends AbstractFlag<Boolean> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Boolean parse(Player player, String userInput) {
|
||||
public Boolean parse(Player player, String userInput) {
|
||||
if (userInput.equalsIgnoreCase("true") || userInput.equalsIgnoreCase("yes")
|
||||
|| userInput.equalsIgnoreCase("on")
|
||||
|| userInput.equalsIgnoreCase("1")) {
|
||||
|
@ -41,4 +40,4 @@ public class BooleanFlag extends AbstractFlag<Boolean> {
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package org.codemc.worldguardwrapper.flags;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.codemc.worldguardwrapper.implementation.AbstractFlag;
|
||||
|
||||
/**
|
||||
* A flag that stores a double.
|
||||
*/
|
||||
public class DoubleFlag extends AbstractFlag<Double> {
|
||||
public class DoubleFlag extends AbstractWrappedFlag<Double> {
|
||||
|
||||
public DoubleFlag(String name) {
|
||||
this(name, 0d);
|
||||
|
@ -35,4 +34,4 @@ public class DoubleFlag extends AbstractFlag<Double> {
|
|||
return Double.parseDouble(userInput);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
package org.codemc.worldguardwrapper.flags;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.codemc.worldguardwrapper.implementation.AbstractFlag;
|
||||
|
||||
/**
|
||||
* A flag that stores an enum value.
|
||||
*/
|
||||
public class EnumFlag<T extends Enum<T>> extends AbstractFlag<T> {
|
||||
|
||||
private Class<T> enumClass;
|
||||
public class EnumFlag<T extends Enum<T>> extends AbstractWrappedFlag<T> {
|
||||
|
||||
public EnumFlag(String name, Class<T> enumClass) {
|
||||
this(name, enumClass, null);
|
||||
|
@ -20,11 +17,12 @@ public class EnumFlag<T extends Enum<T>> extends AbstractFlag<T> {
|
|||
|
||||
/**
|
||||
* Get the enum class.
|
||||
*
|
||||
* TODO: really needed? we already have getType() -Gab
|
||||
*
|
||||
* @return The enum class
|
||||
*/
|
||||
public Class<T> getEnumClass() {
|
||||
return enumClass;
|
||||
return getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -35,7 +33,7 @@ public class EnumFlag<T extends Enum<T>> extends AbstractFlag<T> {
|
|||
@Override
|
||||
public T deserialize(Object serialized) {
|
||||
if (serialized instanceof String) {
|
||||
return Enum.valueOf(enumClass, (String) serialized);
|
||||
return Enum.valueOf(getEnumClass(), (String) serialized);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -43,7 +41,7 @@ public class EnumFlag<T extends Enum<T>> extends AbstractFlag<T> {
|
|||
|
||||
@Override
|
||||
public T parse(Player player, String userInput) {
|
||||
return Enum.valueOf(enumClass, userInput);
|
||||
return Enum.valueOf(getEnumClass(), userInput);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package org.codemc.worldguardwrapper.flags;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.codemc.worldguardwrapper.implementation.AbstractFlag;
|
||||
|
||||
/**
|
||||
* A flag that stores an integer.
|
||||
*/
|
||||
public class IntegerFlag extends AbstractFlag<Integer> {
|
||||
public class IntegerFlag extends AbstractWrappedFlag<Integer> {
|
||||
|
||||
public IntegerFlag(String name) {
|
||||
this(name, 0);
|
||||
|
@ -35,4 +34,4 @@ public class IntegerFlag extends AbstractFlag<Integer> {
|
|||
return Integer.parseInt(userInput);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
package org.codemc.worldguardwrapper.flags;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.codemc.worldguardwrapper.implementation.AbstractFlag;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A flag that stores a bukkit location.
|
||||
*/
|
||||
public class LocationFlag extends AbstractFlag<Location> {
|
||||
public class LocationFlag extends AbstractWrappedFlag<Location> {
|
||||
|
||||
public LocationFlag(String name) {
|
||||
this(name, null);
|
||||
|
@ -43,22 +42,22 @@ public class LocationFlag extends AbstractFlag<Location> {
|
|||
|
||||
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;
|
||||
|
||||
|
@ -97,5 +96,5 @@ public class LocationFlag extends AbstractFlag<Location> {
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,36 +1,32 @@
|
|||
package org.codemc.worldguardwrapper.flags;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.codemc.worldguardwrapper.implementation.AbstractFlag;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* A flag that stores a set of values of the sub flag's type.
|
||||
*/
|
||||
public class SetFlag<T> extends AbstractFlag<Set<T>> {
|
||||
public class SetFlag<T> extends AbstractWrappedFlag<Set<T>> {
|
||||
|
||||
private AbstractFlag<T> subFlag;
|
||||
private AbstractWrappedFlag<T> subFlag;
|
||||
|
||||
public SetFlag(String name, AbstractFlag<T> subFlag) {
|
||||
public SetFlag(String name, AbstractWrappedFlag<T> subFlag) {
|
||||
this(name, new HashSet<>(), subFlag);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public SetFlag(String name, Set<T> defaultValue, AbstractFlag<T> subFlag) {
|
||||
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 AbstractFlag<T> getSubType() {
|
||||
public AbstractWrappedFlag<T> getSubType() {
|
||||
return subFlag;
|
||||
}
|
||||
|
||||
|
@ -77,5 +73,5 @@ public class SetFlag<T> extends AbstractFlag<Set<T>> {
|
|||
return items;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package org.codemc.worldguardwrapper.flags;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.codemc.worldguardwrapper.implementation.AbstractFlag;
|
||||
|
||||
/**
|
||||
* A flag that stores a string.
|
||||
*/
|
||||
public class StringFlag extends AbstractFlag<String> {
|
||||
public class StringFlag extends AbstractWrappedFlag<String> {
|
||||
|
||||
public StringFlag(String name) {
|
||||
this(name, "");
|
||||
|
@ -31,4 +30,4 @@ public class StringFlag extends AbstractFlag<String> {
|
|||
return userInput;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package org.codemc.worldguardwrapper.region;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface WrappedRegion {
|
||||
|
||||
String getId();
|
||||
|
||||
Optional<Object> getFlag(String name);
|
||||
|
||||
Map<String, Object> getFlags();
|
||||
|
||||
int getPriority();
|
||||
|
||||
}
|
|
@ -1,30 +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.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>worldguardwrapper-implementation-aggregated</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>WorldGuardWrapper-Implementation-Aggregated</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-implementation-v6</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-implementation-v7</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -7,10 +7,18 @@
|
|||
<parent>
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper-implementation</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<version>1.0.1-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.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
package org.codemc.worldguardwrapper.implementation;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public abstract class AbstractRegion {
|
||||
|
||||
private String id;
|
||||
|
||||
public abstract Object getFlag(String name);
|
||||
|
||||
public abstract Map<String, Object> getFlags();
|
||||
|
||||
public abstract int getPriority();
|
||||
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package org.codemc.worldguardwrapper.implementation;
|
||||
|
||||
public abstract class AbstractWorldGuardImplementation implements IWorldGuardImplementation {
|
||||
|
||||
protected AbstractWorldGuardImplementation() {
|
||||
}
|
||||
}
|
|
@ -1,45 +1,46 @@
|
|||
package org.codemc.worldguardwrapper.implementation;
|
||||
|
||||
import lombok.NonNull;
|
||||
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 java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import lombok.NonNull;
|
||||
|
||||
public interface IWorldGuardImplementation {
|
||||
|
||||
/**
|
||||
* Get an instance of the WorldGuardPlugin class
|
||||
*
|
||||
*
|
||||
* @return The WorldGuard plugin
|
||||
*/
|
||||
JavaPlugin getWorldGuardPlugin();
|
||||
|
||||
/**
|
||||
* Get the API version of the loaded WorldGuard plugin (e.g. 6 or 7).
|
||||
*
|
||||
*
|
||||
* @return The API version
|
||||
*/
|
||||
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
|
||||
* @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
|
||||
|
@ -48,7 +49,7 @@ public interface IWorldGuardImplementation {
|
|||
|
||||
/**
|
||||
* 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
|
||||
|
@ -59,32 +60,32 @@ public interface IWorldGuardImplementation {
|
|||
|
||||
/**
|
||||
* Query a flag's value for a given player at a given location.
|
||||
*
|
||||
*
|
||||
* @param player The player
|
||||
* @param location The location
|
||||
* @param flag The flag
|
||||
* @return The flag's value
|
||||
*/
|
||||
default <T> Optional<T> queryFlag(Player player, @NonNull Location location, @NonNull AbstractFlag<T> flag) {
|
||||
default <T> Optional<T> queryFlag(Player player, @NonNull Location location, @NonNull AbstractWrappedFlag<T> flag) {
|
||||
return queryFlag(player, location, flag.getName(), flag.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a flag to WorldGuard's flag registry.
|
||||
*
|
||||
*
|
||||
* @param flag The flag to register
|
||||
* @return Whether the flag has been registered
|
||||
*/
|
||||
<T> boolean registerFlag(@NonNull AbstractFlag<T> flag);
|
||||
<T> boolean registerFlag(@NonNull AbstractWrappedFlag<T> flag);
|
||||
|
||||
/**
|
||||
* Get a region by its ID.
|
||||
*
|
||||
*
|
||||
* @param world The world
|
||||
* @param id ID of the region
|
||||
* @param id ID of the region
|
||||
* @return The region
|
||||
*/
|
||||
Optional<AbstractRegion> getRegion(World world, String id);
|
||||
Optional<WrappedRegion> getRegion(World world, String id);
|
||||
|
||||
/**
|
||||
* Get an unmodifiable map of regions containing the state of the
|
||||
|
@ -96,13 +97,14 @@ public interface IWorldGuardImplementation {
|
|||
* @param world The world
|
||||
* @return A map of regions
|
||||
*/
|
||||
Map<String, AbstractRegion> getRegions(World world);
|
||||
Map<String, WrappedRegion> getRegions(World world);
|
||||
|
||||
/**
|
||||
* Get a set of regions at the given location.
|
||||
*
|
||||
*
|
||||
* @param location The location
|
||||
* @return A set of regions
|
||||
*/
|
||||
Set<AbstractRegion> getRegions(Location location);
|
||||
Set<WrappedRegion> getRegions(Location location);
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper-parent</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>worldguardwrapper-implementation</artifactId>
|
||||
|
@ -17,7 +17,6 @@
|
|||
<module>interface</module>
|
||||
<module>v6</module>
|
||||
<module>v7</module>
|
||||
<module>aggregated</module>
|
||||
</modules>
|
||||
|
||||
<name>WorldGuardWrapper-Implementation</name>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper-implementation</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>worldguardwrapper-implementation-v6</artifactId>
|
||||
|
@ -18,7 +18,7 @@
|
|||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-implementation-interface</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
|
|
|
@ -1,88 +1,67 @@
|
|||
package org.codemc.worldguardwrapper.implementation.v6;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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 lombok.NoArgsConstructor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.codemc.worldguardwrapper.implementation.AbstractWrappedEvent;
|
||||
import org.codemc.worldguardwrapper.event.AbstractWrappedEvent;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class EventListener implements Listener {
|
||||
|
||||
private Class<? extends AbstractWrappedEvent> useBlockEventClass;
|
||||
private Class<? extends AbstractWrappedEvent> useEntityEventClass;
|
||||
private Class<? extends AbstractWrappedEvent> damageEntityEventClass;
|
||||
|
||||
@EventHandler
|
||||
public void onUseBlock(UseBlockEvent e) {
|
||||
Player player = e.getCause().getFirstPlayer();
|
||||
public void onUseBlock(UseBlockEvent worldGuardEvent) {
|
||||
Player player = worldGuardEvent.getCause().getFirstPlayer();
|
||||
if (player == null) {
|
||||
// Only forward player events for now
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
AbstractWrappedEvent event = useBlockEventClass
|
||||
.getConstructor(Event.class, Player.class, World.class, List.class, Material.class)
|
||||
.newInstance(e.getOriginalEvent(), player, e.getWorld(), e.getBlocks(), e.getEffectiveMaterial());
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
e.setResult(event.getResult());
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
ex.printStackTrace(); // TODO: Handle differently
|
||||
}
|
||||
AbstractWrappedEvent event = new org.codemc.worldguardwrapper.event.UseBlockEvent(
|
||||
worldGuardEvent.getOriginalEvent(),
|
||||
player, worldGuardEvent.getWorld(),
|
||||
worldGuardEvent.getBlocks(),
|
||||
worldGuardEvent.getEffectiveMaterial());
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
worldGuardEvent.setResult(event.getResult());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onUseEntity(UseEntityEvent e) {
|
||||
Player player = e.getCause().getFirstPlayer();
|
||||
public void onUseEntity(UseEntityEvent worldGuardEvent) {
|
||||
Player player = worldGuardEvent.getCause().getFirstPlayer();
|
||||
if (player == null) {
|
||||
// Only forward player events for now
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
AbstractWrappedEvent event = useEntityEventClass
|
||||
.getConstructor(Event.class, Player.class, Location.class, Entity.class)
|
||||
.newInstance(e.getOriginalEvent(), player, e.getTarget(), e.getEntity());
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
e.setResult(event.getResult());
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
ex.printStackTrace(); // TODO: Handle differently
|
||||
}
|
||||
AbstractWrappedEvent event = new org.codemc.worldguardwrapper.event.UseEntityEvent(
|
||||
worldGuardEvent.getOriginalEvent(),
|
||||
player,
|
||||
worldGuardEvent.getTarget(),
|
||||
worldGuardEvent.getEntity());
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
worldGuardEvent.setResult(event.getResult());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamageEntity(DamageEntityEvent e) {
|
||||
Player player = e.getCause().getFirstPlayer();
|
||||
public void onDamageEntity(DamageEntityEvent worldGuardEvent) {
|
||||
Player player = worldGuardEvent.getCause().getFirstPlayer();
|
||||
if (player == null) {
|
||||
// Only forward player events for now
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
AbstractWrappedEvent event = damageEntityEventClass
|
||||
.getConstructor(Event.class, Player.class, Location.class, Entity.class)
|
||||
.newInstance(e.getOriginalEvent(), player, e.getTarget(), e.getEntity());
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
e.setResult(event.getResult());
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
ex.printStackTrace(); // TODO: Handle differently
|
||||
}
|
||||
AbstractWrappedEvent event = new org.codemc.worldguardwrapper.event.DamageEntityEvent(
|
||||
worldGuardEvent.getOriginalEvent(),
|
||||
player,
|
||||
worldGuardEvent.getTarget(),
|
||||
worldGuardEvent.getEntity());
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
worldGuardEvent.setResult(event.getResult());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
package org.codemc.worldguardwrapper.implementation.v6;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
|
@ -17,26 +11,23 @@ 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.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.codemc.worldguardwrapper.implementation.AbstractFlag;
|
||||
import org.codemc.worldguardwrapper.implementation.AbstractRegion;
|
||||
import org.codemc.worldguardwrapper.implementation.AbstractWorldGuardImplementation;
|
||||
import org.codemc.worldguardwrapper.flags.AbstractWrappedFlag;
|
||||
import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation;
|
||||
import org.codemc.worldguardwrapper.region.WrappedRegion;
|
||||
|
||||
import lombok.NonNull;
|
||||
import java.util.*;
|
||||
|
||||
public class WorldGuardImplementation extends AbstractWorldGuardImplementation {
|
||||
@NoArgsConstructor
|
||||
public class WorldGuardImplementation implements IWorldGuardImplementation {
|
||||
|
||||
private final WorldGuardPlugin plugin;
|
||||
private final FlagRegistry flagRegistry;
|
||||
|
||||
public WorldGuardImplementation() {
|
||||
plugin = WorldGuardPlugin.inst();
|
||||
flagRegistry = plugin.getFlagRegistry();
|
||||
}
|
||||
private final WorldGuardPlugin plugin = WorldGuardPlugin.inst();
|
||||
private final FlagRegistry flagRegistry = plugin.getFlagRegistry();
|
||||
|
||||
private Optional<LocalPlayer> wrapPlayer(Player player) {
|
||||
return Optional.ofNullable(player).map(bukkitPlayer -> plugin.wrapPlayer(player));
|
||||
|
@ -58,8 +49,14 @@ public class WorldGuardImplementation extends AbstractWorldGuardImplementation {
|
|||
return getApplicableRegions(location).map(applicableRegions -> applicableRegions.queryState(wrapPlayer(player).orElse(null), stateFlags));
|
||||
}
|
||||
|
||||
private AbstractRegion toRegion(ProtectedRegion region) {
|
||||
return new AbstractRegion(region.getId()) {
|
||||
private WrappedRegion toRegion(ProtectedRegion region) {
|
||||
return new WrappedRegion() {
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return region.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getFlags() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
|
@ -68,14 +65,16 @@ public class WorldGuardImplementation extends AbstractWorldGuardImplementation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object getFlag(String name) {
|
||||
return region.getFlag(flagRegistry.get(name));
|
||||
public Optional<Object> getFlag(String name) {
|
||||
return Optional.ofNullable(flagRegistry.get(name))
|
||||
.map(region::getFlag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return region.getPriority();
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -120,7 +119,7 @@ public class WorldGuardImplementation extends AbstractWorldGuardImplementation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> boolean registerFlag(AbstractFlag<T> flag) {
|
||||
public <T> boolean registerFlag(AbstractWrappedFlag<T> flag) {
|
||||
Flag<T> wgFlag = new Flag<T>(flag.getName()) {
|
||||
@Override
|
||||
public T getDefault() {
|
||||
|
@ -152,25 +151,25 @@ public class WorldGuardImplementation extends AbstractWorldGuardImplementation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Optional<AbstractRegion> getRegion(World world, String id) {
|
||||
public Optional<WrappedRegion> getRegion(World world, String id) {
|
||||
return getWorldManager(world).map(regionManager -> toRegion(regionManager.getRegion(id)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, AbstractRegion> getRegions(World world) {
|
||||
public Map<String, WrappedRegion> getRegions(World world) {
|
||||
RegionManager regionManager = plugin.getRegionManager(world);
|
||||
Map<String, ProtectedRegion> regions = regionManager.getRegions();
|
||||
|
||||
Map<String, AbstractRegion> map = new HashMap<>();
|
||||
Map<String, WrappedRegion> map = new HashMap<>();
|
||||
regions.forEach((name, region) -> map.put(name, toRegion(region)));
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<AbstractRegion> getRegions(Location location) {
|
||||
public Set<WrappedRegion> getRegions(Location location) {
|
||||
ApplicableRegionSet regionSet = getApplicableRegions(location).orElse(null);
|
||||
Set<AbstractRegion> set = new HashSet<>();
|
||||
Set<WrappedRegion> set = new HashSet<>();
|
||||
|
||||
if (regionSet == null) {
|
||||
return set;
|
||||
|
@ -179,4 +178,5 @@ public class WorldGuardImplementation extends AbstractWorldGuardImplementation {
|
|||
regionSet.forEach(region -> set.add(toRegion(region)));
|
||||
return set;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper-implementation</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>worldguardwrapper-implementation-v7</artifactId>
|
||||
|
@ -18,7 +18,7 @@
|
|||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-implementation-interface</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
|
|
|
@ -1,88 +1,67 @@
|
|||
package org.codemc.worldguardwrapper.implementation.v7;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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 lombok.NoArgsConstructor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.codemc.worldguardwrapper.implementation.AbstractWrappedEvent;
|
||||
import org.codemc.worldguardwrapper.event.AbstractWrappedEvent;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class EventListener implements Listener {
|
||||
|
||||
private Class<? extends AbstractWrappedEvent> useBlockEventClass;
|
||||
private Class<? extends AbstractWrappedEvent> useEntityEventClass;
|
||||
private Class<? extends AbstractWrappedEvent> damageEntityEventClass;
|
||||
|
||||
@EventHandler
|
||||
public void onUseBlock(UseBlockEvent e) {
|
||||
Player player = e.getCause().getFirstPlayer();
|
||||
public void onUseBlock(UseBlockEvent worldGuardEvent) {
|
||||
Player player = worldGuardEvent.getCause().getFirstPlayer();
|
||||
if (player == null) {
|
||||
// Only forward player events for now
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
AbstractWrappedEvent event = useBlockEventClass
|
||||
.getConstructor(Event.class, Player.class, World.class, List.class, Material.class)
|
||||
.newInstance(e.getOriginalEvent(), player, e.getWorld(), e.getBlocks(), e.getEffectiveMaterial());
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
e.setResult(event.getResult());
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
ex.printStackTrace(); // TODO: Handle differently
|
||||
}
|
||||
AbstractWrappedEvent event = new org.codemc.worldguardwrapper.event.UseBlockEvent(
|
||||
worldGuardEvent.getOriginalEvent(),
|
||||
player, worldGuardEvent.getWorld(),
|
||||
worldGuardEvent.getBlocks(),
|
||||
worldGuardEvent.getEffectiveMaterial());
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
worldGuardEvent.setResult(event.getResult());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onUseEntity(UseEntityEvent e) {
|
||||
Player player = e.getCause().getFirstPlayer();
|
||||
public void onUseEntity(UseEntityEvent worldGuardEvent) {
|
||||
Player player = worldGuardEvent.getCause().getFirstPlayer();
|
||||
if (player == null) {
|
||||
// Only forward player events for now
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
AbstractWrappedEvent event = useEntityEventClass
|
||||
.getConstructor(Event.class, Player.class, Location.class, Entity.class)
|
||||
.newInstance(e.getOriginalEvent(), player, e.getTarget(), e.getEntity());
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
e.setResult(event.getResult());
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
ex.printStackTrace(); // TODO: Handle differently
|
||||
}
|
||||
AbstractWrappedEvent event = new org.codemc.worldguardwrapper.event.UseEntityEvent(
|
||||
worldGuardEvent.getOriginalEvent(),
|
||||
player,
|
||||
worldGuardEvent.getTarget(),
|
||||
worldGuardEvent.getEntity());
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
worldGuardEvent.setResult(event.getResult());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamageEntity(DamageEntityEvent e) {
|
||||
Player player = e.getCause().getFirstPlayer();
|
||||
public void onDamageEntity(DamageEntityEvent worldGuardEvent) {
|
||||
Player player = worldGuardEvent.getCause().getFirstPlayer();
|
||||
if (player == null) {
|
||||
// Only forward player events for now
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
AbstractWrappedEvent event = damageEntityEventClass
|
||||
.getConstructor(Event.class, Player.class, Location.class, Entity.class)
|
||||
.newInstance(e.getOriginalEvent(), player, e.getTarget(), e.getEntity());
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
e.setResult(event.getResult());
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
ex.printStackTrace(); // TODO: Handle differently
|
||||
}
|
||||
AbstractWrappedEvent event = new org.codemc.worldguardwrapper.event.DamageEntityEvent(
|
||||
worldGuardEvent.getOriginalEvent(),
|
||||
player,
|
||||
worldGuardEvent.getTarget(),
|
||||
worldGuardEvent.getEntity());
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
worldGuardEvent.setResult(event.getResult());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
package org.codemc.worldguardwrapper.implementation.v7;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
|
@ -20,19 +14,20 @@ 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.ProtectedRegion;
|
||||
|
||||
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.implementation.AbstractFlag;
|
||||
import org.codemc.worldguardwrapper.implementation.AbstractRegion;
|
||||
import org.codemc.worldguardwrapper.implementation.AbstractWorldGuardImplementation;
|
||||
import org.codemc.worldguardwrapper.flags.AbstractWrappedFlag;
|
||||
import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation;
|
||||
import org.codemc.worldguardwrapper.region.WrappedRegion;
|
||||
|
||||
import lombok.NonNull;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class WorldGuardImplementation extends AbstractWorldGuardImplementation {
|
||||
public class WorldGuardImplementation implements IWorldGuardImplementation {
|
||||
|
||||
private final WorldGuard core;
|
||||
private final FlagRegistry flagRegistry;
|
||||
|
@ -68,24 +63,32 @@ public class WorldGuardImplementation extends AbstractWorldGuardImplementation {
|
|||
return getApplicableRegions(location).map(applicableRegions -> applicableRegions.queryState(wrapPlayer(player).orElse(null), stateFlags));
|
||||
}
|
||||
|
||||
private AbstractRegion toRegion(ProtectedRegion region) {
|
||||
return new AbstractRegion(region.getId()) {
|
||||
private WrappedRegion toRegion(ProtectedRegion region) {
|
||||
return new WrappedRegion() {
|
||||
|
||||
@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 Object getFlag(String name) {
|
||||
return region.getFlag(flagRegistry.get(name));
|
||||
public Optional<Object> getFlag(String name) {
|
||||
return Optional.ofNullable(flagRegistry.get(name))
|
||||
.map(region::getFlag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return region.getPriority();
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -130,7 +133,7 @@ public class WorldGuardImplementation extends AbstractWorldGuardImplementation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> boolean registerFlag(AbstractFlag<T> flag) {
|
||||
public <T> boolean registerFlag(AbstractWrappedFlag<T> flag) {
|
||||
Flag<T> wgFlag = new Flag<T>(flag.getName()) {
|
||||
@Override
|
||||
public T getDefault() {
|
||||
|
@ -149,7 +152,7 @@ public class WorldGuardImplementation extends AbstractWorldGuardImplementation {
|
|||
|
||||
@Override
|
||||
public T parseInput(FlagContext context) throws InvalidFlagFormat {
|
||||
return flag.parse(getPlayer(context.getPlayerSender()).get(), context.getUserInput());
|
||||
return flag.parse(getPlayer(context.getPlayerSender()).orElse(null), context.getUserInput());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -162,31 +165,34 @@ public class WorldGuardImplementation extends AbstractWorldGuardImplementation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Optional<AbstractRegion> getRegion(World world, String id) {
|
||||
return getWorldManager(world).map(regionManager -> toRegion(regionManager.getRegion(id)));
|
||||
public Optional<WrappedRegion> getRegion(World world, String id) {
|
||||
return getWorldManager(world)
|
||||
.map(regionManager -> regionManager.getRegion(id))
|
||||
.map(this::toRegion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, AbstractRegion> getRegions(World world) {
|
||||
public Map<String, WrappedRegion> 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, AbstractRegion> map = new HashMap<>();
|
||||
Map<String, WrappedRegion> map = new HashMap<>();
|
||||
regions.forEach((name, region) -> map.put(name, toRegion(region)));
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<AbstractRegion> getRegions(Location location) {
|
||||
public Set<WrappedRegion> getRegions(Location location) {
|
||||
ApplicableRegionSet regionSet = getApplicableRegions(location).orElse(null);
|
||||
Set<AbstractRegion> set = new HashSet<>();
|
||||
|
||||
if (regionSet == null) {
|
||||
return set;
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
regionSet.forEach(region -> set.add(toRegion(region)));
|
||||
return set;
|
||||
return regionSet.getRegions().stream()
|
||||
.map(this::toRegion)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
|
|
48
library/pom.xml
Normal file
48
library/pom.xml
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?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-parent</artifactId>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>worldguardwrapper</artifactId>
|
||||
|
||||
<name>WorldGuardWrapper-Library</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-implementation-v6</artifactId>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-implementation-v7</artifactId>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -1,19 +1,20 @@
|
|||
package org.codemc.worldguardwrapper;
|
||||
|
||||
import lombok.experimental.Delegate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.codemc.worldguardwrapper.event.DamageEntityEvent;
|
||||
import org.codemc.worldguardwrapper.event.UseBlockEvent;
|
||||
import org.codemc.worldguardwrapper.event.UseEntityEvent;
|
||||
import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation;
|
||||
|
||||
import lombok.experimental.Delegate;
|
||||
|
||||
public class WorldGuardWrapper implements IWorldGuardImplementation {
|
||||
|
||||
private static WorldGuardWrapper instance;
|
||||
|
||||
/**
|
||||
* Returns the wrapper singleton instance.
|
||||
*
|
||||
* @return the wrapper singleton
|
||||
*/
|
||||
public static WorldGuardWrapper getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new WorldGuardWrapper();
|
||||
|
@ -26,24 +27,21 @@ public class WorldGuardWrapper implements IWorldGuardImplementation {
|
|||
private Listener eventListener;
|
||||
|
||||
private WorldGuardWrapper() {
|
||||
// TODO: better way to detect version
|
||||
try {
|
||||
Class.forName("com.sk89q.worldguard.WorldGuard");
|
||||
delegate = new org.codemc.worldguardwrapper.implementation.v7.WorldGuardImplementation();
|
||||
eventListener = new org.codemc.worldguardwrapper.implementation.v7.EventListener(
|
||||
UseBlockEvent.class, UseEntityEvent.class, DamageEntityEvent.class);
|
||||
eventListener = new org.codemc.worldguardwrapper.implementation.v7.EventListener();
|
||||
} catch (ClassNotFoundException e) {
|
||||
delegate = new org.codemc.worldguardwrapper.implementation.v6.WorldGuardImplementation();
|
||||
eventListener = new org.codemc.worldguardwrapper.implementation.v6.EventListener(
|
||||
UseBlockEvent.class, UseEntityEvent.class, DamageEntityEvent.class);
|
||||
eventListener = new org.codemc.worldguardwrapper.implementation.v6.EventListener();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forward WorldGuard event calls to wrapped events to allow listening to them
|
||||
* without having to use WorldGuard's events.
|
||||
*
|
||||
* @param plugin The plugin
|
||||
* without having to use WorldGuard's events. This is optional.
|
||||
*
|
||||
* @param plugin the plugin instance
|
||||
*/
|
||||
public void registerEvents(JavaPlugin plugin) {
|
||||
Bukkit.getPluginManager().registerEvents(eventListener, plugin);
|
3
pom.xml
3
pom.xml
|
@ -6,11 +6,12 @@
|
|||
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper-parent</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>api</module>
|
||||
<module>library</module>
|
||||
<module>implementation</module>
|
||||
</modules>
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user