Add legacy (WG 6.1) support

This commit is contained in:
Gabriele C 2019-02-23 01:00:04 +01:00
parent 4c0738f95a
commit a88cab6cc9
17 changed files with 636 additions and 19 deletions

View File

@ -21,7 +21,7 @@ How to include WorldEditWrapper into your maven project:
<dependency> <dependency>
<groupId>org.codemc.worldguardwrapper</groupId> <groupId>org.codemc.worldguardwrapper</groupId>
<artifactId>worldguardwrapper</artifactId> <artifactId>worldguardwrapper</artifactId>
<version>1.1.2-SNAPSHOT</version> <version>1.1.4-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>
``` ```

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.codemc.worldguardwrapper</groupId> <groupId>org.codemc.worldguardwrapper</groupId>
<artifactId>worldguardwrapper-parent</artifactId> <artifactId>worldguardwrapper-parent</artifactId>
<version>1.1.3-SNAPSHOT</version> <version>1.1.4-SNAPSHOT</version>
</parent> </parent>
<artifactId>worldguardwrapper-api</artifactId> <artifactId>worldguardwrapper-api</artifactId>

View File

@ -0,0 +1,41 @@
<?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.1.4-SNAPSHOT</version>
</parent>
<artifactId>worldguardwrapper-implementation-legacy</artifactId>
<name>WorldGuardWrapper-Implementation-Legacy</name>
<repositories>
<repository>
<id>sk89q-repo</id>
<url>http://maven.sk89q.com/repo/</url>
<snapshots>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>worldguardwrapper-api</artifactId>
<version>1.1.4-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldguard</artifactId>
<version>6.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,185 @@
package org.codemc.worldguardwrapper.implementation.legacy;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import org.codemc.worldguardwrapper.flag.IWrappedFlag;
import org.codemc.worldguardwrapper.flag.WrappedState;
import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation;
import org.codemc.worldguardwrapper.implementation.legacy.flag.AbstractWrappedFlag;
import org.codemc.worldguardwrapper.implementation.legacy.flag.WrappedPrimitiveFlag;
import org.codemc.worldguardwrapper.implementation.legacy.flag.WrappedStatusFlag;
import org.codemc.worldguardwrapper.implementation.legacy.region.WrappedRegion;
import org.codemc.worldguardwrapper.implementation.legacy.utility.WorldGuardVectorUtilities;
import org.codemc.worldguardwrapper.region.IWrappedRegion;
import java.util.*;
import java.util.stream.Collectors;
@NoArgsConstructor
public class WorldGuardImplementation implements IWorldGuardImplementation {
private final WorldGuardPlugin 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(plugin.getRegionManager(world));
}
private Optional<ApplicableRegionSet> getApplicableRegions(@NonNull Location location) {
return getWorldManager(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))));
}
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));
}
// TODO: find a better way to define wrapper mappings and register mappings
@SuppressWarnings("unchecked")
private <T> IWrappedFlag<T> wrap(Flag<?> flag, Class<T> type) {
final IWrappedFlag<T> wrappedFlag;
if (type.equals(WrappedState.class)) {
wrappedFlag = (IWrappedFlag<T>) new WrappedStatusFlag((Flag<StateFlag.State>) flag);
} else if (type.equals(Boolean.class) || type.equals(boolean.class)) {
wrappedFlag = new WrappedPrimitiveFlag(flag);
} else if (type.equals(Double.class) || type.equals(double.class)) {
wrappedFlag = new WrappedPrimitiveFlag(flag);
} else if (type.equals(Enum.class)) {
wrappedFlag = new WrappedPrimitiveFlag(flag);
} else if (type.equals(Integer.class) || type.equals(int.class)) {
wrappedFlag = new WrappedPrimitiveFlag(flag);
} else if (type.equals(Location.class)) {
wrappedFlag = new WrappedPrimitiveFlag(flag);
} else if (type.equals(String.class)) {
wrappedFlag = new WrappedPrimitiveFlag(flag);
} else if (type.equals(Vector.class)) {
wrappedFlag = new WrappedPrimitiveFlag(flag);
} else {
throw new IllegalArgumentException("Unsupported flag type " + type.getName());
}
return wrappedFlag;
}
@Override
public JavaPlugin getWorldGuardPlugin() {
return WorldGuardPlugin.inst();
}
@Override
public int getApiVersion() {
return -6;
}
@Override
public <T> Optional<IWrappedFlag<T>> getFlag(String name, Class<T> type) {
for (Flag<?> currentFlag : DefaultFlag.getFlags()) {
if (currentFlag.getName().equalsIgnoreCase(name)) {
return Optional.of(wrap(currentFlag, type));
}
}
return Optional.empty();
}
@Override
public <T> Optional<T> queryFlag(Player player, Location location, IWrappedFlag<T> flag) {
AbstractWrappedFlag<T> wrappedFlag = (AbstractWrappedFlag<T>) flag;
return wrappedFlag.fromWGValue(queryValue(player, location, wrappedFlag.getHandle()));
}
@Override
public <T> Optional<IWrappedFlag<T>> registerFlag(String name, 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) {
return getWorldManager(world).map(regionManager -> new WrappedRegion(world, regionManager.getRegion(id)));
}
@Override
public Map<String, IWrappedRegion> getRegions(World world) {
RegionManager regionManager = plugin.getRegionManager(world);
Map<String, ProtectedRegion> regions = regionManager.getRegions();
Map<String, IWrappedRegion> map = new HashMap<>();
regions.forEach((name, region) -> map.put(name, new WrappedRegion(world, region)));
return map;
}
@Override
public Set<IWrappedRegion> getRegions(Location location) {
ApplicableRegionSet regionSet = getApplicableRegions(location).orElse(null);
Set<IWrappedRegion> set = new HashSet<>();
if (regionSet == null) {
return set;
}
regionSet.forEach(region -> set.add(new WrappedRegion(location.getWorld(), region)));
return set;
}
@Override
public Set<IWrappedRegion> getRegions(Location minimum, Location maximum) {
ApplicableRegionSet regionSet = getApplicableRegions(minimum, maximum).orElse(null);
Set<IWrappedRegion> set = new HashSet<>();
if (regionSet == null) {
return set;
}
regionSet.forEach(region -> set.add(new WrappedRegion(minimum.getWorld(), region)));
return set;
}
@Override
public Optional<IWrappedRegion> addRegion(String id, List<Location> points, int minY, int maxY) {
ProtectedRegion region;
World world = points.get(0).getWorld();
if (points.size() == 2) {
region = new ProtectedCuboidRegion(id, WorldGuardVectorUtilities.toBlockVector(points.get(0)), WorldGuardVectorUtilities.toBlockVector(points.get(1)));
} else {
region = new ProtectedPolygonalRegion(id, WorldGuardVectorUtilities.toBlockVector2DList(points), minY, maxY);
}
Optional<RegionManager> manager = getWorldManager(world);
if (manager.isPresent()) {
manager.get().addRegion(region);
return Optional.of(new WrappedRegion(world, region));
} else {
return Optional.empty();
}
}
@Override
public Optional<Set<IWrappedRegion>> removeRegion(World world, String id) {
Optional<Set<ProtectedRegion>> set = getWorldManager(world).map(manager -> manager.removeRegion(id));
return set.map(protectedRegions -> protectedRegions.stream().map(region -> new WrappedRegion(world, region))
.collect(Collectors.toSet()));
}
}

View File

@ -0,0 +1,100 @@
package org.codemc.worldguardwrapper.implementation.legacy.event;
import com.sk89q.worldguard.bukkit.event.block.UseBlockEvent;
import com.sk89q.worldguard.bukkit.event.entity.DamageEntityEvent;
import com.sk89q.worldguard.bukkit.event.entity.UseEntityEvent;
import com.sk89q.worldguard.protection.events.DisallowedPVPEvent;
import lombok.NoArgsConstructor;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Result;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.codemc.worldguardwrapper.event.*;
@NoArgsConstructor
public class EventListener implements Listener {
@EventHandler(priority = EventPriority.LOW)
public void onUseBlock(UseBlockEvent worldGuardEvent) {
Player player = worldGuardEvent.getCause().getFirstPlayer();
if (player == null) {
// Only forward player events for now
return;
}
AbstractWrappedEvent event = new WrappedUseBlockEvent(
worldGuardEvent.getOriginalEvent(),
player, worldGuardEvent.getWorld(),
worldGuardEvent.getBlocks(),
worldGuardEvent.getEffectiveMaterial());
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.getResult() != Result.DEFAULT) {
// DEFAULT = Result probably has not been touched by the handler,
// so don't touch the original result either.
worldGuardEvent.setResult(event.getResult());
}
}
@EventHandler(priority = EventPriority.LOW)
public void onUseEntity(UseEntityEvent worldGuardEvent) {
Player player = worldGuardEvent.getCause().getFirstPlayer();
if (player == null) {
// Only forward player events for now
return;
}
AbstractWrappedEvent event = new WrappedUseEntityEvent(
worldGuardEvent.getOriginalEvent(),
player,
worldGuardEvent.getTarget(),
worldGuardEvent.getEntity());
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.getResult() != Result.DEFAULT) {
// DEFAULT = Result probably has not been touched by the handler,
// so don't touch the original result either.
worldGuardEvent.setResult(event.getResult());
}
}
@EventHandler(priority = EventPriority.LOW)
public void onDamageEntity(DamageEntityEvent worldGuardEvent) {
Player player = worldGuardEvent.getCause().getFirstPlayer();
if (player == null) {
// Only forward player events for now
return;
}
AbstractWrappedEvent event = new WrappedDamageEntityEvent(
worldGuardEvent.getOriginalEvent(),
player,
worldGuardEvent.getTarget(),
worldGuardEvent.getEntity());
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.getResult() != Result.DEFAULT) {
// DEFAULT = Result probably has not been touched by the handler,
// so don't touch the original result either.
worldGuardEvent.setResult(event.getResult());
}
}
@EventHandler(priority = EventPriority.LOW)
public void onDisallowedPVP(DisallowedPVPEvent worldGuardEvent) {
AbstractWrappedEvent event = new WrappedDisallowedPVPEvent(
worldGuardEvent.getAttacker(),
worldGuardEvent.getDefender(),
worldGuardEvent.getCause());
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.getResult() != Result.DEFAULT) {
// DEFAULT = Result probably has not been touched by the handler,
// so don't touch the original result either.
worldGuardEvent.setCancelled(event.getResult() == Result.DENY);
}
}
}

View File

@ -0,0 +1,30 @@
package org.codemc.worldguardwrapper.implementation.legacy.flag;
import com.sk89q.worldguard.protection.flags.Flag;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.codemc.worldguardwrapper.flag.IWrappedFlag;
import java.util.Optional;
@AllArgsConstructor
@Getter
public abstract class AbstractWrappedFlag<T> implements IWrappedFlag<T> {
private final Flag<?> handle;
@Override
public String getName() {
return handle.getName();
}
public abstract Optional<T> fromWGValue(Object value);
public abstract Optional<Object> fromWrapperValue(T value);
@Override
public Optional<T> getDefaultValue() {
return fromWGValue(handle.getDefault());
}
}

View File

@ -0,0 +1,23 @@
package org.codemc.worldguardwrapper.implementation.legacy.flag;
import com.sk89q.worldguard.protection.flags.Flag;
import java.util.Optional;
public class WrappedPrimitiveFlag<T> extends AbstractWrappedFlag<T> {
public WrappedPrimitiveFlag(Flag<T> handle) {
super(handle);
}
@Override
public Optional<T> fromWGValue(Object value) {
return Optional.ofNullable((T) value);
}
@Override
public Optional<Object> fromWrapperValue(T value) {
return Optional.ofNullable(value);
}
}

View File

@ -0,0 +1,28 @@
package org.codemc.worldguardwrapper.implementation.legacy.flag;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import org.codemc.worldguardwrapper.flag.IWrappedStatusFlag;
import org.codemc.worldguardwrapper.flag.WrappedState;
import java.util.Optional;
public class WrappedStatusFlag extends AbstractWrappedFlag<WrappedState> implements IWrappedStatusFlag {
public WrappedStatusFlag(Flag<StateFlag.State> handle) {
super(handle);
}
@Override
public Optional<WrappedState> fromWGValue(Object value) {
return Optional.ofNullable(value)
.map(state -> state == StateFlag.State.ALLOW ? WrappedState.ALLOW : WrappedState.DENY);
}
@Override
public Optional<Object> fromWrapperValue(WrappedState value) {
return Optional.ofNullable(value)
.map(state -> state == WrappedState.ALLOW ? StateFlag.State.ALLOW : StateFlag.State.DENY);
}
}

View File

@ -0,0 +1,169 @@
package org.codemc.worldguardwrapper.implementation.legacy.region;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.bukkit.Location;
import org.bukkit.World;
import org.codemc.worldguardwrapper.flag.IWrappedFlag;
import org.codemc.worldguardwrapper.implementation.legacy.utility.WorldGuardVectorUtilities;
import org.codemc.worldguardwrapper.implementation.legacy.flag.AbstractWrappedFlag;
import org.codemc.worldguardwrapper.region.IWrappedDomain;
import org.codemc.worldguardwrapper.region.IWrappedRegion;
import org.codemc.worldguardwrapper.selection.ICuboidSelection;
import org.codemc.worldguardwrapper.selection.IPolygonalSelection;
import org.codemc.worldguardwrapper.selection.ISelection;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
@AllArgsConstructor
@Getter
public class WrappedRegion implements IWrappedRegion {
private final World world;
private final ProtectedRegion handle;
@Override
public ISelection getSelection() {
if (handle instanceof IPolygonalSelection) {
return new IPolygonalSelection() {
@Override
public Set<Location> getPoints() {
return handle.getPoints().stream()
.map(vector -> new BlockVector(vector.toVector()))
.map(vector -> WorldGuardVectorUtilities.fromBlockVector(world, vector))
.collect(Collectors.toSet());
}
@Override
public int getMinimumY() {
return ((IPolygonalSelection) handle).getMinimumY();
}
@Override
public int getMaximumY() {
return ((IPolygonalSelection) handle).getMaximumY();
}
};
}
return new ICuboidSelection() {
@Override
public Location getMinimumPoint() {
return WorldGuardVectorUtilities.fromBlockVector(world, handle.getMinimumPoint());
}
@Override
public Location getMaximumPoint() {
return WorldGuardVectorUtilities.fromBlockVector(world, handle.getMaximumPoint());
}
};
}
@Override
public String getId() {
return handle.getId();
}
@SuppressWarnings("unchecked")
@Override
public <T> Optional<T> getFlag(IWrappedFlag<T> flag) {
AbstractWrappedFlag<T> wrappedFlag = (AbstractWrappedFlag<T>) flag;
return Optional.ofNullable(handle.getFlag(wrappedFlag.getHandle()))
.map(value -> (T) wrappedFlag.fromWGValue(value));
}
@SuppressWarnings("unchecked")
@Override
public <T> void setFlag(IWrappedFlag<T> flag, T value) {
AbstractWrappedFlag<T> wrappedFlag = (AbstractWrappedFlag<T>) flag;
handle.setFlag((Flag<Object>) wrappedFlag.getHandle(), wrappedFlag.fromWrapperValue(value).orElse(null));
}
@Override
public int getPriority() {
return handle.getPriority();
}
@Override
public IWrappedDomain getOwners() {
return new IWrappedDomain() {
@Override
public Set<UUID> getPlayers() {
return handle.getOwners().getUniqueIds();
}
@Override
public void addPlayer(UUID uuid) {
handle.getOwners().addPlayer(uuid);
}
@Override
public void removePlayer(UUID uuid) {
handle.getOwners().removePlayer(uuid);
}
@Override
public Set<String> getGroups() {
return handle.getOwners().getGroups();
}
@Override
public void addGroup(String name) {
handle.getOwners().addGroup(name);
}
@Override
public void removeGroup(String name) {
handle.getOwners().removeGroup(name);
}
};
}
@Override
public IWrappedDomain getMembers() {
return new IWrappedDomain() {
@Override
public Set<UUID> getPlayers() {
return handle.getMembers().getUniqueIds();
}
@Override
public void addPlayer(UUID uuid) {
handle.getMembers().addPlayer(uuid);
}
@Override
public void removePlayer(UUID uuid) {
handle.getMembers().removePlayer(uuid);
}
@Override
public Set<String> getGroups() {
return handle.getMembers().getGroups();
}
@Override
public void addGroup(String name) {
handle.getMembers().addGroup(name);
}
@Override
public void removeGroup(String name) {
handle.getMembers().removeGroup(name);
}
};
}
@Override
public boolean contains(Location location) {
return handle.contains(WorldGuardVectorUtilities.toBlockVector(location));
}
}

View File

@ -0,0 +1,27 @@
package org.codemc.worldguardwrapper.implementation.legacy.utility;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.BlockVector2D;
import lombok.experimental.UtilityClass;
import org.bukkit.Location;
import org.bukkit.World;
import java.util.List;
import java.util.stream.Collectors;
@UtilityClass
public class WorldGuardVectorUtilities {
public BlockVector toBlockVector(Location location) {
return new BlockVector(location.getX(), location.getY(), location.getZ());
}
public Location fromBlockVector(World world, BlockVector vector) {
return new Location(world, vector.getX(), vector.getY(), vector.getZ());
}
public List<BlockVector2D> toBlockVector2DList(List<Location> locations) {
return locations.stream().map(location -> new BlockVector2D(location.getX(), location.getZ())).collect(Collectors.toList());
}
}

View File

@ -7,13 +7,14 @@
<parent> <parent>
<groupId>org.codemc.worldguardwrapper</groupId> <groupId>org.codemc.worldguardwrapper</groupId>
<artifactId>worldguardwrapper-parent</artifactId> <artifactId>worldguardwrapper-parent</artifactId>
<version>1.1.3-SNAPSHOT</version> <version>1.1.4-SNAPSHOT</version>
</parent> </parent>
<artifactId>worldguardwrapper-implementation</artifactId> <artifactId>worldguardwrapper-implementation</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>
<modules> <modules>
<module>legacy</module>
<module>v6</module> <module>v6</module>
<module>v7</module> <module>v7</module>
<module>v7fawe</module> <module>v7fawe</module>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.codemc.worldguardwrapper</groupId> <groupId>org.codemc.worldguardwrapper</groupId>
<artifactId>worldguardwrapper-implementation</artifactId> <artifactId>worldguardwrapper-implementation</artifactId>
<version>1.1.3-SNAPSHOT</version> <version>1.1.4-SNAPSHOT</version>
</parent> </parent>
<artifactId>worldguardwrapper-implementation-v6</artifactId> <artifactId>worldguardwrapper-implementation-v6</artifactId>
@ -28,7 +28,7 @@
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>worldguardwrapper-api</artifactId> <artifactId>worldguardwrapper-api</artifactId>
<version>1.1.3-SNAPSHOT</version> <version>1.1.4-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.codemc.worldguardwrapper</groupId> <groupId>org.codemc.worldguardwrapper</groupId>
<artifactId>worldguardwrapper-implementation</artifactId> <artifactId>worldguardwrapper-implementation</artifactId>
<version>1.1.3-SNAPSHOT</version> <version>1.1.4-SNAPSHOT</version>
</parent> </parent>
<artifactId>worldguardwrapper-implementation-v7</artifactId> <artifactId>worldguardwrapper-implementation-v7</artifactId>
@ -28,7 +28,7 @@
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>worldguardwrapper-api</artifactId> <artifactId>worldguardwrapper-api</artifactId>
<version>1.1.3-SNAPSHOT</version> <version>1.1.4-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.codemc.worldguardwrapper</groupId> <groupId>org.codemc.worldguardwrapper</groupId>
<artifactId>worldguardwrapper-implementation</artifactId> <artifactId>worldguardwrapper-implementation</artifactId>
<version>1.1.3-SNAPSHOT</version> <version>1.1.4-SNAPSHOT</version>
</parent> </parent>
<artifactId>worldguardwrapper-implementation-v7-fawe</artifactId> <artifactId>worldguardwrapper-implementation-v7-fawe</artifactId>
@ -35,7 +35,7 @@
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>worldguardwrapper-api</artifactId> <artifactId>worldguardwrapper-api</artifactId>
<version>1.1.3-SNAPSHOT</version> <version>1.1.4-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.codemc.worldguardwrapper</groupId> <groupId>org.codemc.worldguardwrapper</groupId>
<artifactId>worldguardwrapper-parent</artifactId> <artifactId>worldguardwrapper-parent</artifactId>
<version>1.1.3-SNAPSHOT</version> <version>1.1.4-SNAPSHOT</version>
</parent> </parent>
<artifactId>worldguardwrapper</artifactId> <artifactId>worldguardwrapper</artifactId>
@ -18,22 +18,27 @@
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>worldguardwrapper-api</artifactId> <artifactId>worldguardwrapper-api</artifactId>
<version>1.1.3-SNAPSHOT</version> <version>1.1.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>worldguardwrapper-implementation-legacy</artifactId>
<version>1.1.4-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>worldguardwrapper-implementation-v6</artifactId> <artifactId>worldguardwrapper-implementation-v6</artifactId>
<version>1.1.3-SNAPSHOT</version> <version>1.1.4-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>worldguardwrapper-implementation-v7</artifactId> <artifactId>worldguardwrapper-implementation-v7</artifactId>
<version>1.1.3-SNAPSHOT</version> <version>1.1.4-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>worldguardwrapper-implementation-v7-fawe</artifactId> <artifactId>worldguardwrapper-implementation-v7-fawe</artifactId>
<version>1.1.3-SNAPSHOT</version> <version>1.1.4-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -27,16 +27,24 @@ public class WorldGuardWrapper implements IWorldGuardImplementation {
private Listener listener; private Listener listener;
private WorldGuardWrapper() { private WorldGuardWrapper() {
boolean legacy; int targetVersion;
try { try {
Class.forName("com.sk89q.worldguard.WorldGuard"); Class.forName("com.sk89q.worldguard.WorldGuard");
legacy = false; targetVersion = 7;
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
legacy = true; try {
Class.forName("com.sk89q.worldguard.protection.flags.registry.FlagRegistry");
targetVersion = 6;
} catch (ClassNotFoundException e1) {
targetVersion = -6;
} }
if (legacy) { }
if (targetVersion == 6) {
implementation = new org.codemc.worldguardwrapper.implementation.v6.WorldGuardImplementation(); implementation = new org.codemc.worldguardwrapper.implementation.v6.WorldGuardImplementation();
listener = new org.codemc.worldguardwrapper.implementation.v6.event.EventListener(); listener = new org.codemc.worldguardwrapper.implementation.v6.event.EventListener();
} else if (targetVersion == -6) {
implementation = new org.codemc.worldguardwrapper.implementation.legacy.WorldGuardImplementation();
listener = new org.codemc.worldguardwrapper.implementation.legacy.event.EventListener();
} else { } else {
if (Bukkit.getPluginManager().isPluginEnabled("FastAsyncWorldEdit")) { if (Bukkit.getPluginManager().isPluginEnabled("FastAsyncWorldEdit")) {
implementation = new org.codemc.worldguardwrapper.implementation.v7fawe.WorldGuardImplementation(); implementation = new org.codemc.worldguardwrapper.implementation.v7fawe.WorldGuardImplementation();

View File

@ -6,7 +6,7 @@
<groupId>org.codemc.worldguardwrapper</groupId> <groupId>org.codemc.worldguardwrapper</groupId>
<artifactId>worldguardwrapper-parent</artifactId> <artifactId>worldguardwrapper-parent</artifactId>
<version>1.1.3-SNAPSHOT</version> <version>1.1.4-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<modules> <modules>