Improved catchers

This commit is contained in:
Arasple 2020-01-21 14:05:38 +08:00
parent a880637c40
commit f6da4781e7
2 changed files with 9 additions and 4 deletions

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;
@ -74,7 +74,7 @@ public class TLocaleJson extends TLocaleSerialize {
BaseComponent[] component = TextComponent.fromLegacyText(text); BaseComponent[] component = TextComponent.fromLegacyText(text);
arg.forEach((key, value) -> { arg.forEach((key, value) -> {
if (key.equalsIgnoreCase("suggest")) { if (key.equalsIgnoreCase("suggest")) {
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")) { } else if (key.equalsIgnoreCase("url")) {

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() {
} }
} }
} }