Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-26 00:00:41 +01:00
Automatic ip & port for plugins (#438)
* Automatically set Bukkit ip and port * Automatically set Velocity ip and port * Automatically set BungeeCord ip and port * Moved the config init line to prevent config issues * Automatically set Sponge ip and port
Dieser Commit ist enthalten in:
Ursprung
fc17b7cc7a
Commit
7f29710006
@ -25,11 +25,11 @@
|
|||||||
|
|
||||||
package org.geysermc.platform.bukkit;
|
package org.geysermc.platform.bukkit;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.geysermc.common.PlatformType;
|
import org.geysermc.common.PlatformType;
|
||||||
import org.geysermc.common.command.ICommandManager;
|
|
||||||
import org.geysermc.connector.GeyserConnector;
|
|
||||||
import org.geysermc.common.bootstrap.IGeyserBootstrap;
|
import org.geysermc.common.bootstrap.IGeyserBootstrap;
|
||||||
|
import org.geysermc.connector.GeyserConnector;
|
||||||
import org.geysermc.connector.command.CommandManager;
|
import org.geysermc.connector.command.CommandManager;
|
||||||
import org.geysermc.platform.bukkit.command.GeyserBukkitCommandExecutor;
|
import org.geysermc.platform.bukkit.command.GeyserBukkitCommandExecutor;
|
||||||
import org.geysermc.platform.bukkit.command.GeyserBukkitCommandManager;
|
import org.geysermc.platform.bukkit.command.GeyserBukkitCommandManager;
|
||||||
@ -54,6 +54,15 @@ public class GeyserBukkitPlugin extends JavaPlugin implements IGeyserBootstrap {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't change the ip if its listening on all interfaces
|
||||||
|
// By default this should be 127.0.0.1 but may need to be changed in some circumstances
|
||||||
|
if (!Bukkit.getIp().equals("0.0.0.0")) {
|
||||||
|
getConfig().set("remote.address", Bukkit.getIp());
|
||||||
|
}
|
||||||
|
|
||||||
|
getConfig().set("remote.port", Bukkit.getPort());
|
||||||
|
saveConfig();
|
||||||
|
|
||||||
this.geyserLogger = new GeyserBukkitLogger(getLogger(), geyserConfig.isDebugMode());
|
this.geyserLogger = new GeyserBukkitLogger(getLogger(), geyserConfig.isDebugMode());
|
||||||
this.connector = GeyserConnector.start(PlatformType.BUKKIT, this);
|
this.connector = GeyserConnector.start(PlatformType.BUKKIT, this);
|
||||||
|
|
||||||
|
@ -25,14 +25,14 @@
|
|||||||
|
|
||||||
package org.geysermc.platform.bungeecord;
|
package org.geysermc.platform.bungeecord;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.config.ListenerInfo;
|
||||||
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.config.Configuration;
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
import net.md_5.bungee.config.YamlConfiguration;
|
||||||
|
|
||||||
import org.geysermc.common.PlatformType;
|
import org.geysermc.common.PlatformType;
|
||||||
import org.geysermc.connector.GeyserConnector;
|
|
||||||
import org.geysermc.common.bootstrap.IGeyserBootstrap;
|
import org.geysermc.common.bootstrap.IGeyserBootstrap;
|
||||||
|
import org.geysermc.connector.GeyserConnector;
|
||||||
import org.geysermc.connector.command.CommandManager;
|
import org.geysermc.connector.command.CommandManager;
|
||||||
import org.geysermc.platform.bungeecord.command.GeyserBungeeCommandExecutor;
|
import org.geysermc.platform.bungeecord.command.GeyserBungeeCommandExecutor;
|
||||||
import org.geysermc.platform.bungeecord.command.GeyserBungeeCommandManager;
|
import org.geysermc.platform.bungeecord.command.GeyserBungeeCommandManager;
|
||||||
@ -40,6 +40,7 @@ import org.geysermc.platform.bungeecord.command.GeyserBungeeCommandManager;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -81,8 +82,31 @@ public class GeyserBungeePlugin extends Plugin implements IGeyserBootstrap {
|
|||||||
|
|
||||||
this.geyserConfig = new GeyserBungeeConfiguration(getDataFolder(), configuration);
|
this.geyserConfig = new GeyserBungeeConfiguration(getDataFolder(), configuration);
|
||||||
|
|
||||||
|
boolean configHasChanged = false;
|
||||||
|
|
||||||
|
if (getProxy().getConfig().getListeners().size() == 1) {
|
||||||
|
ListenerInfo listener = getProxy().getConfig().getListeners().toArray(new ListenerInfo[0])[0];
|
||||||
|
|
||||||
|
InetSocketAddress javaAddr = listener.getHost();
|
||||||
|
|
||||||
|
// Don't change the ip if its listening on all interfaces
|
||||||
|
// By default this should be 127.0.0.1 but may need to be changed in some circumstances
|
||||||
|
if (!javaAddr.getHostString().equals("0.0.0.0")) {
|
||||||
|
configuration.set("remote.address", javaAddr.getHostString());
|
||||||
|
}
|
||||||
|
|
||||||
|
configuration.set("remote.port", javaAddr.getPort());
|
||||||
|
|
||||||
|
configHasChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (geyserConfig.getMetrics().getUniqueId().equals("generateduuid")) {
|
if (geyserConfig.getMetrics().getUniqueId().equals("generateduuid")) {
|
||||||
configuration.set("metrics.uuid", UUID.randomUUID().toString());
|
configuration.set("metrics.uuid", UUID.randomUUID().toString());
|
||||||
|
|
||||||
|
configHasChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (configHasChanged) {
|
||||||
try {
|
try {
|
||||||
ConfigurationProvider.getProvider(YamlConfiguration.class).save(configuration, new File(getDataFolder(), "config.yml"));
|
ConfigurationProvider.getProvider(YamlConfiguration.class).save(configuration, new File(getDataFolder(), "config.yml"));
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
|
@ -26,13 +26,11 @@
|
|||||||
package org.geysermc.platform.sponge;
|
package org.geysermc.platform.sponge;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import ninja.leaping.configurate.ConfigurationNode;
|
||||||
import ninja.leaping.configurate.loader.ConfigurationLoader;
|
import ninja.leaping.configurate.loader.ConfigurationLoader;
|
||||||
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
|
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
|
||||||
|
|
||||||
import org.geysermc.common.PlatformType;
|
import org.geysermc.common.PlatformType;
|
||||||
import org.geysermc.common.bootstrap.IGeyserBootstrap;
|
import org.geysermc.common.bootstrap.IGeyserBootstrap;
|
||||||
import org.geysermc.common.command.ICommandManager;
|
|
||||||
import org.geysermc.connector.GeyserConnector;
|
import org.geysermc.connector.GeyserConnector;
|
||||||
import org.geysermc.connector.command.CommandManager;
|
import org.geysermc.connector.command.CommandManager;
|
||||||
import org.geysermc.connector.utils.FileUtils;
|
import org.geysermc.connector.utils.FileUtils;
|
||||||
@ -48,6 +46,7 @@ import org.spongepowered.api.plugin.Plugin;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Plugin(id = "geyser", name = GeyserConnector.NAME + "-Sponge", version = GeyserConnector.VERSION, url = "https://geysermc.org", authors = "GeyserMC")
|
@Plugin(id = "geyser", name = GeyserConnector.NAME + "-Sponge", version = GeyserConnector.VERSION, url = "https://geysermc.org", authors = "GeyserMC")
|
||||||
@ -80,14 +79,31 @@ public class GeyserSpongePlugin implements IGeyserBootstrap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ConfigurationLoader loader = YAMLConfigurationLoader.builder().setPath(configFile.toPath()).build();
|
ConfigurationLoader loader = YAMLConfigurationLoader.builder().setPath(configFile.toPath()).build();
|
||||||
|
ConfigurationNode config;
|
||||||
try {
|
try {
|
||||||
this.geyserConfig = new GeyserSpongeConfiguration(configDir, loader.load());
|
config = loader.load();
|
||||||
|
this.geyserConfig = new GeyserSpongeConfiguration(configDir, config);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.warn("Failed to load config.yml!");
|
logger.warn("Failed to load config.yml!");
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfigurationNode serverIP = config.getNode("remote").getNode("address");
|
||||||
|
ConfigurationNode serverPort = config.getNode("remote").getNode("port");
|
||||||
|
|
||||||
|
if (Sponge.getServer().getBoundAddress().isPresent()) {
|
||||||
|
InetSocketAddress javaAddr = Sponge.getServer().getBoundAddress().get();
|
||||||
|
|
||||||
|
// Don't change the ip if its listening on all interfaces
|
||||||
|
// By default this should be 127.0.0.1 but may need to be changed in some circumstances
|
||||||
|
if (!javaAddr.getHostString().equals("0.0.0.0")) {
|
||||||
|
serverIP.setValue("127.0.0.1");
|
||||||
|
}
|
||||||
|
|
||||||
|
serverPort.setValue(javaAddr.getPort());
|
||||||
|
}
|
||||||
|
|
||||||
this.geyserLogger = new GeyserSpongeLogger(logger, geyserConfig.isDebugMode());
|
this.geyserLogger = new GeyserSpongeLogger(logger, geyserConfig.isDebugMode());
|
||||||
this.connector = GeyserConnector.start(PlatformType.SPONGE, this);
|
this.connector = GeyserConnector.start(PlatformType.SPONGE, this);
|
||||||
this.geyserCommandManager = new GeyserSpongeCommandManager(Sponge.getCommandManager(), connector);
|
this.geyserCommandManager = new GeyserSpongeCommandManager(Sponge.getCommandManager(), connector);
|
||||||
|
@ -27,9 +27,8 @@ package org.geysermc.platform.velocity;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import org.geysermc.common.IGeyserConfiguration;
|
import org.geysermc.common.IGeyserConfiguration;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@ -86,7 +85,10 @@ public class GeyserVelocityConfiguration implements IGeyserConfiguration {
|
|||||||
@Getter
|
@Getter
|
||||||
public static class RemoteConfiguration implements IRemoteConfiguration {
|
public static class RemoteConfiguration implements IRemoteConfiguration {
|
||||||
|
|
||||||
|
@Setter
|
||||||
private String address;
|
private String address;
|
||||||
|
|
||||||
|
@Setter
|
||||||
private int port;
|
private int port;
|
||||||
|
|
||||||
private String motd1;
|
private String motd1;
|
||||||
|
@ -33,6 +33,7 @@ import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
|||||||
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
||||||
import com.velocitypowered.api.plugin.Plugin;
|
import com.velocitypowered.api.plugin.Plugin;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
import org.geysermc.common.PlatformType;
|
import org.geysermc.common.PlatformType;
|
||||||
import org.geysermc.common.bootstrap.IGeyserBootstrap;
|
import org.geysermc.common.bootstrap.IGeyserBootstrap;
|
||||||
import org.geysermc.connector.GeyserConnector;
|
import org.geysermc.connector.GeyserConnector;
|
||||||
@ -43,6 +44,7 @@ import org.slf4j.Logger;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Plugin(id = "geyser", name = GeyserConnector.NAME + "-Velocity", version = GeyserConnector.VERSION, url = "https://geysermc.org", authors = "GeyserMC")
|
@Plugin(id = "geyser", name = GeyserConnector.NAME + "-Velocity", version = GeyserConnector.VERSION, url = "https://geysermc.org", authors = "GeyserMC")
|
||||||
@ -51,6 +53,9 @@ public class GeyserVelocityPlugin implements IGeyserBootstrap {
|
|||||||
@Inject
|
@Inject
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ProxyServer server;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private CommandManager commandManager;
|
private CommandManager commandManager;
|
||||||
|
|
||||||
@ -73,6 +78,16 @@ public class GeyserVelocityPlugin implements IGeyserBootstrap {
|
|||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InetSocketAddress javaAddr = server.getBoundAddress();
|
||||||
|
|
||||||
|
// Don't change the ip if its listening on all interfaces
|
||||||
|
// By default this should be 127.0.0.1 but may need to be changed in some circumstances
|
||||||
|
if (!javaAddr.getHostString().equals("0.0.0.0")) {
|
||||||
|
geyserConfig.getRemote().setAddress(javaAddr.getHostString());
|
||||||
|
}
|
||||||
|
|
||||||
|
geyserConfig.getRemote().setPort(javaAddr.getPort());
|
||||||
|
|
||||||
this.geyserLogger = new GeyserVelocityLogger(logger, geyserConfig.isDebugMode());
|
this.geyserLogger = new GeyserVelocityLogger(logger, geyserConfig.isDebugMode());
|
||||||
this.connector = GeyserConnector.start(PlatformType.VELOCITY, this);
|
this.connector = GeyserConnector.start(PlatformType.VELOCITY, this);
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren