diff --git a/pom.xml b/pom.xml
index 0e0a834..f9be092 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
pw.yumc
MiaoChat
- 1.3.3
+ 1.5
${project.name}
@@ -62,6 +62,9 @@
+
${java.home}/lib/rt.jar
diff --git a/proguard.conf b/proguard.conf
index f12adfb..444289e 100644
--- a/proguard.conf
+++ b/proguard.conf
@@ -26,7 +26,9 @@
-keepclassmembers class * implements org.bukkit.event.Listener {
@org.bukkit.event.EventHandler ;
}
-
+-keepclassmembers class * implements net.md_5.bungee.api.plugin.Listener {
+ @net.md_5.bungee.event.EventHandler ;
+}
# -----保护枚举方法的完整性-----
-keepclassmembers enum * {
public static **[] values();
diff --git a/src/main/java/pw/yumc/MiaoChat/MiaoChat.java b/src/main/java/pw/yumc/MiaoChat/MiaoChat.java
index 451fb4e..3774cbd 100644
--- a/src/main/java/pw/yumc/MiaoChat/MiaoChat.java
+++ b/src/main/java/pw/yumc/MiaoChat/MiaoChat.java
@@ -50,8 +50,13 @@ public class MiaoChat extends JavaPlugin implements CommandExecutor, PluginMessa
public void onEnable() {
new ChatListener();
new CommandManager("MiaoChat", this);
- Bukkit.getMessenger().registerIncomingPluginChannel(this, MiaoMessage.CHANNEL, this);
- Bukkit.getMessenger().registerOutgoingPluginChannel(this, MiaoMessage.CHANNEL);
+ if (getChatConfig().isBungeeCord()) {
+ Log.info("已开启 BUngeeCord 模式!");
+ Bukkit.getMessenger().registerIncomingPluginChannel(this, MiaoMessage.CHANNEL, this);
+ Bukkit.getMessenger().registerOutgoingPluginChannel(this, MiaoMessage.CHANNEL);
+ Bukkit.getMessenger().registerIncomingPluginChannel(this, MiaoMessage.NORMALCHANNEL, this);
+ Bukkit.getMessenger().registerOutgoingPluginChannel(this, MiaoMessage.NORMALCHANNEL);
+ }
L10N.getName(new ItemStack(Material.AIR));
}
@@ -83,6 +88,10 @@ public class MiaoChat extends JavaPlugin implements CommandExecutor, PluginMessa
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
if (MiaoMessage.CHANNEL.equals(channel)) {
send(message);
+ } else if (MiaoMessage.NORMALCHANNEL.equals(channel)) {
+ for (Player p : C.Player.getOnlinePlayers()) {
+ p.sendMessage(MiaoMessage.decode(message).getJson());
+ }
}
}
}
diff --git a/src/main/java/pw/yumc/MiaoChat/MiaoChatBungee.java b/src/main/java/pw/yumc/MiaoChat/MiaoChatBungee.java
index 5f8cf6c..589f3fc 100644
--- a/src/main/java/pw/yumc/MiaoChat/MiaoChatBungee.java
+++ b/src/main/java/pw/yumc/MiaoChat/MiaoChatBungee.java
@@ -11,11 +11,11 @@ import java.net.InetSocketAddress;
public class MiaoChatBungee extends Plugin implements Listener {
@EventHandler
public void handle(final PluginMessageEvent event) {
- if (event.getTag().equals(MiaoMessage.CHANNEL)) {
+ if (event.getTag().equals(MiaoMessage.CHANNEL) || event.getTag().equals(MiaoMessage.NORMALCHANNEL)) {
InetSocketAddress origin = event.getSender().getAddress();
for (ServerInfo server : getProxy().getServers().values()) {
if (!server.getAddress().equals(origin) && server.getPlayers().size() > 0) {
- server.sendData(MiaoMessage.CHANNEL, event.getData());
+ server.sendData(event.getTag(), event.getData());
}
}
}
@@ -24,6 +24,8 @@ public class MiaoChatBungee extends Plugin implements Listener {
@Override
public void onEnable() {
getProxy().registerChannel(MiaoMessage.CHANNEL);
+ getProxy().registerChannel(MiaoMessage.NORMALCHANNEL);
getProxy().getPluginManager().registerListener(this, this);
+ getLogger().info("注意: 通过BC转发的聊天信息将不会在控制台显示 仅客户端可见!");
}
}
diff --git a/src/main/java/pw/yumc/MiaoChat/MiaoMessage.java b/src/main/java/pw/yumc/MiaoChat/MiaoMessage.java
index 2e2ab27..ed50cf8 100644
--- a/src/main/java/pw/yumc/MiaoChat/MiaoMessage.java
+++ b/src/main/java/pw/yumc/MiaoChat/MiaoMessage.java
@@ -10,6 +10,7 @@ import com.google.common.io.ByteStreams;
public class MiaoMessage {
public static final String CHANNEL = "MiaoChat";
+ public static final String NORMALCHANNEL = "MiaoChatNM";
private String json;
private MiaoMessage(String json) {
@@ -30,6 +31,7 @@ public class MiaoMessage {
}
public byte[] encode() {
+ if (json.getBytes().length > 32000) { return null; }
final ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF(json);
return out.toByteArray();
diff --git a/src/main/java/pw/yumc/MiaoChat/config/CLICKTYPE.java b/src/main/java/pw/yumc/MiaoChat/config/CLICKTYPE.java
index 4191faf..e3787ef 100644
--- a/src/main/java/pw/yumc/MiaoChat/config/CLICKTYPE.java
+++ b/src/main/java/pw/yumc/MiaoChat/config/CLICKTYPE.java
@@ -3,5 +3,5 @@ package pw.yumc.MiaoChat.config;
public enum CLICKTYPE {
COMMAND,
SUGGEST,
- OPENURL;
+ OPENURL
}
diff --git a/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java b/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java
index 30b3140..24ba714 100644
--- a/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java
+++ b/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java
@@ -1,17 +1,12 @@
package pw.yumc.MiaoChat.config;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.Map;
-
import org.bukkit.entity.Player;
-
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.bukkit.P;
import pw.yumc.YumCore.config.FileConfig;
+import java.util.*;
+
/**
*
* @since 2016年9月9日 下午4:40:50
@@ -24,9 +19,11 @@ public class ChatConfig {
private LinkedList rules;
private FileConfig config;
private FileConfig format;
+ private boolean BungeeCord;
public ChatConfig() {
config = P.getConfig();
+ BungeeCord = config.getBoolean("BungeeCord");
format = new FileConfig("format.yml");
rulecomp = new RuleComparator();
formats = new HashMap<>();
@@ -34,6 +31,13 @@ public class ChatConfig {
load();
}
+ /**
+ * @return 是否为BC模式
+ */
+ public boolean isBungeeCord() {
+ return BungeeCord;
+ }
+
/**
* 获得玩家可用的消息处理
*
@@ -43,9 +47,7 @@ public class ChatConfig {
public ChatRule getChatRule(Player player) {
for (ChatRule cr : rules) {
Log.debug(cr.getName());
- if (cr.check(player)) {
- return cr;
- }
+ if (cr.check(player)) { return cr; }
}
return null;
}
diff --git a/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java b/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java
index 578fc23..f325707 100644
--- a/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java
+++ b/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java
@@ -43,38 +43,7 @@ public class ChatListener implements Listener {
new SubscribeTask(true, true);
}
- public void execute(final String commandList) {
- execute(commandList, false);
- }
-
- public void execute(final String command, final boolean queued) {
- final Iterator extends Player> it = C.Player.getOnlinePlayers().iterator();
- if (it.hasNext()) {
- final Player p = it.next();
- p.sendPluginMessage(P.instance, MiaoMessage.CHANNEL, MiaoMessage.encode(command));
- } else if (queued) {
- queue.offer(command);
- } else {
- throw new RuntimeException("None player channel registered! Use queued");
- }
- }
-
- private boolean processQueued() {
- if (!queue.isEmpty()) {
- final Iterator extends Player> it = C.Player.getOnlinePlayers().iterator();
- if (!it.hasNext()) { return false; }
- final Player p = it.next();
- String command = queue.poll();
- while (command != null) {
- p.sendPluginMessage(P.instance, MiaoMessage.CHANNEL, MiaoMessage.encode(command));
- command = queue.poll();
- }
- return true;
- }
- return false;
- }
-
- @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onChat(AsyncPlayerChatEvent e) {
Player p = e.getPlayer();
ChatRule cr = cc.getChatRule(e.getPlayer());
@@ -158,8 +127,17 @@ public class ChatListener implements Listener {
tr.send(p);
} else {
plist = C.Player.getOnlinePlayers();
+ if (cc.isBungeeCord()) {
+ byte[] mm = MiaoMessage.encode(tr.toJsonString());
+ if (mm == null) {
+ p.sendPluginMessage(P.instance, MiaoMessage.NORMALCHANNEL, MiaoMessage.encode(tr.toOldMessageFormat()));
+ } else {
+ p.sendPluginMessage(P.instance, MiaoMessage.CHANNEL, mm);
+ }
+ }
}
for (Entity ne : plist) {
+ // 此处必须进行强制转换 老版本服务器的Entity没有getName()
if (ne instanceof Player && !offList.contains(((Player) ne).getName())) {
tr.send(ne);
}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index e401334..e67f9b4 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -1,6 +1,8 @@
#配置文件版本号 请勿修改
-Version: 1.2
+Version: 1.3
+#BC跨服模式
+BungeeCord: true
#格式列表
Formats:
#格式名称 对应当前文件夹下的default.yml