Skip to content
This repository has been archived by the owner on Dec 5, 2020. It is now read-only.

Commit

Permalink
1.62
Browse files Browse the repository at this point in the history
  • Loading branch information
Arasple committed Dec 1, 2019
1 parent f64d8c2 commit c58213d
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.arasple.mc</groupId>
<artifactId>TrChat</artifactId>
<version>1.61</version>
<version>1.62</version>
<packaging>jar</packaging>

<name>TrChat</name>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/me/arasple/mc/trchat/TrChatBungee.java
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand All @@ -12,6 +13,7 @@ public class TrChatBungee extends Plugin {
@Override
public void onEnable() {
new MetricsBungee(this);
getProxy().getPluginManager().registerListener(this, new ListenerBungeeTransfer());
}

}
Original file line number Diff line number Diff line change
@@ -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) {
}
}

}
2 changes: 1 addition & 1 deletion src/main/java/me/arasple/mc/trchat/chat/ChatFormats.java
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -15,6 +16,7 @@
*/
public class JsonComponent {

private String requirement;
private String text;
private String hover;
private String suggest;
Expand Down Expand Up @@ -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<JsonComponent> loadList(Object parts) {
Expand All @@ -55,6 +60,9 @@ public static List<JsonComponent> 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)));
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/me/arasple/mc/trchat/utils/Js.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@ public static boolean checkCondition(OfflinePlayer ofPlayer, String requirement)
try {
player = (Player) ofPlayer;
} catch (Throwable e) {
System.out.println("FUCKED: " + requirement);
return true;
}

Map<String, Object> bind = new HashMap<>();
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()));
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/formats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ NORMAL:
&r
# 该组件的点击执行命令
command: '/tpa %player_name%'
# 此项为可选项, 如果设置则玩家必须有该权限才会显示这个组件 (不写或null则默认显示)
permission: null
# 此项为可选项, 如果设置则玩家必须满足此表达式才会显示该组件 (不写或null则默认显示)
requirement: null
part-before-player:
text: ' '
player:
Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/updates.md
Original file line number Diff line number Diff line change
@@ -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:
- 修正裁剪了敏感词库
Expand Down

0 comments on commit c58213d

Please sign in to comment.