4
1
mirror of https://e.coding.net/circlecloud/MiaoChat.git synced 2024-11-21 14:28:46 +00:00

feat: 添加分组载入

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-12-22 20:31:42 +08:00
parent f806fdad0e
commit 593ecfa48c
3 changed files with 67 additions and 18 deletions

18
pom.xml
View File

@ -13,14 +13,6 @@
</resource> </resource>
</resources> </resources>
<plugins> <plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
@ -78,16 +70,12 @@
<url>http://ci.yumc.pw/job/${project.artifactId}/</url> <url>http://ci.yumc.pw/job/${project.artifactId}/</url>
</ciManagement> </ciManagement>
<properties> <properties>
<update.description></update.description> <env.GIT_COMMIT>DEV</env.GIT_COMMIT>
<update.changes></update.changes>
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties> </properties>
<repositories> <repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository> <repository>
<id>yumc-repo</id> <id>yumc-repo</id>
<url>http://repo.yumc.pw/content/groups/public/</url> <url>http://repo.yumc.pw/content/groups/public/</url>

View File

@ -1,19 +1,22 @@
package pw.yumc.MiaoChat; package pw.yumc.MiaoChat;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.List; import java.util.*;
import java.util.Map;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.api.plugin.Plugin;
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;
public class MiaoChatBungee extends Plugin implements Listener { public class MiaoChatBungee extends Plugin implements Listener {
private Map<InetSocketAddress, List<ServerInfo>> group; private Map<InetSocketAddress, Set<InetSocketAddress>> 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)) {
@ -31,11 +34,54 @@ public class MiaoChatBungee extends Plugin implements Listener {
config = new FileConfig(this, "group.yml"); 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());
}
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<>();
for (String sname : servers) {
serISA.add(temp.get(sname));
}
serISA.remove(null);
for (String sname : servers) {
InetSocketAddress isadd = temp.get(sname);
if (isadd != null) {
unused.remove(isadd);
groups.put(isadd, serISA);
}
}
}
for (InetSocketAddress unser : unused) {
groups.put(unser, unused);
}
}
@Override @Override
public void onEnable() { public void onEnable() {
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") {
@Override
public void execute(CommandSender commandSender, String[] args) {
if (args.length > 1) {
switch (args[0].toLowerCase()) {
case "reload":
onLoad();
break;
case "version":
commandSender.sendMessage(getDescription().getVersion());
break;
}
}
}
});
getLogger().info("注意: 通过BC转发的聊天信息将不会在控制台显示 仅客户端可见!"); getLogger().info("注意: 通过BC转发的聊天信息将不会在控制台显示 仅客户端可见!");
} }
} }

View File

@ -0,0 +1,15 @@
#配置版本号 请勿修改
Version: 1.0
#跨服分组
#注: 未在分组内的服务器会被分配到独立的一组
#注: 内部分组名称为 ungroup 下方如有定义将无效
Groups:
#普通分组
normal:
- 'sc1'
- 'sc2'
#游戏分组
games:
- 'bw1'
- 'sg1'