fix: 修复已知问题

This commit is contained in:
2022-10-29 07:06:16 +08:00
parent 29305a6aab
commit 43b9a6dc5b
5 changed files with 9 additions and 12 deletions

View File

@@ -26,6 +26,7 @@ public class HamsterBallPlugin extends JavaPlugin {
logger.info("BallBukkitAPI 已初始化."); logger.info("BallBukkitAPI 已初始化.");
try { try {
BallBukkitAPI.getInstance().enable(); BallBukkitAPI.getInstance().enable();
logger.info("BallBukkitAPI 已启动.");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
sync(Bukkit::shutdown); sync(Bukkit::shutdown);

View File

@@ -14,7 +14,7 @@ dependencies {
processResources { processResources {
inputs.property "version", project.version inputs.property "version", project.version
filesMatching("plugin.yml") { filesMatching("bungee.yml") {
expand "version": project.version expand "version": project.version
} }
duplicatesStrategy(DuplicatesStrategy.EXCLUDE) duplicatesStrategy(DuplicatesStrategy.EXCLUDE)

View File

@@ -19,9 +19,10 @@ public class HamsterBallPlugin extends Plugin {
instance = this; instance = this;
Logger logger = getLogger(); Logger logger = getLogger();
BallBungeeCordAPI.init(); BallBungeeCordAPI.init();
logger.info("BallBukkitAPI 已初始化."); logger.info("BallBungeeCordAPI 已初始化.");
try { try {
BallBungeeCordAPI.getInstance().enable(); BallBungeeCordAPI.getInstance().enable();
logger.info("BallBungeeCordAPI 已启动.");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
ProxyServer.getInstance().stop(); ProxyServer.getInstance().stop();
@@ -32,7 +33,7 @@ public class HamsterBallPlugin extends Plugin {
public void onEnable() { public void onEnable() {
Logger logger = getLogger(); Logger logger = getLogger();
ProxyServer.getInstance().getPluginManager().registerListener(this, BallBungeeCordListener.INSTANCE); ProxyServer.getInstance().getPluginManager().registerListener(this, BallBungeeCordListener.INSTANCE);
logger.info("已注册 BallBukkitListener."); logger.info("已注册 BallBungeeCordListener.");
logger.info("HamsterBall 已启动."); logger.info("HamsterBall 已启动.");
} }

View File

@@ -7,14 +7,10 @@ import cn.hamster3.mc.plugin.ball.common.entity.BallServerType;
import cn.hamster3.mc.plugin.core.bungee.HamsterBallPlugin; import cn.hamster3.mc.plugin.core.bungee.HamsterBallPlugin;
import cn.hamster3.mc.plugin.core.bungee.listener.BallBungeeCordListener; import cn.hamster3.mc.plugin.core.bungee.listener.BallBungeeCordListener;
import cn.hamster3.mc.plugin.core.bungee.util.BungeeCordUtils; import cn.hamster3.mc.plugin.core.bungee.util.BungeeCordUtils;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ListenerInfo;
import net.md_5.bungee.config.Configuration; import net.md_5.bungee.config.Configuration;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.net.InetSocketAddress;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Optional;
public class BallBungeeCordAPI extends BallAPI { public class BallBungeeCordAPI extends BallAPI {
public BallBungeeCordAPI(@NotNull BallConfig config) { public BallBungeeCordAPI(@NotNull BallConfig config) {
@@ -25,22 +21,19 @@ public class BallBungeeCordAPI extends BallAPI {
return (BallBungeeCordAPI) instance; return (BallBungeeCordAPI) instance;
} }
@SuppressWarnings("deprecation")
public static void init() { public static void init() {
if (instance != null) { if (instance != null) {
return; return;
} }
HamsterBallPlugin plugin = HamsterBallPlugin.getInstance(); HamsterBallPlugin plugin = HamsterBallPlugin.getInstance();
Configuration pluginConfig = BungeeCordUtils.getPluginConfig(plugin); Configuration pluginConfig = BungeeCordUtils.getPluginConfig(plugin);
Optional<InetSocketAddress> address = ProxyServer.getInstance().getConfig().getListeners().stream().findFirst().map(ListenerInfo::getHost);
String host = pluginConfig.getString("server-info.name.host", address.map(InetSocketAddress::getHostName).orElse(""));
BallConfig config = new BallConfig( BallConfig config = new BallConfig(
new BallServerInfo( new BallServerInfo(
pluginConfig.getString("server-info.id"), pluginConfig.getString("server-info.id"),
pluginConfig.getString("server-info.name"), pluginConfig.getString("server-info.name"),
BallServerType.GAME, BallServerType.GAME,
host.isEmpty() ? "127.0.0.1" : host, pluginConfig.getString("server-info.host", ""),
pluginConfig.getInt("server-info.name.port", address.map(InetSocketAddress::getPort).orElse(25577)) pluginConfig.getInt("server-info.port", 25577)
), ),
pluginConfig.getString("ball-server.host"), pluginConfig.getString("ball-server.host"),
pluginConfig.getInt("ball-server.port"), pluginConfig.getInt("ball-server.port"),

View File

@@ -8,3 +8,5 @@ server-info:
id: "BungeeCord" id: "BungeeCord"
# 服务端名称,用于展示给玩家看 # 服务端名称,用于展示给玩家看
name: "代理端" name: "代理端"
host: 0.0.0.0
port: 25577