Actually make it work... + Cleanup

This commit is contained in:
Gabriele C 2020-10-22 03:33:33 +02:00
parent c57c0c9df5
commit 5edc204685
14 changed files with 260 additions and 128 deletions

View File

@ -1,7 +1,6 @@
package org.codemc.worldguardwrapper.implementation.legacy.flag; package org.codemc.worldguardwrapper.implementation.legacy.flag;
import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.Flag;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.codemc.worldguardwrapper.implementation.legacy.utility.WorldGuardFlagUtilities; import org.codemc.worldguardwrapper.implementation.legacy.utility.WorldGuardFlagUtilities;

View File

@ -10,20 +10,16 @@ import lombok.Getter;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.codemc.worldguardwrapper.flag.IWrappedFlag; import org.codemc.worldguardwrapper.flag.IWrappedFlag;
import org.codemc.worldguardwrapper.implementation.legacy.flag.AbstractWrappedFlag;
import org.codemc.worldguardwrapper.implementation.legacy.utility.WorldGuardFlagUtilities; import org.codemc.worldguardwrapper.implementation.legacy.utility.WorldGuardFlagUtilities;
import org.codemc.worldguardwrapper.implementation.legacy.utility.WorldGuardVectorUtilities; 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.IWrappedDomain;
import org.codemc.worldguardwrapper.region.IWrappedRegion; import org.codemc.worldguardwrapper.region.IWrappedRegion;
import org.codemc.worldguardwrapper.selection.ICuboidSelection; import org.codemc.worldguardwrapper.selection.ICuboidSelection;
import org.codemc.worldguardwrapper.selection.IPolygonalSelection; import org.codemc.worldguardwrapper.selection.IPolygonalSelection;
import org.codemc.worldguardwrapper.selection.ISelection; import org.codemc.worldguardwrapper.selection.ISelection;
import java.util.HashMap; import java.util.*;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@AllArgsConstructor @AllArgsConstructor

View File

@ -4,7 +4,7 @@ import com.google.common.collect.Maps;
import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.StateFlag; import com.sk89q.worldguard.protection.flags.StateFlag;
import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -15,8 +15,6 @@ import org.codemc.worldguardwrapper.implementation.legacy.flag.AbstractWrappedFl
import org.codemc.worldguardwrapper.implementation.legacy.flag.WrappedPrimitiveFlag; import org.codemc.worldguardwrapper.implementation.legacy.flag.WrappedPrimitiveFlag;
import org.codemc.worldguardwrapper.implementation.legacy.flag.WrappedStatusFlag; import org.codemc.worldguardwrapper.implementation.legacy.flag.WrappedStatusFlag;
import lombok.experimental.UtilityClass;
import java.util.Map; import java.util.Map;
@UtilityClass @UtilityClass

View File

@ -24,4 +24,11 @@
<properties> <properties>
<maven.deploy.skip>true</maven.deploy.skip> <maven.deploy.skip>true</maven.deploy.skip>
</properties> </properties>
<dependencies>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
</dependency>
</dependencies>
</project> </project>

View File

@ -1,7 +1,5 @@
package org.codemc.worldguardwrapper.implementation.v6; package org.codemc.worldguardwrapper.implementation.v6;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterators; import com.google.common.collect.Iterators;
import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.BlockVector;
@ -18,9 +16,9 @@ import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion; import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.session.MoveType;
import com.sk89q.worldguard.session.Session; import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler; import com.sk89q.worldguard.session.handler.Handler;
import javassist.util.proxy.ProxyFactory;
import lombok.NonNull; import lombok.NonNull;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
@ -33,6 +31,7 @@ import org.codemc.worldguardwrapper.flag.WrappedState;
import org.codemc.worldguardwrapper.handler.IHandler; import org.codemc.worldguardwrapper.handler.IHandler;
import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation; import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation;
import org.codemc.worldguardwrapper.implementation.v6.flag.AbstractWrappedFlag; import org.codemc.worldguardwrapper.implementation.v6.flag.AbstractWrappedFlag;
import org.codemc.worldguardwrapper.implementation.v6.handler.ProxyHandler;
import org.codemc.worldguardwrapper.implementation.v6.region.WrappedRegion; import org.codemc.worldguardwrapper.implementation.v6.region.WrappedRegion;
import org.codemc.worldguardwrapper.implementation.v6.utility.WorldGuardFlagUtilities; import org.codemc.worldguardwrapper.implementation.v6.utility.WorldGuardFlagUtilities;
import org.codemc.worldguardwrapper.implementation.v6.utility.WorldGuardVectorUtilities; import org.codemc.worldguardwrapper.implementation.v6.utility.WorldGuardVectorUtilities;
@ -42,7 +41,8 @@ import org.codemc.worldguardwrapper.selection.ICuboidSelection;
import org.codemc.worldguardwrapper.selection.IPolygonalSelection; import org.codemc.worldguardwrapper.selection.IPolygonalSelection;
import org.codemc.worldguardwrapper.selection.ISelection; import org.codemc.worldguardwrapper.selection.ISelection;
import javax.annotation.Nullable; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.*; import java.util.*;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -86,7 +86,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
.orElse(null), flag)); .orElse(null), flag));
} }
private IWrappedRegionSet wrapRegionSet(@NonNull World world, @NonNull ApplicableRegionSet regionSet) { public IWrappedRegionSet wrapRegionSet(@NonNull World world, @NonNull ApplicableRegionSet regionSet) {
return new IWrappedRegionSet() { return new IWrappedRegionSet() {
@SuppressWarnings("NullableProblems") @SuppressWarnings("NullableProblems")
@ -156,43 +156,29 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
@Override @Override
public void registerHandler(Supplier<IHandler> factory) { public void registerHandler(Supplier<IHandler> factory) {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setUseCache(false);
proxyFactory.setSuperclass(ProxyHandler.class);
Class<? extends ProxyHandler> handlerClass;
Constructor<? extends ProxyHandler> handlerConstructor;
try {
//noinspection unchecked
handlerClass = (Class<? extends ProxyHandler>) proxyFactory.createClass();
handlerConstructor = handlerClass.getDeclaredConstructor(WorldGuardImplementation.class, IHandler.class, Session.class);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
worldGuardPlugin.getSessionManager().registerHandler(new Handler.Factory<Handler>() { worldGuardPlugin.getSessionManager().registerHandler(new Handler.Factory<Handler>() {
@Override @Override
public Handler create(Session session) { public Handler create(Session session) {
IHandler handler = factory.get(); IHandler handler = factory.get();
return new Handler(session) { try {
@Override return handlerConstructor.newInstance(WorldGuardImplementation.this, handler, session);
public void initialize(Player player, Location current, ApplicableRegionSet set) { } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
handler.initialize(player, current, wrapRegionSet(current.getWorld(), set)); throw new RuntimeException(e);
} }
@Override
public boolean testMoveTo(Player player, Location from, Location to, ApplicableRegionSet toSet, MoveType moveType) {
return handler.testMoveTo(player, from, to, wrapRegionSet(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, wrapRegionSet(to.getWorld(), toSet), mappedEntered, mappedExited, moveType.name());
}
@Override
public void tick(Player player, ApplicableRegionSet set) {
handler.tick(player, wrapRegionSet(player.getWorld(), set));
}
@Nullable
@Override
public StateFlag.State getInvincibility(Player player) {
WrappedState state = handler.getInvincibility(player);
if (state == null) {
return null;
}
return state == WrappedState.ALLOW ? StateFlag.State.ALLOW : StateFlag.State.DENY;
}
};
} }
}, null); }, null);
} }

View File

@ -1,7 +1,6 @@
package org.codemc.worldguardwrapper.implementation.v6.flag; package org.codemc.worldguardwrapper.implementation.v6.flag;
import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.Flag;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.codemc.worldguardwrapper.implementation.v6.utility.WorldGuardFlagUtilities; import org.codemc.worldguardwrapper.implementation.v6.utility.WorldGuardFlagUtilities;

View File

@ -0,0 +1,64 @@
package org.codemc.worldguardwrapper.implementation.v6.handler;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableSet;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.session.MoveType;
import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.codemc.worldguardwrapper.flag.WrappedState;
import org.codemc.worldguardwrapper.handler.IHandler;
import org.codemc.worldguardwrapper.implementation.v6.WorldGuardImplementation;
import org.codemc.worldguardwrapper.implementation.v6.region.WrappedRegion;
import org.codemc.worldguardwrapper.region.IWrappedRegion;
import javax.annotation.Nullable;
import java.util.Set;
public class ProxyHandler extends Handler {
private final WorldGuardImplementation implementation;
private final IHandler handler;
public ProxyHandler(WorldGuardImplementation implementation, IHandler handler, Session session) {
super(session);
this.implementation = implementation;
this.handler = handler;
}
@Override
public void initialize(Player player, Location current, ApplicableRegionSet set) {
handler.initialize(player, current, implementation.wrapRegionSet(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());
}
@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());
}
@Override
public void tick(Player player, ApplicableRegionSet set) {
handler.tick(player, implementation.wrapRegionSet(player.getWorld(), set));
}
@Nullable
@Override
public StateFlag.State getInvincibility(Player player) {
WrappedState state = handler.getInvincibility(player);
if (state == null) {
return null;
}
return state == WrappedState.ALLOW ? StateFlag.State.ALLOW : StateFlag.State.DENY;
}
}

View File

@ -4,7 +4,7 @@ import com.google.common.collect.Maps;
import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.StateFlag; import com.sk89q.worldguard.protection.flags.StateFlag;
import lombok.experimental.UtilityClass;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@ -14,8 +14,6 @@ import org.codemc.worldguardwrapper.implementation.v6.flag.AbstractWrappedFlag;
import org.codemc.worldguardwrapper.implementation.v6.flag.WrappedPrimitiveFlag; import org.codemc.worldguardwrapper.implementation.v6.flag.WrappedPrimitiveFlag;
import org.codemc.worldguardwrapper.implementation.v6.flag.WrappedStatusFlag; import org.codemc.worldguardwrapper.implementation.v6.flag.WrappedStatusFlag;
import lombok.experimental.UtilityClass;
import java.util.Map; import java.util.Map;
@UtilityClass @UtilityClass

View File

@ -1,7 +1,5 @@
package org.codemc.worldguardwrapper.implementation.v7; package org.codemc.worldguardwrapper.implementation.v7;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterators; import com.google.common.collect.Iterators;
import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.IncompleteRegionException;
@ -23,9 +21,9 @@ import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion; import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.session.MoveType;
import com.sk89q.worldguard.session.Session; import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler; import com.sk89q.worldguard.session.handler.Handler;
import javassist.util.proxy.ProxyFactory;
import lombok.NonNull; import lombok.NonNull;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
@ -38,6 +36,7 @@ import org.codemc.worldguardwrapper.flag.WrappedState;
import org.codemc.worldguardwrapper.handler.IHandler; import org.codemc.worldguardwrapper.handler.IHandler;
import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation; import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation;
import org.codemc.worldguardwrapper.implementation.v7.flag.AbstractWrappedFlag; import org.codemc.worldguardwrapper.implementation.v7.flag.AbstractWrappedFlag;
import org.codemc.worldguardwrapper.implementation.v7.handler.ProxyHandler;
import org.codemc.worldguardwrapper.implementation.v7.region.WrappedRegion; import org.codemc.worldguardwrapper.implementation.v7.region.WrappedRegion;
import org.codemc.worldguardwrapper.implementation.v7.utility.WorldGuardFlagUtilities; import org.codemc.worldguardwrapper.implementation.v7.utility.WorldGuardFlagUtilities;
import org.codemc.worldguardwrapper.region.IWrappedRegion; import org.codemc.worldguardwrapper.region.IWrappedRegion;
@ -46,7 +45,8 @@ import org.codemc.worldguardwrapper.selection.ICuboidSelection;
import org.codemc.worldguardwrapper.selection.IPolygonalSelection; import org.codemc.worldguardwrapper.selection.IPolygonalSelection;
import org.codemc.worldguardwrapper.selection.ISelection; import org.codemc.worldguardwrapper.selection.ISelection;
import javax.annotation.Nullable; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.*; import java.util.*;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -92,7 +92,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
.orElse(null), flag)); .orElse(null), flag));
} }
private IWrappedRegionSet wrapRegionSet(@NonNull World world, @NonNull ApplicableRegionSet regionSet) { public IWrappedRegionSet wrapRegionSet(@NonNull World world, @NonNull ApplicableRegionSet regionSet) {
return new IWrappedRegionSet() { return new IWrappedRegionSet() {
@SuppressWarnings("NullableProblems") @SuppressWarnings("NullableProblems")
@ -162,53 +162,29 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
@Override @Override
public void registerHandler(Supplier<IHandler> factory) { public void registerHandler(Supplier<IHandler> factory) {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setUseCache(false);
proxyFactory.setSuperclass(ProxyHandler.class);
Class<? extends ProxyHandler> handlerClass;
Constructor<? extends ProxyHandler> handlerConstructor;
try {
//noinspection unchecked
handlerClass = (Class<? extends ProxyHandler>) proxyFactory.createClass();
handlerConstructor = handlerClass.getDeclaredConstructor(WorldGuardImplementation.class, IHandler.class, Session.class);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
core.getPlatform().getSessionManager().registerHandler(new Handler.Factory<Handler>() { core.getPlatform().getSessionManager().registerHandler(new Handler.Factory<Handler>() {
@Override @Override
public Handler create(Session session) { public Handler create(Session session) {
IHandler handler = factory.get(); IHandler handler = factory.get();
return new Handler(session) { try {
@Override return handlerConstructor.newInstance(WorldGuardImplementation.this, handler, session);
public void initialize(LocalPlayer player, com.sk89q.worldedit.util.Location current, ApplicableRegionSet set) { } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
Player bukkitPlayer = BukkitAdapter.adapt(player); throw new RuntimeException(e);
Location bukkitLocation = BukkitAdapter.adapt(current);
handler.initialize(bukkitPlayer, bukkitLocation, wrapRegionSet(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) {
Player bukkitPlayer = BukkitAdapter.adapt(player);
Location bukkitFrom = BukkitAdapter.adapt(from);
Location bukkitTo = BukkitAdapter.adapt(to);
return handler.testMoveTo(bukkitPlayer, bukkitFrom, bukkitTo, wrapRegionSet(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) {
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, wrapRegionSet(bukkitTo.getWorld(), toSet), mappedEntered, mappedExited, moveType.name());
}
@Override
public void tick(LocalPlayer player, ApplicableRegionSet set) {
Player bukkitPlayer = BukkitAdapter.adapt(player);
handler.tick(bukkitPlayer, wrapRegionSet(bukkitPlayer.getWorld(), set));
}
@Nullable
@Override
public StateFlag.State getInvincibility(LocalPlayer player) {
Player bukkitPlayer = BukkitAdapter.adapt(player);
WrappedState state = handler.getInvincibility(bukkitPlayer);
if (state == null) {
return null;
}
return state == WrappedState.ALLOW ? StateFlag.State.ALLOW : StateFlag.State.DENY;
}
};
} }
}, null); }, null);
} }

View File

@ -3,7 +3,6 @@ package org.codemc.worldguardwrapper.implementation.v7.flag;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.Flag;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.codemc.worldguardwrapper.implementation.v7.utility.WorldGuardFlagUtilities; import org.codemc.worldguardwrapper.implementation.v7.utility.WorldGuardFlagUtilities;

View File

@ -0,0 +1,76 @@
package org.codemc.worldguardwrapper.implementation.v7.handler;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableSet;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.session.MoveType;
import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.codemc.worldguardwrapper.flag.WrappedState;
import org.codemc.worldguardwrapper.handler.IHandler;
import org.codemc.worldguardwrapper.implementation.v7.WorldGuardImplementation;
import org.codemc.worldguardwrapper.implementation.v7.region.WrappedRegion;
import org.codemc.worldguardwrapper.region.IWrappedRegion;
import javax.annotation.Nullable;
import java.util.Set;
public class ProxyHandler extends Handler {
private final WorldGuardImplementation implementation;
private final IHandler handler;
public ProxyHandler(WorldGuardImplementation implementation, IHandler handler, Session session) {
super(session);
this.implementation = implementation;
this.handler = handler;
}
@Override
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));
}
@Override
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());
}
@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) {
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());
}
@Override
public void tick(LocalPlayer player, ApplicableRegionSet set) {
Player bukkitPlayer = BukkitAdapter.adapt(player);
handler.tick(bukkitPlayer, implementation.wrapRegionSet(bukkitPlayer.getWorld(), set));
}
@Nullable
@Override
public StateFlag.State getInvincibility(LocalPlayer player) {
Player bukkitPlayer = BukkitAdapter.adapt(player);
WrappedState state = handler.getInvincibility(bukkitPlayer);
if (state == null) {
return null;
}
return state == WrappedState.ALLOW ? StateFlag.State.ALLOW : StateFlag.State.DENY;
}
}

View File

@ -19,21 +19,25 @@
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>worldguardwrapper-api</artifactId> <artifactId>worldguardwrapper-api</artifactId>
<version>1.2.0-SNAPSHOT</version> <version>1.2.0-SNAPSHOT</version>
<optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>worldguardwrapper-implementation-legacy</artifactId> <artifactId>worldguardwrapper-implementation-legacy</artifactId>
<version>1.2.0-SNAPSHOT</version> <version>1.2.0-SNAPSHOT</version>
<optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>worldguardwrapper-implementation-v6</artifactId> <artifactId>worldguardwrapper-implementation-v6</artifactId>
<version>1.2.0-SNAPSHOT</version> <version>1.2.0-SNAPSHOT</version>
<optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>worldguardwrapper-implementation-v7</artifactId> <artifactId>worldguardwrapper-implementation-v7</artifactId>
<version>1.2.0-SNAPSHOT</version> <version>1.2.0-SNAPSHOT</version>
<optional>true</optional>
</dependency> </dependency>
</dependencies> </dependencies>
@ -42,6 +46,14 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<configuration>
<relocations>
<relocation>
<pattern>javassist</pattern>
<shadedPattern>org.codemc.worldguardwrapper.shaded.javassist</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>

22
pom.xml
View File

@ -61,6 +61,7 @@
</repository> </repository>
</repositories> </repositories>
<dependencyManagement>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
@ -92,6 +93,24 @@
<version>1.18.16</version> <version>1.18.16</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.27.0-GA</version>
<optional>true</optional>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
@ -150,6 +169,9 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version> <version>3.2.4</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>