Merge remote-tracking branch 'origin/master'

This commit is contained in:
IzzelAliz 2020-01-22 12:08:04 +08:00
commit 52e68d6366
3 changed files with 16 additions and 9 deletions

View File

@ -70,7 +70,7 @@ public class SimpleReflection {
} }
Field field = fields.get(fieldName); Field field = fields.get(fieldName);
if (value == null) { if (value == null) {
TLogger.getGlobalLogger().error("Field Not Found: " + nmsClass.getName()); return;
} }
try { try {
field.set(instance, value); field.set(instance, value);
@ -86,7 +86,7 @@ public class SimpleReflection {
} }
Field field = fields.get(fieldName); Field field = fields.get(fieldName);
if (field == null) { if (field == null) {
TLogger.getGlobalLogger().error("Field Not Found: " + nmsClass.getName()); return null;
} }
try { try {
return field.get(instance); return field.get(instance);
@ -103,7 +103,7 @@ public class SimpleReflection {
} }
Field field = fields.get(fieldName); Field field = fields.get(fieldName);
if (field == null) { if (field == null) {
TLogger.getGlobalLogger().error("Field Not Found: " + nmsClass.getName()); return null;
} }
try { try {
return (T) field.get(instance); return (T) field.get(instance);
@ -113,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())) {
@ -127,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();
@ -139,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() {
} }
} }
} }