mirror of
https://github.com/CodeMC/WorldGuardWrapper.git
synced 2025-01-18 04:02:38 +01:00
Initial commit
This commit is contained in:
commit
e5c2270f53
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
# Auto detect text files and perform LF normalization
|
||||||
|
* text=auto
|
68
.gitignore
vendored
Normal file
68
.gitignore
vendored
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
# Java source files
|
||||||
|
*.class
|
||||||
|
MANIFEST.MF
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.ear
|
||||||
|
hs_err_pid*
|
||||||
|
|
||||||
|
# Mac
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
# Intellij
|
||||||
|
*.iml
|
||||||
|
*.java___jb_tmp___
|
||||||
|
.idea/*
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
/out/
|
||||||
|
.idea_modules/
|
||||||
|
atlassian-ide-plugin.xml
|
||||||
|
com_crashlytics_export_strings.xml
|
||||||
|
crashlytics.properties
|
||||||
|
crashlytics-build.properties
|
||||||
|
|
||||||
|
# Eclipse
|
||||||
|
*.pydevproject
|
||||||
|
.metadata
|
||||||
|
.gradle
|
||||||
|
bin/
|
||||||
|
tmp/
|
||||||
|
*.tmp
|
||||||
|
*.bak
|
||||||
|
*.swp
|
||||||
|
*~.nib
|
||||||
|
local.properties
|
||||||
|
.settings/
|
||||||
|
.loadpath
|
||||||
|
.project
|
||||||
|
.externalToolBuilders/
|
||||||
|
*.launch
|
||||||
|
.cproject
|
||||||
|
.classpath
|
||||||
|
.buildpath
|
||||||
|
.target
|
||||||
|
.texlipse
|
||||||
|
|
||||||
|
# Maven
|
||||||
|
target/
|
||||||
|
pom.xml.tag
|
||||||
|
pom.xml.releaseBackup
|
||||||
|
pom.xml.versionsBackup
|
||||||
|
pom.xml.next
|
||||||
|
release.properties
|
||||||
|
dependency-reduced-pom.xml
|
||||||
|
buildNumber.properties
|
||||||
|
|
||||||
|
# NetBeans
|
||||||
|
nbproject/private/
|
||||||
|
build/
|
||||||
|
nbbuild/
|
||||||
|
dist/
|
||||||
|
nbdist/
|
||||||
|
nbactions.xml
|
||||||
|
nb-configuration.xml
|
||||||
|
.nb-gradle/
|
||||||
|
|
||||||
|
# Git
|
||||||
|
!.gitignore
|
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
The MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2010-2018 CodeMC https://github.com/CodeMC/WorldGuardWrapper
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
42
api/pom.xml
Normal file
42
api/pom.xml
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
<?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.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
</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>
|
|
@ -0,0 +1,20 @@
|
||||||
|
package org.codemc.worldguardwrapper;
|
||||||
|
|
||||||
|
import lombok.experimental.Delegate;
|
||||||
|
import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation;
|
||||||
|
|
||||||
|
public class WorldGuardWrapper implements IWorldGuardImplementation {
|
||||||
|
|
||||||
|
@Delegate
|
||||||
|
private IWorldGuardImplementation implementation;
|
||||||
|
|
||||||
|
public WorldGuardWrapper() {
|
||||||
|
// TODO: better way to detect version
|
||||||
|
try {
|
||||||
|
Class.forName("com.sk89q.worldguard.WorldGuard");
|
||||||
|
implementation = new org.codemc.worldguardwrapper.implementation.v7.WorldGuardImplementation();
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
implementation = new org.codemc.worldguardwrapper.implementation.v6.WorldGuardImplementation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
implementation/aggregated/pom.xml
Normal file
30
implementation/aggregated/pom.xml
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
<?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>
|
16
implementation/interface/pom.xml
Normal file
16
implementation/interface/pom.xml
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<?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-interface</artifactId>
|
||||||
|
|
||||||
|
<name>WorldGuardWrapper-Implementation-Interface</name>
|
||||||
|
</project>
|
|
@ -0,0 +1,7 @@
|
||||||
|
package org.codemc.worldguardwrapper.implementation;
|
||||||
|
|
||||||
|
public abstract class AbstractWorldGuardImplementation implements IWorldGuardImplementation {
|
||||||
|
|
||||||
|
protected AbstractWorldGuardImplementation() {
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package org.codemc.worldguardwrapper.implementation;
|
||||||
|
|
||||||
|
import lombok.NonNull;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface IWorldGuardImplementation {
|
||||||
|
|
||||||
|
int getApiVersion();
|
||||||
|
|
||||||
|
// String flag
|
||||||
|
|
||||||
|
Optional<String> queryStringFlag(Player player, @NonNull Location location, @NonNull String flagId);
|
||||||
|
|
||||||
|
boolean registerStringFlag(@NonNull String flagId, @NonNull String defaultValue);
|
||||||
|
|
||||||
|
// State flag
|
||||||
|
|
||||||
|
Optional<Boolean> queryStateFlag(Player player, @NonNull Location location, @NonNull String flagId);
|
||||||
|
|
||||||
|
boolean registerStateFlag(@NonNull String flagId, @NonNull Boolean defaultValue);
|
||||||
|
}
|
35
implementation/pom.xml
Normal file
35
implementation/pom.xml
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<?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.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>worldguardwrapper-implementation</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
<modules>
|
||||||
|
<module>interface</module>
|
||||||
|
<module>v6</module>
|
||||||
|
<module>v7</module>
|
||||||
|
<module>aggregated</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
<name>WorldGuardWrapper-Implementation</name>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>codemc-repo</id>
|
||||||
|
<url>https://repo.codemc.org/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>sk89q-repo</id>
|
||||||
|
<url>http://maven.sk89q.com/repo/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
</project>
|
74
implementation/v6/pom.xml
Normal file
74
implementation/v6/pom.xml
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
<?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-v6</artifactId>
|
||||||
|
|
||||||
|
<name>WorldGuardWrapper-Implementation-V6</name>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>worldguardwrapper-implementation-interface</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.sk89q.worldguard</groupId>
|
||||||
|
<artifactId>worldguard-legacy</artifactId>
|
||||||
|
<version>6.2</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.sk89q.worldedit</groupId>
|
||||||
|
<artifactId>worldedit-core</artifactId>
|
||||||
|
<version>6.1.4-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>de.schlichtherle</groupId>
|
||||||
|
<artifactId>truezip</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>com.google.guava</groupId>
|
||||||
|
<artifactId>guava</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>rhino</groupId>
|
||||||
|
<artifactId>js</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<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>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>com.sk89q.lib</groupId>
|
||||||
|
<artifactId>jlibnoise</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>com.sk89q</groupId>
|
||||||
|
<artifactId>jchronic</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,96 @@
|
||||||
|
package org.codemc.worldguardwrapper.implementation.v6;
|
||||||
|
|
||||||
|
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.StateFlag;
|
||||||
|
import com.sk89q.worldguard.protection.flags.StringFlag;
|
||||||
|
import com.sk89q.worldguard.protection.flags.registry.FlagConflictException;
|
||||||
|
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
|
||||||
|
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||||
|
import lombok.NonNull;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.codemc.worldguardwrapper.implementation.AbstractWorldGuardImplementation;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class WorldGuardImplementation extends AbstractWorldGuardImplementation {
|
||||||
|
|
||||||
|
private final WorldGuardPlugin plugin;
|
||||||
|
private final FlagRegistry flagRegistry;
|
||||||
|
|
||||||
|
public WorldGuardImplementation() {
|
||||||
|
plugin = WorldGuardPlugin.inst();
|
||||||
|
flagRegistry = plugin.getFlagRegistry();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Optional<LocalPlayer> wrapPlayer(Player player) {
|
||||||
|
return Optional.ofNullable(player).map(bukkitPlayer -> plugin.wrapPlayer(player));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Optional<RegionManager> getWorldManager(@NonNull World world) {
|
||||||
|
return Optional.ofNullable(plugin.getRegionManager(world));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Optional<ApplicableRegionSet> getApplicableRegions(@NonNull Location location) {
|
||||||
|
return getWorldManager(location.getWorld()).map(manager -> manager.getApplicableRegions(location));
|
||||||
|
}
|
||||||
|
|
||||||
|
private <V> Optional<V> queryValue(Player player, @NonNull Location location, @NonNull Flag<V> flag) {
|
||||||
|
return getApplicableRegions(location).map(applicableRegions -> applicableRegions.queryValue(wrapPlayer(player).orElse(null), flag));
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getApiVersion() {
|
||||||
|
return 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
// String flag
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<String> queryStringFlag(Player player, @NonNull Location location, @NonNull String flagId) {
|
||||||
|
Flag<?> flag = flagRegistry.get(flagId);
|
||||||
|
if (!(flag instanceof StringFlag)) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
return queryValue(player, location, (StringFlag) flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean registerStringFlag(@NonNull String flagId, @NonNull String defaultValue) {
|
||||||
|
try {
|
||||||
|
flagRegistry.register(new StringFlag(flagId, defaultValue));
|
||||||
|
return true;
|
||||||
|
} catch (FlagConflictException ignored) {
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// State flag
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean registerStateFlag(@NonNull String flagId, @NonNull Boolean defaultValue) {
|
||||||
|
try {
|
||||||
|
flagRegistry.register(new StateFlag(flagId, defaultValue));
|
||||||
|
return true;
|
||||||
|
} catch (FlagConflictException ignored) {
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
104
implementation/v7/pom.xml
Normal file
104
implementation/v7/pom.xml
Normal file
|
@ -0,0 +1,104 @@
|
||||||
|
<?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-v7</artifactId>
|
||||||
|
|
||||||
|
<name>WorldGuardWrapper-Implementation-V7</name>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>worldguardwrapper-implementation-interface</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.sk89q.worldguard</groupId>
|
||||||
|
<artifactId>worldguard-legacy</artifactId>
|
||||||
|
<version>7.0.0-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>bukkit</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>com.sk89q.intake</groupId>
|
||||||
|
<artifactId>intake</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<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>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>com.googlecode.json-simple</groupId>
|
||||||
|
<artifactId>json-simple</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>net.sf.opencsv</groupId>
|
||||||
|
<artifactId>opencsv</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>com.sk89q</groupId>
|
||||||
|
<artifactId>commandbook</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<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>com.sk89q</groupId>
|
||||||
|
<artifactId>dummypermscompat</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,106 @@
|
||||||
|
package org.codemc.worldguardwrapper.implementation.v7;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
|
import com.sk89q.worldguard.LocalPlayer;
|
||||||
|
import com.sk89q.worldguard.WorldGuard;
|
||||||
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
|
import com.sk89q.worldguard.internal.platform.WorldGuardPlatform;
|
||||||
|
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||||
|
import com.sk89q.worldguard.protection.flags.Flag;
|
||||||
|
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||||
|
import com.sk89q.worldguard.protection.flags.StringFlag;
|
||||||
|
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.RegionContainer;
|
||||||
|
import lombok.NonNull;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.codemc.worldguardwrapper.implementation.AbstractWorldGuardImplementation;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class WorldGuardImplementation extends AbstractWorldGuardImplementation {
|
||||||
|
|
||||||
|
private final WorldGuard core;
|
||||||
|
private final FlagRegistry flagRegistry;
|
||||||
|
private final WorldGuardPlatform platform;
|
||||||
|
private final RegionContainer container;
|
||||||
|
private final WorldGuardPlugin plugin;
|
||||||
|
|
||||||
|
public WorldGuardImplementation() {
|
||||||
|
core = WorldGuard.getInstance();
|
||||||
|
flagRegistry = core.getFlagRegistry();
|
||||||
|
platform = core.getPlatform();
|
||||||
|
container = platform.getRegionContainer();
|
||||||
|
plugin = WorldGuardPlugin.inst();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Optional<LocalPlayer> wrapPlayer(Player player) {
|
||||||
|
return Optional.ofNullable(player).map(bukkitPlayer -> plugin.wrapPlayer(player));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Optional<RegionManager> getWorldManager(@NonNull World world) {
|
||||||
|
return Optional.ofNullable(container.get(BukkitAdapter.adapt(world)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Optional<ApplicableRegionSet> getApplicableRegions(@NonNull Location location) {
|
||||||
|
return getWorldManager(location.getWorld()).map(manager -> manager.getApplicableRegions(BukkitAdapter.asVector(location)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private <V> Optional<V> queryValue(Player player, @NonNull Location location, @NonNull Flag<V> flag) {
|
||||||
|
return getApplicableRegions(location).map(applicableRegions -> applicableRegions.queryValue(wrapPlayer(player).orElse(null), flag));
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getApiVersion() {
|
||||||
|
return 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
// String flag
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<String> queryStringFlag(Player player, @NonNull Location location, @NonNull String flagId) {
|
||||||
|
Flag<?> flag = flagRegistry.get(flagId);
|
||||||
|
if (!(flag instanceof StringFlag)) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
return queryValue(player, location, (StringFlag) flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean registerStringFlag(@NonNull String flagId, @NonNull String defaultValue) {
|
||||||
|
try {
|
||||||
|
flagRegistry.register(new StringFlag(flagId, defaultValue));
|
||||||
|
return true;
|
||||||
|
} catch (FlagConflictException ignored) {
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// State flag
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean registerStateFlag(@NonNull String flagId, @NonNull Boolean defaultValue) {
|
||||||
|
try {
|
||||||
|
flagRegistry.register(new StateFlag(flagId, defaultValue));
|
||||||
|
return true;
|
||||||
|
} catch (FlagConflictException ignored) {
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
168
pom.xml
Normal file
168
pom.xml
Normal file
|
@ -0,0 +1,168 @@
|
||||||
|
<?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>
|
||||||
|
|
||||||
|
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||||
|
<artifactId>worldguardwrapper-parent</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
<modules>
|
||||||
|
<module>api</module>
|
||||||
|
<module>implementation</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
<name>WorldGuardWrapper-Parent</name>
|
||||||
|
<description>A wrapper for the WorldGuard API that allows plugins to support both v6 and v7 APIs.</description>
|
||||||
|
<url>https://github.com/CodeMC/WorldGuardWrapper</url>
|
||||||
|
<inceptionYear>2018</inceptionYear>
|
||||||
|
|
||||||
|
<scm>
|
||||||
|
<connection>scm:git:https://github.com/CodeMC/WorldGuardWrapper.git</connection>
|
||||||
|
<developerConnection>scm:git:git@github.com:CodeMC/WorldGuardWrapper.git</developerConnection>
|
||||||
|
<url>https://github.com/CodeMC/WorldGuardWrapper</url>
|
||||||
|
</scm>
|
||||||
|
|
||||||
|
<ciManagement>
|
||||||
|
<system>jenkins</system>
|
||||||
|
<url>http://ci.codemc.org/job/CodeMC/job/HolographicDisplays/</url>
|
||||||
|
</ciManagement>
|
||||||
|
|
||||||
|
<issueManagement>
|
||||||
|
<system>GitHub</system>
|
||||||
|
<url>https://github.com/CodeMC/WorldGuardWrapper/issues</url>
|
||||||
|
</issueManagement>
|
||||||
|
|
||||||
|
<distributionManagement>
|
||||||
|
<snapshotRepository>
|
||||||
|
<id>codemc-snapshots</id>
|
||||||
|
<url>https://repo.codemc.org/repository/maven-snapshots/</url>
|
||||||
|
</snapshotRepository>
|
||||||
|
<repository>
|
||||||
|
<id>codemc-releases</id>
|
||||||
|
<url>https://repo.codemc.org/repository/maven-releases/</url>
|
||||||
|
</repository>
|
||||||
|
</distributionManagement>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<spigot-api.version>1.13-R0.1-SNAPSHOT</spigot-api.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>spigotmc-repo</id>
|
||||||
|
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>${spigot-api.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>com.googlecode.json-simple</groupId>
|
||||||
|
<artifactId>json-simple</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.yaml</groupId>
|
||||||
|
<artifactId>snakeyaml</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>net.md-5</groupId>
|
||||||
|
<artifactId>bungeecord-chat</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<defaultGoal>clean package</defaultGoal>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-clean-plugin</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.7.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>${java.version}</source>
|
||||||
|
<target>${java.version}</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.22.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
<version>3.0.1</version>
|
||||||
|
<configuration>
|
||||||
|
<show>public</show>
|
||||||
|
<failOnError>false</failOnError>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
<version>3.0.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.1.1</version>
|
||||||
|
<configuration>
|
||||||
|
<minimizeJar>false</minimizeJar>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-install-plugin</artifactId>
|
||||||
|
<version>2.5.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
<version>2.8.2</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
Loading…
Reference in New Issue
Block a user