From c58213d2ba351937f826f45acd9cf1d12f055b25 Mon Sep 17 00:00:00 2001 From: Arasple Date: Sun, 1 Dec 2019 10:28:12 +0800 Subject: [PATCH] 1.62 --- pom.xml | 2 +- .../me/arasple/mc/trchat/TrChatBungee.java | 2 + .../trchat/bungee/ListenerBungeeTransfer.java | 56 +++++++++++++++++++ .../arasple/mc/trchat/chat/ChatFormats.java | 2 +- .../chat/format/objects/JsonComponent.java | 15 +++++ .../java/me/arasple/mc/trchat/utils/Js.java | 5 +- src/main/resources/formats.yml | 4 +- src/main/resources/updates.md | 7 ++- 8 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 src/main/java/me/arasple/mc/trchat/bungee/ListenerBungeeTransfer.java diff --git a/pom.xml b/pom.xml index 3024e014..72678fd1 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.arasple.mc TrChat - 1.61 + 1.62 jar TrChat diff --git a/src/main/java/me/arasple/mc/trchat/TrChatBungee.java b/src/main/java/me/arasple/mc/trchat/TrChatBungee.java index b196fccf..24534945 100644 --- a/src/main/java/me/arasple/mc/trchat/TrChatBungee.java +++ b/src/main/java/me/arasple/mc/trchat/TrChatBungee.java @@ -1,6 +1,7 @@ package me.arasple.mc.trchat; import me.arasple.mc.trchat.bstats.MetricsBungee; +import me.arasple.mc.trchat.bungee.ListenerBungeeTransfer; import net.md_5.bungee.api.plugin.Plugin; /** @@ -12,6 +13,7 @@ public class TrChatBungee extends Plugin { @Override public void onEnable() { new MetricsBungee(this); + getProxy().getPluginManager().registerListener(this, new ListenerBungeeTransfer()); } } diff --git a/src/main/java/me/arasple/mc/trchat/bungee/ListenerBungeeTransfer.java b/src/main/java/me/arasple/mc/trchat/bungee/ListenerBungeeTransfer.java new file mode 100644 index 00000000..758e2956 --- /dev/null +++ b/src/main/java/me/arasple/mc/trchat/bungee/ListenerBungeeTransfer.java @@ -0,0 +1,56 @@ +package me.arasple.mc.trchat.bungee; + +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.event.PluginMessageEvent; +import net.md_5.bungee.api.plugin.Listener; +import net.md_5.bungee.chat.ComponentSerializer; +import net.md_5.bungee.event.EventHandler; + +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.IOException; + +/** + * @author Arasple + * @date 2019/8/16 18:40 + */ +public class ListenerBungeeTransfer implements Listener { + + @EventHandler + public void onTransfer(PluginMessageEvent e) { + try { + ByteArrayInputStream byteArray = new ByteArrayInputStream(e.getData()); + DataInputStream in = new DataInputStream(byteArray); + + String subChannel = in.readUTF(); + String type = in.readUTF(); + + if ("TrChat".equals(subChannel)) { + if ("SendRaw".equals(type)) { + String to = in.readUTF(); + ProxiedPlayer player = ProxyServer.getInstance().getPlayers().stream().filter(p -> p.getName().equalsIgnoreCase(to)).findFirst().orElse(null); + + if (player != null && player.isConnected()) { + String raw = in.readUTF(); + player.sendMessage(ComponentSerializer.parse(raw)); + } + } + if ("BroadcastRaw".equals(type)) { + String raw = in.readUTF(); + ProxyServer.getInstance().broadcast(ComponentSerializer.parse(raw)); + } + if ("SendRawPerm".equals(type)) { + String raw = in.readUTF(); + String perm = in.readUTF(); + + ProxyServer.getInstance().getPlayers().stream().filter(p -> p.hasPermission(perm)).forEach(p -> { + p.sendMessage(ComponentSerializer.parse(raw)); + }); + } + } + } catch (IOException ignored) { + } + } + +} diff --git a/src/main/java/me/arasple/mc/trchat/chat/ChatFormats.java b/src/main/java/me/arasple/mc/trchat/chat/ChatFormats.java index 79972167..1128af1e 100644 --- a/src/main/java/me/arasple/mc/trchat/chat/ChatFormats.java +++ b/src/main/java/me/arasple/mc/trchat/chat/ChatFormats.java @@ -26,7 +26,7 @@ public static Format getFormat(ChatType type, Player player) { public static void loadFormats(CommandSender... notify) { long start = System.currentTimeMillis(); - formats.clear(); + formats.entrySet().clear(); for (ChatType chatType : ChatType.values()) { if (TrChatFiles.getFormats().contains(chatType.name())) { diff --git a/src/main/java/me/arasple/mc/trchat/chat/format/objects/JsonComponent.java b/src/main/java/me/arasple/mc/trchat/chat/format/objects/JsonComponent.java index 00b2d7f6..240f4a59 100644 --- a/src/main/java/me/arasple/mc/trchat/chat/format/objects/JsonComponent.java +++ b/src/main/java/me/arasple/mc/trchat/chat/format/objects/JsonComponent.java @@ -2,6 +2,7 @@ import io.izzel.taboolib.module.tellraw.TellrawJson; import io.izzel.taboolib.util.Strings; +import me.arasple.mc.trchat.utils.Js; import me.arasple.mc.trchat.utils.Vars; import org.bukkit.OfflinePlayer; @@ -15,6 +16,7 @@ */ public class JsonComponent { + private String requirement; private String text; private String hover; private String suggest; @@ -45,6 +47,9 @@ public JsonComponent(LinkedHashMap partSection) { if (partSection.containsKey("url")) { setUrl(String.valueOf(partSection.get("url"))); } + if (partSection.containsKey("requirement")) { + setRequirement(String.valueOf(partSection.get("requirement"))); + } } public static List loadList(Object parts) { @@ -55,6 +60,9 @@ public static List loadList(Object parts) { public TellrawJson toTellrawJson(OfflinePlayer player, Object... vars) { TellrawJson tellraw = TellrawJson.create(); + if (!Js.checkCondition(player, getRequirement())) { + return tellraw; + } tellraw.append(text != null ? Vars.replace(player, Strings.replaceWithOrder(text, vars)) : "§8[§fNull§8]"); if (hover != null) { tellraw.hoverText(Vars.replace(player, Strings.replaceWithOrder(hover, vars))); @@ -88,6 +96,13 @@ public String convertHoverText(Object object) { /* GETTERS && SETTERS */ + public String getRequirement() { + return requirement; + } + + public void setRequirement(String requirement) { + this.requirement = requirement; + } public String getText() { return text; diff --git a/src/main/java/me/arasple/mc/trchat/utils/Js.java b/src/main/java/me/arasple/mc/trchat/utils/Js.java index a2065cd7..a18bbb0d 100644 --- a/src/main/java/me/arasple/mc/trchat/utils/Js.java +++ b/src/main/java/me/arasple/mc/trchat/utils/Js.java @@ -26,6 +26,7 @@ public static boolean checkCondition(OfflinePlayer ofPlayer, String requirement) try { player = (Player) ofPlayer; } catch (Throwable e) { + System.out.println("FUCKED: " + requirement); return true; } @@ -33,10 +34,8 @@ public static boolean checkCondition(OfflinePlayer ofPlayer, String requirement) bind.put("player", player); bind.put("bukkitServer", Bukkit.getServer()); requirement = Vars.replace(player, requirement); - if (player.hasPermission(requirement)) { - return true; - } try { + System.out.println("RUN JS: " + requirement); return (boolean) Scripts.compile(requirement).eval(new SimpleBindings(bind)); } catch (Throwable e) { TLocale.sendTo(player, "ERROR.JS", requirement, e.getMessage(), Arrays.toString(e.getStackTrace())); diff --git a/src/main/resources/formats.yml b/src/main/resources/formats.yml index 6b915a55..eb471601 100644 --- a/src/main/resources/formats.yml +++ b/src/main/resources/formats.yml @@ -43,8 +43,8 @@ NORMAL: &r # 该组件的点击执行命令 command: '/tpa %player_name%' - # 此项为可选项, 如果设置则玩家必须有该权限才会显示这个组件 (不写或null则默认显示) - permission: null + # 此项为可选项, 如果设置则玩家必须满足此表达式才会显示该组件 (不写或null则默认显示) + requirement: null part-before-player: text: ' ' player: diff --git a/src/main/resources/updates.md b/src/main/resources/updates.md index 4554ee98..c0782cc8 100644 --- a/src/main/resources/updates.md +++ b/src/main/resources/updates.md @@ -1,7 +1,12 @@ # TrChat Update Logs # #### VERSION 1.6 - - ##### 1.6 :) + - ##### 1.62 + - DATE: 2019.12.1 + - OVERVIEW: + - 修复了 Bungee 版不工作 + - 现在单个 JSON 组件也支持使用 "Requirement" 属性 + - ##### 1.61 - DATE: 2019.11.30 - OVERVIEW: - 修正裁剪了敏感词库