# Conflicts:
#	src/main/scala/io/izzel/taboolib/module/lite/SimpleReflection.java
This commit is contained in:
sky 2020-01-23 18:18:48 +08:00
commit 1483ba8e84
4 changed files with 19 additions and 30 deletions

View File

@ -44,9 +44,6 @@ shadowJar {
// MANIFEST.MF lib // MANIFEST.MF lib
taskActions.removeIf { it.actionClassName.contains 'configureShadowTask' } taskActions.removeIf { it.actionClassName.contains 'configureShadowTask' }
// MANIFEST.MF lib
taskActions.removeIf { it.actionClassName.contains 'configureShadowTask' }
dependencies { dependencies {
it.include it.dependency('org.apache.commons:.*') it.include it.dependency('org.apache.commons:.*')
it.include it.dependency('org.ow2.asm:.*') it.include it.dependency('org.ow2.asm:.*')

View File

@ -1,7 +1,6 @@
package io.izzel.taboolib.module.lite; package io.izzel.taboolib.module.lite;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import io.izzel.taboolib.TabooLibAPI; import io.izzel.taboolib.TabooLibAPI;
import io.izzel.taboolib.module.locale.logger.TLogger; import io.izzel.taboolib.module.locale.logger.TLogger;
import io.izzel.taboolib.util.Ref; import io.izzel.taboolib.util.Ref;
@ -11,7 +10,6 @@ import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map; import java.util.Map;
import java.util.Set;
/** /**
* @Author 坏黑 * @Author 坏黑
@ -20,7 +18,6 @@ import java.util.Set;
public class SimpleReflection { public class SimpleReflection {
private static Map<String, Map<String, Field>> fieldCached = Maps.newHashMap(); private static Map<String, Map<String, Field>> fieldCached = Maps.newHashMap();
private static Set<String> fieldLogger = Sets.newHashSet();
public static boolean isExists(Class<?> nmsClass) { public static boolean isExists(Class<?> nmsClass) {
return fieldCached.containsKey(nmsClass.getName()); return fieldCached.containsKey(nmsClass.getName());
@ -69,15 +66,11 @@ public class SimpleReflection {
public static void setFieldValue(Class<?> nmsClass, Object instance, String fieldName, Object value) { public static void setFieldValue(Class<?> nmsClass, Object instance, String fieldName, Object value) {
Map<String, Field> fields = fieldCached.get(nmsClass.getName()); Map<String, Field> fields = fieldCached.get(nmsClass.getName());
if (fields == null) { if (fields == null) {
if (fieldLogger.add(nmsClass.getName() + "$" + fieldName)) { TLogger.getGlobalLogger().error("Field Not Found: " + nmsClass.getName());
TLogger.getGlobalLogger().error("Field Not Found: " + nmsClass.getName() + "$" + fieldName);
}
} }
Field field = fields.get(fieldName); Field field = fields.get(fieldName);
if (value == null) { if (value == null) {
if (fieldLogger.add(nmsClass.getName() + "$" + fieldName)) { return;
TLogger.getGlobalLogger().error("Field Not Found: " + nmsClass.getName() + "$" + fieldName);
}
} }
try { try {
field.set(instance, value); field.set(instance, value);
@ -89,15 +82,11 @@ public class SimpleReflection {
public static Object getFieldValue(Class<?> nmsClass, Object instance, String fieldName) { public static Object getFieldValue(Class<?> nmsClass, Object instance, String fieldName) {
Map<String, Field> fields = fieldCached.get(nmsClass.getName()); Map<String, Field> fields = fieldCached.get(nmsClass.getName());
if (fields == null) { if (fields == null) {
if (fieldLogger.add(nmsClass.getName() + "$" + fieldName)) { TLogger.getGlobalLogger().error("Field Not Found: " + nmsClass.getName());
TLogger.getGlobalLogger().error("Field Not Found: " + nmsClass.getName() + "$" + fieldName);
}
} }
Field field = fields.get(fieldName); Field field = fields.get(fieldName);
if (field == null) { if (field == null) {
if (fieldLogger.add(nmsClass.getName() + "$" + fieldName)) { return null;
TLogger.getGlobalLogger().error("Field Not Found: " + nmsClass.getName() + "$" + fieldName);
}
} }
try { try {
return field.get(instance); return field.get(instance);
@ -110,15 +99,11 @@ public class SimpleReflection {
public static <T> T getFieldValue(Class<?> nmsClass, Object instance, String fieldName, T def) { public static <T> T getFieldValue(Class<?> nmsClass, Object instance, String fieldName, T def) {
Map<String, Field> fields = fieldCached.get(nmsClass.getName()); Map<String, Field> fields = fieldCached.get(nmsClass.getName());
if (fields == null) { if (fields == null) {
if (fieldLogger.add(nmsClass.getName() + "$" + fieldName)) { TLogger.getGlobalLogger().error("Field Not Found: " + nmsClass.getName());
TLogger.getGlobalLogger().error("Field Not Found: " + nmsClass.getName() + "$" + fieldName);
}
} }
Field field = fields.get(fieldName); Field field = fields.get(fieldName);
if (field == null) { if (field == null) {
if (fieldLogger.add(nmsClass.getName() + "$" + fieldName)) { return null;
TLogger.getGlobalLogger().error("Field Not Found: " + nmsClass.getName() + "$" + fieldName);
}
} }
try { try {
return (T) field.get(instance); return (T) field.get(instance);
@ -128,7 +113,7 @@ public class SimpleReflection {
return def; return def;
} }
public static Class getListType(Field field) { public static Class getListType(Field field) {
Type genericType = field.getGenericType(); Type genericType = field.getGenericType();
try { try {
if (ParameterizedType.class.isAssignableFrom(genericType.getClass())) { if (ParameterizedType.class.isAssignableFrom(genericType.getClass())) {
@ -142,7 +127,7 @@ public class SimpleReflection {
return null; return null;
} }
public static Class[] getMapType(Field field) { public static Class[] getMapType(Field field) {
Class[] mapType = new Class[2]; Class[] mapType = new Class[2];
try { try {
Type genericType = field.getGenericType(); Type genericType = field.getGenericType();
@ -154,6 +139,6 @@ public class SimpleReflection {
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); t.printStackTrace();
} }
return mapType[1] == null ? null : mapType ; return mapType[1] == null ? null : mapType;
} }
} }

View File

@ -4,9 +4,9 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import io.izzel.taboolib.TabooLib; import io.izzel.taboolib.TabooLib;
import io.izzel.taboolib.module.compat.PlaceholderHook;
import io.izzel.taboolib.module.locale.TLocale; import io.izzel.taboolib.module.locale.TLocale;
import io.izzel.taboolib.module.locale.TLocaleSerialize; import io.izzel.taboolib.module.locale.TLocaleSerialize;
import io.izzel.taboolib.module.compat.PlaceholderHook;
import io.izzel.taboolib.module.tellraw.TellrawJson; import io.izzel.taboolib.module.tellraw.TellrawJson;
import io.izzel.taboolib.util.Strings; import io.izzel.taboolib.util.Strings;
import io.izzel.taboolib.util.Variables; import io.izzel.taboolib.util.Variables;
@ -77,6 +77,8 @@ public class TLocaleJson extends TLocaleSerialize {
Arrays.stream(component).forEach(baseComponent -> baseComponent.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, String.valueOf(value)))); Arrays.stream(component).forEach(baseComponent -> baseComponent.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, String.valueOf(value))));
} else if (key.equalsIgnoreCase("command") || "commands".equalsIgnoreCase(key)) { } else if (key.equalsIgnoreCase("command") || "commands".equalsIgnoreCase(key)) {
Arrays.stream(component).forEach(baseComponent -> baseComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.valueOf(value)))); Arrays.stream(component).forEach(baseComponent -> baseComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.valueOf(value))));
} else if (key.equalsIgnoreCase("url")) {
Arrays.stream(component).forEach(baseComponent -> baseComponent.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, String.valueOf(value))));
} else if (key.equalsIgnoreCase("hover")) { } else if (key.equalsIgnoreCase("hover")) {
Arrays.stream(component).forEach(baseComponent -> baseComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(TLocale.Translate.setColored(String.valueOf(value))).create()))); Arrays.stream(component).forEach(baseComponent -> baseComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(TLocale.Translate.setColored(String.valueOf(value))).create())));
} }

View File

@ -39,13 +39,13 @@ public class Catchers implements Listener {
e.setCancelled(true); e.setCancelled(true);
// 1.14 supported. // 1.14 supported.
Bukkit.getScheduler().runTask(TabooLib.getPlugin(), () -> { Bukkit.getScheduler().runTask(TabooLib.getPlugin(), () -> {
Catcher catcher = playerdata.get(e.getPlayer().getName()).getFirst();
// 退出 // 退出
if (e.getMessage().equalsIgnoreCase("quit()")) { if (e.getMessage().split(" ")[0].matches(catcher.quit())) {
playerdata.get(e.getPlayer().getName()).removeFirst().cancel(); playerdata.get(e.getPlayer().getName()).removeFirst().cancel();
} }
// 默认 // 默认
else { else {
Catcher catcher = playerdata.get(e.getPlayer().getName()).getFirst();
// 如果终止引导 // 如果终止引导
if (!catcher.after(e.getMessage())) { if (!catcher.after(e.getMessage())) {
playerdata.get(e.getPlayer().getName()).removeFirst(); playerdata.get(e.getPlayer().getName()).removeFirst();
@ -59,6 +59,10 @@ public class Catchers implements Listener {
public interface Catcher { public interface Catcher {
default String quit() {
return "(?i)quit|cancel|exit";
}
default Catcher before() { default Catcher before() {
return this; return this;
} }
@ -67,5 +71,6 @@ public class Catchers implements Listener {
default void cancel() { default void cancel() {
} }
} }
} }