feat(hamster-auto-server-info): 功能完成
This commit is contained in:
9
hamster-auto-server-info/build.gradle
Normal file
9
hamster-auto-server-info/build.gradle
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
version = '1.0.0'
|
||||||
|
setArchivesBaseName("HamsterAuto-ServerInfo")
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
//noinspection VulnerableLibrariesLocal
|
||||||
|
compileOnly "net.md-5:bungeecord-api:${bungee_api_version}"
|
||||||
|
|
||||||
|
compileOnly "cn.hamster3.mc.plugin.ball:common:${hamster_ball_version}"
|
||||||
|
}
|
@@ -0,0 +1,37 @@
|
|||||||
|
package cn.hamster3.mc.plugin.auto.server.info;
|
||||||
|
|
||||||
|
import cn.hamster3.mc.plugin.auto.server.info.listener.ServerInfoListener;
|
||||||
|
import cn.hamster3.mc.plugin.auto.server.info.util.ServerInfoUtils;
|
||||||
|
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
||||||
|
import cn.hamster3.mc.plugin.ball.common.entity.BallServerInfo;
|
||||||
|
import cn.hamster3.mc.plugin.ball.common.entity.BallServerType;
|
||||||
|
import cn.hamster3.mc.plugin.ball.common.listener.BallListener;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
|
||||||
|
public class ServerInfoPlugin extends Plugin implements BallListener {
|
||||||
|
private static ServerInfoPlugin instance;
|
||||||
|
|
||||||
|
public static ServerInfoPlugin getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoad() {
|
||||||
|
instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
ProxyServer.getInstance().getServers().clear();
|
||||||
|
for (BallServerInfo serverInfo : BallAPI.getInstance().getAllServerInfo().values()) {
|
||||||
|
if (serverInfo.getType() != BallServerType.GAME) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ProxyServer.getInstance().getServers().put(serverInfo.getId(), ServerInfoUtils.getServerInfo(serverInfo));
|
||||||
|
getLogger().info("已添加子服 " + serverInfo.getId() + " 的接入点配置.");
|
||||||
|
}
|
||||||
|
BallAPI.getInstance().addListener(ServerInfoListener.INSTANCE);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,39 @@
|
|||||||
|
package cn.hamster3.mc.plugin.auto.server.info.listener;
|
||||||
|
|
||||||
|
import cn.hamster3.mc.plugin.auto.server.info.ServerInfoPlugin;
|
||||||
|
import cn.hamster3.mc.plugin.auto.server.info.util.ServerInfoUtils;
|
||||||
|
import cn.hamster3.mc.plugin.ball.common.entity.BallServerInfo;
|
||||||
|
import cn.hamster3.mc.plugin.ball.common.entity.BallServerType;
|
||||||
|
import cn.hamster3.mc.plugin.ball.common.event.server.ServerOfflineEvent;
|
||||||
|
import cn.hamster3.mc.plugin.ball.common.event.server.ServerOnlineEvent;
|
||||||
|
import cn.hamster3.mc.plugin.ball.common.listener.BallListener;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ServerInfoListener implements BallListener {
|
||||||
|
public static final ServerInfoListener INSTANCE = new ServerInfoListener();
|
||||||
|
|
||||||
|
private ServerInfoListener() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onServerOnline(@NotNull ServerOnlineEvent event) {
|
||||||
|
BallServerInfo serverInfo = event.getServerInfo();
|
||||||
|
if (serverInfo.getType() != BallServerType.GAME) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ProxyServer.getInstance().getServers().put(serverInfo.getId(), ServerInfoUtils.getServerInfo(serverInfo));
|
||||||
|
ServerInfoPlugin.getInstance().getLogger().info("已添加子服 " + serverInfo.getId() + " 的接入点配置.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onServerOffline(@NotNull ServerOfflineEvent event) {
|
||||||
|
Map<String, ServerInfo> map = ProxyServer.getInstance().getServers();
|
||||||
|
if (map.remove(event.getServerID()) != null) {
|
||||||
|
ServerInfoPlugin.getInstance().getLogger().info("已移除子服 " + event.getServerID() + " 的接入点配置.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,19 @@
|
|||||||
|
package cn.hamster3.mc.plugin.auto.server.info.util;
|
||||||
|
|
||||||
|
import cn.hamster3.mc.plugin.ball.common.entity.BallServerInfo;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
|
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
|
||||||
|
public final class ServerInfoUtils {
|
||||||
|
|
||||||
|
public static ServerInfo getServerInfo(BallServerInfo serverInfo) {
|
||||||
|
return ProxyServer.getInstance().constructServerInfo(
|
||||||
|
serverInfo.getId(),
|
||||||
|
new InetSocketAddress(serverInfo.getHost(), serverInfo.getPort()),
|
||||||
|
serverInfo.getName(),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user