diff --git a/src/main/scala/io/izzel/taboolib/module/lite/SimpleReflection.java b/src/main/scala/io/izzel/taboolib/module/lite/SimpleReflection.java index 60c92c2..52c642e 100644 --- a/src/main/scala/io/izzel/taboolib/module/lite/SimpleReflection.java +++ b/src/main/scala/io/izzel/taboolib/module/lite/SimpleReflection.java @@ -2,7 +2,6 @@ package io.izzel.taboolib.module.lite; import com.google.common.collect.Maps; import io.izzel.taboolib.TabooLibAPI; -import io.izzel.taboolib.module.locale.logger.TLogger; import io.izzel.taboolib.util.Ref; import java.lang.reflect.Field; @@ -65,7 +64,7 @@ public class SimpleReflection { public static void setFieldValue(Class nmsClass, Object instance, String fieldName, Object value) { Map fields = fieldCached.get(nmsClass.getName()); if (fields == null) { - TLogger.getGlobalLogger().error("Field Not Found: " + nmsClass.getName()); + return; } Field field = fields.get(fieldName); if (value == null) { @@ -81,7 +80,7 @@ public class SimpleReflection { public static Object getFieldValue(Class nmsClass, Object instance, String fieldName) { Map fields = fieldCached.get(nmsClass.getName()); if (fields == null) { - TLogger.getGlobalLogger().error("Field Not Found: " + nmsClass.getName()); + return null; } Field field = fields.get(fieldName); if (field == null) { @@ -99,7 +98,7 @@ public class SimpleReflection { public static T getFieldValue(Class nmsClass, Object instance, String fieldName, T def) { Map fields = fieldCached.get(nmsClass.getName()); if (fields == null) { - TLogger.getGlobalLogger().error("Field Not Found: " + nmsClass.getName()); + return null; } Field field = fields.get(fieldName); if (field == null) { diff --git a/src/main/scala/io/izzel/taboolib/util/Ref.java b/src/main/scala/io/izzel/taboolib/util/Ref.java index 367ff03..983c075 100644 --- a/src/main/scala/io/izzel/taboolib/util/Ref.java +++ b/src/main/scala/io/izzel/taboolib/util/Ref.java @@ -1,5 +1,6 @@ package io.izzel.taboolib.util; +import com.google.common.base.Preconditions; import com.google.gson.annotations.SerializedName; import io.izzel.taboolib.TabooLib; import io.izzel.taboolib.TabooLibAPI; @@ -56,6 +57,7 @@ public class Ref { } public static void putField(Object src, Field field, Object value) { + Preconditions.checkNotNull(field); if (Modifier.isStatic(field.getModifiers())) { Object base = getUnsafe().staticFieldBase(field); long offset = getUnsafe().staticFieldOffset(field); @@ -97,6 +99,8 @@ public class Ref { } public static Object getField(Object src, Field field) { + Preconditions.checkNotNull(field); + getUnsafe().ensureClassInitialized(field.getDeclaringClass()); if (Modifier.isStatic(field.getModifiers())) { Object base = getUnsafe().staticFieldBase(field); long offset = getUnsafe().staticFieldOffset(field); diff --git a/src/main/scala/io/izzel/taboolib/util/item/MapBuilder.java b/src/main/scala/io/izzel/taboolib/util/item/MapBuilder.java index 2e6d65c..431bda2 100644 --- a/src/main/scala/io/izzel/taboolib/util/item/MapBuilder.java +++ b/src/main/scala/io/izzel/taboolib/util/item/MapBuilder.java @@ -1,5 +1,6 @@ package io.izzel.taboolib.util.item; +import io.izzel.taboolib.util.Reflection; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -161,7 +162,10 @@ public class MapBuilder { if (isNewVersion) { MapMeta mapMeta = (MapMeta) item.getItemMeta(); - mapMeta.setMapView(map); + try { + Reflection.invokeMethod(mapMeta, "setMapView", map); + } catch (Throwable ignored) { + } item.setItemMeta(mapMeta); } else { item.setDurability(getMapId(map));