mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Merge latest master; copy over old Geyser-Bukkit configs
This commit is contained in:
commit
cc3b4c3eda
68 changed files with 1308 additions and 829 deletions
|
@ -71,6 +71,10 @@
|
|||
<pattern>it.unimi.dsi.fastutil</pattern>
|
||||
<shadedPattern>org.geysermc.platform.spigot.shaded.fastutil</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.fasterxml.jackson</pattern>
|
||||
<shadedPattern>org.geysermc.platform.bukkit.shaded.jackson</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
|
|
@ -25,120 +25,29 @@
|
|||
|
||||
package org.geysermc.platform.spigot;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
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 GeyserSpigotConfiguration implements GeyserConfiguration {
|
||||
@Getter
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class GeyserSpigotConfiguration extends GeyserJacksonConfiguration {
|
||||
|
||||
private FileConfiguration config;
|
||||
private File dataFolder;
|
||||
|
||||
private BukkitBedrockConfiguration bedrockConfig;
|
||||
private BukkitRemoteConfiguration remoteConfig;
|
||||
private BukkitMetricsInfo metricsInfo;
|
||||
|
||||
private Map<String, BukkitUserAuthenticationInfo> userAuthInfo = new HashMap<>();
|
||||
@JsonProperty("floodgate-key-file")
|
||||
private String floodgateKeyFile;
|
||||
|
||||
private Path floodgateKey;
|
||||
|
||||
public GeyserSpigotConfiguration(File dataFolder, FileConfiguration config) {
|
||||
this.dataFolder = dataFolder;
|
||||
this.config = config;
|
||||
|
||||
bedrockConfig = new BukkitBedrockConfiguration();
|
||||
remoteConfig = new BukkitRemoteConfiguration();
|
||||
metricsInfo = new BukkitMetricsInfo();
|
||||
|
||||
if (!config.contains("userAuths"))
|
||||
return;
|
||||
|
||||
for (String key : config.getConfigurationSection("userAuths").getKeys(false)) {
|
||||
userAuthInfo.put(key, new BukkitUserAuthenticationInfo(key));
|
||||
}
|
||||
}
|
||||
|
||||
public void loadFloodgate(GeyserSpigotPlugin plugin) {
|
||||
Plugin floodgate = Bukkit.getPluginManager().getPlugin("floodgate-bukkit");
|
||||
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 IBedrockConfiguration getBedrock() {
|
||||
return bedrockConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRemoteConfiguration getRemote() {
|
||||
return remoteConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, BukkitUserAuthenticationInfo> 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(), plugin.getConfig().getString("floodgate-key-file", "public-key.pem")), floodgate, floodgate != null ? floodgate.getDataFolder().toPath() : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -150,92 +59,4 @@ public class GeyserSpigotConfiguration implements GeyserConfiguration {
|
|||
public boolean isCacheChunks() {
|
||||
return true; // We override this as with Bukkit, we have direct access to the server implementation
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAboveBedrockNetherBuilding() {
|
||||
return config.getBoolean("above-bedrock-nether-building", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMetricsInfo getMetrics() {
|
||||
return metricsInfo;
|
||||
}
|
||||
|
||||
public class BukkitBedrockConfiguration 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 BukkitRemoteConfiguration 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 BukkitUserAuthenticationInfo implements IUserAuthenticationInfo {
|
||||
|
||||
private String key;
|
||||
|
||||
public BukkitUserAuthenticationInfo(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 BukkitMetricsInfo 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,10 +28,10 @@ package org.geysermc.platform.spigot;
|
|||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
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.network.translators.world.WorldManager;
|
||||
import org.geysermc.connector.ping.GeyserLegacyPingPassthrough;
|
||||
import org.geysermc.connector.ping.IGeyserPingPassthrough;
|
||||
|
@ -39,9 +39,14 @@ import org.geysermc.platform.spigot.command.GeyserSpigotCommandExecutor;
|
|||
import org.geysermc.platform.spigot.command.GeyserSpigotCommandManager;
|
||||
import org.geysermc.platform.spigot.world.GeyserSpigotBlockPlaceListener;
|
||||
import org.geysermc.platform.spigot.world.GeyserSpigotWorldManager;
|
||||
import org.geysermc.connector.utils.FileUtils;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
|
||||
|
||||
|
@ -56,26 +61,41 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
|
|||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
saveDefaultConfig();
|
||||
|
||||
this.geyserConfig = new GeyserSpigotConfiguration(getDataFolder(), getConfig());
|
||||
if (geyserConfig.getMetrics().getUniqueId().equals("generateduuid")) {
|
||||
getConfig().set("metrics.uuid", UUID.randomUUID().toString());
|
||||
saveConfig();
|
||||
// This is manually done instead of using Bukkit methods to save the config because otherwise comments get removed
|
||||
try {
|
||||
if (!getDataFolder().exists()) {
|
||||
getDataFolder().mkdir();
|
||||
File bukkitConfig = new File("plugins/Geyser-Bukkit/config.yml");
|
||||
if (bukkitConfig.exists()) { // Copy over old configs
|
||||
getLogger().log(Level.INFO, "Existing config found in the Geyser-Bukkit folder; copying over...");
|
||||
Files.copy(bukkitConfig.toPath(), new File(getDataFolder().toString() + "/config.yml").toPath());
|
||||
getLogger().log(Level.INFO, "Copied!");
|
||||
}
|
||||
}
|
||||
File configFile = FileUtils.fileOrCopiedFromResource(new File(getDataFolder(), "config.yml"), "config.yml", (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()));
|
||||
this.geyserConfig = FileUtils.loadConfig(configFile, GeyserSpigotConfiguration.class);
|
||||
} 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();
|
||||
}
|
||||
|
||||
// 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") && !Bukkit.getIp().equals("")) {
|
||||
getConfig().set("remote.address", Bukkit.getIp());
|
||||
geyserConfig.getRemote().setAddress(Bukkit.getIp());
|
||||
}
|
||||
|
||||
getConfig().set("remote.port", Bukkit.getPort());
|
||||
saveConfig();
|
||||
geyserConfig.getRemote().setPort(Bukkit.getPort());
|
||||
|
||||
this.geyserLogger = new GeyserSpigotLogger(getLogger(), geyserConfig.isDebugMode());
|
||||
GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger);
|
||||
|
||||
if (geyserConfig.getRemote().getAuthType().equals("floodgate") && Bukkit.getPluginManager().getPlugin("floodgate-bukkit") == null) {
|
||||
geyserLogger.severe("Auth type set to Floodgate but Floodgate not found! Disabling...");
|
||||
this.getPluginLoader().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
geyserConfig.loadFloodgate(this);
|
||||
|
||||
this.connector = GeyserConnector.start(PlatformType.SPIGOT, this);
|
||||
|
@ -113,7 +133,8 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
|
|||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
connector.shutdown();
|
||||
if (connector != null)
|
||||
connector.shutdown();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue