forked from GeyserMC/Geyser
Configuration updates (#653)
* Configuration updates The main feature of this commit is switching Bukkit and BungeeCord to using Jackson configuration. This allows comments to load. Along with this, the Jackson configs have been consolidated into one abstract class, and a check is made to ensure auth-type cannot be set to Floodgate if Floodgate is not installed. * Add deleted file; remove imports * Re-add changing of Bukkit port * Alphabetize import * Alphabetize Bungee import * Updates * Swap values in GeyserJacksonConfiguration * Add a null check for GeyserConnector in Bukkit's onDisable
This commit is contained in:
parent
7231758a19
commit
34b367bfc3
18 changed files with 223 additions and 641 deletions
|
@ -25,216 +25,29 @@
|
|||
|
||||
package org.geysermc.platform.bungeecord;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import lombok.Getter;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import org.geysermc.connector.FloodgateKeyLoader;
|
||||
import org.geysermc.connector.GeyserConfiguration;
|
||||
import org.geysermc.connector.configuration.GeyserJacksonConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class GeyserBungeeConfiguration implements GeyserConfiguration {
|
||||
|
||||
private File dataFolder;
|
||||
private Configuration config;
|
||||
|
||||
private BungeeBedrockConfiguration bedrockConfig;
|
||||
private BungeeRemoteConfiguration remoteConfig;
|
||||
private BungeeMetricsInfo metricsInfo;
|
||||
|
||||
private Map<String, BungeeUserAuthenticationInfo> userAuthInfo = new HashMap<>();
|
||||
@Getter
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class GeyserBungeeConfiguration extends GeyserJacksonConfiguration {
|
||||
|
||||
private Path floodgateKey;
|
||||
|
||||
public GeyserBungeeConfiguration(File dataFolder, Configuration config) {
|
||||
this.dataFolder = dataFolder;
|
||||
this.config = config;
|
||||
|
||||
bedrockConfig = new BungeeBedrockConfiguration();
|
||||
remoteConfig = new BungeeRemoteConfiguration();
|
||||
metricsInfo = new BungeeMetricsInfo();
|
||||
|
||||
if (!config.contains("userAuths"))
|
||||
return;
|
||||
|
||||
for (String key : config.getSection("userAuths").getKeys()) {
|
||||
userAuthInfo.put(key, new BungeeUserAuthenticationInfo(key));
|
||||
}
|
||||
}
|
||||
|
||||
public void loadFloodgate(GeyserBungeePlugin plugin) {
|
||||
public void loadFloodgate(GeyserBungeePlugin plugin, Configuration configuration) {
|
||||
Plugin floodgate = plugin.getProxy().getPluginManager().getPlugin("floodgate-bungee");
|
||||
floodgateKey = FloodgateKeyLoader.getKey(plugin.getGeyserLogger(), this, Paths.get(dataFolder.toString(), config.getString("floodgate-key-file", "public-key.pem")), floodgate, floodgate != null ? floodgate.getDataFolder().toPath() : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BungeeBedrockConfiguration getBedrock() {
|
||||
return bedrockConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BungeeRemoteConfiguration getRemote() {
|
||||
return remoteConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, BungeeUserAuthenticationInfo> getUserAuths() {
|
||||
return userAuthInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCommandSuggestions() {
|
||||
return config.getBoolean("command-suggestions", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPassthroughMotd() {
|
||||
return config.getBoolean("passthrough-motd", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPassthroughPlayerCounts() {
|
||||
return config.getBoolean("passthrough-player-counts", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLegacyPingPassthrough() {
|
||||
return config.getBoolean("legacy-ping-passthrough", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPingPassthroughInterval() {
|
||||
return config.getInt("ping-passthrough-interval", 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxPlayers() {
|
||||
return config.getInt("max-players", 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugMode() {
|
||||
return config.getBoolean("debug-mode", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGeneralThreadPool() {
|
||||
return config.getInt("general-thread-pool", 32);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowThirdPartyCapes() {
|
||||
return config.getBoolean("allow-third-party-capes", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowThirdPartyEars() {
|
||||
return config.getBoolean("allow-third-party-ears", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultLocale() {
|
||||
return config.getString("default-locale", "en_us");
|
||||
floodgateKey = FloodgateKeyLoader.getKey(plugin.getGeyserLogger(), this, Paths.get(plugin.getDataFolder().toString(), configuration.getString("floodgate-key-file"), "public-key.pem"), floodgate, floodgate != null ? floodgate.getDataFolder().toPath() : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getFloodgateKeyFile() {
|
||||
return floodgateKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheChunks() {
|
||||
return config.getBoolean("cache-chunks", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAboveBedrockNetherBuilding() {
|
||||
return config.getBoolean("above-bedrock-nether-building", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BungeeMetricsInfo getMetrics() {
|
||||
return metricsInfo;
|
||||
}
|
||||
|
||||
public class BungeeBedrockConfiguration implements IBedrockConfiguration {
|
||||
|
||||
@Override
|
||||
public String getAddress() {
|
||||
return config.getString("bedrock.address", "0.0.0.0");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPort() {
|
||||
return config.getInt("bedrock.port", 25565);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMotd1() {
|
||||
return config.getString("bedrock.motd1", "GeyserMC");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMotd2() {
|
||||
return config.getString("bedrock.motd2", "GeyserMC");
|
||||
}
|
||||
}
|
||||
|
||||
public class BungeeRemoteConfiguration implements IRemoteConfiguration {
|
||||
|
||||
@Override
|
||||
public String getAddress() {
|
||||
return config.getString("remote.address", "127.0.0.1");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPort() {
|
||||
return config.getInt("remote.port", 25565);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthType() {
|
||||
return config.getString("remote.auth-type", "online");
|
||||
}
|
||||
}
|
||||
|
||||
public class BungeeUserAuthenticationInfo implements IUserAuthenticationInfo {
|
||||
|
||||
private String key;
|
||||
|
||||
public BungeeUserAuthenticationInfo(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEmail() {
|
||||
return config.getString("userAuths." + key + ".email");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return config.getString("userAuths." + key + ".password");
|
||||
}
|
||||
}
|
||||
|
||||
public class BungeeMetricsInfo implements IMetricsInfo {
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return config.getBoolean("metrics.enabled", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUniqueId() {
|
||||
return config.getString("metrics.uuid", "generateduuid");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getConfigVersion() {
|
||||
return config.getInt("config-version", 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,20 +31,19 @@ import net.md_5.bungee.config.Configuration;
|
|||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
import org.geysermc.common.PlatformType;
|
||||
import org.geysermc.connector.GeyserConfiguration;
|
||||
import org.geysermc.connector.GeyserConnector;
|
||||
import org.geysermc.connector.bootstrap.GeyserBootstrap;
|
||||
import org.geysermc.connector.command.CommandManager;
|
||||
import org.geysermc.connector.configuration.GeyserConfiguration;
|
||||
import org.geysermc.connector.ping.GeyserLegacyPingPassthrough;
|
||||
import org.geysermc.connector.ping.IGeyserPingPassthrough;
|
||||
import org.geysermc.connector.utils.FileUtils;
|
||||
import org.geysermc.platform.bungeecord.command.GeyserBungeeCommandExecutor;
|
||||
import org.geysermc.platform.bungeecord.command.GeyserBungeeCommandManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.file.Files;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
@ -62,32 +61,18 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
|
|||
if (!getDataFolder().exists())
|
||||
getDataFolder().mkdir();
|
||||
|
||||
File file = new File(getDataFolder(), "config.yml");
|
||||
Configuration configuration = null;
|
||||
|
||||
if (!file.exists()) {
|
||||
try (InputStream in = getResourceAsStream("config.yml")) {
|
||||
Files.copy(in, file.toPath());
|
||||
} catch (IOException ex) {
|
||||
getLogger().log(Level.SEVERE, "Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex);
|
||||
return;
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (!getDataFolder().exists())
|
||||
getDataFolder().mkdir();
|
||||
File configFile = FileUtils.fileOrCopiedFromResource(new File(getDataFolder(), "config.yml"), "config.yml", (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()));
|
||||
this.geyserConfig = FileUtils.loadConfig(configFile, GeyserBungeeConfiguration.class);
|
||||
configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "config.yml"));
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException ex) {
|
||||
getLogger().log(Level.WARNING, "Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex);
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
if (configuration == null) {
|
||||
getLogger().severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!");
|
||||
return;
|
||||
}
|
||||
|
||||
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];
|
||||
|
||||
|
@ -96,33 +81,21 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
|
|||
// 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") && !javaAddr.getHostString().equals("")) {
|
||||
configuration.set("remote.address", javaAddr.getHostString());
|
||||
this.geyserConfig.getRemote().setAddress(javaAddr.getHostString());
|
||||
}
|
||||
|
||||
configuration.set("remote.port", javaAddr.getPort());
|
||||
|
||||
configHasChanged = true;
|
||||
}
|
||||
|
||||
if (geyserConfig.getMetrics().getUniqueId().equals("generateduuid")) {
|
||||
configuration.set("metrics.uuid", UUID.randomUUID().toString());
|
||||
|
||||
configHasChanged = true;
|
||||
}
|
||||
|
||||
if (configHasChanged) {
|
||||
try {
|
||||
ConfigurationProvider.getProvider(YamlConfiguration.class).save(configuration, new File(getDataFolder(), "config.yml"));
|
||||
} catch (IOException ex) {
|
||||
getLogger().log(Level.SEVERE, "Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex);
|
||||
return;
|
||||
}
|
||||
this.geyserConfig.getRemote().setPort(javaAddr.getPort());
|
||||
}
|
||||
|
||||
this.geyserLogger = new GeyserBungeeLogger(getLogger(), geyserConfig.isDebugMode());
|
||||
GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger);
|
||||
|
||||
geyserConfig.loadFloodgate(this);
|
||||
if (geyserConfig.getRemote().getAuthType().equals("floodgate") && getProxy().getPluginManager().getPlugin("floodgate-bungee") == null) {
|
||||
geyserLogger.severe("Auth type set to Floodgate but Floodgate not found! Disabling...");
|
||||
return;
|
||||
}
|
||||
|
||||
geyserConfig.loadFloodgate(this, configuration);
|
||||
|
||||
this.connector = GeyserConnector.start(PlatformType.BUNGEECORD, this);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue