mirror of
https://github.com/CodeMC/WorldGuardWrapper.git
synced 2025-01-18 04:02:38 +01:00
Update dependencies, bump version, enhance code style
This commit is contained in:
parent
b553ccba91
commit
38104d506d
|
@ -10,6 +10,7 @@ A wrapper for the WorldGuard API that allows plugins to support both v6 and v7 A
|
|||
How to include WorldEditWrapper into your maven project:
|
||||
|
||||
```xml
|
||||
<project>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>codemc-repo</id>
|
||||
|
@ -21,9 +22,10 @@ How to include WorldEditWrapper into your maven project:
|
|||
<dependency>
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<version>1.2.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
```
|
||||
|
||||
Remember to include/relocate the library into your final jar, example:
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper-parent</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<version>1.2.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.codemc.worldguardwrapper.event;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
@ -20,10 +21,12 @@ public class WrappedDamageEntityEvent extends AbstractWrappedEvent {
|
|||
private final Entity entity;
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.codemc.worldguardwrapper.event;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
|
@ -17,10 +18,12 @@ public class WrappedDisallowedPVPEvent extends AbstractWrappedEvent {
|
|||
private final Event cause;
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.codemc.worldguardwrapper.event;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
|
@ -24,10 +25,12 @@ public class WrappedUseBlockEvent extends AbstractWrappedEvent {
|
|||
private final Material effectiveMaterial;
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.codemc.worldguardwrapper.event;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
@ -20,10 +21,12 @@ public class WrappedUseEntityEvent extends AbstractWrappedEvent {
|
|||
private final Entity entity;
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.codemc.worldguardwrapper.flag;
|
|||
|
||||
import java.util.Optional;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public interface IWrappedFlag<T> {
|
||||
|
||||
String getName();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
package org.codemc.worldguardwrapper.flag;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public interface IWrappedStatusFlag extends IWrappedFlag<WrappedState> {
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.codemc.worldguardwrapper.flag;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public enum WrappedState {
|
||||
ALLOW,
|
||||
DENY;
|
||||
|
|
|
@ -8,17 +8,31 @@ import org.codemc.worldguardwrapper.region.IWrappedRegionSet;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public interface IHandler {
|
||||
|
||||
default void initialize(Player player, Location current, IWrappedRegionSet regionSet) {
|
||||
}
|
||||
|
||||
default boolean testMoveTo(Player player, Location from, Location to, IWrappedRegionSet regionSet, String moveType) {
|
||||
default boolean testMoveTo(
|
||||
Player player,
|
||||
Location from,
|
||||
Location to,
|
||||
IWrappedRegionSet regionSet,
|
||||
String moveType
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
default boolean onCrossBoundary(Player player, Location from, Location to, IWrappedRegionSet toSet,
|
||||
Set<IWrappedRegion> entered, Set<IWrappedRegion> exited, String moveType) {
|
||||
default boolean onCrossBoundary(
|
||||
Player player,
|
||||
Location from,
|
||||
Location to,
|
||||
IWrappedRegionSet toSet,
|
||||
Set<IWrappedRegion> entered,
|
||||
Set<IWrappedRegion> exited,
|
||||
String moveType
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ import org.codemc.worldguardwrapper.selection.ISelection;
|
|||
import java.util.*;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public interface IWorldGuardImplementation {
|
||||
|
||||
/**
|
||||
|
@ -58,7 +59,7 @@ public interface IWorldGuardImplementation {
|
|||
*
|
||||
* @param name The flag name
|
||||
* @param type The flag type
|
||||
* @return The flag, empty if it doesn't exists
|
||||
* @return The flag, empty if it doesn't exist
|
||||
*/
|
||||
<T> Optional<IWrappedFlag<T>> getFlag(String name, Class<T> type);
|
||||
|
||||
|
@ -149,7 +150,11 @@ public interface IWorldGuardImplementation {
|
|||
* @param point2 The second point of the region
|
||||
* @return The added region
|
||||
*/
|
||||
default Optional<IWrappedRegion> 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);
|
||||
}
|
||||
|
||||
|
@ -168,7 +173,8 @@ public interface IWorldGuardImplementation {
|
|||
IPolygonalSelection sel = (IPolygonalSelection) selection;
|
||||
return addRegion(id, new ArrayList<>(sel.getPoints()), sel.getMinimumY(), sel.getMaximumY());
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Unknown " + selection.getClass().getSimpleName() + " selection type!");
|
||||
throw new UnsupportedOperationException("Unknown " + selection.getClass().getSimpleName()
|
||||
+ " selection type!");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.codemc.worldguardwrapper.region;
|
|||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public interface IWrappedDomain {
|
||||
|
||||
Set<UUID> getPlayers();
|
||||
|
|
|
@ -7,6 +7,7 @@ import org.codemc.worldguardwrapper.selection.ISelection;
|
|||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public interface IWrappedRegion {
|
||||
|
||||
ISelection getSelection();
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.util.Collection;
|
|||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public interface IWrappedRegionSet extends Iterable<IWrappedRegion> {
|
||||
|
||||
boolean isVirtual();
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.codemc.worldguardwrapper.selection;
|
|||
|
||||
import org.bukkit.Location;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public interface ICuboidSelection extends ISelection {
|
||||
|
||||
Location getMinimumPoint();
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.bukkit.Location;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public interface IPolygonalSelection extends ISelection {
|
||||
|
||||
Set<Location> getPoints();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
package org.codemc.worldguardwrapper.selection;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public interface ISelection {
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.Collection;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@UtilityClass
|
||||
public class SelectionUtilities {
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper-implementation</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<version>1.2.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
|||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-api</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<version>1.2.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -62,23 +62,31 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
}
|
||||
|
||||
private Optional<ApplicableRegionSet> getApplicableRegions(@NonNull Location location) {
|
||||
return getWorldManager(location.getWorld()).map(manager -> manager.getApplicableRegions(location));
|
||||
return getWorldManager(Objects.requireNonNull(location.getWorld()))
|
||||
.map(manager -> manager.getApplicableRegions(location));
|
||||
}
|
||||
|
||||
private Optional<ApplicableRegionSet> getApplicableRegions(@NonNull Location minimum, @NonNull Location maximum) {
|
||||
return getWorldManager(minimum.getWorld()).map(manager -> manager.getApplicableRegions(
|
||||
new ProtectedCuboidRegion("temp", WorldGuardVectorUtilities.toBlockVector(minimum), WorldGuardVectorUtilities.toBlockVector(maximum))));
|
||||
return getWorldManager(Objects.requireNonNull(minimum.getWorld()))
|
||||
.map(manager ->
|
||||
manager.getApplicableRegions(
|
||||
new ProtectedCuboidRegion(
|
||||
"temp",
|
||||
WorldGuardVectorUtilities.toBlockVector(minimum),
|
||||
WorldGuardVectorUtilities.toBlockVector(maximum)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private <V> Optional<V> queryValue(Player player, @NonNull Location location, @NonNull Flag<V> flag) {
|
||||
return getApplicableRegions(location).map(applicableRegions -> applicableRegions.queryValue(wrapPlayer(player)
|
||||
.orElse(null), flag));
|
||||
return getApplicableRegions(location)
|
||||
.map(applicableRegions -> applicableRegions.queryValue(wrapPlayer(player).orElse(null), flag));
|
||||
}
|
||||
|
||||
private IWrappedRegionSet wrapRegionSet(@NonNull World world, @NonNull ApplicableRegionSet regionSet) {
|
||||
return new IWrappedRegionSet() {
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@Override
|
||||
public Iterator<IWrappedRegion> iterator() {
|
||||
return Iterators.transform(regionSet.iterator(), region -> new WrappedRegion(world, region));
|
||||
|
@ -159,7 +167,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> queryFlag(Player player, Location location, IWrappedFlag<T> flag) {
|
||||
public <T> Optional<T> queryFlag(Player player, @NonNull Location location, @NonNull IWrappedFlag<T> flag) {
|
||||
AbstractWrappedFlag<T> wrappedFlag = (AbstractWrappedFlag<T>) flag;
|
||||
|
||||
return queryValue(player, location, wrappedFlag.getHandle()).flatMap(wrappedFlag::fromWGValue);
|
||||
|
@ -198,19 +206,19 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<IWrappedFlag<T>> registerFlag(String name, Class<T> type, T defaultValue) {
|
||||
public <T> Optional<IWrappedFlag<T>> registerFlag(@NonNull String name, @NonNull Class<T> type, T defaultValue) {
|
||||
throw new UnsupportedOperationException("Custom flags aren't supported in this version of WorldGuard!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<IWrappedRegion> getRegion(World world, String id) {
|
||||
public Optional<IWrappedRegion> getRegion(@NonNull World world, @NonNull String id) {
|
||||
return getWorldManager(world)
|
||||
.map(regionManager -> regionManager.getRegion(id))
|
||||
.map(region -> new WrappedRegion(world, region));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IWrappedRegion> getRegions(World world) {
|
||||
public Map<String, IWrappedRegion> getRegions(@NonNull World world) {
|
||||
RegionManager regionManager = worldGuardPlugin.getRegionManager(world);
|
||||
Map<String, ProtectedRegion> regions = regionManager.getRegions();
|
||||
|
||||
|
@ -221,7 +229,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<IWrappedRegion> getRegions(Location location) {
|
||||
public Set<IWrappedRegion> getRegions(@NonNull Location location) {
|
||||
ApplicableRegionSet regionSet = getApplicableRegions(location).orElse(null);
|
||||
Set<IWrappedRegion> set = new HashSet<>();
|
||||
|
||||
|
@ -234,7 +242,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<IWrappedRegion> getRegions(Location minimum, Location maximum) {
|
||||
public Set<IWrappedRegion> getRegions(@NonNull Location minimum, @NonNull Location maximum) {
|
||||
ApplicableRegionSet regionSet = getApplicableRegions(minimum, maximum).orElse(null);
|
||||
Set<IWrappedRegion> set = new HashSet<>();
|
||||
|
||||
|
@ -248,17 +256,27 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
|
||||
@Override
|
||||
public Optional<IWrappedRegionSet> getRegionSet(@NonNull Location location) {
|
||||
return getApplicableRegions(location).map(regionSet -> wrapRegionSet(location.getWorld(), regionSet));
|
||||
return getApplicableRegions(location)
|
||||
.map(regionSet -> wrapRegionSet(Objects.requireNonNull(location.getWorld()), regionSet));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<IWrappedRegion> addRegion(String id, List<Location> points, int minY, int maxY) {
|
||||
public Optional<IWrappedRegion> addRegion(@NonNull String id, @NonNull List<Location> points, int minY, int maxY) {
|
||||
ProtectedRegion region;
|
||||
World world = points.get(0).getWorld();
|
||||
World world = Objects.requireNonNull(points.get(0).getWorld());
|
||||
if (points.size() == 2) {
|
||||
region = new ProtectedCuboidRegion(id, WorldGuardVectorUtilities.toBlockVector(points.get(0)), WorldGuardVectorUtilities.toBlockVector(points.get(1)));
|
||||
region = new ProtectedCuboidRegion(
|
||||
id,
|
||||
WorldGuardVectorUtilities.toBlockVector(points.get(0)),
|
||||
WorldGuardVectorUtilities.toBlockVector(points.get(1))
|
||||
);
|
||||
} else {
|
||||
region = new ProtectedPolygonalRegion(id, WorldGuardVectorUtilities.toBlockVector2DList(points), minY, maxY);
|
||||
region = new ProtectedPolygonalRegion(
|
||||
id,
|
||||
WorldGuardVectorUtilities.toBlockVector2DList(points),
|
||||
minY,
|
||||
maxY
|
||||
);
|
||||
}
|
||||
|
||||
Optional<RegionManager> manager = getWorldManager(world);
|
||||
|
@ -271,7 +289,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Optional<Set<IWrappedRegion>> removeRegion(World world, String id) {
|
||||
public Optional<Set<IWrappedRegion>> removeRegion(@NonNull World world, @NonNull String id) {
|
||||
Optional<Set<ProtectedRegion>> set = getWorldManager(world).map(manager -> manager.removeRegion(id));
|
||||
return set.map(protectedRegions -> protectedRegions.stream().map(region -> new WrappedRegion(world, region))
|
||||
.collect(Collectors.toSet()));
|
||||
|
@ -299,7 +317,12 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
public Set<Location> getPoints() {
|
||||
return ((Polygonal2DSelection) selection).getNativePoints().stream()
|
||||
.map(vector -> new BlockVector(vector.toVector()))
|
||||
.map(vector -> WorldGuardVectorUtilities.fromBlockVector(selection.getWorld(), vector))
|
||||
.map(vector ->
|
||||
WorldGuardVectorUtilities.fromBlockVector(
|
||||
selection.getWorld(),
|
||||
vector
|
||||
)
|
||||
)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
|
@ -314,7 +337,8 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
}
|
||||
};
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Unsupported " + selection.getClass().getSimpleName() + " selection!");
|
||||
throw new UnsupportedOperationException("Unsupported " + selection.getClass().getSimpleName()
|
||||
+ " selection!");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -64,7 +64,8 @@ public class WorldGuardFlagUtilities {
|
|||
|
||||
public Map.Entry<IWrappedFlag<?>, Object> wrap(Flag<?> flag, Object value) {
|
||||
IWrappedFlag<?> wrappedFlag = wrapFixType(flag, value.getClass());
|
||||
Object wrappedValue = ((AbstractWrappedFlag<?>) wrappedFlag).fromWGValue(value).get(); // value is non-null
|
||||
Object wrappedValue = ((AbstractWrappedFlag<?>) wrappedFlag).fromWGValue(value)
|
||||
.orElseThrow(NullPointerException::new); // value should never be null
|
||||
return Maps.immutableEntry(wrappedFlag, wrappedValue);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,9 @@ public class WorldGuardVectorUtilities {
|
|||
}
|
||||
|
||||
public List<BlockVector2D> toBlockVector2DList(List<Location> locations) {
|
||||
return locations.stream().map(location -> new BlockVector2D(location.getX(), location.getZ())).collect(Collectors.toList());
|
||||
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-parent</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<version>1.2.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper-implementation</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<version>1.2.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
|||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-api</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<version>1.2.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -64,8 +64,12 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
}
|
||||
|
||||
private Optional<LocalPlayer> wrapPlayer(OfflinePlayer player) {
|
||||
return Optional.ofNullable(player).map(bukkitPlayer -> bukkitPlayer.isOnline() ?
|
||||
worldGuardPlugin.wrapPlayer((Player) bukkitPlayer) : worldGuardPlugin.wrapOfflinePlayer(bukkitPlayer));
|
||||
return Optional.ofNullable(player).map(bukkitPlayer -> {
|
||||
if (bukkitPlayer.isOnline()) {
|
||||
return worldGuardPlugin.wrapPlayer((Player) bukkitPlayer);
|
||||
}
|
||||
return worldGuardPlugin.wrapOfflinePlayer(bukkitPlayer);
|
||||
});
|
||||
}
|
||||
|
||||
private Optional<RegionManager> getWorldManager(@NonNull World world) {
|
||||
|
@ -73,23 +77,29 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
}
|
||||
|
||||
private Optional<ApplicableRegionSet> getApplicableRegions(@NonNull Location location) {
|
||||
return getWorldManager(location.getWorld()).map(manager -> manager.getApplicableRegions(location));
|
||||
return getWorldManager(Objects.requireNonNull(location.getWorld()))
|
||||
.map(manager -> manager.getApplicableRegions(location));
|
||||
}
|
||||
|
||||
private Optional<ApplicableRegionSet> getApplicableRegions(@NonNull Location minimum, @NonNull Location maximum) {
|
||||
return getWorldManager(minimum.getWorld()).map(manager -> manager.getApplicableRegions(
|
||||
new ProtectedCuboidRegion("temp", WorldGuardVectorUtilities.toBlockVector(minimum), WorldGuardVectorUtilities.toBlockVector(maximum))));
|
||||
return getWorldManager(Objects.requireNonNull(minimum.getWorld()))
|
||||
.map(manager -> manager.getApplicableRegions(
|
||||
new ProtectedCuboidRegion(
|
||||
"temp",
|
||||
WorldGuardVectorUtilities.toBlockVector(minimum),
|
||||
WorldGuardVectorUtilities.toBlockVector(maximum)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
private <V> Optional<V> queryValue(Player player, @NonNull Location location, @NonNull Flag<V> flag) {
|
||||
return getApplicableRegions(location).map(applicableRegions -> applicableRegions.queryValue(wrapPlayer(player)
|
||||
.orElse(null), flag));
|
||||
return getApplicableRegions(location)
|
||||
.map(applicableRegions -> applicableRegions.queryValue(wrapPlayer(player).orElse(null), flag));
|
||||
}
|
||||
|
||||
public IWrappedRegionSet wrapRegionSet(@NonNull World world, @NonNull ApplicableRegionSet regionSet) {
|
||||
return new IWrappedRegionSet() {
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@Override
|
||||
public Iterator<IWrappedRegion> iterator() {
|
||||
return Iterators.transform(regionSet.iterator(), region -> new WrappedRegion(world, region));
|
||||
|
@ -138,8 +148,10 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
|
||||
@Override
|
||||
public Set<IWrappedRegion> getRegions() {
|
||||
return regionSet.getRegions().stream()
|
||||
.map(region -> new WrappedRegion(world, region)).collect(Collectors.toSet());
|
||||
return regionSet.getRegions()
|
||||
.stream()
|
||||
.map(region -> new WrappedRegion(world, region))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -165,7 +177,11 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
try {
|
||||
//noinspection unchecked
|
||||
handlerClass = (Class<? extends ProxyHandler>) proxyFactory.createClass();
|
||||
handlerConstructor = handlerClass.getDeclaredConstructor(WorldGuardImplementation.class, IHandler.class, Session.class);
|
||||
handlerConstructor = handlerClass.getDeclaredConstructor(
|
||||
WorldGuardImplementation.class,
|
||||
IHandler.class,
|
||||
Session.class
|
||||
);
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -190,7 +206,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> queryFlag(Player player, Location location, IWrappedFlag<T> flag) {
|
||||
public <T> Optional<T> queryFlag(Player player, @NonNull Location location, @NonNull IWrappedFlag<T> flag) {
|
||||
AbstractWrappedFlag<T> wrappedFlag = (AbstractWrappedFlag<T>) flag;
|
||||
return queryValue(player, location, wrappedFlag.getHandle()).flatMap(wrappedFlag::fromWGValue);
|
||||
}
|
||||
|
@ -229,7 +245,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Override
|
||||
public <T> Optional<IWrappedFlag<T>> registerFlag(String name, Class<T> type, T defaultValue) {
|
||||
public <T> Optional<IWrappedFlag<T>> registerFlag(@NonNull String name, @NonNull Class<T> type, T defaultValue) {
|
||||
final Flag<?> flag;
|
||||
if (type.equals(WrappedState.class)) {
|
||||
flag = new StateFlag(name, defaultValue == WrappedState.ALLOW);
|
||||
|
@ -259,14 +275,14 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Optional<IWrappedRegion> getRegion(World world, String id) {
|
||||
public Optional<IWrappedRegion> getRegion(@NonNull World world, @NonNull String id) {
|
||||
return getWorldManager(world)
|
||||
.map(regionManager -> regionManager.getRegion(id))
|
||||
.map(region -> new WrappedRegion(world, region));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IWrappedRegion> getRegions(World world) {
|
||||
public Map<String, IWrappedRegion> getRegions(@NonNull World world) {
|
||||
RegionManager regionManager = worldGuardPlugin.getRegionManager(world);
|
||||
Map<String, ProtectedRegion> regions = regionManager.getRegions();
|
||||
|
||||
|
@ -277,7 +293,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<IWrappedRegion> getRegions(Location location) {
|
||||
public Set<IWrappedRegion> getRegions(@NonNull Location location) {
|
||||
ApplicableRegionSet regionSet = getApplicableRegions(location).orElse(null);
|
||||
Set<IWrappedRegion> set = new HashSet<>();
|
||||
|
||||
|
@ -290,7 +306,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<IWrappedRegion> getRegions(Location minimum, Location maximum) {
|
||||
public Set<IWrappedRegion> getRegions(@NonNull Location minimum, @NonNull Location maximum) {
|
||||
ApplicableRegionSet regionSet = getApplicableRegions(minimum, maximum).orElse(null);
|
||||
Set<IWrappedRegion> set = new HashSet<>();
|
||||
|
||||
|
@ -304,17 +320,27 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
|
||||
@Override
|
||||
public Optional<IWrappedRegionSet> getRegionSet(@NonNull Location location) {
|
||||
return getApplicableRegions(location).map(regionSet -> wrapRegionSet(location.getWorld(), regionSet));
|
||||
return getApplicableRegions(location)
|
||||
.map(regionSet -> wrapRegionSet(Objects.requireNonNull(location.getWorld()), regionSet));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<IWrappedRegion> addRegion(String id, List<Location> points, int minY, int maxY) {
|
||||
public Optional<IWrappedRegion> addRegion(@NonNull String id, @NonNull List<Location> points, int minY, int maxY) {
|
||||
ProtectedRegion region;
|
||||
World world = points.get(0).getWorld();
|
||||
World world = Objects.requireNonNull(points.get(0).getWorld());
|
||||
if (points.size() == 2) {
|
||||
region = new ProtectedCuboidRegion(id, WorldGuardVectorUtilities.toBlockVector(points.get(0)), WorldGuardVectorUtilities.toBlockVector(points.get(1)));
|
||||
region = new ProtectedCuboidRegion(
|
||||
id,
|
||||
WorldGuardVectorUtilities.toBlockVector(points.get(0)),
|
||||
WorldGuardVectorUtilities.toBlockVector(points.get(1))
|
||||
);
|
||||
} else {
|
||||
region = new ProtectedPolygonalRegion(id, WorldGuardVectorUtilities.toBlockVector2DList(points), minY, maxY);
|
||||
region = new ProtectedPolygonalRegion(
|
||||
id,
|
||||
WorldGuardVectorUtilities.toBlockVector2DList(points),
|
||||
minY,
|
||||
maxY
|
||||
);
|
||||
}
|
||||
|
||||
Optional<RegionManager> manager = getWorldManager(world);
|
||||
|
@ -327,10 +353,13 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Optional<Set<IWrappedRegion>> removeRegion(World world, String id) {
|
||||
public Optional<Set<IWrappedRegion>> removeRegion(@NonNull World world, @NonNull String id) {
|
||||
Optional<Set<ProtectedRegion>> set = getWorldManager(world).map(manager -> manager.removeRegion(id));
|
||||
return set.map(protectedRegions -> protectedRegions.stream().map(region -> new WrappedRegion(world, region))
|
||||
.collect(Collectors.toSet()));
|
||||
return set.map(protectedRegions ->
|
||||
protectedRegions.stream()
|
||||
.map(region -> new WrappedRegion(world, region))
|
||||
.collect(Collectors.toSet())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -355,7 +384,12 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
public Set<Location> getPoints() {
|
||||
return ((Polygonal2DSelection) selection).getNativePoints().stream()
|
||||
.map(vector -> new BlockVector(vector.toVector()))
|
||||
.map(vector -> WorldGuardVectorUtilities.fromBlockVector(selection.getWorld(), vector))
|
||||
.map(vector ->
|
||||
WorldGuardVectorUtilities.fromBlockVector(
|
||||
selection.getWorld(),
|
||||
vector
|
||||
)
|
||||
)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
|
@ -370,7 +404,8 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
}
|
||||
};
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Unsupported " + selection.getClass().getSimpleName() + " selection!");
|
||||
throw new UnsupportedOperationException("Unsupported " + selection.getClass().getSimpleName()
|
||||
+ " selection!");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.codemc.worldguardwrapper.implementation.v6.region.WrappedRegion;
|
|||
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class ProxyHandler extends Handler {
|
||||
|
@ -32,19 +33,48 @@ public class ProxyHandler extends Handler {
|
|||
|
||||
@Override
|
||||
public void initialize(Player player, Location current, ApplicableRegionSet set) {
|
||||
handler.initialize(player, current, implementation.wrapRegionSet(current.getWorld(), set));
|
||||
handler.initialize(
|
||||
player,
|
||||
current,
|
||||
implementation.wrapRegionSet(Objects.requireNonNull(current.getWorld()), set)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testMoveTo(Player player, Location from, Location to, ApplicableRegionSet toSet, MoveType moveType) {
|
||||
return handler.testMoveTo(player, from, to, implementation.wrapRegionSet(to.getWorld(), toSet), moveType.name());
|
||||
return handler.testMoveTo(player,
|
||||
from,
|
||||
to,
|
||||
implementation.wrapRegionSet(Objects.requireNonNull(to.getWorld()), toSet),
|
||||
moveType.name()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType) {
|
||||
Set<IWrappedRegion> mappedEntered = ImmutableSet.copyOf(Collections2.transform(entered, region -> new WrappedRegion(to.getWorld(), region)));
|
||||
Set<IWrappedRegion> mappedExited = ImmutableSet.copyOf(Collections2.transform(exited, region -> new WrappedRegion(from.getWorld(), region)));
|
||||
return handler.onCrossBoundary(player, from, to, implementation.wrapRegionSet(to.getWorld(), toSet), mappedEntered, mappedExited, moveType.name());
|
||||
public boolean onCrossBoundary(
|
||||
Player player,
|
||||
Location from,
|
||||
Location to,
|
||||
ApplicableRegionSet toSet,
|
||||
Set<ProtectedRegion> entered,
|
||||
Set<ProtectedRegion> exited,
|
||||
MoveType moveType
|
||||
) {
|
||||
Set<IWrappedRegion> mappedEntered = ImmutableSet.copyOf(
|
||||
Collections2.transform(entered, region -> new WrappedRegion(to.getWorld(), region))
|
||||
);
|
||||
Set<IWrappedRegion> mappedExited = ImmutableSet.copyOf(
|
||||
Collections2.transform(exited, region -> new WrappedRegion(from.getWorld(), region))
|
||||
);
|
||||
return handler.onCrossBoundary(
|
||||
player,
|
||||
from,
|
||||
to,
|
||||
implementation.wrapRegionSet(Objects.requireNonNull(to.getWorld()), toSet),
|
||||
mappedEntered,
|
||||
mappedExited,
|
||||
moveType.name()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,7 +21,8 @@ public class WorldGuardVectorUtilities {
|
|||
}
|
||||
|
||||
public List<BlockVector2D> toBlockVector2DList(List<Location> locations) {
|
||||
return locations.stream().map(location -> new BlockVector2D(location.getX(), location.getZ())).collect(Collectors.toList());
|
||||
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.2.0-SNAPSHOT</version>
|
||||
<version>1.2.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -29,13 +29,13 @@
|
|||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-api</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<version>1.2.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
<artifactId>worldguard-bukkit</artifactId>
|
||||
<version>7.0.7</version>
|
||||
<version>7.0.8</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
|
|
|
@ -13,15 +13,7 @@ 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.BooleanFlag;
|
||||
import com.sk89q.worldguard.protection.flags.DoubleFlag;
|
||||
import com.sk89q.worldguard.protection.flags.EnumFlag;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.IntegerFlag;
|
||||
import com.sk89q.worldguard.protection.flags.LocationFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StringFlag;
|
||||
import com.sk89q.worldguard.protection.flags.VectorFlag;
|
||||
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;
|
||||
|
@ -54,15 +46,7 @@ import org.codemc.worldguardwrapper.selection.ISelection;
|
|||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -77,8 +61,12 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
}
|
||||
|
||||
private Optional<LocalPlayer> wrapPlayer(OfflinePlayer player) {
|
||||
return Optional.ofNullable(player).map(bukkitPlayer -> bukkitPlayer.isOnline() ?
|
||||
WorldGuardPlugin.inst().wrapPlayer((Player) bukkitPlayer) : WorldGuardPlugin.inst().wrapOfflinePlayer(bukkitPlayer));
|
||||
return Optional.ofNullable(player).map(bukkitPlayer -> {
|
||||
if (bukkitPlayer.isOnline()) {
|
||||
return WorldGuardPlugin.inst().wrapPlayer((Player) bukkitPlayer);
|
||||
}
|
||||
return WorldGuardPlugin.inst().wrapOfflinePlayer(bukkitPlayer);
|
||||
});
|
||||
}
|
||||
|
||||
private Optional<RegionManager> getWorldManager(@NonNull World world) {
|
||||
|
@ -86,23 +74,29 @@ 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(Objects.requireNonNull(location.getWorld()))
|
||||
.map(manager -> manager.getApplicableRegions(BukkitAdapter.asBlockVector(location)));
|
||||
}
|
||||
|
||||
private Optional<ApplicableRegionSet> getApplicableRegions(@NonNull Location minimum, @NonNull Location maximum) {
|
||||
return getWorldManager(minimum.getWorld()).map(manager -> manager.getApplicableRegions(
|
||||
new ProtectedCuboidRegion("temp", BukkitAdapter.asBlockVector(minimum), BukkitAdapter.asBlockVector(maximum))));
|
||||
return getWorldManager(Objects.requireNonNull(minimum.getWorld()))
|
||||
.map(manager -> manager.getApplicableRegions(
|
||||
new ProtectedCuboidRegion(
|
||||
"temp",
|
||||
BukkitAdapter.asBlockVector(minimum),
|
||||
BukkitAdapter.asBlockVector(maximum)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
private <V> Optional<V> queryValue(Player player, @NonNull Location location, @NonNull Flag<V> flag) {
|
||||
return getApplicableRegions(location).map(applicableRegions -> applicableRegions.queryValue(wrapPlayer(player)
|
||||
.orElse(null), flag));
|
||||
return getApplicableRegions(location)
|
||||
.map(applicableRegions -> applicableRegions.queryValue(wrapPlayer(player).orElse(null), flag));
|
||||
}
|
||||
|
||||
public IWrappedRegionSet wrapRegionSet(@NonNull World world, @NonNull ApplicableRegionSet regionSet) {
|
||||
return new IWrappedRegionSet() {
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@Override
|
||||
public Iterator<IWrappedRegion> iterator() {
|
||||
return Iterators.transform(regionSet.iterator(), region -> new WrappedRegion(world, region));
|
||||
|
@ -178,7 +172,11 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
try {
|
||||
//noinspection unchecked
|
||||
handlerClass = (Class<? extends ProxyHandler>) proxyFactory.createClass();
|
||||
handlerConstructor = handlerClass.getDeclaredConstructor(WorldGuardImplementation.class, IHandler.class, Session.class);
|
||||
handlerConstructor = handlerClass.getDeclaredConstructor(
|
||||
WorldGuardImplementation.class,
|
||||
IHandler.class,
|
||||
Session.class
|
||||
);
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -203,7 +201,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> queryFlag(Player player, Location location, IWrappedFlag<T> flag) {
|
||||
public <T> Optional<T> queryFlag(Player player, @NonNull Location location, @NonNull IWrappedFlag<T> flag) {
|
||||
AbstractWrappedFlag<T> wrappedFlag = (AbstractWrappedFlag<T>) flag;
|
||||
return queryValue(player, location, wrappedFlag.getHandle()).flatMap(wrappedFlag::fromWGValue);
|
||||
}
|
||||
|
@ -242,7 +240,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Override
|
||||
public <T> Optional<IWrappedFlag<T>> registerFlag(String name, Class<T> type, T defaultValue) {
|
||||
public <T> Optional<IWrappedFlag<T>> registerFlag(@NonNull String name, @NonNull Class<T> type, T defaultValue) {
|
||||
final Flag<?> flag;
|
||||
if (type.equals(WrappedState.class)) {
|
||||
flag = new StateFlag(name, defaultValue == WrappedState.ALLOW);
|
||||
|
@ -272,14 +270,14 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Optional<IWrappedRegion> getRegion(World world, String id) {
|
||||
public Optional<IWrappedRegion> getRegion(@NonNull World world, @NonNull String id) {
|
||||
return getWorldManager(world)
|
||||
.map(regionManager -> regionManager.getRegion(id))
|
||||
.map(region -> new WrappedRegion(world, region));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IWrappedRegion> getRegions(World world) {
|
||||
public Map<String, IWrappedRegion> getRegions(@NonNull World world) {
|
||||
RegionManager regionManager = core.getPlatform().getRegionContainer().get(new BukkitWorld(world));
|
||||
if (regionManager == null) {
|
||||
return Collections.emptyMap();
|
||||
|
@ -292,7 +290,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<IWrappedRegion> getRegions(Location location) {
|
||||
public Set<IWrappedRegion> getRegions(@NonNull Location location) {
|
||||
ApplicableRegionSet regionSet = getApplicableRegions(location).orElse(null);
|
||||
if (regionSet == null) {
|
||||
return Collections.emptySet();
|
||||
|
@ -304,7 +302,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<IWrappedRegion> getRegions(Location minimum, Location maximum) {
|
||||
public Set<IWrappedRegion> getRegions(@NonNull Location minimum, @NonNull Location maximum) {
|
||||
ApplicableRegionSet regionSet = getApplicableRegions(minimum, maximum).orElse(null);
|
||||
if (regionSet == null) {
|
||||
return Collections.emptySet();
|
||||
|
@ -321,9 +319,9 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Optional<IWrappedRegion> addRegion(String id, List<Location> points, int minY, int maxY) {
|
||||
public Optional<IWrappedRegion> addRegion(@NonNull String id, @NonNull List<Location> points, int minY, int maxY) {
|
||||
ProtectedRegion region;
|
||||
World world = points.get(0).getWorld();
|
||||
World world = Objects.requireNonNull(points.get(0).getWorld());
|
||||
if (points.size() == 2) {
|
||||
region = new ProtectedCuboidRegion(id, BukkitAdapter.asBlockVector(points.get(0)),
|
||||
BukkitAdapter.asBlockVector(points.get(1)));
|
||||
|
@ -345,7 +343,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Optional<Set<IWrappedRegion>> removeRegion(World world, String id) {
|
||||
public Optional<Set<IWrappedRegion>> removeRegion(@NonNull World world, @NonNull String id) {
|
||||
Optional<Set<ProtectedRegion>> set = getWorldManager(world).map(manager -> manager.removeRegion(id));
|
||||
return set.map(protectedRegions -> protectedRegions.stream()
|
||||
.map(region -> new WrappedRegion(world, region)).collect(Collectors.toSet()));
|
||||
|
@ -355,13 +353,18 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
public Optional<ISelection> getPlayerSelection(@NonNull Player player) {
|
||||
Region region;
|
||||
try {
|
||||
region = WorldEdit.getInstance().getSessionManager().get(BukkitAdapter.adapt(player)).getSelection(BukkitAdapter.adapt(player.getWorld()));
|
||||
region = WorldEdit.getInstance()
|
||||
.getSessionManager()
|
||||
.get(BukkitAdapter.adapt(player))
|
||||
.getSelection(BukkitAdapter.adapt(player.getWorld()));
|
||||
} catch (IncompleteRegionException e) {
|
||||
region = null;
|
||||
}
|
||||
return Optional.ofNullable(region)
|
||||
.map(selection -> {
|
||||
World world = Optional.ofNullable(selection.getWorld()).map(BukkitAdapter::adapt).orElse(null);
|
||||
World world = Optional.ofNullable(selection.getWorld())
|
||||
.map(BukkitAdapter::adapt)
|
||||
.orElse(null);
|
||||
if (world == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -398,7 +401,8 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
}
|
||||
};
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Unsupported " + selection.getClass().getSimpleName() + " selection!");
|
||||
throw new UnsupportedOperationException("Unsupported " + selection.getClass().getSimpleName()
|
||||
+ " selection!");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.codemc.worldguardwrapper.implementation.v7.region.WrappedRegion;
|
|||
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class ProxyHandler extends Handler {
|
||||
|
@ -36,25 +37,61 @@ public class ProxyHandler extends Handler {
|
|||
public void initialize(LocalPlayer player, com.sk89q.worldedit.util.Location current, ApplicableRegionSet set) {
|
||||
Player bukkitPlayer = BukkitAdapter.adapt(player);
|
||||
Location bukkitLocation = BukkitAdapter.adapt(current);
|
||||
handler.initialize(bukkitPlayer, bukkitLocation, implementation.wrapRegionSet(bukkitLocation.getWorld(), set));
|
||||
handler.initialize(
|
||||
bukkitPlayer,
|
||||
bukkitLocation,
|
||||
implementation.wrapRegionSet(Objects.requireNonNull(bukkitLocation.getWorld()),set)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testMoveTo(LocalPlayer player, com.sk89q.worldedit.util.Location from, com.sk89q.worldedit.util.Location to, ApplicableRegionSet toSet, MoveType moveType) {
|
||||
public boolean testMoveTo(
|
||||
LocalPlayer player,
|
||||
com.sk89q.worldedit.util.Location from,
|
||||
com.sk89q.worldedit.util.Location to,
|
||||
ApplicableRegionSet toSet,
|
||||
MoveType moveType
|
||||
) {
|
||||
Player bukkitPlayer = BukkitAdapter.adapt(player);
|
||||
Location bukkitFrom = BukkitAdapter.adapt(from);
|
||||
Location bukkitTo = BukkitAdapter.adapt(to);
|
||||
return handler.testMoveTo(bukkitPlayer, bukkitFrom, bukkitTo, implementation.wrapRegionSet(bukkitTo.getWorld(), toSet), moveType.name());
|
||||
return handler.testMoveTo(
|
||||
bukkitPlayer,
|
||||
bukkitFrom,
|
||||
bukkitTo,
|
||||
implementation.wrapRegionSet(Objects.requireNonNull(bukkitTo.getWorld()), toSet),
|
||||
moveType.name()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCrossBoundary(LocalPlayer player, com.sk89q.worldedit.util.Location from, com.sk89q.worldedit.util.Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType) {
|
||||
public boolean onCrossBoundary(
|
||||
LocalPlayer player,
|
||||
com.sk89q.worldedit.util.Location from,
|
||||
com.sk89q.worldedit.util.Location to,
|
||||
ApplicableRegionSet toSet,
|
||||
Set<ProtectedRegion> entered,
|
||||
Set<ProtectedRegion> exited,
|
||||
MoveType moveType
|
||||
) {
|
||||
Player bukkitPlayer = BukkitAdapter.adapt(player);
|
||||
Location bukkitFrom = BukkitAdapter.adapt(from);
|
||||
Location bukkitTo = BukkitAdapter.adapt(to);
|
||||
Set<IWrappedRegion> mappedEntered = ImmutableSet.copyOf(Collections2.transform(entered, region -> new WrappedRegion(bukkitTo.getWorld(), region)));
|
||||
Set<IWrappedRegion> mappedExited = ImmutableSet.copyOf(Collections2.transform(exited, region -> new WrappedRegion(bukkitFrom.getWorld(), region)));
|
||||
return handler.onCrossBoundary(bukkitPlayer, bukkitFrom, bukkitTo, implementation.wrapRegionSet(bukkitTo.getWorld(), toSet), mappedEntered, mappedExited, moveType.name());
|
||||
Set<IWrappedRegion> mappedEntered = ImmutableSet.copyOf(Collections2.transform(entered, region ->
|
||||
new WrappedRegion(bukkitTo.getWorld(), region)
|
||||
));
|
||||
Set<IWrappedRegion> mappedExited = ImmutableSet.copyOf(Collections2.transform(exited, region ->
|
||||
new WrappedRegion(bukkitFrom.getWorld(), region)
|
||||
));
|
||||
return handler.onCrossBoundary(
|
||||
bukkitPlayer,
|
||||
bukkitFrom,
|
||||
bukkitTo,
|
||||
implementation.wrapRegionSet(Objects.requireNonNull(bukkitTo.getWorld()), toSet),
|
||||
mappedEntered,
|
||||
mappedExited,
|
||||
moveType.name()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper-parent</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<version>1.2.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -19,25 +19,25 @@
|
|||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-api</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<version>1.2.1-SNAPSHOT</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-implementation-legacy</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<version>1.2.1-SNAPSHOT</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-implementation-v6</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<version>1.2.1-SNAPSHOT</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-implementation-v7</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<version>1.2.1-SNAPSHOT</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
|
|
@ -6,6 +6,8 @@ import org.bukkit.event.Listener;
|
|||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation;
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class WorldGuardWrapper implements IWorldGuardImplementation {
|
||||
|
||||
private static WorldGuardWrapper instance;
|
||||
|
@ -23,8 +25,8 @@ public class WorldGuardWrapper implements IWorldGuardImplementation {
|
|||
}
|
||||
|
||||
@Delegate
|
||||
private IWorldGuardImplementation implementation;
|
||||
private Listener listener;
|
||||
private final IWorldGuardImplementation implementation;
|
||||
private final Listener listener;
|
||||
|
||||
private WorldGuardWrapper() {
|
||||
int targetVersion;
|
||||
|
@ -46,15 +48,6 @@ public class WorldGuardWrapper implements IWorldGuardImplementation {
|
|||
implementation = new org.codemc.worldguardwrapper.implementation.legacy.WorldGuardImplementation();
|
||||
listener = new org.codemc.worldguardwrapper.implementation.legacy.event.EventListener();
|
||||
} else {
|
||||
/*
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("FastAsyncWorldEdit")) {
|
||||
implementation = new org.codemc.worldguardwrapper.implementation.v7fawe.WorldGuardImplementation();
|
||||
listener = new org.codemc.worldguardwrapper.implementation.v7fawe.event.EventListener();
|
||||
} else {
|
||||
implementation = new org.codemc.worldguardwrapper.implementation.v7.WorldGuardImplementation();
|
||||
listener = new org.codemc.worldguardwrapper.implementation.v7.event.EventListener();
|
||||
}
|
||||
*/
|
||||
implementation = new org.codemc.worldguardwrapper.implementation.v7.WorldGuardImplementation();
|
||||
listener = new org.codemc.worldguardwrapper.implementation.v7.event.EventListener();
|
||||
}
|
||||
|
|
30
pom.xml
30
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>org.codemc.worldguardwrapper</groupId>
|
||||
<artifactId>worldguardwrapper-parent</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<version>1.2.1-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
|
@ -28,7 +28,7 @@
|
|||
|
||||
<ciManagement>
|
||||
<system>jenkins</system>
|
||||
<url>http://ci.codemc.org/job/CodeMC/job/HolographicDisplays/</url>
|
||||
<url>https://ci.codemc.io/job/CodeMC/job/WorldGuardWrapper/</url>
|
||||
</ciManagement>
|
||||
|
||||
<issueManagement>
|
||||
|
@ -50,7 +50,7 @@
|
|||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<spigot-api.version>1.19.1-R0.1-SNAPSHOT</spigot-api.version>
|
||||
<spigot-api.version>1.20.1-R0.1-SNAPSHOT</spigot-api.version>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
|
@ -89,13 +89,13 @@
|
|||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.24</version>
|
||||
<version>1.18.28</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.javassist</groupId>
|
||||
<artifactId>javassist</artifactId>
|
||||
<version>3.29.1-GA</version>
|
||||
<version>3.29.2-GA</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -134,17 +134,17 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<version>3.3.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<version>3.3.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.10.1</version>
|
||||
<version>3.11.0</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
|
@ -154,17 +154,17 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
<version>3.1.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.2.2</version>
|
||||
<version>3.3.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.4.1</version>
|
||||
<version>3.5.0</version>
|
||||
<configuration>
|
||||
<show>public</show>
|
||||
<failOnError>false</failOnError>
|
||||
|
@ -173,12 +173,12 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.2.1</version>
|
||||
<version>3.3.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<version>3.5.0</version>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
|
@ -186,12 +186,12 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<version>3.1.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.1.1</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
|
Loading…
Reference in New Issue
Block a user