Add Sponge platform bootstrap

This commit is contained in:
RednedEpic 2019-12-21 16:18:34 -06:00
parent 1fbbb87689
commit 70fd9867f5
7 changed files with 396 additions and 9 deletions

View File

@ -25,21 +25,19 @@
package org.geysermc.platform.bukkit;
import lombok.AllArgsConstructor;
import org.geysermc.common.logger.IGeyserLogger;
import java.util.logging.Level;
import java.util.logging.Logger;
@AllArgsConstructor
public class GeyserBukkitLogger implements IGeyserLogger {
private Logger logger;
private boolean debugMode;
public GeyserBukkitLogger(Logger logger, boolean debugMode) {
this.logger = logger;
this.debugMode = debugMode;
}
@Override
public void severe(String message) {
logger.severe(message);

View File

@ -33,7 +33,7 @@
<modules>
<module>bukkit</module>
<module>bungeecord</module>
<!-- <module>sponge</module> -->
<module>sponge</module>
<module>standalone</module>
<!-- <module>velocity</module> -->
</modules>

84
bootstrap/sponge/pom.xml Normal file
View File

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.geysermc</groupId>
<artifactId>bootstrap-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<artifactId>bootstrap-sponge</artifactId>
<dependencies>
<dependency>
<groupId>org.geysermc</groupId>
<artifactId>connector</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.spongepowered</groupId>
<artifactId>spongeapi</artifactId>
<version>7.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${outputName}-Sponge</finalName>
<directory>../../target</directory>
<resources>
<resource>
<directory>src/main/resources/</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>com.fasterxml.jackson</pattern>
<shadedPattern>org.geysermc.platform.sponge.shaded.jackson</shadedPattern>
</relocation>
<relocation>
<pattern>io.netty</pattern>
<shadedPattern>org.geysermc.platform.sponge.shaded.netty</shadedPattern>
</relocation>
</relocations>
<minimizeJar>true</minimizeJar>
</configuration>
</execution>
</executions>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*</exclude>
</excludes>
</filter>
</filters>
<artifactSet>
<excludes>
<exclude>com.google.code.gson:*</exclude>
<exclude>org.yaml:*</exclude>
<exclude>com.nukkitx:fastutil-lite:*</exclude>
<exclude>org.slf4j:*</exclude>
<exclude>org.ow2.asm:*</exclude>
</excludes>
</artifactSet>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,161 @@
package org.geysermc.platform.sponge;
import lombok.AllArgsConstructor;
import ninja.leaping.configurate.ConfigurationNode;
import org.geysermc.common.IGeyserConfiguration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class GeyserSpongeConfiguration implements IGeyserConfiguration {
private ConfigurationNode node;
private SpongeBedrockConfiguration bedrockConfig;
private SpongeRemoteConfiguration remoteConfig;
private SpongeMetricsInfo metricsInfo;
private Map<String, SpongeUserAuthenticationInfo> userAuthInfo = new HashMap<>();
public GeyserSpongeConfiguration(ConfigurationNode node) {
this.node = node;
this.bedrockConfig = new SpongeBedrockConfiguration(node.getNode("bedrock"));
this.remoteConfig = new SpongeRemoteConfiguration(node.getNode("remote"));
this.metricsInfo = new SpongeMetricsInfo();
if (node.getNode("userAuths").getValue() == null)
return;
for (String key : (List<String>) node.getNode("userAuths").getValue()) {
userAuthInfo.put(key, new SpongeUserAuthenticationInfo(key));
}
}
@Override
public SpongeBedrockConfiguration getBedrock() {
return bedrockConfig;
}
@Override
public SpongeRemoteConfiguration getRemote() {
return remoteConfig;
}
@Override
public Map<String, SpongeUserAuthenticationInfo> getUserAuths() {
return userAuthInfo;
}
@Override
public boolean isPingPassthrough() {
return node.getNode("ping-passthrough").getBoolean(false);
}
@Override
public int getMaxPlayers() {
return node.getNode("max-players").getInt(100);
}
@Override
public boolean isDebugMode() {
return node.getNode("debug-mode").getBoolean(false);
}
@Override
public int getGeneralThreadPool() {
return node.getNode("genereal-thread-pool").getInt(32);
}
@Override
public boolean isAllowThirdPartyCapes() {
return node.getNode("allow-third-party-capes").getBoolean(true);
}
@Override
public SpongeMetricsInfo getMetrics() {
return metricsInfo;
}
@AllArgsConstructor
public class SpongeBedrockConfiguration implements IBedrockConfiguration {
private ConfigurationNode node;
@Override
public String getAddress() {
return node.getNode("address").getString("0.0.0.0");
}
@Override
public int getPort() {
return node.getNode("port").getInt(19132);
}
@Override
public String getMotd1() {
return node.getNode("motd1").getString("GeyserMC");
}
@Override
public String getMotd2() {
return node.getNode("motd2").getString("GeyserMC");
}
}
@AllArgsConstructor
public class SpongeRemoteConfiguration implements IRemoteConfiguration {
private ConfigurationNode node;
@Override
public String getAddress() {
return node.getNode("address").getString("127.0.0.1");
}
@Override
public int getPort() {
return node.getNode("port").getInt(25565);
}
@Override
public String getAuthType() {
return node.getNode("auth-type").getString("online");
}
}
public class SpongeUserAuthenticationInfo implements IUserAuthenticationInfo {
private String key;
public SpongeUserAuthenticationInfo(String key) {
this.key = key;
}
@Override
public String getEmail() {
return node.getNode("userAuths").getNode(key).getNode("email").getString();
}
@Override
public String getPassword() {
return node.getNode("userAuths").getNode(key).getNode("password").getString();
}
}
public class SpongeMetricsInfo implements IMetricsInfo {
@Override
public boolean isEnabled() {
return node.getNode("metrics").getNode("enabled").getBoolean(true);
}
@Override
public String getUniqueId() {
return node.getNode("metrics").getNode("uuid").getString("generateduuid");
}
}
}

View File

@ -0,0 +1,54 @@
package org.geysermc.platform.sponge;
import lombok.AllArgsConstructor;
import org.geysermc.common.logger.IGeyserLogger;
import org.slf4j.Logger;
@AllArgsConstructor
public class GeyserSpongeLogger implements IGeyserLogger {
private Logger logger;
private boolean debugMode;
@Override
public void severe(String message) {
logger.error(message);
}
@Override
public void severe(String message, Throwable error) {
logger.error(message, error);
}
@Override
public void error(String message) {
logger.error(message);
}
@Override
public void error(String message, Throwable error) {
logger.error(message, error);
}
@Override
public void warning(String message) {
logger.warn(message);
}
@Override
public void info(String message) {
logger.info(message);
}
@Override
public void debug(String message) {
if (debugMode)
info(message);
}
@Override
public void setDebug(boolean debugMode) {
this.debugMode = debugMode;
}
}

View File

@ -0,0 +1,87 @@
package org.geysermc.platform.sponge;
import com.google.inject.Inject;
import ninja.leaping.configurate.loader.ConfigurationLoader;
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
import org.geysermc.common.PlatformType;
import org.geysermc.common.bootstrap.IGeyserBootstrap;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.utils.FileUtils;
import org.slf4j.Logger;
import org.spongepowered.api.config.ConfigDir;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
import org.spongepowered.api.event.game.state.GameStoppedEvent;
import org.spongepowered.api.plugin.Plugin;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
@Plugin(id = "geyser", name = GeyserConnector.NAME + "-Sponge", version = GeyserConnector.VERSION, url = "https://geysermc.org", authors = "GeyserMC")
public class GeyserSpongePlugin implements IGeyserBootstrap {
@Inject
private Logger logger;
@Inject
@ConfigDir(sharedRoot = false)
private File configDir;
private GeyserSpongeConfiguration geyserConfig;
private GeyserSpongeLogger geyserLogger;
@Override
public void onEnable() {
if (!configDir.exists())
configDir.mkdirs();
File configFile = null;
try {
configFile = FileUtils.fileOrCopiedFromResource(new File(configDir, "config.yml"), "config.yml", (file) -> file.replaceAll("generateduuid", UUID.randomUUID().toString()));
} catch (IOException ex) {
logger.warn("Failed to copy config.yml from jar path!");
ex.printStackTrace();
}
ConfigurationLoader loader = YAMLConfigurationLoader.builder().setPath(configFile.toPath()).build();
try {
this.geyserConfig = new GeyserSpongeConfiguration(loader.load());
} catch (IOException ex) {
logger.warn("Failed to load config.yml!");
ex.printStackTrace();
return;
}
this.geyserLogger = new GeyserSpongeLogger(logger, geyserConfig.isDebugMode());
GeyserConnector.start(PlatformType.SPONGE, this);
}
@Override
public void onDisable() {
GeyserConnector.stop();
}
@Override
public GeyserSpongeConfiguration getGeyserConfig() {
return geyserConfig;
}
@Override
public GeyserSpongeLogger getGeyserLogger() {
return geyserLogger;
}
@Listener
public void onServerStart(GameStartedServerEvent event) {
onEnable();
}
@Listener
public void onServerStop(GameStoppedEvent event) {
onDisable();
}
}

View File

@ -2,19 +2,24 @@ package org.geysermc.connector.utils;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import org.geysermc.connector.GeyserConnector;
import java.io.*;
import java.util.function.Function;
public class FileUtils {
public static <T> T loadConfig(File src, Class<T> valueType) throws IOException {
ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
return objectMapper.readValue(src, valueType);
}
public static File fileOrCopiedFromResource(String name, Function<String, String> s) throws IOException {
File file = new File(name);
return fileOrCopiedFromResource(new File(name), name, s);
}
public static File fileOrCopiedFromResource(File file, String name, Function<String, String> s) throws IOException {
if (!file.exists()) {
FileOutputStream fos = new FileOutputStream(file);
InputStream input = GeyserConnector.class.getResourceAsStream("/" + name); // resources need leading "/" prefix
@ -34,6 +39,4 @@ public class FileUtils {
return file;
}
}