diff --git a/pom.xml b/pom.xml
index 2b79a19..7e5641e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
MiaoChat
- 1.8.8
+ 1.8.9
pw.yumc
@@ -13,8 +13,10 @@
- §a正式版本 §bv1.8.7 §a兼容 Spigot 1.13.2
+ §a正式版本 §bv1.8.9 §a兼容 Spigot 1.13.2
+ §619-05-31 §a增强: 跨服聊天压缩数据 增加可传输内容大小;
+ §619-05-29 §c修复: 1.7.10不兼容的问题;
§619-02-23 §c修复: BungeeCord 兼容性问题;
diff --git a/src/main/java/pw/yumc/MiaoChat/MiaoChat.java b/src/main/java/pw/yumc/MiaoChat/MiaoChat.java
index 3c51916..8ab9071 100644
--- a/src/main/java/pw/yumc/MiaoChat/MiaoChat.java
+++ b/src/main/java/pw/yumc/MiaoChat/MiaoChat.java
@@ -15,7 +15,6 @@ import org.bukkit.plugin.messaging.PluginMessageListener;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
-
import me.clip.placeholderapi.PlaceholderAPI;
import me.clip.placeholderapi.PlaceholderHook;
import pw.yumc.MiaoChat.config.ChatConfig;
@@ -74,8 +73,8 @@ public class MiaoChat extends JavaPlugin implements Executor, PluginMessageListe
Bukkit.getPluginManager().registerEvents(this, this);
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);
+ Bukkit.getMessenger().registerIncomingPluginChannel(this, MiaoMessage.NORMAL_CHANNEL, this);
+ Bukkit.getMessenger().registerOutgoingPluginChannel(this, MiaoMessage.NORMAL_CHANNEL);
}
}
@@ -88,6 +87,7 @@ public class MiaoChat extends JavaPlugin implements Executor, PluginMessageListe
return getChatConfig().getServername();
case "bserver":
return ServerName;
+ default:
}
return "未知的参数";
}
@@ -134,7 +134,7 @@ public class MiaoChat extends JavaPlugin implements Executor, PluginMessageListe
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
if (MiaoMessage.CHANNEL.equals(channel)) {
send(message);
- } else if (MiaoMessage.NORMALCHANNEL.equals(channel)) {
+ } else if (MiaoMessage.NORMAL_CHANNEL.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 488e8a3..f9cbf2d 100644
--- a/src/main/java/pw/yumc/MiaoChat/MiaoChatBungee.java
+++ b/src/main/java/pw/yumc/MiaoChat/MiaoChatBungee.java
@@ -1,7 +1,6 @@
package pw.yumc.MiaoChat;
import java.net.InetSocketAddress;
-import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -18,13 +17,16 @@ import net.md_5.bungee.event.EventHandler;
import pw.yumc.MiaoChat.bungee.FileConfig;
import pw.yumc.MiaoChat.bungee.Log;
+/**
+ * @author MiaoWoo
+ */
public class MiaoChatBungee extends Plugin implements Listener {
private Map> groups;
private FileConfig config;
@EventHandler
public void handle(final PluginMessageEvent event) {
- if (event.getTag().equals(MiaoMessage.CHANNEL) || event.getTag().equals(MiaoMessage.NORMALCHANNEL)) {
+ if (event.getTag().equals(MiaoMessage.CHANNEL) || event.getTag().equals(MiaoMessage.NORMAL_CHANNEL)) {
InetSocketAddress origin = event.getSender().getAddress();
if (groups.containsKey(origin)) {
groups.get(origin).forEach(server -> {
@@ -45,43 +47,40 @@ public class MiaoChatBungee extends Plugin implements Listener {
public void loadGroup() {
groups = new HashMap<>();
Map temp = getProxy().getServers();
- Set unused = new HashSet<>();
+ Set unused = new HashSet<>(temp.values());
Configuration groupSel = config.getSection("Groups");
- Collection groupname = groupSel.getKeys();
- groupname.forEach(gname -> {
- Set servers = new HashSet<>(groupSel.getStringList(gname));
- Set sers = new HashSet<>();
- servers.forEach(sname -> sers.add(temp.get(sname)));
- sers.remove(null);
- servers.forEach(sname -> {
- ServerInfo isadd = temp.get(sname);
- if (isadd != null) {
- unused.remove(isadd);
- groups.put(isadd.getAddress(), sers);
+ groupSel.getKeys().forEach(groupName -> {
+ Set servers = new HashSet<>(groupSel.getStringList(groupName));
+ Set serverInfos = new HashSet<>();
+ servers.forEach(s -> {
+ if (temp.containsKey(s)) {
+ ServerInfo serverInfo = temp.get(s);
+ unused.remove(serverInfo);
+ groups.put(serverInfo.getAddress(), serverInfos);
}
});
});
- unused.forEach(unser -> groups.put(unser.getAddress(), unused));
+ unused.forEach(serverInfo -> groups.put(serverInfo.getAddress(), unused));
}
@Override
public void onEnable() {
loadGroup();
getProxy().registerChannel(MiaoMessage.CHANNEL);
- getProxy().registerChannel(MiaoMessage.NORMALCHANNEL);
+ getProxy().registerChannel(MiaoMessage.NORMAL_CHANNEL);
getProxy().getPluginManager().registerListener(this, this);
getProxy().getPluginManager().registerCommand(this, new Command("MiaoChat", "MiaoChat.admin", "mct") {
@Override
public void execute(CommandSender commandSender, String[] args) {
if (args.length > 0) {
switch (args[0].toLowerCase()) {
- case "reload":
- config.reload();
- loadGroup();
- commandSender.sendMessage("§a配置文件已重载!");
- return;
- case "version":
- default:
+ case "reload":
+ config.reload();
+ loadGroup();
+ commandSender.sendMessage("§a配置文件已重载!");
+ return;
+ case "version":
+ default:
}
}
commandSender.sendMessage("§6插件版本: §av" + getDescription().getVersion());
diff --git a/src/main/java/pw/yumc/MiaoChat/MiaoMessage.java b/src/main/java/pw/yumc/MiaoChat/MiaoMessage.java
index fc2d65e..20d7c7c 100644
--- a/src/main/java/pw/yumc/MiaoChat/MiaoMessage.java
+++ b/src/main/java/pw/yumc/MiaoChat/MiaoMessage.java
@@ -1,16 +1,24 @@
package pw.yumc.MiaoChat;
-import com.google.common.io.ByteArrayDataInput;
-import com.google.common.io.ByteArrayDataOutput;
-import com.google.common.io.ByteStreams;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
+
+import lombok.SneakyThrows;
/**
* Created on 16-9-8.
+ * @author MiaoWoo
*/
public class MiaoMessage {
- public static final String CHANNEL = "MiaoChat:MiaoChat".toLowerCase();
- public static final String NORMALCHANNEL = "MiaoChat:MiaoChatNM".toLowerCase();
+ public static final String CHANNEL = "MiaoChat:Default".toLowerCase();
+ public static final String NORMAL_CHANNEL = "MiaoChat:Normal".toLowerCase();
+ private static final int MAX_MESSAGE_LENGTH = 32000;
private String json;
private MiaoMessage(String json) {
@@ -21,19 +29,33 @@ public class MiaoMessage {
return new MiaoMessage(in).encode();
}
+ @SneakyThrows
public static MiaoMessage decode(byte[] in) {
- final ByteArrayDataInput input = ByteStreams.newDataInput(in);
- return new MiaoMessage(input.readUTF());
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ copy(new GZIPInputStream(new ByteArrayInputStream(in)), baos);
+ return new MiaoMessage(baos.toString("UTF-8"));
}
public String getJson() {
return json;
}
+ @SneakyThrows
public byte[] encode() {
- if (json.getBytes().length > 32000) { return null; }
- final ByteArrayDataOutput out = ByteStreams.newDataOutput();
- out.writeUTF(json);
- return out.toByteArray();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ copy(new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)), new GZIPOutputStream(baos));
+ if (baos.size() > MAX_MESSAGE_LENGTH) { return null; }
+ return baos.toByteArray();
+ }
+
+ @SneakyThrows
+ private static void copy(InputStream input, OutputStream output) {
+ byte[] buffer = new byte[1024];
+ int n;
+ while ((n = input.read(buffer)) != -1) {
+ output.write(buffer, 0, n);
+ }
+ input.close();
+ output.close();
}
}
\ No newline at end of file
diff --git a/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java b/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java
index a71d3a8..4cbdde8 100644
--- a/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java
+++ b/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java
@@ -28,6 +28,9 @@ import pw.yumc.YumCore.statistic.Statistics;
import pw.yumc.YumCore.tellraw.Tellraw;
import pw.yumc.YumCore.update.SubscribeTask;
+/**
+ * @author MiaoWoo
+ */
public class ChatListener implements Listener {
public static Set offList = new HashSet<>();
private static Pattern ITEM_PATTERN = Pattern.compile("%([i1-9]?)");
@@ -111,7 +114,7 @@ public class ChatListener implements Listener {
byte[] mm = MiaoMessage.encode(tr.toJsonString());
// 数据流等于NULL代表数据超长
if (mm == null) {
- p.sendPluginMessage(P.instance, MiaoMessage.NORMALCHANNEL, MiaoMessage.encode(tr.toOldMessageFormat()));
+ p.sendPluginMessage(P.instance, MiaoMessage.NORMAL_CHANNEL, MiaoMessage.encode(tr.toOldMessageFormat()));
} else {
p.sendPluginMessage(P.instance, MiaoMessage.CHANNEL, mm);
}
diff --git a/src/main/resources/group.yml b/src/main/resources/group.yml
index 95982d5..0745489 100644
--- a/src/main/resources/group.yml
+++ b/src/main/resources/group.yml
@@ -7,9 +7,9 @@ Version: 1.0
Groups:
#普通分组
normal:
- - 'sc1'
- - 'sc2'
+ # - 'sc1'
+ # - 'sc2'
#游戏分组
games:
- - 'bw1'
- - 'sg1'
\ No newline at end of file
+# - 'bw1'
+# - 'sg1'
\ No newline at end of file