diff --git a/Compatibility/src/main/java/com/songoda/core/compatibility/MethodMapping.java b/Compatibility/src/main/java/com/songoda/core/compatibility/MethodMapping.java index 56063606..2b2bbc11 100644 --- a/Compatibility/src/main/java/com/songoda/core/compatibility/MethodMapping.java +++ b/Compatibility/src/main/java/com/songoda/core/compatibility/MethodMapping.java @@ -6,46 +6,53 @@ import java.lang.reflect.Method; public enum MethodMapping { - MC_ITEM_STACK__GET_TAG("getTag", "s"), - MC_ITEM_STACK__SET_TAG("setTag", "c", ClassMapping.NBT_TAG_COMPOUND.getClazz()), + MC_ITEM_STACK__GET_TAG("getTag", "getTag", "s"), + MC_ITEM_STACK__SET_TAG("setTag", "setTag", "c", ClassMapping.NBT_TAG_COMPOUND.getClazz()), - MC_NBT_TAG_COMPOUND__SET("set", "a", String.class, ClassMapping.NBT_BASE.getClazz()), - MC_NBT_TAG_COMPOUND__SET_SHORT("setShort", "a", String.class), - MC_NBT_TAG_COMPOUND__SET_STRING("setString", "a", String.class, String.class), - MC_NBT_TAG_COMPOUND__REMOVE("remove", "r", String.class, short.class), + MC_NBT_TAG_COMPOUND__SET("set", "set", "a", String.class, ClassMapping.NBT_BASE.getClazz()), + MC_NBT_TAG_COMPOUND__SET_SHORT("setShort", "setShort", "a", String.class), + MC_NBT_TAG_COMPOUND__SET_STRING("setString", "setString", "a", String.class, String.class), + MC_NBT_TAG_COMPOUND__REMOVE("remove", "remove", "r", String.class, short.class), - CB_ITEM_STACK__AS_NMS_COPY("asNMSCopy", ItemStack.class), - CB_ITEM_STACK__AS_CRAFT_MIRROR("asCraftMirror", ClassMapping.ITEM_STACK.getClazz()), + CB_ITEM_STACK__AS_NMS_COPY("asNMSCopy", "asNMSCopy", ItemStack.class), + CB_ITEM_STACK__AS_CRAFT_MIRROR("asCraftMirror", "asCraftMirror", ClassMapping.ITEM_STACK.getClazz()), - MC_NBT_TAG_LIST__ADD("a", "add", "add", ClassMapping.NBT_BASE.getClazz()), + MC_NBT_TAG_LIST__ADD("add", "a", "add", "add", ClassMapping.NBT_BASE.getClazz()), - WORLD_BOARDER__SET_CENTER("setCenter", "setCenter", "c", double.class, double.class), - WORLD_BOARDER__SET_SIZE("setSize", "setSize", "a", double.class), + WORLD_BOARDER__SET_CENTER("setCenter", "setCenter", "setCenter", "c", double.class, double.class), + WORLD_BOARDER__SET_SIZE("setSize", "setSize", "setSize", "a", double.class), - WORLD_BOARDER__SET_WARNING_TIME("setWarningTime", "setWarningTime", "b", int.class), - WORLD_BOARDER__SET_WARNING_DISTANCE("setWarningDistance", "setWarningDistance", "c", int.class), - WORLD_BOARDER__TRANSITION_SIZE_BETWEEN("transitionSizeBetween", "transitionSizeBetween", "a", double.class, double.class, long.class); + WORLD_BOARDER__SET_WARNING_TIME("setWarningTime", "setWarningTime", "setWarningTime", "b", int.class), + WORLD_BOARDER__SET_WARNING_DISTANCE("setWarningDistance", "setWarningDistance", "setWarningDistance", "c", int.class), + WORLD_BOARDER__TRANSITION_SIZE_BETWEEN("transitionSizeBetween", "transitionSizeBetween", "transitionSizeBetween", "a", double.class, double.class, long.class); + private final String saneFallback; private final String _1_14; private final String _1_17; private final String _1_18; private final Class[] paramaters; - MethodMapping(String _1_14, String _1_17, String _1_18, Class... paramaters) { + MethodMapping(String saneFallback, String _1_14, String _1_17, String _1_18, Class... paramaters) { + this.saneFallback = saneFallback; + this._1_14 = _1_14; this._1_17 = _1_17; this._1_18 = _1_18; this.paramaters = paramaters; } - MethodMapping(String _1_17, String _1_18, Class... paramaters) { + MethodMapping(String saneFallback, String _1_17, String _1_18, Class... paramaters) { + this.saneFallback = saneFallback; + this._1_14 = null; this._1_17 = _1_17; this._1_18 = _1_18; this.paramaters = paramaters; } - MethodMapping(String _1_18, Class... paramaters) { + MethodMapping(String saneFallback, String _1_18, Class... paramaters) { + this.saneFallback = saneFallback; + this._1_14 = null; this._1_17 = null; this._1_18 = _1_18; @@ -54,7 +61,6 @@ public enum MethodMapping { public Method getMethod(Class clazz) { try { - String methodName = _1_18; switch (ServerVersion.getServerVersion()) { case V1_14: @@ -67,12 +73,28 @@ public enum MethodMapping { break; } - Method method = clazz.getDeclaredMethod(methodName, paramaters); - method.setAccessible(true); + try { + Method method = clazz.getDeclaredMethod(methodName, paramaters); + method.setAccessible(true); - return method; - } catch (Exception e) { - return null; + return method; + } catch (NoSuchMethodException ex) { + if (saneFallback != null) { + try { + Method method = clazz.getDeclaredMethod(saneFallback, paramaters); + method.setAccessible(true); + + return method; + } catch (NoSuchMethodException innerEx) { + ex.printStackTrace(); + innerEx.printStackTrace(); + } + } + } + } catch (Exception ex) { + ex.printStackTrace(); } + + return null; } }