+ fixed SimpleI18n

+ fixed WorldGuardHook
This commit is contained in:
坏黑 2019-05-22 11:17:03 +08:00
parent 0d8e9f60f2
commit ad7d0c9d93
2 changed files with 24 additions and 4 deletions

View File

@ -19,7 +19,6 @@ import java.io.StringReader;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
public class ConfigUtils { public class ConfigUtils {
@ -199,7 +198,8 @@ public class ConfigUtils {
configuration.loadFromString(yaml); configuration.loadFromString(yaml);
return configuration; return configuration;
} catch (Exception e) { } 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; return configuration;
} }

View File

@ -1,6 +1,8 @@
package me.skymc.taboolib.support; package me.skymc.taboolib.support;
import com.google.common.base.Preconditions; 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.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion;
@ -9,6 +11,7 @@ import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.lang.reflect.Method;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -19,12 +22,20 @@ import java.util.stream.Collectors;
public class SupportWorldGuard { public class SupportWorldGuard {
public static final SupportWorldGuard INSTANCE = new SupportWorldGuard(); public static final SupportWorldGuard INSTANCE = new SupportWorldGuard();
private WorldGuardPlugin worldGuard; private WorldGuardPlugin worldGuard;
private Method getRegionManager;
public SupportWorldGuard() { public SupportWorldGuard() {
Preconditions.checkNotNull(Bukkit.getServer().getPluginManager().getPlugin("WorldGuard"), "WorldGuard was not found."); Preconditions.checkNotNull(Bukkit.getServer().getPluginManager().getPlugin("WorldGuard"), "WorldGuard was not found.");
worldGuard = WorldGuardPlugin.inst(); 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() { public WorldGuardPlugin getWorldGuard() {
@ -32,7 +43,16 @@ public class SupportWorldGuard {
} }
public RegionManager getRegionManager(World world) { 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) { public boolean isRegionManagerExists(World world) {