From ad7d0c9d93516de41cd363eb653c719aca8dafde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Wed, 22 May 2019 11:17:03 +0800 Subject: [PATCH] + fixed SimpleI18n + fixed WorldGuardHook --- .../skymc/taboolib/fileutils/ConfigUtils.java | 4 ++-- .../taboolib/support/SupportWorldGuard.java | 24 +++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main/scala/me/skymc/taboolib/fileutils/ConfigUtils.java b/src/main/scala/me/skymc/taboolib/fileutils/ConfigUtils.java index e989d52..d31635b 100644 --- a/src/main/scala/me/skymc/taboolib/fileutils/ConfigUtils.java +++ b/src/main/scala/me/skymc/taboolib/fileutils/ConfigUtils.java @@ -19,7 +19,6 @@ import java.io.StringReader; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.nio.charset.Charset; -import java.util.LinkedHashMap; import java.util.Map; public class ConfigUtils { @@ -199,7 +198,8 @@ public class ConfigUtils { configuration.loadFromString(yaml); return configuration; } catch (Exception e) { - TLocale.Logger.error("FILE-UTILS.FAIL-LOAD-CONFIGURATION", plugin.getName(), file.getName()); + TLocale.Logger.error("FILE-UTILS.FAIL-LOAD-CONFIGURATION", plugin.getName(), file.getPath()); + e.printStackTrace(); } return configuration; } diff --git a/src/main/scala/me/skymc/taboolib/support/SupportWorldGuard.java b/src/main/scala/me/skymc/taboolib/support/SupportWorldGuard.java index f28fc62..836967c 100644 --- a/src/main/scala/me/skymc/taboolib/support/SupportWorldGuard.java +++ b/src/main/scala/me/skymc/taboolib/support/SupportWorldGuard.java @@ -1,6 +1,8 @@ package me.skymc.taboolib.support; import com.google.common.base.Preconditions; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldguard.WorldGuard; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.ProtectedRegion; @@ -9,6 +11,7 @@ import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; +import java.lang.reflect.Method; import java.util.Collection; import java.util.List; import java.util.stream.Collectors; @@ -19,12 +22,20 @@ import java.util.stream.Collectors; public class SupportWorldGuard { public static final SupportWorldGuard INSTANCE = new SupportWorldGuard(); - private WorldGuardPlugin worldGuard; + private Method getRegionManager; public SupportWorldGuard() { Preconditions.checkNotNull(Bukkit.getServer().getPluginManager().getPlugin("WorldGuard"), "WorldGuard was not found."); worldGuard = WorldGuardPlugin.inst(); + if (!worldGuard.getDescription().getVersion().startsWith("7")) { + try { + getRegionManager = WorldGuardPlugin.class.getDeclaredMethod("getRegionManager", World.class); + getRegionManager.setAccessible(true); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + } } public WorldGuardPlugin getWorldGuard() { @@ -32,7 +43,16 @@ public class SupportWorldGuard { } public RegionManager getRegionManager(World world) { - return this.worldGuard.getRegionManager(world); + if (worldGuard.getDescription().getVersion().startsWith("7")) { + return WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world)); + } else { + try { + return (RegionManager) getRegionManager.invoke(worldGuard, world); + } catch (Throwable t) { + t.printStackTrace(); + } + return null; + } } public boolean isRegionManagerExists(World world) {