WG 7 hotfix

This commit is contained in:
Gabriele C 2018-11-16 18:26:31 +01:00
parent fd1178edce
commit 7efc516a14
3 changed files with 112 additions and 23 deletions

View File

@ -26,10 +26,6 @@
</properties>
<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>

View File

@ -20,6 +20,94 @@
<artifactId>worldguardwrapper-implementation-interface</artifactId>
<version>1.0.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>7.0.0-20181112.023924-25</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
</exclusion>
<exclusion>
<groupId>io.papermc</groupId>
<artifactId>paperlib</artifactId>
</exclusion>
<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>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-legacy</artifactId>

View File

@ -1,9 +1,10 @@
package org.codemc.worldguardwrapper.implementation.v7;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
@ -43,6 +44,22 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
plugin = WorldGuardPlugin.inst();
}
// Adapters
private static Vector toVector(Location location) {
return new Vector(location.getX(), location.getY(), location.getZ());
}
private static BlockVector toBlockVector(Location location) {
return new BlockVector(location.getX(), location.getY(), location.getZ());
}
private static List<BlockVector2D> toBlockVector2DList(List<Location> locations) {
return locations.stream()
.map(location -> new BlockVector2D(location.getX(), location.getZ()))
.collect(Collectors.toList());
}
private Optional<LocalPlayer> wrapPlayer(Player player) {
return Optional.ofNullable(player).map(bukkitPlayer -> plugin.wrapPlayer(player));
}
@ -56,7 +73,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
}
private Optional<ApplicableRegionSet> getApplicableRegions(@NonNull Location location) {
return getWorldManager(location.getWorld()).map(manager -> manager.getApplicableRegions(BukkitAdapter.asBlockVector(location)));
return getWorldManager(location.getWorld()).map(manager -> manager.getApplicableRegions(toVector(location)));
}
private <V> Optional<V> queryValue(Player player, @NonNull Location location, @NonNull Flag<V> flag) {
@ -67,14 +84,6 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
return getApplicableRegions(location).map(applicableRegions -> applicableRegions.queryState(wrapPlayer(player).orElse(null), stateFlags));
}
private BlockVector3 toBlockVector3(Location location) {
return BlockVector3.at(location.getX(), location.getY(), location.getZ());
}
private List<BlockVector2> toBlockVector2List(List<Location> locations) {
return locations.stream().map(location -> BlockVector2.at(location.getX(), location.getZ())).collect(Collectors.toList());
}
private WrappedRegion toRegion(ProtectedRegion region) {
return new WrappedRegion() {
@ -103,7 +112,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
@Override
public boolean contains(Location location) {
return region.contains(toBlockVector3(location));
return region.contains(toVector(location));
}
};
@ -217,9 +226,9 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
public Optional<WrappedRegion> addRegion(String id, List<Location> points, int minY, int maxY) {
ProtectedRegion region;
if (points.size() == 2) {
region = new ProtectedCuboidRegion(id, toBlockVector3(points.get(0)), toBlockVector3(points.get(1)));
region = new ProtectedCuboidRegion(id, toBlockVector(points.get(0)), toBlockVector(points.get(1)));
} else {
region = new ProtectedPolygonalRegion(id, toBlockVector2List(points), minY, maxY);
region = new ProtectedPolygonalRegion(id, toBlockVector2DList(points), minY, maxY);
}
Optional<RegionManager> manager = getWorldManager(points.get(0).getWorld());
@ -234,10 +243,6 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
@Override
public Optional<Set<WrappedRegion>> removeRegion(World world, String id) {
Optional<Set<ProtectedRegion>> set = getWorldManager(world).map(manager -> manager.removeRegion(id));
if (set.isPresent()) {
return Optional.of(set.get().stream().map(region -> toRegion(region)).collect(Collectors.toSet()));
} else {
return Optional.empty();
}
return set.map(protectedRegions -> protectedRegions.stream().map(this::toRegion).collect(Collectors.toSet()));
}
}