mirror of
https://e.coding.net/circlecloud/MiaoChat.git
synced 2024-11-14 13:28:46 +00:00
feat: 完善BungeeCord模式
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
7d72c97c3b
commit
cfe7f8c919
5
pom.xml
5
pom.xml
@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>pw.yumc</groupId>
|
<groupId>pw.yumc</groupId>
|
||||||
<artifactId>MiaoChat</artifactId>
|
<artifactId>MiaoChat</artifactId>
|
||||||
<version>1.3.3</version>
|
<version>1.5</version>
|
||||||
<build>
|
<build>
|
||||||
<finalName>${project.name}</finalName>
|
<finalName>${project.name}</finalName>
|
||||||
<resources>
|
<resources>
|
||||||
@ -62,6 +62,9 @@
|
|||||||
<options>
|
<options>
|
||||||
<option>-repackageclasses \ʼ.ʽ.ʾ.${project.artifactId}</option>
|
<option>-repackageclasses \ʼ.ʽ.ʾ.${project.artifactId}</option>
|
||||||
<option>-keep class ${project.groupId}.${project.artifactId}.${project.artifactId}</option>
|
<option>-keep class ${project.groupId}.${project.artifactId}.${project.artifactId}</option>
|
||||||
|
<option>-keep class
|
||||||
|
${project.groupId}.${project.artifactId}.${project.artifactId}Bungee
|
||||||
|
</option>
|
||||||
</options>
|
</options>
|
||||||
<libs>
|
<libs>
|
||||||
<lib>${java.home}/lib/rt.jar</lib>
|
<lib>${java.home}/lib/rt.jar</lib>
|
||||||
|
@ -26,7 +26,9 @@
|
|||||||
-keepclassmembers class * implements org.bukkit.event.Listener {
|
-keepclassmembers class * implements org.bukkit.event.Listener {
|
||||||
@org.bukkit.event.EventHandler <methods>;
|
@org.bukkit.event.EventHandler <methods>;
|
||||||
}
|
}
|
||||||
|
-keepclassmembers class * implements net.md_5.bungee.api.plugin.Listener {
|
||||||
|
@net.md_5.bungee.event.EventHandler <methods>;
|
||||||
|
}
|
||||||
# -----保护枚举方法的完整性-----
|
# -----保护枚举方法的完整性-----
|
||||||
-keepclassmembers enum * {
|
-keepclassmembers enum * {
|
||||||
public static **[] values();
|
public static **[] values();
|
||||||
|
@ -50,8 +50,13 @@ public class MiaoChat extends JavaPlugin implements CommandExecutor, PluginMessa
|
|||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
new ChatListener();
|
new ChatListener();
|
||||||
new CommandManager("MiaoChat", this);
|
new CommandManager("MiaoChat", this);
|
||||||
Bukkit.getMessenger().registerIncomingPluginChannel(this, MiaoMessage.CHANNEL, this);
|
if (getChatConfig().isBungeeCord()) {
|
||||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, MiaoMessage.CHANNEL);
|
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));
|
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) {
|
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
||||||
if (MiaoMessage.CHANNEL.equals(channel)) {
|
if (MiaoMessage.CHANNEL.equals(channel)) {
|
||||||
send(message);
|
send(message);
|
||||||
|
} else if (MiaoMessage.NORMALCHANNEL.equals(channel)) {
|
||||||
|
for (Player p : C.Player.getOnlinePlayers()) {
|
||||||
|
p.sendMessage(MiaoMessage.decode(message).getJson());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,11 @@ import java.net.InetSocketAddress;
|
|||||||
public class MiaoChatBungee extends Plugin implements Listener {
|
public class MiaoChatBungee extends Plugin implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void handle(final PluginMessageEvent event) {
|
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();
|
InetSocketAddress origin = event.getSender().getAddress();
|
||||||
for (ServerInfo server : getProxy().getServers().values()) {
|
for (ServerInfo server : getProxy().getServers().values()) {
|
||||||
if (!server.getAddress().equals(origin) && server.getPlayers().size() > 0) {
|
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
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
getProxy().registerChannel(MiaoMessage.CHANNEL);
|
getProxy().registerChannel(MiaoMessage.CHANNEL);
|
||||||
|
getProxy().registerChannel(MiaoMessage.NORMALCHANNEL);
|
||||||
getProxy().getPluginManager().registerListener(this, this);
|
getProxy().getPluginManager().registerListener(this, this);
|
||||||
|
getLogger().info("注意: 通过BC转发的聊天信息将不会在控制台显示 仅客户端可见!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import com.google.common.io.ByteStreams;
|
|||||||
public class MiaoMessage {
|
public class MiaoMessage {
|
||||||
|
|
||||||
public static final String CHANNEL = "MiaoChat";
|
public static final String CHANNEL = "MiaoChat";
|
||||||
|
public static final String NORMALCHANNEL = "MiaoChatNM";
|
||||||
private String json;
|
private String json;
|
||||||
|
|
||||||
private MiaoMessage(String json) {
|
private MiaoMessage(String json) {
|
||||||
@ -30,6 +31,7 @@ public class MiaoMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public byte[] encode() {
|
public byte[] encode() {
|
||||||
|
if (json.getBytes().length > 32000) { return null; }
|
||||||
final ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
final ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
out.writeUTF(json);
|
out.writeUTF(json);
|
||||||
return out.toByteArray();
|
return out.toByteArray();
|
||||||
|
@ -3,5 +3,5 @@ package pw.yumc.MiaoChat.config;
|
|||||||
public enum CLICKTYPE {
|
public enum CLICKTYPE {
|
||||||
COMMAND,
|
COMMAND,
|
||||||
SUGGEST,
|
SUGGEST,
|
||||||
OPENURL;
|
OPENURL
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,12 @@
|
|||||||
package pw.yumc.MiaoChat.config;
|
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 org.bukkit.entity.Player;
|
||||||
|
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
import pw.yumc.YumCore.bukkit.P;
|
import pw.yumc.YumCore.bukkit.P;
|
||||||
import pw.yumc.YumCore.config.FileConfig;
|
import pw.yumc.YumCore.config.FileConfig;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @since 2016年9月9日 下午4:40:50
|
* @since 2016年9月9日 下午4:40:50
|
||||||
@ -24,9 +19,11 @@ public class ChatConfig {
|
|||||||
private LinkedList<ChatRule> rules;
|
private LinkedList<ChatRule> rules;
|
||||||
private FileConfig config;
|
private FileConfig config;
|
||||||
private FileConfig format;
|
private FileConfig format;
|
||||||
|
private boolean BungeeCord;
|
||||||
|
|
||||||
public ChatConfig() {
|
public ChatConfig() {
|
||||||
config = P.getConfig();
|
config = P.getConfig();
|
||||||
|
BungeeCord = config.getBoolean("BungeeCord");
|
||||||
format = new FileConfig("format.yml");
|
format = new FileConfig("format.yml");
|
||||||
rulecomp = new RuleComparator();
|
rulecomp = new RuleComparator();
|
||||||
formats = new HashMap<>();
|
formats = new HashMap<>();
|
||||||
@ -34,6 +31,13 @@ public class ChatConfig {
|
|||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 是否为BC模式
|
||||||
|
*/
|
||||||
|
public boolean isBungeeCord() {
|
||||||
|
return BungeeCord;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得玩家可用的消息处理
|
* 获得玩家可用的消息处理
|
||||||
*
|
*
|
||||||
@ -43,9 +47,7 @@ public class ChatConfig {
|
|||||||
public ChatRule getChatRule(Player player) {
|
public ChatRule getChatRule(Player player) {
|
||||||
for (ChatRule cr : rules) {
|
for (ChatRule cr : rules) {
|
||||||
Log.debug(cr.getName());
|
Log.debug(cr.getName());
|
||||||
if (cr.check(player)) {
|
if (cr.check(player)) { return cr; }
|
||||||
return cr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -43,38 +43,7 @@ public class ChatListener implements Listener {
|
|||||||
new SubscribeTask(true, true);
|
new SubscribeTask(true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void execute(final String commandList) {
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
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)
|
|
||||||
public void onChat(AsyncPlayerChatEvent e) {
|
public void onChat(AsyncPlayerChatEvent e) {
|
||||||
Player p = e.getPlayer();
|
Player p = e.getPlayer();
|
||||||
ChatRule cr = cc.getChatRule(e.getPlayer());
|
ChatRule cr = cc.getChatRule(e.getPlayer());
|
||||||
@ -158,8 +127,17 @@ public class ChatListener implements Listener {
|
|||||||
tr.send(p);
|
tr.send(p);
|
||||||
} else {
|
} else {
|
||||||
plist = C.Player.getOnlinePlayers();
|
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) {
|
for (Entity ne : plist) {
|
||||||
|
// 此处必须进行强制转换 老版本服务器的Entity没有getName()
|
||||||
if (ne instanceof Player && !offList.contains(((Player) ne).getName())) {
|
if (ne instanceof Player && !offList.contains(((Player) ne).getName())) {
|
||||||
tr.send(ne);
|
tr.send(ne);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#配置文件版本号 请勿修改
|
#配置文件版本号 请勿修改
|
||||||
Version: 1.2
|
Version: 1.3
|
||||||
|
|
||||||
|
#BC跨服模式
|
||||||
|
BungeeCord: true
|
||||||
#格式列表
|
#格式列表
|
||||||
Formats:
|
Formats:
|
||||||
#格式名称 对应当前文件夹下的default.yml
|
#格式名称 对应当前文件夹下的default.yml
|
||||||
|
Loading…
Reference in New Issue
Block a user