Nearly done with waitingrows!
This commit is contained in:
parent
0c53cfae5e
commit
761dd4bf30
13 changed files with 437 additions and 139 deletions
|
@ -28,7 +28,7 @@ public class LGUtil {
|
|||
private static Object lampAanData;
|
||||
private static Object lampUitData;
|
||||
|
||||
public LGUtil() throws ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
public LGUtil() {
|
||||
offsets.add(new Vector(1, 0, 0));
|
||||
offsets.add(new Vector(-1, 0, 0));
|
||||
offsets.add(new Vector(0, 1, 0));
|
||||
|
@ -36,16 +36,17 @@ public class LGUtil {
|
|||
offsets.add(new Vector(0, 0, 1));
|
||||
offsets.add(new Vector(0, 0, -1));
|
||||
|
||||
Class<?> blockDataClass = Class.forName("org.bukkit.block.data.BlockData");
|
||||
Method methodCreateBlockData = Bukkit.class.getMethod("createBlockData", String.class);
|
||||
getBlockDataMethod = Block.class.getMethod("getBlockData");
|
||||
setBlockDataMethod = Block.class.getMethod("setBlockData", blockDataClass,
|
||||
Boolean.TYPE);
|
||||
getAsStringMethod = blockDataClass.getMethod("getAsString");
|
||||
lampAanData = methodCreateBlockData.invoke(null, "minecraft:redstone_lamp[lit=true]");
|
||||
lampUitData = methodCreateBlockData.invoke(null, "minecraft:redstone_lamp[lit=false]");
|
||||
|
||||
nieuweVersie = true;
|
||||
try {
|
||||
Class<?> blockDataClass = Class.forName("org.bukkit.block.data.BlockData");
|
||||
Method methodCreateBlockData = Bukkit.class.getMethod("createBlockData", String.class);
|
||||
getBlockDataMethod = Block.class.getMethod("getBlockData");
|
||||
setBlockDataMethod = Block.class.getMethod("setBlockData", blockDataClass,
|
||||
Boolean.TYPE);
|
||||
getAsStringMethod = blockDataClass.getMethod("getAsString");
|
||||
lampAanData = methodCreateBlockData.invoke(null, "minecraft:redstone_lamp[lit=true]");
|
||||
lampUitData = methodCreateBlockData.invoke(null, "minecraft:redstone_lamp[lit=false]");
|
||||
nieuweVersie = true;
|
||||
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {}
|
||||
}
|
||||
|
||||
public static boolean zetLampAan(Block lampBlock) {
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package nl.sbdeveloper.themeparkplus.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class Reflection {
|
||||
private static String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
|
||||
@Nullable
|
||||
public static Class<?> getCraftBukkitClass(String name) {
|
||||
try {
|
||||
return Class.forName("org.bukkit.craftbukkit." + version + "." + name);
|
||||
} catch (ClassNotFoundException var2) {
|
||||
var2.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Class<?> getNMSClass(String name) {
|
||||
try {
|
||||
return Class.forName("net.minecraft.server." + version + "." + name);
|
||||
} catch (ClassNotFoundException var2) {
|
||||
var2.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Class<?> getClass(String name) {
|
||||
try {
|
||||
return Class.forName(name);
|
||||
} catch (ClassNotFoundException var2) {
|
||||
var2.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
package nl.sbdeveloper.themeparkplus.util;
|
||||
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class WEUtil {
|
||||
private static WorldEditPlugin wep;
|
||||
|
||||
public WEUtil() {
|
||||
wep = (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Region getSelection(Player p) {
|
||||
LocalSession session;
|
||||
try {
|
||||
session = wep.getSession(p);
|
||||
} catch (Exception e) {
|
||||
// sometimes after a reload getSession create errors with WorldEdit, this prevent error spam
|
||||
return null;
|
||||
}
|
||||
|
||||
return getSelectedRegion(session);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Region getSelectedRegion(@Nullable LocalSession session) {
|
||||
if (session != null && session.getSelectionWorld() != null) {
|
||||
RegionSelector selector = session.getRegionSelector(session.getSelectionWorld());
|
||||
|
||||
if (selector.isDefined()) {
|
||||
try {
|
||||
return selector.getRegion();
|
||||
} catch (IncompleteRegionException e) {
|
||||
Bukkit.getLogger().warning("[ThemeParkPlus] Region still incomplete");
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,195 @@
|
|||
package nl.sbdeveloper.themeparkplus.util;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class WorldGuardLegacyManager {
|
||||
|
||||
private static String wgVerStr = null;
|
||||
private static WorldGuardLegacyManager instance = null;
|
||||
|
||||
public static WorldGuardLegacyManager getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new WorldGuardLegacyManager();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public WorldGuardPlugin getWorldGuard() {
|
||||
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
|
||||
if (!(plugin instanceof WorldGuardPlugin)) {
|
||||
return null;
|
||||
}
|
||||
return (WorldGuardPlugin) plugin;
|
||||
}
|
||||
|
||||
public WorldEditPlugin getWorldEdit() {
|
||||
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
if (!(plugin instanceof WorldEditPlugin)) {
|
||||
return null;
|
||||
}
|
||||
return (WorldEditPlugin) plugin;
|
||||
}
|
||||
|
||||
public ProtectedRegion getLowerCasePlot(World w, String regionname) {
|
||||
for (ProtectedRegion pr : getRegionManager(w).getRegions().values()) {
|
||||
if (pr.getId().toLowerCase().equalsIgnoreCase(regionname)) {
|
||||
return pr;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public RegionManager getRegionManager(World w) {
|
||||
if (getWgVer().contains("7.")) {
|
||||
try {
|
||||
Class<?> wgClass = Reflection.getClass("com.sk89q.worldguard.WorldGuard");
|
||||
|
||||
Object instance = wgClass.getDeclaredMethod("getInstance").invoke(null);
|
||||
Class<?> wgInstanceClass = instance.getClass();
|
||||
|
||||
Object platform = wgInstanceClass.getDeclaredMethod("getPlatform").invoke(instance);
|
||||
Class<?> wgPlatformClass = platform.getClass();
|
||||
|
||||
Object regionContainer = wgPlatformClass.getDeclaredMethod("getRegionContainer").invoke(platform);
|
||||
Class<?> wgRegionContainer = regionContainer.getClass();
|
||||
|
||||
return (RegionManager) wgRegionContainer.getSuperclass()
|
||||
.getMethod("get", com.sk89q.worldedit.world.World.class)
|
||||
.invoke(regionContainer, new BukkitWorld(w));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
return getWorldGuard().getRegionManager(w);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<ProtectedRegion> getRegions(Location loc) {
|
||||
ArrayList<ProtectedRegion> regions = new ArrayList<>();
|
||||
if (getWgVer().contains("7.")) {
|
||||
try {
|
||||
RegionManager mngr = getRegionManager(loc.getWorld());
|
||||
|
||||
Class<?> blockVector3 = Reflection.getClass("com.sk89q.worldedit.math.BlockVector3");
|
||||
|
||||
Method applicableRegions = mngr.getClass().getDeclaredMethod("getApplicableRegions", blockVector3);
|
||||
|
||||
Method blockVectorAt = blockVector3.getDeclaredMethod("at", double.class, double.class, double.class);
|
||||
Object blockVector = blockVectorAt.invoke(null, loc.getX(), loc.getY(), loc.getZ());
|
||||
|
||||
Object regionSet = applicableRegions.invoke(mngr, blockVector);
|
||||
|
||||
Method getregions = regionSet.getClass().getMethod("getRegions");
|
||||
|
||||
regions = new ArrayList<>(((HashSet<ProtectedRegion>) getregions.invoke(regionSet)));
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
regions = new ArrayList<>(getRegionManager(loc.getWorld())
|
||||
.getApplicableRegions(new Vector(loc.getX(), loc.getY(), loc.getZ())).getRegions());
|
||||
}
|
||||
|
||||
regions.sort(Comparator.comparing(ProtectedRegion::getPriority));
|
||||
return regions;
|
||||
}
|
||||
|
||||
public ProtectedCuboidRegion getProtectedCubiodRegion(String regionname, Location loc1, Location loc2) {
|
||||
if (getWgVer().contains("7.")) {
|
||||
try {
|
||||
|
||||
Object bvloc1 = getBlockVectorV3(loc1);
|
||||
Object bvloc2 = getBlockVectorV3(loc2);
|
||||
|
||||
Class<?> prCbRg = Reflection.getClass("com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion");
|
||||
|
||||
return (ProtectedCuboidRegion) prCbRg.getConstructor(String.class, bvloc1.getClass(), bvloc2.getClass())
|
||||
.newInstance(regionname, bvloc1, bvloc2);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
return new ProtectedCuboidRegion(regionname,
|
||||
new com.sk89q.worldedit.BlockVector(loc1.getX(), loc1.getY(), loc1.getZ()),
|
||||
new com.sk89q.worldedit.BlockVector(loc2.getX(), loc2.getY(), loc2.getZ()));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object getBlockVectorV3(@NotNull Location loc) throws Exception {
|
||||
Class<?> blockVector3 = Reflection.getClass("com.sk89q.worldedit.math.BlockVector3");
|
||||
|
||||
Method blockVectorAt = blockVector3.getDeclaredMethod("at", double.class, double.class, double.class);
|
||||
return blockVectorAt.invoke(null, loc.getX(), loc.getY(), loc.getZ());
|
||||
}
|
||||
|
||||
public FlagRegistry getFlagRegistry() {
|
||||
if (getWgVer().contains("7.")) {
|
||||
try {
|
||||
Class<?> wgClass = Reflection.getClass("com.sk89q.worldguard.WorldGuard");
|
||||
|
||||
Object instance = wgClass.getDeclaredMethod("getInstance").invoke(null);
|
||||
Class<?> wgInstanceClass = instance.getClass();
|
||||
Method declaredMethod = wgInstanceClass.getDeclaredMethod("getFlagRegistry");
|
||||
return (FlagRegistry) declaredMethod.invoke(instance);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return getWorldGuard().getFlagRegistry();
|
||||
}
|
||||
}
|
||||
|
||||
public ApplicableRegionSet getApplicableRegionSet(Location loc) {
|
||||
if (getWgVer().contains("7.")) {
|
||||
try {
|
||||
RegionManager mngr = getRegionManager(loc.getWorld());
|
||||
|
||||
Class<?> blockVector3 = Reflection.getClass("com.sk89q.worldedit.math.BlockVector3");
|
||||
|
||||
Method applicableRegions = mngr.getClass().getDeclaredMethod("getApplicableRegions", blockVector3);
|
||||
|
||||
Method blockVectorAt = blockVector3.getDeclaredMethod("at", double.class, double.class, double.class);
|
||||
Object blockVector = blockVectorAt.invoke(null, loc.getX(), loc.getY(), loc.getZ());
|
||||
|
||||
Object regionSet = applicableRegions.invoke(mngr, blockVector);
|
||||
|
||||
return (ApplicableRegionSet) regionSet;
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return getRegionManager(loc.getWorld()).getApplicableRegions(new Vector(loc.getX(), loc.getY(), loc.getZ()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getWgVer() {
|
||||
if (wgVerStr == null) {
|
||||
wgVerStr = Bukkit.getPluginManager().getPlugin("WorldGuard").getDescription().getVersion();
|
||||
}
|
||||
return wgVerStr;
|
||||
}
|
||||
}
|
Reference in a new issue