mirror of
https://e.coding.net/circlecloud/MiaoChat.git
synced 2024-12-21 19:08:47 +00:00
feat: 完善分组发送 完善获取服务器
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
593ecfa48c
commit
62e5d23914
@ -6,7 +6,7 @@
|
||||
-dontnote
|
||||
|
||||
# -----混淆时应用侵入式重载-----
|
||||
-overloadaggressively
|
||||
-overloadaggressively
|
||||
|
||||
# -----启用混淆字典-----
|
||||
-obfuscationdictionary obf.dict
|
||||
@ -16,38 +16,36 @@
|
||||
# -----保留所有属性
|
||||
-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 {
|
||||
@org.bukkit.event.EventHandler <methods>;
|
||||
-keepclassmembers class * implements org.bukkit.event.Listener {
|
||||
@org.bukkit.event.EventHandler <methods>;
|
||||
}
|
||||
-keepclassmembers class * implements net.md_5.bungee.api.plugin.Listener {
|
||||
@net.md_5.bungee.event.EventHandler <methods>;
|
||||
}
|
||||
|
||||
# -----保护枚举方法的完整性-----
|
||||
-keepclassmembers enum * {
|
||||
public static **[] values();
|
||||
public static ** valueOf(java.lang.String);
|
||||
-keepclassmembers enum * {
|
||||
public static **[] values();
|
||||
public static ** valueOf(java.lang.String);
|
||||
}
|
||||
|
||||
# -----保护配置注入不被清理-----
|
||||
-keepclassmembers class * extends **.config**Inject** {
|
||||
<fields>;
|
||||
-keepclassmembers class * extends **.config.inject.Inject** {
|
||||
<fields>;
|
||||
}
|
||||
|
||||
# -----保护注解命令方法不被清理-----
|
||||
-keepclassmembers class **.commands.annotation.** { <methods>; }
|
||||
-keepclassmembers class * implements **.commands**CommandExecutor { <methods>; }
|
||||
-keepclassmembers class **.commands.annotation.** {<methods>;}
|
||||
-keepclassmembers class * implements **.commands.interfaces.Executor {<methods>;}
|
||||
|
||||
# -----保护注解NotProguard标记-----
|
||||
-keep class **.NotProguard
|
||||
-keep @**.NotProguard class * {*;}
|
||||
-keepclassmembers class * {
|
||||
@**.NotProguard <fields>;
|
||||
@**.NotProguard <methods>;
|
||||
-keepclassmembers class * {
|
||||
@**.NotProguard <fields>;
|
||||
@**.NotProguard <methods>;
|
||||
}
|
@ -5,10 +5,19 @@ import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
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.plugin.java.JavaPlugin;
|
||||
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.listeners.ChatListener;
|
||||
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.global.L10N;
|
||||
|
||||
public class MiaoChat extends JavaPlugin implements Executor, PluginMessageListener {
|
||||
public class MiaoChat extends JavaPlugin implements Executor, PluginMessageListener, Listener {
|
||||
private FileConfig cfg;
|
||||
private ChatConfig chatConfig;
|
||||
private String ServerName;
|
||||
|
||||
public ChatConfig getChatConfig() {
|
||||
return chatConfig;
|
||||
@ -52,12 +62,27 @@ public class MiaoChat extends JavaPlugin implements Executor, PluginMessageListe
|
||||
new ChatListener();
|
||||
new CommandSub("MiaoChat", this);
|
||||
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().registerOutgoingPluginChannel(this, MiaoMessage.CHANNEL);
|
||||
Bukkit.getMessenger().registerIncomingPluginChannel(this, MiaoMessage.NORMALCHANNEL, this);
|
||||
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));
|
||||
}
|
||||
|
||||
@ -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
|
||||
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
||||
if (MiaoMessage.CHANNEL.equals(channel)) {
|
||||
@ -93,6 +133,20 @@ public class MiaoChat extends JavaPlugin implements Executor, PluginMessageListe
|
||||
for (Player p : C.Player.getOnlinePlayers()) {
|
||||
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.event.EventHandler;
|
||||
import pw.yumc.MiaoChat.bungee.FileConfig;
|
||||
import pw.yumc.MiaoChat.bungee.Log;
|
||||
|
||||
public class MiaoChatBungee extends Plugin implements Listener {
|
||||
private Map<InetSocketAddress, Set<InetSocketAddress>> groups;
|
||||
private Map<InetSocketAddress, Set<ServerInfo>> groups;
|
||||
private FileConfig config;
|
||||
|
||||
@EventHandler
|
||||
public void handle(final PluginMessageEvent event) {
|
||||
if (event.getTag().equals(MiaoMessage.CHANNEL) || event.getTag().equals(MiaoMessage.NORMALCHANNEL)) {
|
||||
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) {
|
||||
server.sendData(event.getTag(), event.getData());
|
||||
}
|
||||
@ -31,55 +32,57 @@ public class MiaoChatBungee extends Plugin implements Listener {
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
Log.init(this);
|
||||
config = new FileConfig(this, "group.yml");
|
||||
}
|
||||
|
||||
public void loadGroup() {
|
||||
Map<String, InetSocketAddress> temp = new HashMap<>();
|
||||
Set<InetSocketAddress> unused = new HashSet<>();
|
||||
for (ServerInfo server : getProxy().getServers().values()) {
|
||||
temp.put(server.getName(), server.getAddress());
|
||||
}
|
||||
groups = new HashMap<>();
|
||||
Map<String, ServerInfo> temp = getProxy().getServers();
|
||||
Set<ServerInfo> unused = new HashSet<>();
|
||||
Configuration groupSel = config.getSection("Groups");
|
||||
Collection<String> groupname = groupSel.getKeys();
|
||||
for (String gname : groupname) {
|
||||
Set<String> servers = new HashSet<>(groupSel.getStringList(gname));
|
||||
Set<InetSocketAddress> serISA = new HashSet<>();
|
||||
Set<ServerInfo> sers = new HashSet<>();
|
||||
for (String sname : servers) {
|
||||
serISA.add(temp.get(sname));
|
||||
sers.add(temp.get(sname));
|
||||
}
|
||||
serISA.remove(null);
|
||||
sers.remove(null);
|
||||
for (String sname : servers) {
|
||||
InetSocketAddress isadd = temp.get(sname);
|
||||
ServerInfo isadd = temp.get(sname);
|
||||
if (isadd != null) {
|
||||
unused.remove(isadd);
|
||||
groups.put(isadd, serISA);
|
||||
groups.put(isadd.getAddress(), sers);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (InetSocketAddress unser : unused) {
|
||||
groups.put(unser, unused);
|
||||
for (ServerInfo unser : unused) {
|
||||
groups.put(unser.getAddress(), unused);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
loadGroup();
|
||||
getProxy().registerChannel(MiaoMessage.CHANNEL);
|
||||
getProxy().registerChannel(MiaoMessage.NORMALCHANNEL);
|
||||
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 > 1) {
|
||||
if (args.length > 0) {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "reload":
|
||||
onLoad();
|
||||
break;
|
||||
config.reload();
|
||||
loadGroup();
|
||||
commandSender.sendMessage("§a配置文件已重载!");
|
||||
return;
|
||||
case "version":
|
||||
commandSender.sendMessage(getDescription().getVersion());
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
commandSender.sendMessage("§6插件版本: §av" + getDescription().getVersion());
|
||||
}
|
||||
});
|
||||
getLogger().info("注意: 通过BC转发的聊天信息将不会在控制台显示 仅客户端可见!");
|
||||
|
@ -171,6 +171,9 @@ public class FileConfig {
|
||||
this.file = new File(plugin.getDataFolder(), name);
|
||||
try {
|
||||
if (!file.exists()) {
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
Files.copy(plugin.getResourceAsStream(name), file.toPath());
|
||||
}
|
||||
this.config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
|
||||
@ -191,7 +194,15 @@ public class FileConfig {
|
||||
Log.w("配置文件保存失败!");
|
||||
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 FileConfig config;
|
||||
private FileConfig format;
|
||||
private String servername;
|
||||
private boolean BungeeCord;
|
||||
|
||||
public ChatConfig() {
|
||||
@ -58,6 +59,7 @@ public class ChatConfig {
|
||||
}
|
||||
|
||||
public void load() {
|
||||
servername = config.getMessage("Server");
|
||||
formats.clear();
|
||||
for (String name : format.getKeys(false)) {
|
||||
formats.put(name, new ChatMessagePart(format.getConfigurationSection(name)));
|
||||
@ -73,6 +75,10 @@ public class ChatConfig {
|
||||
Collections.sort(rules, rulecomp);
|
||||
}
|
||||
|
||||
public String getServername() {
|
||||
return servername;
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
format.reload();
|
||||
load();
|
||||
|
@ -23,7 +23,6 @@ import pw.yumc.YumCore.tellraw.Tellraw;
|
||||
*/
|
||||
public class ChatRule extends InjectConfigurationSection {
|
||||
private transient static MiaoChat plugin = P.getPlugin();
|
||||
private transient static ChatConfig cc = plugin.getChatConfig();
|
||||
private transient static Pattern FORMAT_PATTERN = Pattern.compile("[\\[]([^\\[\\]]+)[]]");
|
||||
private transient String name;
|
||||
@Default("50")
|
||||
@ -97,7 +96,7 @@ public class ChatRule extends InjectConfigurationSection {
|
||||
public Tellraw create(Player p) {
|
||||
Tellraw tr = Tellraw.create();
|
||||
for (String format : formats) {
|
||||
ChatMessagePart cmp = cc.getFormats().get(format);
|
||||
ChatMessagePart cmp = plugin.getChatConfig().getFormats().get(format);
|
||||
if (cmp != null) {
|
||||
// Log.d("解析格式: %s", format);
|
||||
cmp.then(tr, p);
|
||||
|
@ -1,8 +1,10 @@
|
||||
#配置文件版本号 请勿修改
|
||||
Version: 1.3
|
||||
Version: 1.6
|
||||
|
||||
#BC跨服模式
|
||||
BungeeCord: true
|
||||
#当前服务器名称(变量为%mct_server%)
|
||||
Server: '§a生存服'
|
||||
#格式列表
|
||||
Formats:
|
||||
#格式名称 对应当前文件夹下的default.yml
|
||||
|
Loading…
Reference in New Issue
Block a user