mirror of
https://github.com/CodeMC/WorldGuardWrapper.git
synced 2025-01-18 12:12:37 +01:00
Actually make it work... + Cleanup
This commit is contained in:
parent
c57c0c9df5
commit
5edc204685
10
.github/dependabot.yml
vendored
10
.github/dependabot.yml
vendored
|
@ -1,7 +1,7 @@
|
|||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: maven
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: daily
|
||||
open-pull-requests-limit: 10
|
||||
- package-ecosystem: maven
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: daily
|
||||
open-pull-requests-limit: 10
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.codemc.worldguardwrapper.implementation.legacy.flag;
|
||||
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.codemc.worldguardwrapper.implementation.legacy.utility.WorldGuardFlagUtilities;
|
||||
|
|
|
@ -10,20 +10,16 @@ import lombok.Getter;
|
|||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
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.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.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@AllArgsConstructor
|
||||
|
|
|
@ -4,7 +4,7 @@ import com.google.common.collect.Maps;
|
|||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
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.WrappedStatusFlag;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@UtilityClass
|
||||
|
|
|
@ -24,4 +24,11 @@
|
|||
<properties>
|
||||
<maven.deploy.skip>true</maven.deploy.skip>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.javassist</groupId>
|
||||
<artifactId>javassist</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
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.sk89q.minecraft.util.commands.CommandException;
|
||||
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.ProtectedPolygonalRegion;
|
||||
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 javassist.util.proxy.ProxyFactory;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
@ -33,6 +31,7 @@ import org.codemc.worldguardwrapper.flag.WrappedState;
|
|||
import org.codemc.worldguardwrapper.handler.IHandler;
|
||||
import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation;
|
||||
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.utility.WorldGuardFlagUtilities;
|
||||
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.ISelection;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -86,7 +86,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
.orElse(null), flag));
|
||||
}
|
||||
|
||||
private IWrappedRegionSet wrapRegionSet(@NonNull World world, @NonNull ApplicableRegionSet regionSet) {
|
||||
public IWrappedRegionSet wrapRegionSet(@NonNull World world, @NonNull ApplicableRegionSet regionSet) {
|
||||
return new IWrappedRegionSet() {
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
|
@ -156,43 +156,29 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
|
||||
@Override
|
||||
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>() {
|
||||
@Override
|
||||
public Handler create(Session session) {
|
||||
IHandler handler = factory.get();
|
||||
return new Handler(session) {
|
||||
@Override
|
||||
public void initialize(Player player, Location current, ApplicableRegionSet set) {
|
||||
handler.initialize(player, current, wrapRegionSet(current.getWorld(), set));
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
};
|
||||
try {
|
||||
return handlerConstructor.newInstance(WorldGuardImplementation.this, handler, session);
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.codemc.worldguardwrapper.implementation.v6.flag;
|
||||
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.codemc.worldguardwrapper.implementation.v6.utility.WorldGuardFlagUtilities;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ import com.google.common.collect.Maps;
|
|||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
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.WrappedStatusFlag;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@UtilityClass
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
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.sk89q.minecraft.util.commands.CommandException;
|
||||
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.ProtectedPolygonalRegion;
|
||||
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 javassist.util.proxy.ProxyFactory;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
@ -38,6 +36,7 @@ import org.codemc.worldguardwrapper.flag.WrappedState;
|
|||
import org.codemc.worldguardwrapper.handler.IHandler;
|
||||
import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation;
|
||||
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.utility.WorldGuardFlagUtilities;
|
||||
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.ISelection;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -92,7 +92,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
.orElse(null), flag));
|
||||
}
|
||||
|
||||
private IWrappedRegionSet wrapRegionSet(@NonNull World world, @NonNull ApplicableRegionSet regionSet) {
|
||||
public IWrappedRegionSet wrapRegionSet(@NonNull World world, @NonNull ApplicableRegionSet regionSet) {
|
||||
return new IWrappedRegionSet() {
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
|
@ -162,53 +162,29 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
|||
|
||||
@Override
|
||||
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>() {
|
||||
@Override
|
||||
public Handler create(Session session) {
|
||||
IHandler handler = factory.get();
|
||||
return new Handler(session) {
|
||||
@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, 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;
|
||||
}
|
||||
};
|
||||
try {
|
||||
return handlerConstructor.newInstance(WorldGuardImplementation.this, handler, session);
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.codemc.worldguardwrapper.implementation.v7.flag;
|
|||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.codemc.worldguardwrapper.implementation.v7.utility.WorldGuardFlagUtilities;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -19,21 +19,25 @@
|
|||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-api</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-implementation-legacy</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-implementation-v6</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>worldguardwrapper-implementation-v7</artifactId>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -42,6 +46,14 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<configuration>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>javassist</pattern>
|
||||
<shadedPattern>org.codemc.worldguardwrapper.shaded.javassist</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
|
|
66
pom.xml
66
pom.xml
|
@ -61,36 +61,55 @@
|
|||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>${spigot-api.version}</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-chat</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.16</version>
|
||||
<scope>provided</scope>
|
||||
</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>
|
||||
<version>${spigot-api.version}</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-chat</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.16</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -150,6 +169,9 @@
|
|||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
|
Loading…
Reference in New Issue
Block a user