forked from circlecloud/MiaoChat
feat: 完善分组发送 完善获取服务器
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
593ecfa48c
commit
62e5d23914
@ -16,11 +16,8 @@
|
|||||||
# -----保留所有属性
|
# -----保留所有属性
|
||||||
-keepattributes **
|
-keepattributes **
|
||||||
|
|
||||||
# -----公共数据不混淆-----
|
|
||||||
-keep class cn.citycraft.CommonData.** {*;}
|
|
||||||
|
|
||||||
# -----保护所有实体中的字段名称-----
|
# -----保护所有实体中的字段名称-----
|
||||||
-keepclassmembers class * implements java.io.Serializable { <fields>; }
|
-keepclassmembers class * implements java.io.Serializable {<fields>;}
|
||||||
|
|
||||||
# -----保护监听方法不被清理-----
|
# -----保护监听方法不被清理-----
|
||||||
-keepclassmembers class * implements org.bukkit.event.Listener {
|
-keepclassmembers class * implements org.bukkit.event.Listener {
|
||||||
@ -29,6 +26,7 @@
|
|||||||
-keepclassmembers class * implements net.md_5.bungee.api.plugin.Listener {
|
-keepclassmembers class * implements net.md_5.bungee.api.plugin.Listener {
|
||||||
@net.md_5.bungee.event.EventHandler <methods>;
|
@net.md_5.bungee.event.EventHandler <methods>;
|
||||||
}
|
}
|
||||||
|
|
||||||
# -----保护枚举方法的完整性-----
|
# -----保护枚举方法的完整性-----
|
||||||
-keepclassmembers enum * {
|
-keepclassmembers enum * {
|
||||||
public static **[] values();
|
public static **[] values();
|
||||||
@ -36,13 +34,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
# -----保护配置注入不被清理-----
|
# -----保护配置注入不被清理-----
|
||||||
-keepclassmembers class * extends **.config**Inject** {
|
-keepclassmembers class * extends **.config.inject.Inject** {
|
||||||
<fields>;
|
<fields>;
|
||||||
}
|
}
|
||||||
|
|
||||||
# -----保护注解命令方法不被清理-----
|
# -----保护注解命令方法不被清理-----
|
||||||
-keepclassmembers class **.commands.annotation.** { <methods>; }
|
-keepclassmembers class **.commands.annotation.** {<methods>;}
|
||||||
-keepclassmembers class * implements **.commands**CommandExecutor { <methods>; }
|
-keepclassmembers class * implements **.commands.interfaces.Executor {<methods>;}
|
||||||
|
|
||||||
# -----保护注解NotProguard标记-----
|
# -----保护注解NotProguard标记-----
|
||||||
-keep class **.NotProguard
|
-keep class **.NotProguard
|
||||||
|
@ -5,10 +5,19 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
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;
|
import pw.yumc.MiaoChat.config.ChatConfig;
|
||||||
import pw.yumc.MiaoChat.listeners.ChatListener;
|
import pw.yumc.MiaoChat.listeners.ChatListener;
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
@ -20,9 +29,10 @@ import pw.yumc.YumCore.commands.interfaces.Executor;
|
|||||||
import pw.yumc.YumCore.config.FileConfig;
|
import pw.yumc.YumCore.config.FileConfig;
|
||||||
import pw.yumc.YumCore.global.L10N;
|
import pw.yumc.YumCore.global.L10N;
|
||||||
|
|
||||||
public class MiaoChat extends JavaPlugin implements Executor, PluginMessageListener {
|
public class MiaoChat extends JavaPlugin implements Executor, PluginMessageListener, Listener {
|
||||||
private FileConfig cfg;
|
private FileConfig cfg;
|
||||||
private ChatConfig chatConfig;
|
private ChatConfig chatConfig;
|
||||||
|
private String ServerName;
|
||||||
|
|
||||||
public ChatConfig getChatConfig() {
|
public ChatConfig getChatConfig() {
|
||||||
return chatConfig;
|
return chatConfig;
|
||||||
@ -52,12 +62,27 @@ public class MiaoChat extends JavaPlugin implements Executor, PluginMessageListe
|
|||||||
new ChatListener();
|
new ChatListener();
|
||||||
new CommandSub("MiaoChat", this);
|
new CommandSub("MiaoChat", this);
|
||||||
if (getChatConfig().isBungeeCord()) {
|
if (getChatConfig().isBungeeCord()) {
|
||||||
Log.info("已开启 BUngeeCord 模式!");
|
Log.info("已开启 BungeeCord 模式!");
|
||||||
|
Bukkit.getMessenger().registerIncomingPluginChannel(this, "BungeeCord", this);
|
||||||
|
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
||||||
|
Bukkit.getPluginManager().registerEvents(this, this);
|
||||||
Bukkit.getMessenger().registerIncomingPluginChannel(this, MiaoMessage.CHANNEL, this);
|
Bukkit.getMessenger().registerIncomingPluginChannel(this, MiaoMessage.CHANNEL, this);
|
||||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, MiaoMessage.CHANNEL);
|
Bukkit.getMessenger().registerOutgoingPluginChannel(this, MiaoMessage.CHANNEL);
|
||||||
Bukkit.getMessenger().registerIncomingPluginChannel(this, MiaoMessage.NORMALCHANNEL, this);
|
Bukkit.getMessenger().registerIncomingPluginChannel(this, MiaoMessage.NORMALCHANNEL, this);
|
||||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, MiaoMessage.NORMALCHANNEL);
|
Bukkit.getMessenger().registerOutgoingPluginChannel(this, MiaoMessage.NORMALCHANNEL);
|
||||||
}
|
}
|
||||||
|
PlaceholderAPI.registerPlaceholderHook("mct", new PlaceholderHook() {
|
||||||
|
@Override
|
||||||
|
public String onPlaceholderRequest(Player player, String s) {
|
||||||
|
switch (s.toLowerCase()) {
|
||||||
|
case "server":
|
||||||
|
return getChatConfig().getServername();
|
||||||
|
case "bserver":
|
||||||
|
return ServerName;
|
||||||
|
}
|
||||||
|
return "未知的参数";
|
||||||
|
}
|
||||||
|
});
|
||||||
L10N.getName(new ItemStack(Material.AIR));
|
L10N.getName(new ItemStack(Material.AIR));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,6 +110,21 @@ public class MiaoChat extends JavaPlugin implements Executor, PluginMessageListe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onJoin(final PlayerJoinEvent e) {
|
||||||
|
Bukkit.getScheduler().runTaskLater(this, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Player p = e.getPlayer();
|
||||||
|
if (p.isOnline()) {
|
||||||
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
|
out.writeUTF("GetServer");
|
||||||
|
p.sendPluginMessage(MiaoChat.this, "BungeeCord", out.toByteArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 10);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
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)) {
|
||||||
@ -93,6 +133,20 @@ public class MiaoChat extends JavaPlugin implements Executor, PluginMessageListe
|
|||||||
for (Player p : C.Player.getOnlinePlayers()) {
|
for (Player p : C.Player.getOnlinePlayers()) {
|
||||||
p.sendMessage(MiaoMessage.decode(message).getJson());
|
p.sendMessage(MiaoMessage.decode(message).getJson());
|
||||||
}
|
}
|
||||||
|
} else if ("BungeeCord".equals(channel)) {
|
||||||
|
final ByteArrayDataInput input = ByteStreams.newDataInput(message);
|
||||||
|
if ("GetServer".equals(input.readUTF())) {
|
||||||
|
ServerName = input.readUTF();
|
||||||
|
Log.d("获取服务器名称: " + ServerName);
|
||||||
|
PlayerJoinEvent.getHandlerList().unregister((Listener) this);
|
||||||
|
Bukkit.getScheduler().runTaskLater(this, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Bukkit.getMessenger().unregisterIncomingPluginChannel(MiaoChat.this, "BungeeCord");
|
||||||
|
Bukkit.getMessenger().unregisterOutgoingPluginChannel(MiaoChat.this, "BungeeCord");
|
||||||
|
}
|
||||||
|
}, 20);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,16 +12,17 @@ import net.md_5.bungee.api.plugin.Plugin;
|
|||||||
import net.md_5.bungee.config.Configuration;
|
import net.md_5.bungee.config.Configuration;
|
||||||
import net.md_5.bungee.event.EventHandler;
|
import net.md_5.bungee.event.EventHandler;
|
||||||
import pw.yumc.MiaoChat.bungee.FileConfig;
|
import pw.yumc.MiaoChat.bungee.FileConfig;
|
||||||
|
import pw.yumc.MiaoChat.bungee.Log;
|
||||||
|
|
||||||
public class MiaoChatBungee extends Plugin implements Listener {
|
public class MiaoChatBungee extends Plugin implements Listener {
|
||||||
private Map<InetSocketAddress, Set<InetSocketAddress>> groups;
|
private Map<InetSocketAddress, Set<ServerInfo>> groups;
|
||||||
private FileConfig config;
|
private FileConfig config;
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void handle(final PluginMessageEvent event) {
|
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.NORMALCHANNEL)) {
|
||||||
InetSocketAddress origin = event.getSender().getAddress();
|
InetSocketAddress origin = event.getSender().getAddress();
|
||||||
for (ServerInfo server : getProxy().getServers().values()) {
|
for (ServerInfo server : groups.get(origin)) {
|
||||||
if (!server.getAddress().equals(origin) && server.getPlayers().size() > 0) {
|
if (!server.getAddress().equals(origin) && server.getPlayers().size() > 0) {
|
||||||
server.sendData(event.getTag(), event.getData());
|
server.sendData(event.getTag(), event.getData());
|
||||||
}
|
}
|
||||||
@ -31,55 +32,57 @@ public class MiaoChatBungee extends Plugin implements Listener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
|
Log.init(this);
|
||||||
config = new FileConfig(this, "group.yml");
|
config = new FileConfig(this, "group.yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadGroup() {
|
public void loadGroup() {
|
||||||
Map<String, InetSocketAddress> temp = new HashMap<>();
|
groups = new HashMap<>();
|
||||||
Set<InetSocketAddress> unused = new HashSet<>();
|
Map<String, ServerInfo> temp = getProxy().getServers();
|
||||||
for (ServerInfo server : getProxy().getServers().values()) {
|
Set<ServerInfo> unused = new HashSet<>();
|
||||||
temp.put(server.getName(), server.getAddress());
|
|
||||||
}
|
|
||||||
Configuration groupSel = config.getSection("Groups");
|
Configuration groupSel = config.getSection("Groups");
|
||||||
Collection<String> groupname = groupSel.getKeys();
|
Collection<String> groupname = groupSel.getKeys();
|
||||||
for (String gname : groupname) {
|
for (String gname : groupname) {
|
||||||
Set<String> servers = new HashSet<>(groupSel.getStringList(gname));
|
Set<String> servers = new HashSet<>(groupSel.getStringList(gname));
|
||||||
Set<InetSocketAddress> serISA = new HashSet<>();
|
Set<ServerInfo> sers = new HashSet<>();
|
||||||
for (String sname : servers) {
|
for (String sname : servers) {
|
||||||
serISA.add(temp.get(sname));
|
sers.add(temp.get(sname));
|
||||||
}
|
}
|
||||||
serISA.remove(null);
|
sers.remove(null);
|
||||||
for (String sname : servers) {
|
for (String sname : servers) {
|
||||||
InetSocketAddress isadd = temp.get(sname);
|
ServerInfo isadd = temp.get(sname);
|
||||||
if (isadd != null) {
|
if (isadd != null) {
|
||||||
unused.remove(isadd);
|
unused.remove(isadd);
|
||||||
groups.put(isadd, serISA);
|
groups.put(isadd.getAddress(), sers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (InetSocketAddress unser : unused) {
|
for (ServerInfo unser : unused) {
|
||||||
groups.put(unser, unused);
|
groups.put(unser.getAddress(), unused);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
loadGroup();
|
||||||
getProxy().registerChannel(MiaoMessage.CHANNEL);
|
getProxy().registerChannel(MiaoMessage.CHANNEL);
|
||||||
getProxy().registerChannel(MiaoMessage.NORMALCHANNEL);
|
getProxy().registerChannel(MiaoMessage.NORMALCHANNEL);
|
||||||
getProxy().getPluginManager().registerListener(this, this);
|
getProxy().getPluginManager().registerListener(this, this);
|
||||||
getProxy().getPluginManager().registerCommand(this, new Command("MiaoChat", "MiaoChat.admin", "mct") {
|
getProxy().getPluginManager().registerCommand(this, new Command("MiaoChat", "MiaoChat.admin", "mct") {
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender commandSender, String[] args) {
|
public void execute(CommandSender commandSender, String[] args) {
|
||||||
if (args.length > 1) {
|
if (args.length > 0) {
|
||||||
switch (args[0].toLowerCase()) {
|
switch (args[0].toLowerCase()) {
|
||||||
case "reload":
|
case "reload":
|
||||||
onLoad();
|
config.reload();
|
||||||
break;
|
loadGroup();
|
||||||
|
commandSender.sendMessage("§a配置文件已重载!");
|
||||||
|
return;
|
||||||
case "version":
|
case "version":
|
||||||
commandSender.sendMessage(getDescription().getVersion());
|
default:
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
commandSender.sendMessage("§6插件版本: §av" + getDescription().getVersion());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
getLogger().info("注意: 通过BC转发的聊天信息将不会在控制台显示 仅客户端可见!");
|
getLogger().info("注意: 通过BC转发的聊天信息将不会在控制台显示 仅客户端可见!");
|
||||||
|
@ -171,6 +171,9 @@ public class FileConfig {
|
|||||||
this.file = new File(plugin.getDataFolder(), name);
|
this.file = new File(plugin.getDataFolder(), name);
|
||||||
try {
|
try {
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
|
if (!file.getParentFile().exists()) {
|
||||||
|
file.getParentFile().mkdirs();
|
||||||
|
}
|
||||||
Files.copy(plugin.getResourceAsStream(name), file.toPath());
|
Files.copy(plugin.getResourceAsStream(name), file.toPath());
|
||||||
}
|
}
|
||||||
this.config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
|
this.config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
|
||||||
@ -191,7 +194,15 @@ public class FileConfig {
|
|||||||
Log.w("配置文件保存失败!");
|
Log.w("配置文件保存失败!");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reload() {
|
||||||
|
try {
|
||||||
|
this.config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.w("配置文件读取失败!");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ public class ChatConfig {
|
|||||||
private LinkedList<ChatRule> rules;
|
private LinkedList<ChatRule> rules;
|
||||||
private FileConfig config;
|
private FileConfig config;
|
||||||
private FileConfig format;
|
private FileConfig format;
|
||||||
|
private String servername;
|
||||||
private boolean BungeeCord;
|
private boolean BungeeCord;
|
||||||
|
|
||||||
public ChatConfig() {
|
public ChatConfig() {
|
||||||
@ -58,6 +59,7 @@ public class ChatConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void load() {
|
public void load() {
|
||||||
|
servername = config.getMessage("Server");
|
||||||
formats.clear();
|
formats.clear();
|
||||||
for (String name : format.getKeys(false)) {
|
for (String name : format.getKeys(false)) {
|
||||||
formats.put(name, new ChatMessagePart(format.getConfigurationSection(name)));
|
formats.put(name, new ChatMessagePart(format.getConfigurationSection(name)));
|
||||||
@ -73,6 +75,10 @@ public class ChatConfig {
|
|||||||
Collections.sort(rules, rulecomp);
|
Collections.sort(rules, rulecomp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getServername() {
|
||||||
|
return servername;
|
||||||
|
}
|
||||||
|
|
||||||
public void reload() {
|
public void reload() {
|
||||||
format.reload();
|
format.reload();
|
||||||
load();
|
load();
|
||||||
|
@ -23,7 +23,6 @@ import pw.yumc.YumCore.tellraw.Tellraw;
|
|||||||
*/
|
*/
|
||||||
public class ChatRule extends InjectConfigurationSection {
|
public class ChatRule extends InjectConfigurationSection {
|
||||||
private transient static MiaoChat plugin = P.getPlugin();
|
private transient static MiaoChat plugin = P.getPlugin();
|
||||||
private transient static ChatConfig cc = plugin.getChatConfig();
|
|
||||||
private transient static Pattern FORMAT_PATTERN = Pattern.compile("[\\[]([^\\[\\]]+)[]]");
|
private transient static Pattern FORMAT_PATTERN = Pattern.compile("[\\[]([^\\[\\]]+)[]]");
|
||||||
private transient String name;
|
private transient String name;
|
||||||
@Default("50")
|
@Default("50")
|
||||||
@ -97,7 +96,7 @@ public class ChatRule extends InjectConfigurationSection {
|
|||||||
public Tellraw create(Player p) {
|
public Tellraw create(Player p) {
|
||||||
Tellraw tr = Tellraw.create();
|
Tellraw tr = Tellraw.create();
|
||||||
for (String format : formats) {
|
for (String format : formats) {
|
||||||
ChatMessagePart cmp = cc.getFormats().get(format);
|
ChatMessagePart cmp = plugin.getChatConfig().getFormats().get(format);
|
||||||
if (cmp != null) {
|
if (cmp != null) {
|
||||||
// Log.d("解析格式: %s", format);
|
// Log.d("解析格式: %s", format);
|
||||||
cmp.then(tr, p);
|
cmp.then(tr, p);
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
#配置文件版本号 请勿修改
|
#配置文件版本号 请勿修改
|
||||||
Version: 1.3
|
Version: 1.6
|
||||||
|
|
||||||
#BC跨服模式
|
#BC跨服模式
|
||||||
BungeeCord: true
|
BungeeCord: true
|
||||||
|
#当前服务器名称(变量为%mct_server%)
|
||||||
|
Server: '§a生存服'
|
||||||
#格式列表
|
#格式列表
|
||||||
Formats:
|
Formats:
|
||||||
#格式名称 对应当前文件夹下的default.yml
|
#格式名称 对应当前文件夹下的default.yml
|
||||||
|
Loading…
Reference in New Issue
Block a user