From 3a219fc597ee87787ec453763c793af2f96fff90 Mon Sep 17 00:00:00 2001 From: Meow J Date: Thu, 23 Jul 2015 01:24:17 +0800 Subject: [PATCH] Fix the compatibility issue with Cauldron. --- build.gradle | 2 +- src/main/java/com/meowj/langutils/LangUtils.java | 11 +++++++++-- .../java/com/meowj/langutils/locale/LocaleHelper.java | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 6b7fea9..6cad190 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ apply plugin: 'maven-publish' group = 'com.meowj' archivesBaseName = 'LangUtils' -version = '1.2.0-1.7.10' +version = '1.2.0.1-1.7.10' final def EULA_ACCEPT = true diff --git a/src/main/java/com/meowj/langutils/LangUtils.java b/src/main/java/com/meowj/langutils/LangUtils.java index 15bb999..8b98342 100644 --- a/src/main/java/com/meowj/langutils/LangUtils.java +++ b/src/main/java/com/meowj/langutils/LangUtils.java @@ -23,12 +23,15 @@ public class LangUtils extends JavaPlugin { public static LangUtils plugin; + private static boolean isCauldron = false; @Override public void onEnable() { plugin = this; - if (getServer().getName().contains("Cauldron") || getServer().getName().contains("MCPC")) - warn("Unsupported environment! Currently, Language Utils does NOT support Cauldron/KCauldron environment!"); + if (getServer().getName().contains("Cauldron") || getServer().getName().contains("MCPC")) { + isCauldron = true; + warn("This API is not designed for Cauldron/KCauldron server, but it should work without problems for VANILLA items/entities. Again, you cannot use this API with items/entities in mods."); + } try { final long startTime = System.currentTimeMillis(); EnumLang.init(); @@ -61,4 +64,8 @@ public void info(String msg) { public void warn(String msg) { getLogger().log(Level.WARNING, msg); } + + public boolean isCauldron() { + return isCauldron; + } } diff --git a/src/main/java/com/meowj/langutils/locale/LocaleHelper.java b/src/main/java/com/meowj/langutils/locale/LocaleHelper.java index 53994cd..a0ca5eb 100644 --- a/src/main/java/com/meowj/langutils/locale/LocaleHelper.java +++ b/src/main/java/com/meowj/langutils/locale/LocaleHelper.java @@ -33,7 +33,7 @@ public class LocaleHelper { public static String getPlayerLanguage(Player player) { try { Object handle = player.getClass().getDeclaredMethod("getHandle").invoke(player, (Object[]) null); - Field f = handle.getClass().getDeclaredField("locale"); + Field f = LangUtils.plugin.isCauldron() ? handle.getClass().getDeclaredField("field_71148_cg") : handle.getClass().getDeclaredField("locale"); f.setAccessible(true); return (String) f.get(handle); } catch (Exception e) {