From 7d645fbf16958079b44d13dc085faefa456de775 Mon Sep 17 00:00:00 2001 From: Tim203 Date: Sat, 30 Nov 2019 13:34:45 +0100 Subject: [PATCH 01/45] First Flootgate commit --- .gitignore | 1 + .../main/java/org/geysermc/api/AuthType.java | 30 ++++++ .../main/java/org/geysermc/api/Connector.java | 5 + connector/pom.xml | 6 ++ .../geysermc/connector/GeyserConnector.java | 12 +-- .../configuration/GeyserConfiguration.java | 3 + .../network/UpstreamPacketHandler.java | 5 - .../network/session/GeyserSession.java | 80 +++++++++++----- .../session/auth/BedrockClientData.java | 91 +++++++++++++++++++ .../connector/utils/LoginEncryptionUtils.java | 16 +++- .../geysermc/connector/utils/SkinUtils.java | 4 +- connector/src/main/resources/config.yml | 8 +- 12 files changed, 219 insertions(+), 42 deletions(-) create mode 100644 api/src/main/java/org/geysermc/api/AuthType.java create mode 100644 connector/src/main/java/org/geysermc/connector/network/session/auth/BedrockClientData.java diff --git a/.gitignore b/.gitignore index f003e0142..9b233578c 100644 --- a/.gitignore +++ b/.gitignore @@ -224,3 +224,4 @@ nbdist/ ### Geyser ### config.yml logs/ +public-key.pem diff --git a/api/src/main/java/org/geysermc/api/AuthType.java b/api/src/main/java/org/geysermc/api/AuthType.java new file mode 100644 index 000000000..55d97c204 --- /dev/null +++ b/api/src/main/java/org/geysermc/api/AuthType.java @@ -0,0 +1,30 @@ +package org.geysermc.api; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +@Getter +public enum AuthType { + OFFLINE("offline"), + ONLINE("online"), + FLOODGATE("floodgate"); + + public static final AuthType[] VALUES = values(); + + private String name; + + public static AuthType getById(int id) { + return id < VALUES.length ? VALUES[id] : OFFLINE; + } + + public static AuthType getByName(String name) { + String lowerCase = name.toLowerCase(); + for (AuthType type : VALUES) { + if (type.getName().equals(lowerCase)) { + return type; + } + } + return OFFLINE; + } +} \ No newline at end of file diff --git a/api/src/main/java/org/geysermc/api/Connector.java b/api/src/main/java/org/geysermc/api/Connector.java index 708372e33..9259eefe8 100644 --- a/api/src/main/java/org/geysermc/api/Connector.java +++ b/api/src/main/java/org/geysermc/api/Connector.java @@ -73,4 +73,9 @@ public interface Connector { * Shuts down the connector */ void shutdown(); + + /** + * The auth type for the remote server + */ + AuthType getAuthType(); } diff --git a/connector/pom.xml b/connector/pom.xml index 60ecfc557..5b4a2bcf5 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -22,6 +22,12 @@ 1.0-SNAPSHOT compile + + org.geysermc + floodgate-common + 1.0-SNAPSHOT + compile + com.fasterxml.jackson.dataformat jackson-dataformat-yaml diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index 4abe763ff..3b7b1a701 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -28,9 +28,9 @@ package org.geysermc.connector; import com.nukkitx.protocol.bedrock.BedrockPacketCodec; import com.nukkitx.protocol.bedrock.BedrockServer; import com.nukkitx.protocol.bedrock.v388.Bedrock_v388; - import lombok.Getter; import org.fusesource.jansi.AnsiConsole; +import org.geysermc.api.AuthType; import org.geysermc.api.Connector; import org.geysermc.api.Geyser; import org.geysermc.api.Player; @@ -66,17 +66,16 @@ import java.util.concurrent.TimeUnit; @Getter public class GeyserConnector implements Connector { - public static final BedrockPacketCodec BEDROCK_PACKET_CODEC = Bedrock_v388.V388_CODEC; - public static final String NAME = "Geyser"; public static final String VERSION = "1.0-SNAPSHOT"; - private final Map players = new HashMap<>(); - private static GeyserConnector instance; + private final Map players = new HashMap<>(); + private RemoteJavaServer remoteServer; + private AuthType authType; private Logger logger; @@ -133,6 +132,7 @@ public class GeyserConnector implements Connector { commandMap = new GeyserCommandMap(this); remoteServer = new RemoteJavaServer(config.getRemote().getAddress(), config.getRemote().getPort()); + authType = AuthType.getByName(config.getRemote().getAuthType()); Geyser.setConnector(this); @@ -158,7 +158,7 @@ public class GeyserConnector implements Connector { metrics = new Metrics("GeyserMC", config.getMetrics().getUUID(), false, java.util.logging.Logger.getLogger("")); metrics.addCustomChart(new Metrics.SingleLineChart("servers", () -> 1)); metrics.addCustomChart(new Metrics.SingleLineChart("players", Geyser::getPlayerCount)); - metrics.addCustomChart(new Metrics.SimplePie("authMode", config.getRemote()::getAuthType)); + metrics.addCustomChart(new Metrics.SimplePie("authMode", getAuthType()::getName)); } double completeTime = (System.currentTimeMillis() - startupTime) / 1000D; diff --git a/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java b/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java index b78fc2279..ba5e63b28 100644 --- a/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java +++ b/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java @@ -37,6 +37,9 @@ public class GeyserConfiguration { private BedrockConfiguration bedrock; private RemoteConfiguration remote; + @JsonProperty("floodgate-key-file") + private String floodgateKeyFile; + private Map userAuths; @JsonProperty("ping-passthrough") diff --git a/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java b/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java index 4990280b9..99fa1c5df 100644 --- a/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java @@ -127,9 +127,4 @@ public class UpstreamPacketHandler extends LoggingPacketHandler { boolean defaultHandler(BedrockPacket packet) { return translateAndDefault(packet); } - - @Override - public boolean handle(InventoryTransactionPacket packet) { - return translateAndDefault(packet); - } } \ No newline at end of file diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index 8f4544d39..aabc3d668 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -29,11 +29,9 @@ import com.github.steveice10.mc.auth.data.GameProfile; import com.github.steveice10.mc.auth.exception.request.RequestException; import com.github.steveice10.mc.protocol.MinecraftProtocol; import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; +import com.github.steveice10.mc.protocol.packet.handshake.client.HandshakePacket; import com.github.steveice10.packetlib.Client; -import com.github.steveice10.packetlib.event.session.ConnectedEvent; -import com.github.steveice10.packetlib.event.session.DisconnectedEvent; -import com.github.steveice10.packetlib.event.session.PacketReceivedEvent; -import com.github.steveice10.packetlib.event.session.SessionAdapter; +import com.github.steveice10.packetlib.event.session.*; import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.tcp.TcpSessionFactory; import com.nukkitx.math.vector.Vector2f; @@ -44,15 +42,10 @@ import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.protocol.bedrock.BedrockServerSession; import com.nukkitx.protocol.bedrock.data.GamePublishSetting; import com.nukkitx.protocol.bedrock.data.GameRule; -import com.nukkitx.protocol.bedrock.packet.AvailableEntityIdentifiersPacket; -import com.nukkitx.protocol.bedrock.packet.BiomeDefinitionListPacket; -import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket; -import com.nukkitx.protocol.bedrock.packet.NetworkChunkPublisherUpdatePacket; -import com.nukkitx.protocol.bedrock.packet.PlayStatusPacket; -import com.nukkitx.protocol.bedrock.packet.StartGamePacket; -import com.nukkitx.protocol.bedrock.packet.TextPacket; +import com.nukkitx.protocol.bedrock.packet.*; import lombok.Getter; import lombok.Setter; +import org.geysermc.api.AuthType; import org.geysermc.api.Player; import org.geysermc.api.RemoteServer; import org.geysermc.api.session.AuthData; @@ -60,22 +53,30 @@ import org.geysermc.api.window.FormWindow; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.inventory.PlayerInventory; +import org.geysermc.connector.network.session.auth.BedrockClientData; import org.geysermc.connector.network.session.cache.*; import org.geysermc.connector.network.translators.Registry; import org.geysermc.connector.network.translators.TranslatorsInit; import org.geysermc.connector.utils.Toolbox; +import org.geysermc.floodgate.util.BedrockData; +import org.geysermc.floodgate.util.EncryptionUtil; +import java.io.IOException; import java.net.InetSocketAddress; +import java.nio.file.Paths; +import java.security.NoSuchAlgorithmException; +import java.security.PublicKey; +import java.security.spec.InvalidKeySpecException; import java.util.UUID; @Getter public class GeyserSession implements Player { - private final GeyserConnector connector; private final UpstreamSession upstream; private RemoteServer remoteServer; private Client downstream; - private AuthData authenticationData; + @Setter private AuthData authenticationData; + @Setter private BedrockClientData clientData; private PlayerEntity playerEntity; private PlayerInventory inventory; @@ -127,7 +128,7 @@ public class GeyserSession implements Player { public void connect(RemoteServer remoteServer) { startGame(); this.remoteServer = remoteServer; - if (!(connector.getConfig().getRemote().getAuthType().hashCode() == "online".hashCode())) { + if (connector.getAuthType() == AuthType.OFFLINE) { connector.getLogger().info("Attempting to login using offline mode... authentication is disabled."); authenticate(authenticationData.getName()); } @@ -181,8 +182,51 @@ public class GeyserSession implements Player { protocol = new MinecraftProtocol(username); } + boolean floodgate = connector.getAuthType() == AuthType.FLOODGATE; + final PublicKey publicKey; + + if (floodgate) { + PublicKey key = null; + try { + key = EncryptionUtil.getKeyFromFile( + Paths.get(connector.getConfig().getFloodgateKeyFile()), + PublicKey.class + ); + } catch (IOException | InvalidKeySpecException | NoSuchAlgorithmException e) { + connector.getLogger().error("Error while reading Floodgate key file", e); + } + publicKey = key; + } else publicKey = null; + downstream = new Client(remoteServer.getAddress(), remoteServer.getPort(), protocol, new TcpSessionFactory()); downstream.getSession().addListener(new SessionAdapter() { + @Override + public void packetSending(PacketSendingEvent event) { + //todo move this somewhere else + if (event.getPacket() instanceof HandshakePacket && floodgate) { + String encrypted = ""; + try { + encrypted = EncryptionUtil.encryptFromInstance(publicKey, new BedrockData( + clientData.getGameVersion(), + authenticationData.getName(), + authenticationData.getXboxUUID(), + clientData.getDeviceOS().ordinal(), + clientData.getLanguageCode(), + clientData.getCurrentInputMode().ordinal() + )); + } catch (Exception e) { + connector.getLogger().error("Failed to encrypt message", e); + } + + HandshakePacket handshakePacket = event.getPacket(); + event.setPacket(new HandshakePacket( + handshakePacket.getProtocolVersion(), + handshakePacket.getHostname() + '\0' + "Geyser-Floodgate" + '\0' + encrypted, + handshakePacket.getPort(), + handshakePacket.getIntent() + )); + } + } @Override public void connected(ConnectedEvent event) { @@ -231,18 +275,10 @@ public class GeyserSession implements Player { closed = true; } - public boolean isClosed() { - return closed; - } - public void close() { disconnect("Server closed."); } - public void setAuthenticationData(AuthData authData) { - authenticationData = authData; - } - @Override public String getName() { return authenticationData.getName(); diff --git a/connector/src/main/java/org/geysermc/connector/network/session/auth/BedrockClientData.java b/connector/src/main/java/org/geysermc/connector/network/session/auth/BedrockClientData.java new file mode 100644 index 000000000..9e7345ce7 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/session/auth/BedrockClientData.java @@ -0,0 +1,91 @@ +package org.geysermc.connector.network.session.auth; + +import com.fasterxml.jackson.annotation.JsonEnumDefaultValue; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; + +import java.util.UUID; + +@JsonIgnoreProperties(ignoreUnknown = true) +@Getter +public class BedrockClientData { + @JsonProperty(value = "GameVersion") + private String gameVersion; + @JsonProperty(value = "ServerAddress") + private String serverAddress; + @JsonProperty(value = "ThirdPartyName") + private String username; + @JsonProperty(value = "LanguageCode") + private String languageCode; + + @JsonProperty(value = "SkinId") + private String skinId; + @JsonProperty(value = "SkinData") + private String skinData; + @JsonProperty(value = "CapeId") + private String capeId; + @JsonProperty(value = "CapeData") + private byte[] capeData; + @JsonProperty(value = "CapeOnClassicSkin") + private boolean capeOnClassicSkin; + @JsonProperty(value = "SkinResourcePatch") + private String geometryName; + @JsonProperty(value = "SkinGeometryData") + private String geometryData; + @JsonProperty(value = "PremiumSkin") + private boolean premiumSkin; + + @JsonProperty(value = "DeviceId") + private UUID deviceId; + @JsonProperty(value = "DeviceModel") + private String deviceModel; + @JsonProperty(value = "DeviceOS") + private DeviceOS deviceOS; + @JsonProperty(value = "UIProfile") + private UIProfile uiProfile; + @JsonProperty(value = "GuiScale") + private int guiScale; + @JsonProperty(value = "CurrentInputMode") + private InputMode currentInputMode; + @JsonProperty(value = "DefaultInputMode") + private InputMode defaultInputMode; + @JsonProperty("PlatformOnlineId") + private String platformOnlineId; + @JsonProperty(value = "PlatformOfflineId") + private String platformOfflineId; + @JsonProperty(value = "SelfSignedId") + private UUID selfSignedId; + @JsonProperty(value = "ClientRandomId") + private long clientRandomId; + + public enum UIProfile { + @JsonEnumDefaultValue + CLASSIC, + POCKET + } + + public enum DeviceOS { + @JsonEnumDefaultValue + UNKOWN, + ANDROID, + IOS, + OSX, + FIREOS, + GEARVR, + HOLOLENS, + WIN10, + WIN32, + DEDICATED, + ORBIS, + NX + } + + public enum InputMode { + @JsonEnumDefaultValue + UNKNOWN, + KEYBOARD_MOUSE, + TOUCH, // I guess Touch? + CONTROLLER + } +} diff --git a/connector/src/main/java/org/geysermc/connector/utils/LoginEncryptionUtils.java b/connector/src/main/java/org/geysermc/connector/utils/LoginEncryptionUtils.java index b94f13cdc..5ccef71c1 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/LoginEncryptionUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/LoginEncryptionUtils.java @@ -9,7 +9,6 @@ import com.nukkitx.network.util.Preconditions; import com.nukkitx.protocol.bedrock.packet.LoginPacket; import com.nukkitx.protocol.bedrock.packet.ServerToClientHandshakePacket; import com.nukkitx.protocol.bedrock.util.EncryptionUtils; -import net.minidev.json.JSONObject; import org.geysermc.api.events.player.PlayerFormResponseEvent; import org.geysermc.api.window.CustomFormBuilder; import org.geysermc.api.window.CustomFormWindow; @@ -20,6 +19,7 @@ import org.geysermc.api.window.response.CustomFormResponse; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.auth.BedrockAuthData; +import org.geysermc.connector.network.session.auth.BedrockClientData; import org.geysermc.connector.network.session.cache.WindowCache; import javax.crypto.SecretKey; @@ -72,7 +72,7 @@ public class LoginEncryptionUtils { encryptConnectionWithCert(connector, session, loginPacket.getSkinData().toString(), certChainData); } - private static void encryptConnectionWithCert(GeyserConnector connector, GeyserSession session, String playerSkin, JsonNode certChainData) { + private static void encryptConnectionWithCert(GeyserConnector connector, GeyserSession session, String clientData, JsonNode certChainData) { try { boolean validChain = validateChainData(certChainData); @@ -85,17 +85,23 @@ public class LoginEncryptionUtils { throw new RuntimeException("AuthData was not found!"); } - JSONObject extraData = (JSONObject) jwt.getPayload().toJSONObject().get("extraData"); - session.setAuthenticationData(new BedrockAuthData(extraData.getAsString("displayName"), UUID.fromString(extraData.getAsString("identity")), extraData.getAsString("XUID"))); + JsonNode extraData = payload.get("extraData"); + session.setAuthenticationData(new BedrockAuthData( + extraData.get("displayName").asText(), + UUID.fromString(extraData.get("identity").asText()), + extraData.get("XUID").asText() + )); if (payload.get("identityPublicKey").getNodeType() != JsonNodeType.STRING) { throw new RuntimeException("Identity Public Key was not found!"); } ECPublicKey identityPublicKey = EncryptionUtils.generateKey(payload.get("identityPublicKey").textValue()); - JWSObject clientJwt = JWSObject.parse(playerSkin); + JWSObject clientJwt = JWSObject.parse(clientData); EncryptionUtils.verifyJwt(clientJwt, identityPublicKey); + session.setClientData(JSON_MAPPER.convertValue(JSON_MAPPER.readTree(clientJwt.getPayload().toBytes()), BedrockClientData.class)); + if (EncryptionUtils.canUseEncryption()) { LoginEncryptionUtils.startEncryptionHandshake(session, identityPublicKey); } diff --git a/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java b/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java index b4c9d7f63..e42ca473e 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java @@ -8,8 +8,8 @@ import com.nukkitx.protocol.bedrock.packet.PlayerListPacket; import lombok.AllArgsConstructor; import lombok.Getter; import org.apache.commons.codec.Charsets; +import org.geysermc.api.AuthType; import org.geysermc.api.Geyser; -import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.network.session.GeyserSession; @@ -96,7 +96,7 @@ public class SkinUtils { return new GameProfileData(skinUrl, capeUrl, isAlex); } catch (Exception exception) { - if (!((GeyserConnector) Geyser.getConnector()).getConfig().getRemote().getAuthType().equals("offline")) { + if (Geyser.getConnector().getAuthType() != AuthType.OFFLINE) { Geyser.getLogger().debug("Got invalid texture data for " + profile.getName() + " " + exception.getMessage()); } // return default skin with default cape when texture data is invalid diff --git a/connector/src/main/resources/config.yml b/connector/src/main/resources/config.yml index f92d6d42f..029a4619e 100644 --- a/connector/src/main/resources/config.yml +++ b/connector/src/main/resources/config.yml @@ -20,10 +20,14 @@ remote: address: 127.0.0.1 # The port of the remote (Java Edition) server port: 25565 - - # Authentication type. Can be offline, online, or hybrid (see the wiki). + # Authentication type. Can be offline, online, or floodgate (see the wiki). auth-type: online +# Floodgate uses encryption to ensure use from authorised sources. +# This should point to the public key generated by Floodgate (Bungee or CraftBukkit) +# You can ignore this when not using Floodgate. +floodgate-key-file: public-key.pem + ## the Xbox/MCPE username is the key for the Java server auth-info ## this allows automatic configuration/login to the remote Java server ## if you are brave/stupid enough to put your Mojang account info into From b12256bc1e969157e36321ce1317c1222ab86ad0 Mon Sep 17 00:00:00 2001 From: Tim203 Date: Sat, 30 Nov 2019 15:32:13 +0100 Subject: [PATCH 02/45] Changed a method name --- .../org/geysermc/connector/network/session/GeyserSession.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index aabc3d668..fc1e687dd 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -206,7 +206,7 @@ public class GeyserSession implements Player { if (event.getPacket() instanceof HandshakePacket && floodgate) { String encrypted = ""; try { - encrypted = EncryptionUtil.encryptFromInstance(publicKey, new BedrockData( + encrypted = EncryptionUtil.encryptBedrockData(publicKey, new BedrockData( clientData.getGameVersion(), authenticationData.getName(), authenticationData.getXboxUUID(), From 1c48279a9fd6144f09f6f5bad7a8a691049d800c Mon Sep 17 00:00:00 2001 From: Tim203 Date: Sat, 30 Nov 2019 18:38:09 +0100 Subject: [PATCH 03/45] Little changes --- api/src/main/java/org/geysermc/api/AuthType.java | 14 +++++--------- .../org/geysermc/connector/GeyserConnector.java | 2 +- .../connector/network/session/GeyserSession.java | 4 ++++ .../network/session/auth/BedrockClientData.java | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/api/src/main/java/org/geysermc/api/AuthType.java b/api/src/main/java/org/geysermc/api/AuthType.java index 55d97c204..6364ba159 100644 --- a/api/src/main/java/org/geysermc/api/AuthType.java +++ b/api/src/main/java/org/geysermc/api/AuthType.java @@ -1,27 +1,23 @@ package org.geysermc.api; -import lombok.AllArgsConstructor; import lombok.Getter; -@AllArgsConstructor @Getter public enum AuthType { - OFFLINE("offline"), - ONLINE("online"), - FLOODGATE("floodgate"); + OFFLINE, + ONLINE, + FLOODGATE; public static final AuthType[] VALUES = values(); - private String name; - public static AuthType getById(int id) { return id < VALUES.length ? VALUES[id] : OFFLINE; } public static AuthType getByName(String name) { - String lowerCase = name.toLowerCase(); + String upperCase = name.toUpperCase(); for (AuthType type : VALUES) { - if (type.getName().equals(lowerCase)) { + if (type.name().equals(upperCase)) { return type; } } diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index 3b7b1a701..5ec21476e 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -158,7 +158,7 @@ public class GeyserConnector implements Connector { metrics = new Metrics("GeyserMC", config.getMetrics().getUUID(), false, java.util.logging.Logger.getLogger("")); metrics.addCustomChart(new Metrics.SingleLineChart("servers", () -> 1)); metrics.addCustomChart(new Metrics.SingleLineChart("players", Geyser::getPlayerCount)); - metrics.addCustomChart(new Metrics.SimplePie("authMode", getAuthType()::getName)); + metrics.addCustomChart(new Metrics.SimplePie("authMode", getAuthType()::name)); } double completeTime = (System.currentTimeMillis() - startupTime) / 1000D; diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index fc1e687dd..e748d2a13 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -198,6 +198,10 @@ public class GeyserSession implements Player { publicKey = key; } else publicKey = null; + if (publicKey != null) { + connector.getLogger().info("Loaded Floodgate key!"); + } + downstream = new Client(remoteServer.getAddress(), remoteServer.getPort(), protocol, new TcpSessionFactory()); downstream.getSession().addListener(new SessionAdapter() { @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/session/auth/BedrockClientData.java b/connector/src/main/java/org/geysermc/connector/network/session/auth/BedrockClientData.java index 9e7345ce7..574ba5447 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/auth/BedrockClientData.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/auth/BedrockClientData.java @@ -37,7 +37,7 @@ public class BedrockClientData { private boolean premiumSkin; @JsonProperty(value = "DeviceId") - private UUID deviceId; + private String deviceId; @JsonProperty(value = "DeviceModel") private String deviceModel; @JsonProperty(value = "DeviceOS") From f1b19fc04e654912c32c7c8117ac19241c4c9654 Mon Sep 17 00:00:00 2001 From: Tim203 Date: Sat, 30 Nov 2019 19:10:29 +0100 Subject: [PATCH 04/45] Little changes --- .../java/org/geysermc/connector/GeyserConnector.java | 2 +- .../connector/network/session/GeyserSession.java | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index 5ec21476e..1af7bb028 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -158,7 +158,7 @@ public class GeyserConnector implements Connector { metrics = new Metrics("GeyserMC", config.getMetrics().getUUID(), false, java.util.logging.Logger.getLogger("")); metrics.addCustomChart(new Metrics.SingleLineChart("servers", () -> 1)); metrics.addCustomChart(new Metrics.SingleLineChart("players", Geyser::getPlayerCount)); - metrics.addCustomChart(new Metrics.SimplePie("authMode", getAuthType()::name)); + metrics.addCustomChart(new Metrics.SimplePie("authMode", () -> getAuthType().name().toLowerCase())); } double completeTime = (System.currentTimeMillis() - startupTime) / 1000D; diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index e748d2a13..11e1852a7 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -128,8 +128,13 @@ public class GeyserSession implements Player { public void connect(RemoteServer remoteServer) { startGame(); this.remoteServer = remoteServer; - if (connector.getAuthType() == AuthType.OFFLINE) { - connector.getLogger().info("Attempting to login using offline mode... authentication is disabled."); + if (connector.getAuthType() != AuthType.ONLINE) { + connector.getLogger().info( + "Attempting to login using " + connector.getAuthType().name().toLowerCase() + " mode... " + + (connector.getAuthType() == AuthType.OFFLINE ? + "authentication is disabled." : "authentication will be encrypted" + ) + ); authenticate(authenticationData.getName()); } From 9a13b566cff7ab84e4dc37ed446b111794368a4a Mon Sep 17 00:00:00 2001 From: Tim203 Date: Sat, 30 Nov 2019 21:30:25 +0100 Subject: [PATCH 05/45] Little changes --- common/pom.xml | 6 ++ .../geysermc/floodgate/util/BedrockData.java | 35 +++++++++ .../floodgate/util/EncryptionUtil.java | 76 +++++++++++++++++++ connector/pom.xml | 6 -- 4 files changed, 117 insertions(+), 6 deletions(-) create mode 100644 common/src/main/java/org/geysermc/floodgate/util/BedrockData.java create mode 100644 common/src/main/java/org/geysermc/floodgate/util/EncryptionUtil.java diff --git a/common/pom.xml b/common/pom.xml index 6a0a6ff04..d54730ff0 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -10,6 +10,12 @@ common + + org.projectlombok + lombok + 1.18.4 + providec + com.github.steveice10 opennbt diff --git a/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java b/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java new file mode 100644 index 000000000..f4efa9716 --- /dev/null +++ b/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java @@ -0,0 +1,35 @@ +package org.geysermc.floodgate.util; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +@Getter +public class BedrockData { + public static final int EXPECTED_LENGTH = 6; + private String version; + private String username; + private String xuid; + private int deviceId; + private String languageCode; + private int inputMode; + private int dataLength; + + public BedrockData(String version, String username, String xuid, int deviceId, String languageCode, int inputMode) { + this(version, username, xuid, deviceId, languageCode, inputMode, EXPECTED_LENGTH); + } + + public static BedrockData fromString(String data) { + String[] split = data.split("\0"); + if (split.length != EXPECTED_LENGTH) return null; + return new BedrockData(split[0], split[1], split[2], Integer.parseInt(split[3]), split[4], Integer.parseInt(split[5]), split.length); + } + + public static BedrockData fromRawData(byte[] data) { + return fromString(new String(data)); + } + + public String toString() { + return version +'\0'+ username +'\0'+ xuid +'\0'+ deviceId +'\0'+ languageCode +'\0'+ inputMode; + } +} diff --git a/common/src/main/java/org/geysermc/floodgate/util/EncryptionUtil.java b/common/src/main/java/org/geysermc/floodgate/util/EncryptionUtil.java new file mode 100644 index 000000000..881d01ba9 --- /dev/null +++ b/common/src/main/java/org/geysermc/floodgate/util/EncryptionUtil.java @@ -0,0 +1,76 @@ +package org.geysermc.floodgate.util; + +import javax.crypto.*; +import javax.crypto.spec.SecretKeySpec; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.*; +import java.security.spec.EncodedKeySpec; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.PKCS8EncodedKeySpec; +import java.security.spec.X509EncodedKeySpec; +import java.util.Base64; + +public class EncryptionUtil { + public static String encrypt(Key key, String data) throws IllegalBlockSizeException, + InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException { + KeyGenerator generator = KeyGenerator.getInstance("AES"); + generator.init(128); + SecretKey secretKey = generator.generateKey(); + + Cipher cipher = Cipher.getInstance("AES"); + cipher.init(Cipher.ENCRYPT_MODE, secretKey); + byte[] encryptedText = cipher.doFinal(data.getBytes()); + + cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); + cipher.init(key instanceof PublicKey ? Cipher.PUBLIC_KEY : Cipher.PRIVATE_KEY, key); + return Base64.getEncoder().encodeToString(cipher.doFinal(secretKey.getEncoded())) + '\0' + + Base64.getEncoder().encodeToString(encryptedText); + } + + public static String encryptBedrockData(Key key, BedrockData data) throws IllegalBlockSizeException, + InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException { + return encrypt(key, data.toString()); + } + + public static byte[] decrypt(Key key, String encryptedData) throws IllegalBlockSizeException, + InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException { + String[] split = encryptedData.split("\0"); + if (split.length != 2) { + throw new IllegalArgumentException("Expected two arguments, got " + split.length); + } + + Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); + cipher.init(key instanceof PublicKey ? Cipher.PUBLIC_KEY : Cipher.PRIVATE_KEY, key); + byte[] decryptedKey = cipher.doFinal(Base64.getDecoder().decode(split[0])); + + SecretKey secretKey = new SecretKeySpec(decryptedKey, 0, decryptedKey.length, "AES"); + cipher = Cipher.getInstance("AES"); + cipher.init(Cipher.DECRYPT_MODE, secretKey); + return cipher.doFinal(Base64.getDecoder().decode(split[1])); + } + + public static BedrockData decryptBedrockData(Key key, String encryptedData) throws IllegalBlockSizeException, + InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException { + return BedrockData.fromRawData(decrypt(key, encryptedData)); + } + + @SuppressWarnings("unchecked") + public static T getKeyFromFile(Path fileLocation, Class keyType) throws + IOException, InvalidKeySpecException, NoSuchAlgorithmException { + boolean isPublicKey = keyType == PublicKey.class; + if (!isPublicKey && keyType != PrivateKey.class) { + throw new RuntimeException("I can only read public and private keys!"); + } + + byte[] key = Files.readAllBytes(fileLocation); + + KeyFactory keyFactory = KeyFactory.getInstance("RSA"); + EncodedKeySpec keySpec = isPublicKey ? new X509EncodedKeySpec(key) : new PKCS8EncodedKeySpec(key); + return (T) (isPublicKey ? + keyFactory.generatePublic(keySpec) : + keyFactory.generatePrivate(keySpec) + ); + } +} diff --git a/connector/pom.xml b/connector/pom.xml index 5b4a2bcf5..60ecfc557 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -22,12 +22,6 @@ 1.0-SNAPSHOT compile - - org.geysermc - floodgate-common - 1.0-SNAPSHOT - compile - com.fasterxml.jackson.dataformat jackson-dataformat-yaml From b7a746535b43ec23a5c008d7247dc22d5bf83216 Mon Sep 17 00:00:00 2001 From: Tim203 Date: Sat, 30 Nov 2019 21:44:48 +0100 Subject: [PATCH 06/45] Little changes --- common/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/pom.xml b/common/pom.xml index d54730ff0..9a972bf22 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -14,7 +14,7 @@ org.projectlombok lombok 1.18.4 - providec + provided com.github.steveice10 From 1c2ef99a546efd1d1d4ae287a8b1845f01032668 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sun, 1 Dec 2019 15:16:52 -0600 Subject: [PATCH 07/45] Separate bootstrap and allow for Geyser to run on Bukkit (Addresses #54) --- api/pom.xml | 2 +- bootstrap/bukkit/pom.xml | 63 +++++++ .../bukkit/GeyserBukkitConfiguration.java | 176 ++++++++++++++++++ .../platform/bukkit/GeyserBukkitLogger.java | 81 ++++++++ .../platform/bukkit/GeyserBukkitPlugin.java | 49 ++++- .../bukkit/src/main/resources/plugin.yml | 5 + bootstrap/pom.xml | 36 ++++ bootstrap/standalone/pom.xml | 63 +++++++ .../platform/standalone/GeyserBootstrap.java | 81 ++++++++ .../standalone}/GeyserConfiguration.java | 46 ++++- .../platform/standalone/GeyserLogger.java | 133 +++++++++++++ common/pom.xml | 48 +---- .../geysermc/common/IGeyserConfiguration.java | 64 +++++-- .../common/bootstrap/IGeyserBootstrap.java | 18 +- connector/pom.xml | 27 +-- .../geysermc/connector/GeyserConnector.java | 46 ++--- .../configuration/UserAuthenticationInfo.java | 31 --- .../connector/console/GeyserLogger.java | 18 +- .../network/ConnectorServerEventHandler.java | 5 +- .../network/UpstreamPacketHandler.java | 6 +- .../geysermc/connector/utils/SkinUtils.java | 4 +- plugin/pom.xml | 39 ---- .../org/geysermc/plugin/GeyserPlugin.java | 47 ----- pom.xml | 4 +- 24 files changed, 837 insertions(+), 255 deletions(-) create mode 100644 bootstrap/bukkit/pom.xml create mode 100644 bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java create mode 100644 bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitLogger.java rename connector/src/main/java/org/geysermc/connector/configuration/BedrockConfiguration.java => bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitPlugin.java (51%) create mode 100644 bootstrap/bukkit/src/main/resources/plugin.yml create mode 100644 bootstrap/pom.xml create mode 100644 bootstrap/standalone/pom.xml create mode 100644 bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java rename {connector/src/main/java/org/geysermc/connector/configuration => bootstrap/standalone/src/main/java/org/geysermc/platform/standalone}/GeyserConfiguration.java (64%) create mode 100644 bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserLogger.java rename connector/src/main/java/org/geysermc/connector/configuration/RemoteConfiguration.java => common/src/main/java/org/geysermc/common/IGeyserConfiguration.java (56%) rename connector/src/main/java/org/geysermc/connector/configuration/MetricInfo.java => common/src/main/java/org/geysermc/common/bootstrap/IGeyserBootstrap.java (81%) delete mode 100644 connector/src/main/java/org/geysermc/connector/configuration/UserAuthenticationInfo.java delete mode 100644 plugin/pom.xml delete mode 100644 plugin/src/main/java/org/geysermc/plugin/GeyserPlugin.java diff --git a/api/pom.xml b/api/pom.xml index a0cbdf87f..2bb85be24 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -6,7 +6,7 @@ org.geysermc geyser-parent - 1.0-SNAPSHOT + parent api diff --git a/bootstrap/bukkit/pom.xml b/bootstrap/bukkit/pom.xml new file mode 100644 index 000000000..02b7d9a2e --- /dev/null +++ b/bootstrap/bukkit/pom.xml @@ -0,0 +1,63 @@ + + + 4.0.0 + + org.geysermc + bootstrap-parent + 1.0-SNAPSHOT + ../ + + bootstrap-bukkit + + + org.geysermc + common + 1.0-SNAPSHOT + compile + + + org.geysermc + connector + 1.0-SNAPSHOT + compile + + + org.spigotmc + spigot-api + 1.14-R0.1-SNAPSHOT + provided + + + + ${outputName}-Bukkit-noshade + clean install + + + src/main/resources/ + true + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.1.0 + + + package + + shade + + + + + ${outputName}-Bukkit + false + true + + + + + \ No newline at end of file diff --git a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java new file mode 100644 index 000000000..e928b9c86 --- /dev/null +++ b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.platform.bukkit; + +import org.bukkit.configuration.file.FileConfiguration; +import org.geysermc.common.IGeyserConfiguration; + +import java.util.HashMap; +import java.util.Map; + +public class GeyserBukkitConfiguration implements IGeyserConfiguration { + + private FileConfiguration config; + + private BukkitBedrockConfiguration bedrockConfig; + private BukkitRemoteConfiguration remoteConfig; + private BukkitMetricsInfo metricsInfo; + + private Map userAuthInfo = new HashMap<>(); + + public GeyserBukkitConfiguration(FileConfiguration config) { + 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)); + } + } + + @Override + public IBedrockConfiguration getBedrock() { + return bedrockConfig; + } + + @Override + public IRemoteConfiguration getRemote() { + return remoteConfig; + } + + @Override + public Map getUserAuths() { + return userAuthInfo; + } + + @Override + public boolean isPingPassthrough() { + return config.getBoolean("ping-passthrough", false); + } + + @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 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"); + } + } +} diff --git a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitLogger.java b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitLogger.java new file mode 100644 index 000000000..12fadc6cc --- /dev/null +++ b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitLogger.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.platform.bukkit; + +import java.util.logging.Level; +import java.util.logging.Logger; + +public class GeyserBukkitLogger implements org.geysermc.api.logger.Logger { + + 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); + } + + @Override + public void severe(String message, Throwable error) { + logger.log(Level.SEVERE, message, error); + } + + @Override + public void error(String message) { + logger.warning(message); + } + + @Override + public void error(String message, Throwable error) { + logger.log(Level.WARNING, message, error); + } + + @Override + public void warning(String message) { + error(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 debug) { + debugMode = debug; + } +} diff --git a/connector/src/main/java/org/geysermc/connector/configuration/BedrockConfiguration.java b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitPlugin.java similarity index 51% rename from connector/src/main/java/org/geysermc/connector/configuration/BedrockConfiguration.java rename to bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitPlugin.java index 2010214ef..86dfadbb6 100644 --- a/connector/src/main/java/org/geysermc/connector/configuration/BedrockConfiguration.java +++ b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitPlugin.java @@ -23,16 +23,47 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.connector.configuration; +package org.geysermc.platform.bukkit; -import lombok.Getter; +import org.bukkit.plugin.java.JavaPlugin; +import org.geysermc.connector.GeyserConnector; +import org.geysermc.common.bootstrap.IGeyserBootstrap; -@Getter -public class BedrockConfiguration { +import java.util.UUID; - private String address; - private int port; +public class GeyserBukkitPlugin extends JavaPlugin implements IGeyserBootstrap { - private String motd1; - private String motd2; -} \ No newline at end of file + private GeyserBukkitConfiguration geyserConfig; + private GeyserBukkitLogger geyserLogger; + + @Override + public void onEnable() { + saveDefaultConfig(); + + geyserConfig = new GeyserBukkitConfiguration(getConfig()); + + if (geyserConfig.getMetrics().getUniqueId().equals("generateduuid")) { + getConfig().set("metrics.uuid", UUID.randomUUID().toString()); + saveConfig(); + } + + geyserLogger = new GeyserBukkitLogger(getLogger(), geyserConfig.isDebugMode()); + + GeyserConnector.start(this, false); + } + + @Override + public void onDisable() { + GeyserConnector.stop(); + } + + @Override + public GeyserBukkitConfiguration getGeyserConfig() { + return geyserConfig; + } + + @Override + public GeyserBukkitLogger getGeyserLogger() { + return geyserLogger; + } +} diff --git a/bootstrap/bukkit/src/main/resources/plugin.yml b/bootstrap/bukkit/src/main/resources/plugin.yml new file mode 100644 index 000000000..b67547f25 --- /dev/null +++ b/bootstrap/bukkit/src/main/resources/plugin.yml @@ -0,0 +1,5 @@ +main: org.geysermc.platform.bukkit.GeyserBukkitPlugin +name: ${outputName}-Bukkit +author: ${project.organization.name} +website: ${project.organization.url} +version: ${project.version} \ No newline at end of file diff --git a/bootstrap/pom.xml b/bootstrap/pom.xml new file mode 100644 index 000000000..5c91b817e --- /dev/null +++ b/bootstrap/pom.xml @@ -0,0 +1,36 @@ + + + 4.0.0 + + org.geysermc + geyser-parent + parent + ../ + + bootstrap-parent + 1.0-SNAPSHOT + pom + + + spigot-public + https://hub.spigotmc.org/nexus/content/repositories/public/ + + + bukkit-public + https://repo.md-5.net/content/repositories/public/ + + + sponge-repo + https://repo.spongepowered.org/maven + + + + bukkit + + standalone + + + \ No newline at end of file diff --git a/bootstrap/standalone/pom.xml b/bootstrap/standalone/pom.xml new file mode 100644 index 000000000..3c38a6c09 --- /dev/null +++ b/bootstrap/standalone/pom.xml @@ -0,0 +1,63 @@ + + + 4.0.0 + + org.geysermc + bootstrap-parent + 1.0-SNAPSHOT + ../ + + bootstrap-standalone + + + org.geysermc + common + 1.0-SNAPSHOT + compile + + + org.geysermc + connector + 1.0-SNAPSHOT + compile + + + + ${outputName}-noshade + clean install + + + org.apache.maven.plugins + maven-jar-plugin + 3.2.0 + + + + org.geysermc.platform.standalone.GeyserBootstrap + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.1.0 + + + package + + shade + + + + + ${outputName} + false + true + + + + + \ No newline at end of file diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java new file mode 100644 index 000000000..014cf83ee --- /dev/null +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.platform.standalone; + +import org.fusesource.jansi.AnsiConsole; +import org.geysermc.common.bootstrap.IGeyserBootstrap; +import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.utils.FileUtils; + +import java.io.File; +import java.io.IOException; +import java.util.UUID; + +public class GeyserBootstrap implements IGeyserBootstrap { + + private GeyserConfiguration geyserConfig; + private GeyserLogger geyserLogger; + + public static void main(String[] args) { + new GeyserBootstrap().onEnable(); + } + + @Override + public void onEnable() { + // Metric + if (!(System.console() == null) && System.getProperty("os.name", "Windows 10").toLowerCase().contains("windows")) { + AnsiConsole.systemInstall(); + } + + geyserLogger = new GeyserLogger(); + + try { + File configFile = FileUtils.fileOrCopiedFromResource("config.yml", (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString())); + geyserConfig = FileUtils.loadConfig(configFile, GeyserConfiguration.class); + } catch (IOException ex) { + getGeyserLogger().severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex); + System.exit(0); + } + + GeyserConnector.start(this, false); + } + + @Override + public void onDisable() { + GeyserConnector.stop(); + System.exit(0); + } + + @Override + public GeyserConfiguration getGeyserConfig() { + return geyserConfig; + } + + @Override + public GeyserLogger getGeyserLogger() { + return geyserLogger; + } +} diff --git a/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserConfiguration.java similarity index 64% rename from connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java rename to bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserConfiguration.java index b78fc2279..e1a442d71 100644 --- a/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserConfiguration.java @@ -23,17 +23,19 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.connector.configuration; +package org.geysermc.platform.standalone; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Getter; +import org.geysermc.common.IGeyserConfiguration; import java.util.Map; @JsonIgnoreProperties(ignoreUnknown = true) @Getter -public class GeyserConfiguration { +public class GeyserConfiguration implements IGeyserConfiguration { + private BedrockConfiguration bedrock; private RemoteConfiguration remote; @@ -54,5 +56,43 @@ public class GeyserConfiguration { @JsonProperty("allow-third-party-capes") private boolean allowThirdPartyCapes; - private MetricInfo metrics; + private MetricsInfo metrics; + + @Getter + public static class BedrockConfiguration implements IBedrockConfiguration { + + private String address; + private int port; + + private String motd1; + private String motd2; + } + + @Getter + public static class RemoteConfiguration implements IRemoteConfiguration { + + private String address; + private int port; + + private String motd1; + private String motd2; + + @JsonProperty("auth-type") + private String authType; + } + + @Getter + public static class UserAuthenticationInfo implements IUserAuthenticationInfo { + private String email; + private String password; + } + + @Getter + public static class MetricsInfo implements IMetricsInfo { + + private boolean enabled; + + @JsonProperty("uuid") + private String uniqueId; + } } diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserLogger.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserLogger.java new file mode 100644 index 000000000..0df4f1f15 --- /dev/null +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserLogger.java @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.platform.standalone; + +import io.sentry.Sentry; +import org.geysermc.api.ChatColor; + +import java.io.File; +import java.io.IOException; +import java.util.Date; +import java.util.logging.*; + +public class GeyserLogger implements org.geysermc.api.logger.Logger { + + private boolean colored = true; + private boolean debug = false; + + public GeyserLogger() { + ConsoleHandler consoleHandler = new ConsoleHandler(); + consoleHandler.setLevel(Level.INFO); + consoleHandler.setFormatter(new SimpleFormatter() { + private static final String format = "[%1$tT][%2$-5s] %3$s %n"; + + @Override + public synchronized String format(LogRecord lr) { + return String.format(format, + new Date(lr.getMillis()), + lr.getLevel().getLocalizedName(), + lr.getMessage() + ); + } + }); + + try { + File logDir = new File("logs"); + logDir.mkdir(); + File logFile = new File(logDir, "latest.log"); + int maxLogFileSize = 20;//Mo + if (logFile.exists() && (logFile.length()) > maxLogFileSize * 1024L * 1024L) + this.warning("Your log file is larger than " + maxLogFileSize + "Mo, you should backup and clean it !"); + FileHandler fileHandler = new FileHandler(logFile.getCanonicalPath(), true); + fileHandler.setLevel(Level.INFO); + fileHandler.setFormatter(new SimpleFormatter() { + private static final String format = "[%1$tF %1$tT][%2$-5s] %3$s %n"; + + @Override + public synchronized String format(LogRecord lr) { + return String.format(format, + new Date(lr.getMillis()), + lr.getLevel().getLocalizedName(), + lr.getMessage() + ); + } + }); + } catch (IOException | SecurityException ex) { + Logger.getLogger(GeyserLogger.class.getName()).log(Level.SEVERE, null, ex); + } + + if (System.getenv().containsKey("DP_SENTRY_CLIENT_KEY")) { + Handler sentryHandler = new io.sentry.jul.SentryHandler(); + sentryHandler.setLevel(Level.SEVERE); + Sentry.init(System.getenv().get("DP_SENTRY_CLIENT_KEY")); + } + } + + @Override + public void severe(String message) { + System.out.println(printConsole(ChatColor.DARK_RED + message, colored)); + } + + @Override + public void severe(String message, Throwable error) { + System.out.println(printConsole(ChatColor.DARK_RED + message + "\n" + error.getMessage(), colored)); + } + + @Override + public void error(String message) { + System.out.println(printConsole(ChatColor.RED + message, colored)); + } + + @Override + public void error(String message, Throwable error) { + System.out.println(printConsole(ChatColor.RED + message + "\n" + error, colored)); + } + + @Override + public void warning(String message) { + System.out.println(printConsole(ChatColor.YELLOW + message, colored)); + } + + @Override + public void info(String message) { + System.out.println(printConsole(ChatColor.WHITE + message, colored)); + } + + @Override + public void debug(String message) { + if (debug) + System.out.println(printConsole(ChatColor.GRAY + message, colored)); + } + + public static String printConsole(String message, boolean colors) { + return colors ? ChatColor.toANSI(message + ChatColor.RESET) : ChatColor.stripColors(message + ChatColor.RESET); + } + + @Override + public void setDebug(boolean debug) { + this.debug = debug; + } +} diff --git a/common/pom.xml b/common/pom.xml index 6a0a6ff04..a7f0f2588 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -6,52 +6,16 @@ org.geysermc geyser-parent - 1.0-SNAPSHOT + parent + ../ common + 1.0-SNAPSHOT - com.github.steveice10 - opennbt - 1.3-SNAPSHOT - compile - - - com.github.steveice10 - packetlib - 1.4-SNAPSHOT - compile - - - com.github.steveice10 - mcauthlib - 1.1-SNAPSHOT - compile - - - com.github.steveice10 - mcprotocollib - 1.14.4-SNAPSHOT - compile - - - com.github.steveice10 - opennbt - - - com.github.steveice10 - packetlib - - - com.github.steveice10 - mcauthlib - - - - - com.auth0 - java-jwt - 3.3.0 + org.geysermc + api + 1.0-SNAPSHOT compile diff --git a/connector/src/main/java/org/geysermc/connector/configuration/RemoteConfiguration.java b/common/src/main/java/org/geysermc/common/IGeyserConfiguration.java similarity index 56% rename from connector/src/main/java/org/geysermc/connector/configuration/RemoteConfiguration.java rename to common/src/main/java/org/geysermc/common/IGeyserConfiguration.java index 7fcf8a2bb..0ea120c57 100644 --- a/connector/src/main/java/org/geysermc/connector/configuration/RemoteConfiguration.java +++ b/common/src/main/java/org/geysermc/common/IGeyserConfiguration.java @@ -23,20 +23,60 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.connector.configuration; +package org.geysermc.common; -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Getter; +import java.util.Map; -@Getter -public class RemoteConfiguration { +public interface IGeyserConfiguration { - private String address; - private int port; + IBedrockConfiguration getBedrock(); - private String motd1; - private String motd2; + IRemoteConfiguration getRemote(); - @JsonProperty("auth-type") - private String authType; -} \ No newline at end of file + Map getUserAuths(); + + boolean isPingPassthrough(); + + int getMaxPlayers(); + + boolean isDebugMode(); + + int getGeneralThreadPool(); + + boolean isAllowThirdPartyCapes(); + + IMetricsInfo getMetrics(); + + interface IBedrockConfiguration { + + String getAddress(); + + int getPort(); + + String getMotd1(); + + String getMotd2(); + } + + interface IRemoteConfiguration { + + String getAddress(); + + int getPort(); + + String getAuthType(); + } + + interface IUserAuthenticationInfo { + String getEmail(); + + String getPassword(); + } + + interface IMetricsInfo { + + boolean isEnabled(); + + String getUniqueId(); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/configuration/MetricInfo.java b/common/src/main/java/org/geysermc/common/bootstrap/IGeyserBootstrap.java similarity index 81% rename from connector/src/main/java/org/geysermc/connector/configuration/MetricInfo.java rename to common/src/main/java/org/geysermc/common/bootstrap/IGeyserBootstrap.java index d108d4b4c..f41d0a1da 100644 --- a/connector/src/main/java/org/geysermc/connector/configuration/MetricInfo.java +++ b/common/src/main/java/org/geysermc/common/bootstrap/IGeyserBootstrap.java @@ -23,16 +23,18 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.connector.configuration; +package org.geysermc.common.bootstrap; -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Getter; +import org.geysermc.api.logger.Logger; +import org.geysermc.common.IGeyserConfiguration; -@Getter -public class MetricInfo { +public interface IGeyserBootstrap { - private boolean enabled; + void onEnable(); - @JsonProperty("uuid") - private String UUID; + void onDisable(); + + IGeyserConfiguration getGeyserConfig(); + + Logger getGeyserLogger(); } diff --git a/connector/pom.xml b/connector/pom.xml index 60ecfc557..c0008f358 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -6,9 +6,11 @@ org.geysermc geyser-parent - 1.0-SNAPSHOT + parent + ../ connector + 1.0-SNAPSHOT org.geysermc @@ -129,30 +131,12 @@ - ${outputName}-noshade - ../target + ${project.artifactId}-${project.version}-noshade - - org.apache.maven.plugins - maven-jar-plugin - - - - org.geysermc.connector.GeyserConnector - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - ${outputName} - - org.apache.maven.plugins maven-shade-plugin + 3.1.0 package @@ -162,7 +146,6 @@ - ${outputName} true true diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index 4abe763ff..215769a27 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -30,15 +30,14 @@ import com.nukkitx.protocol.bedrock.BedrockServer; import com.nukkitx.protocol.bedrock.v388.Bedrock_v388; import lombok.Getter; -import org.fusesource.jansi.AnsiConsole; import org.geysermc.api.Connector; import org.geysermc.api.Geyser; import org.geysermc.api.Player; import org.geysermc.api.command.CommandMap; import org.geysermc.api.logger.Logger; import org.geysermc.api.plugin.Plugin; +import org.geysermc.common.bootstrap.IGeyserBootstrap; import org.geysermc.connector.command.GeyserCommandMap; -import org.geysermc.connector.configuration.GeyserConfiguration; import org.geysermc.connector.console.ConsoleCommandReader; import org.geysermc.connector.console.GeyserLogger; import org.geysermc.connector.metrics.Metrics; @@ -49,17 +48,14 @@ import org.geysermc.connector.network.translators.TranslatorsInit; import org.geysermc.connector.plugin.GeyserPluginLoader; import org.geysermc.connector.plugin.GeyserPluginManager; import org.geysermc.connector.thread.PingPassthroughThread; -import org.geysermc.connector.utils.FileUtils; import org.geysermc.connector.utils.Toolbox; +import org.geysermc.common.IGeyserConfiguration; -import java.io.File; -import java.io.IOException; import java.net.InetSocketAddress; import java.text.DecimalFormat; import java.util.Collection; import java.util.HashMap; import java.util.Map; -import java.util.UUID; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -82,7 +78,7 @@ public class GeyserConnector implements Connector { private CommandMap commandMap; - private GeyserConfiguration config; + private IGeyserConfiguration config; private GeyserPluginManager pluginManager; private boolean shuttingDown = false; @@ -92,21 +88,13 @@ public class GeyserConnector implements Connector { private Metrics metrics; - public static void main(String[] args) { - instance = new GeyserConnector(); - } - - private GeyserConnector() { + private GeyserConnector(IGeyserConfiguration config, Logger logger, boolean loadPlugins) { long startupTime = System.currentTimeMillis(); - // Metric - if (!(System.console() == null) && System.getProperty("os.name", "Windows 10").toLowerCase().contains("windows")) { - AnsiConsole.systemInstall(); - } - instance = this; - this.logger = GeyserLogger.DEFAULT; + this.logger = logger; + GeyserLogger.setLogger(logger); logger.info("******************************************"); logger.info(""); @@ -114,13 +102,7 @@ public class GeyserConnector implements Connector { logger.info(""); logger.info("******************************************"); - try { - File configFile = FileUtils.fileOrCopiedFromResource("config.yml", (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString())); - config = FileUtils.loadConfig(configFile, GeyserConfiguration.class); - } catch (IOException ex) { - logger.severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex); - shutdown(); - } + this.config = config; this.generalThreadPool = Executors.newScheduledThreadPool(config.getGeneralThreadPool()); ConsoleCommandReader consoleReader = new ConsoleCommandReader(this); @@ -137,7 +119,8 @@ public class GeyserConnector implements Connector { Geyser.setConnector(this); pluginManager = new GeyserPluginManager(new GeyserPluginLoader(this)); - pluginManager.getLoader().loadPlugins(); + if (loadPlugins) + pluginManager.getLoader().loadPlugins(); passthroughThread = new PingPassthroughThread(this); if (config.isPingPassthrough()) @@ -155,7 +138,7 @@ public class GeyserConnector implements Connector { }).join(); if (config.getMetrics().isEnabled()) { - metrics = new Metrics("GeyserMC", config.getMetrics().getUUID(), false, java.util.logging.Logger.getLogger("")); + metrics = new Metrics("GeyserMC", config.getMetrics().getUniqueId(), false, java.util.logging.Logger.getLogger("")); metrics.addCustomChart(new Metrics.SingleLineChart("servers", () -> 1)); metrics.addCustomChart(new Metrics.SingleLineChart("players", Geyser::getPlayerCount)); metrics.addCustomChart(new Metrics.SimplePie("authMode", config.getRemote()::getAuthType)); @@ -180,7 +163,6 @@ public class GeyserConnector implements Connector { shuttingDown = true; generalThreadPool.shutdown(); - System.exit(0); } public void addPlayer(GeyserSession player) { @@ -194,4 +176,12 @@ public class GeyserConnector implements Connector { players.remove(player.getAuthenticationData().getUUID()); players.remove(player.getSocketAddress()); } + + public static void start(IGeyserBootstrap bootstrap, boolean loadPlugins) { + instance = new GeyserConnector(bootstrap.getGeyserConfig(), bootstrap.getGeyserLogger(), loadPlugins); + } + + public static void stop() { + instance.shutdown(); + } } diff --git a/connector/src/main/java/org/geysermc/connector/configuration/UserAuthenticationInfo.java b/connector/src/main/java/org/geysermc/connector/configuration/UserAuthenticationInfo.java deleted file mode 100644 index e8ce14243..000000000 --- a/connector/src/main/java/org/geysermc/connector/configuration/UserAuthenticationInfo.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2019 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.connector.configuration; - -public class UserAuthenticationInfo { - public String email; - public String password; -} \ No newline at end of file diff --git a/connector/src/main/java/org/geysermc/connector/console/GeyserLogger.java b/connector/src/main/java/org/geysermc/connector/console/GeyserLogger.java index 7634debce..719667c75 100644 --- a/connector/src/main/java/org/geysermc/connector/console/GeyserLogger.java +++ b/connector/src/main/java/org/geysermc/connector/console/GeyserLogger.java @@ -27,19 +27,21 @@ package org.geysermc.connector.console; import io.sentry.Sentry; import org.geysermc.api.ChatColor; +import org.geysermc.api.logger.Logger; import java.io.File; import java.io.IOException; import java.util.Date; import java.util.logging.*; -public class GeyserLogger implements org.geysermc.api.logger.Logger { +public class GeyserLogger { + public static Logger DEFAULT; + + /* private boolean colored = true; private boolean debug = false; - public static final GeyserLogger DEFAULT = new GeyserLogger(); - private GeyserLogger() { ConsoleHandler consoleHandler = new ConsoleHandler(); consoleHandler.setLevel(Level.INFO); @@ -132,4 +134,14 @@ public class GeyserLogger implements org.geysermc.api.logger.Logger { public void setDebug(boolean debug) { this.debug = debug; } + + */ + + public static String printConsole(String message, boolean colors) { + return colors ? ChatColor.toANSI(message + ChatColor.RESET) : ChatColor.stripColors(message + ChatColor.RESET); + } + + public static void setLogger(Logger logger) { + DEFAULT = logger; + } } diff --git a/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java b/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java index da8c85815..34d36a216 100644 --- a/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java @@ -29,10 +29,9 @@ import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo; import com.nukkitx.protocol.bedrock.BedrockPong; import com.nukkitx.protocol.bedrock.BedrockServerEventHandler; import com.nukkitx.protocol.bedrock.BedrockServerSession; -import org.geysermc.api.Player; import org.geysermc.api.events.PingEvent; +import org.geysermc.common.IGeyserConfiguration; import org.geysermc.connector.GeyserConnector; -import org.geysermc.connector.configuration.GeyserConfiguration; import org.geysermc.connector.console.GeyserLogger; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.utils.MessageUtils; @@ -56,7 +55,7 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler { @Override public BedrockPong onQuery(InetSocketAddress inetSocketAddress) { GeyserLogger.DEFAULT.debug(inetSocketAddress + " has pinged you!"); - GeyserConfiguration config = connector.getConfig(); + IGeyserConfiguration config = connector.getConfig(); PingEvent pongEvent = new PingEvent(inetSocketAddress); pongEvent.setEdition("MCPE"); pongEvent.setGameType("Default"); diff --git a/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java b/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java index 4990280b9..d24e0b337 100644 --- a/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java @@ -27,8 +27,8 @@ package org.geysermc.connector.network; import com.nukkitx.protocol.bedrock.BedrockPacket; import com.nukkitx.protocol.bedrock.packet.*; +import org.geysermc.common.IGeyserConfiguration; import org.geysermc.connector.GeyserConnector; -import org.geysermc.connector.configuration.UserAuthenticationInfo; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.Registry; import org.geysermc.connector.utils.LoginEncryptionUtils; @@ -91,11 +91,11 @@ public class UpstreamPacketHandler extends LoggingPacketHandler { private boolean couldLoginUserByName(String bedrockUsername) { if (connector.getConfig().getUserAuths() != null) { - UserAuthenticationInfo info = connector.getConfig().getUserAuths().get(bedrockUsername); + IGeyserConfiguration.IUserAuthenticationInfo info = connector.getConfig().getUserAuths().get(bedrockUsername); if (info != null) { connector.getLogger().info("using stored credentials for bedrock user " + session.getAuthenticationData().getName()); - session.authenticate(info.email, info.password); + session.authenticate(info.getEmail(), info.getPassword()); // TODO send a message to bedrock user telling them they are connected (if nothing like a motd // somes from the Java server w/in a few seconds) diff --git a/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java b/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java index b4c9d7f63..91910c961 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java @@ -7,12 +7,12 @@ import com.nukkitx.protocol.bedrock.data.SerializedSkin; import com.nukkitx.protocol.bedrock.packet.PlayerListPacket; import lombok.AllArgsConstructor; import lombok.Getter; -import org.apache.commons.codec.Charsets; import org.geysermc.api.Geyser; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.network.session.GeyserSession; +import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.Collections; import java.util.UUID; @@ -80,7 +80,7 @@ public class SkinUtils { try { GameProfile.Property skinProperty = profile.getProperty("textures"); - JsonObject skinObject = SkinProvider.GSON.fromJson(new String(Base64.getDecoder().decode(skinProperty.getValue()), Charsets.UTF_8), JsonObject.class); + JsonObject skinObject = SkinProvider.GSON.fromJson(new String(Base64.getDecoder().decode(skinProperty.getValue()), StandardCharsets.UTF_8), JsonObject.class); JsonObject textures = skinObject.getAsJsonObject("textures"); JsonObject skinTexture = textures.getAsJsonObject("SKIN"); diff --git a/plugin/pom.xml b/plugin/pom.xml deleted file mode 100644 index 9916408b9..000000000 --- a/plugin/pom.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - 4.0.0 - - org.geysermc - geyser-parent - 1.0-SNAPSHOT - - plugin - - - - bungeecord-repo - https://oss.sonatype.org/content/repositories/snapshots - - - dosse-repo - https://raw.github.com/JRakNet/WaifUPnP/master/ - - - - - - net.md-5 - bungeecord-api - 1.14-SNAPSHOT - jar - compile - - - com.whirvis - jraknet - 2.11.8 - compile - - - diff --git a/plugin/src/main/java/org/geysermc/plugin/GeyserPlugin.java b/plugin/src/main/java/org/geysermc/plugin/GeyserPlugin.java deleted file mode 100644 index 98950747b..000000000 --- a/plugin/src/main/java/org/geysermc/plugin/GeyserPlugin.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.geysermc.plugin; - -import com.whirvis.jraknet.RakNetPacket; -import com.whirvis.jraknet.peer.RakNetClientPeer; -import com.whirvis.jraknet.server.RakNetServer; -import com.whirvis.jraknet.server.RakNetServerListener; -import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.api.connection.ConnectedPlayer; -import net.md_5.bungee.api.plugin.Plugin; - -import java.lang.reflect.Field; -import java.net.InetSocketAddress; -import java.util.List; -import java.util.UUID; - -public class GeyserPlugin extends Plugin { - - private List players; - - @SuppressWarnings("unchecked") - @Override - public void onEnable() { - try { - Class clazz = getProxy().getClass(); - Field field = clazz.getDeclaredField("connections"); - field.setAccessible(true); - players = (List) field.get(getProxy()); - } catch (Exception e) { - throw new RuntimeException(e); - } - RakNetServer server = new RakNetServer(new InetSocketAddress("0.0.0.0", 65500), 1000000); - server.addListener(new RakNetServerListener() { - @Override - public void handleMessage(RakNetServer server, RakNetClientPeer peer, RakNetPacket packet, int channel) { - if(packet.getId() == 0) { - } - } - }); - } - private UUID fromXUID(String XUID) { - String one = XUID.substring(0, XUID.length()/2); - String two = XUID.substring(XUID.length()/2, XUID.length()); - long L1 = Long.parseLong(one); - long L2 = Long.parseLong(two); - return new UUID(L1, L2); - } -} diff --git a/pom.xml b/pom.xml index 79b7b5a1a..f02c509a1 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.geysermc geyser-parent - 1.0-SNAPSHOT + parent pom GeyserMC Allows for players from Minecraft Bedrock Edition to join Minecraft Java Edition servers. @@ -32,9 +32,9 @@ api + bootstrap common connector - plugin From e8f4522762aadcf6eb326de0b2d8c41f15da6a58 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sun, 1 Dec 2019 16:52:07 -0600 Subject: [PATCH 08/45] Add BungeeCord plugin module, cleanup POMs --- api/pom.xml | 2 +- bootstrap/bukkit/pom.xml | 7 - bootstrap/bungeecord/pom.xml | 56 ++++++ .../bungeecord/GeyserBungeeConfiguration.java | 177 ++++++++++++++++++ .../bungeecord/GeyserBungeeLogger.java | 81 ++++++++ .../bungeecord/GeyserBungeePlugin.java | 101 ++++++++++ .../bungeecord/src/main/resources/bungee.yml | 5 + bootstrap/pom.xml | 8 +- bootstrap/standalone/pom.xml | 7 - .../platform/standalone/GeyserBootstrap.java | 2 +- connector/pom.xml | 19 -- pom.xml | 1 - 12 files changed, 428 insertions(+), 38 deletions(-) create mode 100644 bootstrap/bungeecord/pom.xml create mode 100644 bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java create mode 100644 bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeLogger.java create mode 100644 bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java create mode 100644 bootstrap/bungeecord/src/main/resources/bungee.yml diff --git a/api/pom.xml b/api/pom.xml index 2bb85be24..2d4b1239d 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -14,7 +14,7 @@ org.projectlombok lombok 1.18.4 - compile + provided com.google.code.gson diff --git a/bootstrap/bukkit/pom.xml b/bootstrap/bukkit/pom.xml index 02b7d9a2e..cbc0ef15f 100644 --- a/bootstrap/bukkit/pom.xml +++ b/bootstrap/bukkit/pom.xml @@ -11,12 +11,6 @@ bootstrap-bukkit - - org.geysermc - common - 1.0-SNAPSHOT - compile - org.geysermc connector @@ -54,7 +48,6 @@ ${outputName}-Bukkit - false true diff --git a/bootstrap/bungeecord/pom.xml b/bootstrap/bungeecord/pom.xml new file mode 100644 index 000000000..3f26909e0 --- /dev/null +++ b/bootstrap/bungeecord/pom.xml @@ -0,0 +1,56 @@ + + + 4.0.0 + + org.geysermc + bootstrap-parent + 1.0-SNAPSHOT + ../ + + bootstrap-bungeecord + + + org.geysermc + connector + 1.0-SNAPSHOT + compile + + + net.md-5 + bungeecord-api + 1.14-SNAPSHOT + provided + + + + ${outputName}-BungeeCord-noshade + clean install + + + src/main/resources/ + true + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.1.0 + + + package + + shade + + + + + ${outputName}-BungeeCord + true + + + + + \ No newline at end of file diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java new file mode 100644 index 000000000..931a09fa6 --- /dev/null +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.platform.bungeecord; + +import net.md_5.bungee.config.Configuration; + +import org.geysermc.common.IGeyserConfiguration; + +import java.util.HashMap; +import java.util.Map; + +public class GeyserBungeeConfiguration implements IGeyserConfiguration { + + private Configuration config; + + private BungeeBedrockConfiguration bedrockConfig; + private BungeeRemoteConfiguration remoteConfig; + private BungeeMetricsInfo metricsInfo; + + private Map userAuthInfo = new HashMap<>(); + + public GeyserBungeeConfiguration(Configuration config) { + 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)); + } + } + + @Override + public BungeeBedrockConfiguration getBedrock() { + return bedrockConfig; + } + + @Override + public BungeeRemoteConfiguration getRemote() { + return remoteConfig; + } + + @Override + public Map getUserAuths() { + return userAuthInfo; + } + + @Override + public boolean isPingPassthrough() { + return config.getBoolean("ping-passthrough", false); + } + + @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 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"); + } + } +} diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeLogger.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeLogger.java new file mode 100644 index 000000000..671f055de --- /dev/null +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeLogger.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.platform.bungeecord; + +import java.util.logging.Level; +import java.util.logging.Logger; + +public class GeyserBungeeLogger implements org.geysermc.api.logger.Logger { + + private Logger logger; + private boolean debugMode; + + public GeyserBungeeLogger(Logger logger, boolean debugMode) { + this.logger = logger; + this.debugMode = debugMode; + } + + @Override + public void severe(String message) { + logger.severe(message); + } + + @Override + public void severe(String message, Throwable error) { + logger.log(Level.SEVERE, message, error); + } + + @Override + public void error(String message) { + logger.warning(message); + } + + @Override + public void error(String message, Throwable error) { + logger.log(Level.WARNING, message, error); + } + + @Override + public void warning(String message) { + error(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 debug) { + debugMode = debug; + } +} diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java new file mode 100644 index 000000000..0a97230d0 --- /dev/null +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.platform.bungeecord; + +import net.md_5.bungee.api.plugin.Plugin; +import net.md_5.bungee.config.Configuration; +import net.md_5.bungee.config.ConfigurationProvider; +import net.md_5.bungee.config.YamlConfiguration; + +import org.geysermc.connector.GeyserConnector; +import org.geysermc.common.bootstrap.IGeyserBootstrap; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.util.UUID; + +public class GeyserBungeePlugin extends Plugin implements IGeyserBootstrap { + + private GeyserBungeeConfiguration geyserConfig; + private GeyserBungeeLogger geyserLogger; + + @Override + public void onEnable() { + 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()); + configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "config.yml")); + } catch (IOException ex) { + geyserLogger.severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex); + return; + } + } + + if (configuration == null) { + geyserLogger.severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!"); + return; + } + + geyserConfig = new GeyserBungeeConfiguration(configuration); + + if (geyserConfig.getMetrics().getUniqueId().equals("generateduuid")) { + configuration.set("metrics.uuid", UUID.randomUUID().toString()); + try { + ConfigurationProvider.getProvider(YamlConfiguration.class).save(configuration, new File(getDataFolder(), "config.yml")); + } catch (IOException ex) { + geyserLogger.severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex); + return; + } + } + + geyserLogger = new GeyserBungeeLogger(getLogger(), geyserConfig.isDebugMode()); + + GeyserConnector.start(this, false); + } + + @Override + public void onDisable() { + GeyserConnector.stop(); + } + + @Override + public GeyserBungeeConfiguration getGeyserConfig() { + return geyserConfig; + } + + @Override + public GeyserBungeeLogger getGeyserLogger() { + return geyserLogger; + } +} diff --git a/bootstrap/bungeecord/src/main/resources/bungee.yml b/bootstrap/bungeecord/src/main/resources/bungee.yml new file mode 100644 index 000000000..8781ea31b --- /dev/null +++ b/bootstrap/bungeecord/src/main/resources/bungee.yml @@ -0,0 +1,5 @@ +main: org.geysermc.platform.bungeecord.GeyserBungeePlugin +name: ${outputName}-BungeeCord +author: ${project.organization.name} +website: ${project.organization.url} +version: ${project.version} \ No newline at end of file diff --git a/bootstrap/pom.xml b/bootstrap/pom.xml index 5c91b817e..7cc7e2ba6 100644 --- a/bootstrap/pom.xml +++ b/bootstrap/pom.xml @@ -25,11 +25,15 @@ sponge-repo https://repo.spongepowered.org/maven + + bungeecord-repo + https://oss.sonatype.org/content/repositories/snapshots + bukkit - + bungeecord + standalone diff --git a/bootstrap/standalone/pom.xml b/bootstrap/standalone/pom.xml index 3c38a6c09..122b29ab9 100644 --- a/bootstrap/standalone/pom.xml +++ b/bootstrap/standalone/pom.xml @@ -11,12 +11,6 @@ bootstrap-standalone - - org.geysermc - common - 1.0-SNAPSHOT - compile - org.geysermc connector @@ -54,7 +48,6 @@ ${outputName} - false true diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java index 014cf83ee..f769c52f0 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java @@ -56,7 +56,7 @@ public class GeyserBootstrap implements IGeyserBootstrap { File configFile = FileUtils.fileOrCopiedFromResource("config.yml", (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString())); geyserConfig = FileUtils.loadConfig(configFile, GeyserConfiguration.class); } catch (IOException ex) { - getGeyserLogger().severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex); + geyserLogger.severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex); System.exit(0); } diff --git a/connector/pom.xml b/connector/pom.xml index c0008f358..d8c42bcf7 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -12,12 +12,6 @@ connector 1.0-SNAPSHOT - - org.geysermc - api - 1.0-SNAPSHOT - compile - org.geysermc common @@ -49,18 +43,6 @@ jar compile - - org.slf4j - slf4j-api - 1.7.5 - compile - - - org.slf4j - slf4j-simple - 1.6.4 - compile - org.projectlombok lombok @@ -146,7 +128,6 @@ - true true diff --git a/pom.xml b/pom.xml index f02c509a1..ce4ad9e9e 100644 --- a/pom.xml +++ b/pom.xml @@ -106,7 +106,6 @@ maven-shade-plugin 3.1.0 - false true From c76c39f3f565e52eea9ce35c518f2214abb2920e Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sun, 1 Dec 2019 17:10:58 -0600 Subject: [PATCH 09/45] Fix Jenkins ...and update non-shaded jar names. --- Jenkinsfile | 2 +- bootstrap/bukkit/pom.xml | 6 +++--- bootstrap/bungeecord/pom.xml | 6 +++--- bootstrap/standalone/pom.xml | 6 +++--- connector/pom.xml | 2 +- pom.xml | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index abe22b6f3..1b908bdf0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -15,7 +15,7 @@ pipeline { } post { success { - archiveArtifacts artifacts: 'target/Geyser.jar', fingerprint: true + archiveArtifacts artifacts: 'target/*.jar', fingerprint: true } } } diff --git a/bootstrap/bukkit/pom.xml b/bootstrap/bukkit/pom.xml index cbc0ef15f..8e597635e 100644 --- a/bootstrap/bukkit/pom.xml +++ b/bootstrap/bukkit/pom.xml @@ -25,7 +25,8 @@ - ${outputName}-Bukkit-noshade + ${outputName}-Bukkit + ../../target clean install @@ -37,7 +38,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.1.0 + 3.2.1 package @@ -47,7 +48,6 @@ - ${outputName}-Bukkit true diff --git a/bootstrap/bungeecord/pom.xml b/bootstrap/bungeecord/pom.xml index 3f26909e0..5d437bbf9 100644 --- a/bootstrap/bungeecord/pom.xml +++ b/bootstrap/bungeecord/pom.xml @@ -25,7 +25,8 @@ - ${outputName}-BungeeCord-noshade + ${outputName}-BungeeCord + ../../target clean install @@ -37,7 +38,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.1.0 + 3.2.1 package @@ -47,7 +48,6 @@ - ${outputName}-BungeeCord true diff --git a/bootstrap/standalone/pom.xml b/bootstrap/standalone/pom.xml index 122b29ab9..03e178955 100644 --- a/bootstrap/standalone/pom.xml +++ b/bootstrap/standalone/pom.xml @@ -19,7 +19,8 @@ - ${outputName}-noshade + ${outputName} + ../../target clean install @@ -37,7 +38,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.1.0 + 3.2.1 package @@ -47,7 +48,6 @@ - ${outputName} true diff --git a/connector/pom.xml b/connector/pom.xml index d8c42bcf7..30ada4544 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -118,7 +118,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.1.0 + 3.2.1 package diff --git a/pom.xml b/pom.xml index ce4ad9e9e..e534fbc0d 100644 --- a/pom.xml +++ b/pom.xml @@ -104,7 +104,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.1.0 + 3.2.1 true From 3e7e34dfb98abad8e3ac3b725f1f86caf50294b9 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sun, 1 Dec 2019 18:28:36 -0600 Subject: [PATCH 10/45] Move command reader into standalone module --- bootstrap/standalone/pom.xml | 25 +++++++++++++++++++ .../platform/standalone/GeyserBootstrap.java | 7 +++++- .../console/ConsoleCommandReader.java | 12 ++++----- .../{ => console}/GeyserLogger.java | 2 +- connector/pom.xml | 25 +++++-------------- .../geysermc/connector/GeyserConnector.java | 7 ++---- 6 files changed, 45 insertions(+), 33 deletions(-) rename {connector/src/main/java/org/geysermc/connector => bootstrap/standalone/src/main/java/org/geysermc/platform/standalone}/console/ConsoleCommandReader.java (93%) rename bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/{ => console}/GeyserLogger.java (98%) diff --git a/bootstrap/standalone/pom.xml b/bootstrap/standalone/pom.xml index 03e178955..7f0aef557 100644 --- a/bootstrap/standalone/pom.xml +++ b/bootstrap/standalone/pom.xml @@ -17,6 +17,31 @@ 1.0-SNAPSHOT compile + + net.minecrell + terminalconsoleappender + 1.0.0 + jar + compile + + + org.slf4j + slf4j-api + 1.7.5 + compile + + + org.slf4j + slf4j-simple + 1.6.4 + compile + + + org.fusesource.jansi + jansi + 1.18 + compile + ${outputName} diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java index f769c52f0..8424fd634 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java @@ -29,6 +29,8 @@ import org.fusesource.jansi.AnsiConsole; import org.geysermc.common.bootstrap.IGeyserBootstrap; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.utils.FileUtils; +import org.geysermc.platform.standalone.console.ConsoleCommandReader; +import org.geysermc.platform.standalone.console.GeyserLogger; import java.io.File; import java.io.IOException; @@ -60,7 +62,10 @@ public class GeyserBootstrap implements IGeyserBootstrap { System.exit(0); } - GeyserConnector.start(this, false); + GeyserConnector connector = GeyserConnector.start(this, false); + + ConsoleCommandReader consoleReader = new ConsoleCommandReader(connector); + consoleReader.startConsole(); } @Override diff --git a/connector/src/main/java/org/geysermc/connector/console/ConsoleCommandReader.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/ConsoleCommandReader.java similarity index 93% rename from connector/src/main/java/org/geysermc/connector/console/ConsoleCommandReader.java rename to bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/ConsoleCommandReader.java index f2c6af7fa..8396228c5 100644 --- a/connector/src/main/java/org/geysermc/connector/console/ConsoleCommandReader.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/ConsoleCommandReader.java @@ -23,12 +23,12 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.connector.console; +package org.geysermc.platform.standalone.console; +import net.minecrell.terminalconsole.TerminalConsoleAppender; import org.geysermc.api.command.ConsoleCommandSender; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.command.GeyserConsoleCommandSender; -import net.minecrell.terminalconsole.TerminalConsoleAppender; import org.jline.reader.EndOfFileException; import org.jline.reader.LineReader; import org.jline.reader.LineReaderBuilder; @@ -45,7 +45,6 @@ public class ConsoleCommandReader { private GeyserConnector connector; private Terminal terminal; - private Thread thread; public ConsoleCommandReader(GeyserConnector connector) { this.connector = connector; @@ -53,7 +52,7 @@ public class ConsoleCommandReader { } public void startConsole() { - thread = new Thread(() -> { + Thread thread = new Thread(() -> { if (terminal != null) { LineReader lineReader = LineReaderBuilder.builder() .appName("Geyser") @@ -74,8 +73,8 @@ public class ConsoleCommandReader { if (line == null) break; } - } catch (UserInterruptException e /* do nothing */) { - // + } catch (UserInterruptException ignore) { + /* do nothing */ } finally { TerminalConsoleAppender.setReader(null); } @@ -93,6 +92,5 @@ public class ConsoleCommandReader { }); thread.setName("ConsoleCommandThread"); - connector.getGeneralThreadPool().execute(thread); } } diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserLogger.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java similarity index 98% rename from bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserLogger.java rename to bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java index 0df4f1f15..0e7af4298 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserLogger.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java @@ -23,7 +23,7 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.platform.standalone; +package org.geysermc.platform.standalone.console; import io.sentry.Sentry; import org.geysermc.api.ChatColor; diff --git a/connector/pom.xml b/connector/pom.xml index 30ada4544..fe01a370f 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -36,25 +36,6 @@ 1.7.0 compile - - net.minecrell - terminalconsoleappender - 1.0.0 - jar - compile - - - org.projectlombok - lombok - 1.18.4 - provided - - - org.fusesource.jansi - jansi - 1.18 - compile - com.nukkitx.protocol bedrock-v388 @@ -111,6 +92,12 @@ + + org.projectlombok + lombok + 1.18.4 + provided + ${project.artifactId}-${project.version}-noshade diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index 215769a27..b25b640ad 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -38,7 +38,6 @@ import org.geysermc.api.logger.Logger; import org.geysermc.api.plugin.Plugin; import org.geysermc.common.bootstrap.IGeyserBootstrap; import org.geysermc.connector.command.GeyserCommandMap; -import org.geysermc.connector.console.ConsoleCommandReader; import org.geysermc.connector.console.GeyserLogger; import org.geysermc.connector.metrics.Metrics; import org.geysermc.connector.network.ConnectorServerEventHandler; @@ -105,8 +104,6 @@ public class GeyserConnector implements Connector { this.config = config; this.generalThreadPool = Executors.newScheduledThreadPool(config.getGeneralThreadPool()); - ConsoleCommandReader consoleReader = new ConsoleCommandReader(this); - consoleReader.startConsole(); logger.setDebug(config.isDebugMode()); @@ -177,8 +174,8 @@ public class GeyserConnector implements Connector { players.remove(player.getSocketAddress()); } - public static void start(IGeyserBootstrap bootstrap, boolean loadPlugins) { - instance = new GeyserConnector(bootstrap.getGeyserConfig(), bootstrap.getGeyserLogger(), loadPlugins); + public static GeyserConnector start(IGeyserBootstrap bootstrap, boolean loadPlugins) { + return new GeyserConnector(bootstrap.getGeyserConfig(), bootstrap.getGeyserLogger(), loadPlugins); } public static void stop() { From 5552f34871905abc02d801d992c2e29326e7cedf Mon Sep 17 00:00:00 2001 From: Redned Date: Mon, 2 Dec 2019 08:27:45 -0600 Subject: [PATCH 11/45] Fix NPE if config was null in BungeeCord module --- .../geysermc/platform/bungeecord/GeyserBungeePlugin.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java index 0a97230d0..5542ed8ea 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java @@ -57,13 +57,13 @@ public class GeyserBungeePlugin extends Plugin implements IGeyserBootstrap { Files.copy(in, file.toPath()); configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "config.yml")); } catch (IOException ex) { - geyserLogger.severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex); + getLogger().severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex); return; } } if (configuration == null) { - geyserLogger.severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!"); + getLogger().severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!"); return; } @@ -74,7 +74,7 @@ public class GeyserBungeePlugin extends Plugin implements IGeyserBootstrap { try { ConfigurationProvider.getProvider(YamlConfiguration.class).save(configuration, new File(getDataFolder(), "config.yml")); } catch (IOException ex) { - geyserLogger.severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex); + getLogger().severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex); return; } } From 433a3b47138539cd2ee9f24829c2c60769e7054c Mon Sep 17 00:00:00 2001 From: Redned Date: Mon, 2 Dec 2019 08:45:51 -0600 Subject: [PATCH 12/45] Fix compile error --- .../org/geysermc/platform/bungeecord/GeyserBungeePlugin.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java index 5542ed8ea..ce2cb81e8 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java @@ -38,6 +38,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.util.UUID; +import java.util.logging.Level; public class GeyserBungeePlugin extends Plugin implements IGeyserBootstrap { @@ -57,7 +58,7 @@ public class GeyserBungeePlugin extends Plugin implements IGeyserBootstrap { Files.copy(in, file.toPath()); configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "config.yml")); } catch (IOException ex) { - getLogger().severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex); + getLogger().log(Level.SEVERE, "Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex); return; } } @@ -74,7 +75,7 @@ public class GeyserBungeePlugin extends Plugin implements IGeyserBootstrap { try { ConfigurationProvider.getProvider(YamlConfiguration.class).save(configuration, new File(getDataFolder(), "config.yml")); } catch (IOException ex) { - getLogger().severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex); + getLogger().log(Level.SEVERE, "Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex); return; } } From 90419fc692ea5e210d8e05f915609ef46b0f68a8 Mon Sep 17 00:00:00 2001 From: EOT3000 <43685885+EOT3000@users.noreply.github.com> Date: Mon, 2 Dec 2019 11:51:48 -0500 Subject: [PATCH 13/45] May or may not work @LegacyGamerHD --- .../org/geysermc/platform/bungeecord/GeyserBungeePlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java index ce2cb81e8..faa8a413a 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java @@ -56,12 +56,12 @@ public class GeyserBungeePlugin extends Plugin implements IGeyserBootstrap { if (!file.exists()) { try (InputStream in = getResourceAsStream("config.yml")) { Files.copy(in, file.toPath()); - configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(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; } } + configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "config.yml")); if (configuration == null) { getLogger().severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!"); From 1e12f5eac9bde11974ee008a5e8cb9e721018c91 Mon Sep 17 00:00:00 2001 From: EOT3000 <43685885+EOT3000@users.noreply.github.com> Date: Mon, 2 Dec 2019 11:54:07 -0500 Subject: [PATCH 14/45] May or may not work.... again --- .../geysermc/platform/bungeecord/GeyserBungeePlugin.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java index faa8a413a..fd0248fd7 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java @@ -61,7 +61,11 @@ public class GeyserBungeePlugin extends Plugin implements IGeyserBootstrap { return; } } - configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "config.yml")); + try { + configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "config.yml")); + } catch(IOException e) { + e.printStackTrace(); + } if (configuration == null) { getLogger().severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!"); From 6f5fc4c85ca56c66228abe265b847194fbae2057 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Wed, 4 Dec 2019 18:56:14 -0600 Subject: [PATCH 15/45] Fix JNI overlap with BungeeCord module --- bootstrap/bungeecord/pom.xml | 6 ++++++ connector/src/main/resources/mappings | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/bootstrap/bungeecord/pom.xml b/bootstrap/bungeecord/pom.xml index 5d437bbf9..e30e87673 100644 --- a/bootstrap/bungeecord/pom.xml +++ b/bootstrap/bungeecord/pom.xml @@ -48,6 +48,12 @@ + + + net.md_5.bungee.jni + org.geysermc.platform.bungeecord.shaded.jni + + true diff --git a/connector/src/main/resources/mappings b/connector/src/main/resources/mappings index 5ec6f1f33..3d4147f00 160000 --- a/connector/src/main/resources/mappings +++ b/connector/src/main/resources/mappings @@ -1 +1 @@ -Subproject commit 5ec6f1f339506129514de59d0e09e9b2c612e8be +Subproject commit 3d4147f001266d01eae6b8479428ca77bb5bf0c3 From f59e4672a0655460335ffabd2bef0dbd2faa0ac9 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sun, 8 Dec 2019 22:41:50 -0600 Subject: [PATCH 16/45] Exclude dependencies already present in servers (only affects plugin) --- api/pom.xml | 6 ------ bootstrap/bukkit/pom.xml | 20 +++++++++++++++++-- bootstrap/bungeecord/pom.xml | 32 ++++++++++++++++++++++-------- bootstrap/standalone/pom.xml | 7 +++---- connector/pom.xml | 27 ------------------------- pom.xml | 38 +++++++++--------------------------- 6 files changed, 54 insertions(+), 76 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index 2d4b1239d..f9a35f4cf 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -10,12 +10,6 @@ api - - org.projectlombok - lombok - 1.18.4 - provided - com.google.code.gson gson diff --git a/bootstrap/bukkit/pom.xml b/bootstrap/bukkit/pom.xml index 8e597635e..46e7a14e9 100644 --- a/bootstrap/bukkit/pom.xml +++ b/bootstrap/bukkit/pom.xml @@ -27,7 +27,6 @@ ${outputName}-Bukkit ../../target - clean install src/main/resources/ @@ -45,10 +44,27 @@ shade + + true + - true + + + *:* + + META-INF/* + + + + + + com.google.code.gson:* + org.yaml:* + io.netty:* + + diff --git a/bootstrap/bungeecord/pom.xml b/bootstrap/bungeecord/pom.xml index e30e87673..58525b64c 100644 --- a/bootstrap/bungeecord/pom.xml +++ b/bootstrap/bungeecord/pom.xml @@ -27,7 +27,6 @@ ${outputName}-BungeeCord ../../target - clean install src/main/resources/ @@ -45,16 +44,33 @@ shade + + + + net.md_5.bungee.jni + org.geysermc.platform.bungeecord.shaded.jni + + + true + - - - net.md_5.bungee.jni - org.geysermc.platform.bungeecord.shaded.jni - - - true + + + *:* + + META-INF/* + + + + + + com.google.code.gson:* + org.yaml:* + io.netty:* + + diff --git a/bootstrap/standalone/pom.xml b/bootstrap/standalone/pom.xml index 7f0aef557..05e63ad73 100644 --- a/bootstrap/standalone/pom.xml +++ b/bootstrap/standalone/pom.xml @@ -46,7 +46,6 @@ ${outputName} ../../target - clean install org.apache.maven.plugins @@ -70,11 +69,11 @@ shade + + true + - - true - diff --git a/connector/pom.xml b/connector/pom.xml index fe01a370f..238b71169 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -92,32 +92,5 @@ - - org.projectlombok - lombok - 1.18.4 - provided - - - ${project.artifactId}-${project.version}-noshade - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.1 - - - package - - shade - - - - - true - - - - diff --git a/pom.xml b/pom.xml index e534fbc0d..2f0908c50 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ geyser-parent parent pom - GeyserMC + Geyser Allows for players from Minecraft Bedrock Edition to join Minecraft Java Edition servers. https://geysermc.org @@ -83,32 +83,12 @@ - - clean install - - - src/main/resources/ - false - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.1 - - true - - - - + + + org.projectlombok + lombok + 1.18.4 + provided + + From 64b04330c333f31dd965f4ac9b56c813b844fe4c Mon Sep 17 00:00:00 2001 From: Tim203 Date: Tue, 17 Dec 2019 23:27:29 +0100 Subject: [PATCH 17/45] Added the player his IP to the transferable data --- .../geysermc/floodgate/util/BedrockData.java | 19 ++++++++++++++----- .../network/session/GeyserSession.java | 5 +++-- .../connector/world/chunk/BlockStorage.java | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java b/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java index f4efa9716..8beeb9987 100644 --- a/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java +++ b/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java @@ -6,30 +6,39 @@ import lombok.Getter; @AllArgsConstructor @Getter public class BedrockData { - public static final int EXPECTED_LENGTH = 6; + public static final int EXPECTED_LENGTH = 7; + public static final String FLOODGATE_IDENTIFIER = "Geyser-Floodgate"; + private String version; private String username; private String xuid; private int deviceId; private String languageCode; private int inputMode; + private String ip; private int dataLength; - public BedrockData(String version, String username, String xuid, int deviceId, String languageCode, int inputMode) { - this(version, username, xuid, deviceId, languageCode, inputMode, EXPECTED_LENGTH); + public BedrockData(String version, String username, String xuid, int deviceId, String languageCode, int inputMode, String ip) { + this(version, username, xuid, deviceId, languageCode, inputMode, ip, EXPECTED_LENGTH); } public static BedrockData fromString(String data) { String[] split = data.split("\0"); if (split.length != EXPECTED_LENGTH) return null; - return new BedrockData(split[0], split[1], split[2], Integer.parseInt(split[3]), split[4], Integer.parseInt(split[5]), split.length); + + return new BedrockData( + split[0], split[1], split[2], Integer.parseInt(split[3]), + split[4], Integer.parseInt(split[5]), split[6], split.length + ); } public static BedrockData fromRawData(byte[] data) { return fromString(new String(data)); } + @Override public String toString() { - return version +'\0'+ username +'\0'+ xuid +'\0'+ deviceId +'\0'+ languageCode +'\0'+ inputMode; + return version +'\0'+ username +'\0'+ xuid +'\0'+ deviceId +'\0'+ languageCode +'\0'+ + inputMode +'\0'+ ip; } } diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index 14654c6a4..8fc6e5e20 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -221,7 +221,8 @@ public class GeyserSession implements Player { authenticationData.getXboxUUID(), clientData.getDeviceOS().ordinal(), clientData.getLanguageCode(), - clientData.getCurrentInputMode().ordinal() + clientData.getCurrentInputMode().ordinal(), + upstream.getSession().getAddress().getAddress().getHostAddress() )); } catch (Exception e) { connector.getLogger().error("Failed to encrypt message", e); @@ -230,7 +231,7 @@ public class GeyserSession implements Player { HandshakePacket handshakePacket = event.getPacket(); event.setPacket(new HandshakePacket( handshakePacket.getProtocolVersion(), - handshakePacket.getHostname() + '\0' + "Geyser-Floodgate" + '\0' + encrypted, + handshakePacket.getHostname() + '\0' + BedrockData.FLOODGATE_IDENTIFIER + '\0' + encrypted, handshakePacket.getPort(), handshakePacket.getIntent() )); diff --git a/connector/src/main/java/org/geysermc/connector/world/chunk/BlockStorage.java b/connector/src/main/java/org/geysermc/connector/world/chunk/BlockStorage.java index dbb967d4e..089b2ec64 100644 --- a/connector/src/main/java/org/geysermc/connector/world/chunk/BlockStorage.java +++ b/connector/src/main/java/org/geysermc/connector/world/chunk/BlockStorage.java @@ -92,7 +92,7 @@ public class BlockStorage { } private int legacyIdFor(int index) { - int runtimeId = this.palette.get(index); + int runtimeId = this.palette.getInt(index); return GlobalBlockPalette.getLegacyId(runtimeId); } From 313228abde11279eb4959e02d826ef20f72472cd Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sat, 21 Dec 2019 10:07:48 -0600 Subject: [PATCH 18/45] Bump NukkitX protocol lib from merge --- connector/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/pom.xml b/connector/pom.xml index d5d9e85a7..217c7c431 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -39,7 +39,7 @@ com.nukkitx.protocol bedrock-v388 - 2.4.0 + 2.4.2 compile From e38322a3ec54cdd4c8ecd343848aa98c21b8d699 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sat, 21 Dec 2019 11:35:48 -0600 Subject: [PATCH 19/45] Nuke plugin API https://media.giphy.com/media/oe33xf3B50fsc/giphy.gif --- api/pom.xml | 20 --- .../main/java/org/geysermc/api/Connector.java | 76 --------- .../java/org/geysermc/api/ConsoleColors.java | 69 -------- .../main/java/org/geysermc/api/Geyser.java | 103 ------------ .../main/java/org/geysermc/api/Player.java | 80 ---------- .../org/geysermc/api/command/Command.java | 67 -------- .../org/geysermc/api/command/CommandMap.java | 53 ------- .../geysermc/api/command/CommandSender.java | 50 ------ .../api/command/ConsoleCommandSender.java | 30 ---- .../org/geysermc/api/events/EventHandler.java | 56 ------- .../org/geysermc/api/events/Listener.java | 33 ---- .../org/geysermc/api/events/PingEvent.java | 53 ------- .../api/events/player/PlayerEvent.java | 39 ----- .../player/PlayerFormResponseEvent.java | 76 --------- .../java/org/geysermc/api/plugin/Plugin.java | 84 ---------- .../geysermc/api/plugin/PluginManager.java | 87 ----------- .../org/geysermc/api/session/AuthData.java | 37 ----- .../platform/bukkit/GeyserBukkitLogger.java | 4 +- .../platform/bukkit/GeyserBukkitPlugin.java | 2 +- .../bungeecord/GeyserBungeeLogger.java | 4 +- .../bungeecord/GeyserBungeePlugin.java | 2 +- .../platform/standalone/GeyserBootstrap.java | 2 +- .../console/ConsoleCommandReader.java | 4 +- .../standalone/console/GeyserLogger.java | 6 +- common/pom.xml | 6 +- .../java/org/geysermc/common}/ChatColor.java | 4 +- .../common/bootstrap/IGeyserBootstrap.java | 4 +- .../geysermc/common/logger/IGeyserLogger.java | 4 +- .../common}/window/CustomFormBuilder.java | 9 +- .../common}/window/CustomFormWindow.java | 16 +- .../geysermc/common}/window/FormWindow.java | 4 +- .../common}/window/ModalFormWindow.java | 4 +- .../common}/window/SimpleFormWindow.java | 6 +- .../common}/window/button/FormButton.java | 2 +- .../common}/window/button/FormImage.java | 2 +- .../window/component/DropdownComponent.java | 2 +- .../window/component/FormComponent.java | 2 +- .../window/component/InputComponent.java | 2 +- .../window/component/LabelComponent.java | 2 +- .../window/component/SliderComponent.java | 4 +- .../window/component/StepSliderComponent.java | 2 +- .../window/component/ToggleComponent.java | 2 +- .../window/response/CustomFormResponse.java | 4 +- .../common}/window/response/FormResponse.java | 2 +- .../window/response/FormResponseData.java | 2 +- .../window/response/ModalFormResponse.java | 3 +- .../window/response/SimpleFormResponse.java | 5 +- .../geysermc/connector/GeyserConnector.java | 68 +++----- .../connector/command/CommandSender.java | 14 ++ .../connector/command/GeyserCommand.java | 47 ++---- .../connector/command/GeyserCommandMap.java | 38 ++--- .../command/GeyserConsoleCommandSender.java | 14 +- .../command/defaults/HelpCommand.java | 17 +- .../command/defaults/StopCommand.java | 6 +- .../connector/console/GeyserLogger.java | 147 ------------------ .../org/geysermc/connector/entity/Entity.java | 6 +- .../connector/entity/PaintingEntity.java | 5 +- .../connector/entity/PlayerEntity.java | 6 +- .../geysermc/connector/metrics/Metrics.java | 11 +- .../network/ConnectorServerEventHandler.java | 60 +++---- .../network/UpstreamPacketHandler.java | 6 +- .../network/remote/RemoteJavaServer.java | 38 ----- .../network/remote}/RemoteServer.java | 24 ++- .../network/session/GeyserSession.java | 32 ++-- .../{BedrockAuthData.java => AuthData.java} | 3 +- .../network/session/cache/WindowCache.java | 10 +- .../network/translators/Registry.java | 4 +- .../BedrockCommandRequestTranslator.java | 7 +- .../bedrock/BedrockMovePlayerTranslator.java | 3 +- .../translators/item/ItemTranslator.java | 5 +- .../translators/java/JavaChatTranslator.java | 3 +- .../JavaPlayerPositionRotationTranslator.java | 4 +- .../entity/spawn/JavaSpawnMobTranslator.java | 4 +- .../spawn/JavaSpawnObjectTranslator.java | 4 +- .../spawn/JavaSpawnPaintingTranslator.java | 5 +- .../spawn/JavaSpawnPlayerTranslator.java | 5 +- .../java/scoreboard/JavaTeamTranslator.java | 5 +- .../scoreboard/JavaUpdateScoreTranslator.java | 5 +- .../java/world/JavaChunkDataTranslator.java | 7 +- .../connector/plugin/GeyserPluginLoader.java | 126 --------------- .../connector/plugin/GeyserPluginManager.java | 107 ------------- .../connector/plugin/PluginListener.java | 28 ---- .../geysermc/connector/plugin/PluginYML.java | 40 ----- .../connector/scoreboard/Scoreboard.java | 6 +- .../connector/utils/InventoryUtils.java | 4 +- .../connector/utils/LoginEncryptionUtils.java | 26 ++-- .../connector/utils/SkinProvider.java | 17 +- .../geysermc/connector/utils/SkinUtils.java | 11 +- .../org/geysermc/connector/utils/Toolbox.java | 6 +- pom.xml | 1 - 90 files changed, 273 insertions(+), 1842 deletions(-) delete mode 100644 api/pom.xml delete mode 100644 api/src/main/java/org/geysermc/api/Connector.java delete mode 100644 api/src/main/java/org/geysermc/api/ConsoleColors.java delete mode 100644 api/src/main/java/org/geysermc/api/Geyser.java delete mode 100644 api/src/main/java/org/geysermc/api/Player.java delete mode 100644 api/src/main/java/org/geysermc/api/command/Command.java delete mode 100644 api/src/main/java/org/geysermc/api/command/CommandMap.java delete mode 100644 api/src/main/java/org/geysermc/api/command/CommandSender.java delete mode 100644 api/src/main/java/org/geysermc/api/command/ConsoleCommandSender.java delete mode 100644 api/src/main/java/org/geysermc/api/events/EventHandler.java delete mode 100644 api/src/main/java/org/geysermc/api/events/Listener.java delete mode 100644 api/src/main/java/org/geysermc/api/events/PingEvent.java delete mode 100644 api/src/main/java/org/geysermc/api/events/player/PlayerEvent.java delete mode 100644 api/src/main/java/org/geysermc/api/events/player/PlayerFormResponseEvent.java delete mode 100644 api/src/main/java/org/geysermc/api/plugin/Plugin.java delete mode 100644 api/src/main/java/org/geysermc/api/plugin/PluginManager.java delete mode 100644 api/src/main/java/org/geysermc/api/session/AuthData.java rename {api/src/main/java/org/geysermc/api => common/src/main/java/org/geysermc/common}/ChatColor.java (99%) rename api/src/main/java/org/geysermc/api/logger/Logger.java => common/src/main/java/org/geysermc/common/logger/IGeyserLogger.java (97%) rename {api/src/main/java/org/geysermc/api => common/src/main/java/org/geysermc/common}/window/CustomFormBuilder.java (88%) rename {api/src/main/java/org/geysermc/api => common/src/main/java/org/geysermc/common}/window/CustomFormWindow.java (90%) rename {api/src/main/java/org/geysermc/api => common/src/main/java/org/geysermc/common}/window/FormWindow.java (94%) rename {api/src/main/java/org/geysermc/api => common/src/main/java/org/geysermc/common}/window/ModalFormWindow.java (95%) rename {api/src/main/java/org/geysermc/api => common/src/main/java/org/geysermc/common}/window/SimpleFormWindow.java (94%) rename {api/src/main/java/org/geysermc/api => common/src/main/java/org/geysermc/common}/window/button/FormButton.java (97%) rename {api/src/main/java/org/geysermc/api => common/src/main/java/org/geysermc/common}/window/button/FormImage.java (97%) rename {api/src/main/java/org/geysermc/api => common/src/main/java/org/geysermc/common}/window/component/DropdownComponent.java (97%) rename {api/src/main/java/org/geysermc/api => common/src/main/java/org/geysermc/common}/window/component/FormComponent.java (96%) rename {api/src/main/java/org/geysermc/api => common/src/main/java/org/geysermc/common}/window/component/InputComponent.java (97%) rename {api/src/main/java/org/geysermc/api => common/src/main/java/org/geysermc/common}/window/component/LabelComponent.java (96%) rename {api/src/main/java/org/geysermc/api => common/src/main/java/org/geysermc/common}/window/component/SliderComponent.java (95%) rename {api/src/main/java/org/geysermc/api => common/src/main/java/org/geysermc/common}/window/component/StepSliderComponent.java (97%) rename {api/src/main/java/org/geysermc/api => common/src/main/java/org/geysermc/common}/window/component/ToggleComponent.java (97%) rename {api/src/main/java/org/geysermc/api => common/src/main/java/org/geysermc/common}/window/response/CustomFormResponse.java (91%) rename {api/src/main/java/org/geysermc/api => common/src/main/java/org/geysermc/common}/window/response/FormResponse.java (96%) rename {api/src/main/java/org/geysermc/api => common/src/main/java/org/geysermc/common}/window/response/FormResponseData.java (96%) rename {api/src/main/java/org/geysermc/api => common/src/main/java/org/geysermc/common}/window/response/ModalFormResponse.java (93%) rename {api/src/main/java/org/geysermc/api => common/src/main/java/org/geysermc/common}/window/response/SimpleFormResponse.java (90%) create mode 100644 connector/src/main/java/org/geysermc/connector/command/CommandSender.java delete mode 100644 connector/src/main/java/org/geysermc/connector/console/GeyserLogger.java delete mode 100644 connector/src/main/java/org/geysermc/connector/network/remote/RemoteJavaServer.java rename {api/src/main/java/org/geysermc/api => connector/src/main/java/org/geysermc/connector/network/remote}/RemoteServer.java (77%) rename connector/src/main/java/org/geysermc/connector/network/session/auth/{BedrockAuthData.java => AuthData.java} (72%) delete mode 100644 connector/src/main/java/org/geysermc/connector/plugin/GeyserPluginLoader.java delete mode 100644 connector/src/main/java/org/geysermc/connector/plugin/GeyserPluginManager.java delete mode 100644 connector/src/main/java/org/geysermc/connector/plugin/PluginListener.java delete mode 100644 connector/src/main/java/org/geysermc/connector/plugin/PluginYML.java diff --git a/api/pom.xml b/api/pom.xml deleted file mode 100644 index f9a35f4cf..000000000 --- a/api/pom.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - 4.0.0 - - org.geysermc - geyser-parent - parent - - api - - - com.google.code.gson - gson - 2.8.2 - compile - - - \ No newline at end of file diff --git a/api/src/main/java/org/geysermc/api/Connector.java b/api/src/main/java/org/geysermc/api/Connector.java deleted file mode 100644 index 708372e33..000000000 --- a/api/src/main/java/org/geysermc/api/Connector.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2019 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.api; - -import org.geysermc.api.command.CommandMap; -import org.geysermc.api.logger.Logger; -import org.geysermc.api.plugin.PluginManager; - -import java.util.Collection; -import java.util.concurrent.ScheduledExecutorService; - -public interface Connector { - - /** - * Returns the logger - * - * @return the logger - */ - Logger getLogger(); - - /** - * Returns the command map - * - * @return the command map - */ - CommandMap getCommandMap(); - - /** - * Returns the plugin manager - * - * @return the plugin manager - */ - PluginManager getPluginManager(); - - /** - * Returns the general thread pool - * - * @return the general thread pool - */ - ScheduledExecutorService getGeneralThreadPool(); - - /** - * Returns a collection of the connected players - * - * @return a collection of the connected players - */ - Collection getConnectedPlayers(); - - /** - * Shuts down the connector - */ - void shutdown(); -} diff --git a/api/src/main/java/org/geysermc/api/ConsoleColors.java b/api/src/main/java/org/geysermc/api/ConsoleColors.java deleted file mode 100644 index a59512275..000000000 --- a/api/src/main/java/org/geysermc/api/ConsoleColors.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2019 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.api; - -public class ConsoleColors { - public static final String RESET = "\u001b[0m"; - - public static final String BOLD = "\u001b[1m"; - public static final String BLINK = "\u001b[5m"; - - public static final String WHITE = "\u001b[30m"; - public static final String RED = "\u001b[31m"; - public static final String GREEN = "\u001b[32m"; - public static final String YELLOW = "\u001b[33m"; - public static final String BLUE = "\u001b[34m"; - public static final String MAGENTA = "\u001b[35m"; - public static final String CYAN = "\u001b[36m"; - public static final String LIGHT_GRAY = "\u001b[37m"; - - public static final String DARK_GRAY = "\u001b[90m"; - public static final String BRIGHT_RED = "\u001b[91m"; - public static final String BRIGHT_GREEN = "\u001b[92m"; - public static final String BRIGHT_YELLOW = "\u001b[93m"; - public static final String BRIGHT_BLUE = "\u001b[94m"; - public static final String BRIGHT_MAGENTA = "\u001b[95m"; - public static final String BRIGHT_CYAN = "\u001b[96m"; - public static final String BLACK = "\u001b[97m"; - - public static final String BLACK_BACKGROUND = "\u001b[30m"; - public static final String RED_BACKGROUND = "\u001b[31m"; - public static final String GREEN_BACKGROUND = "\u001b[32m"; - public static final String YELLOW_BACKGROUND = "\u001b[33m"; - public static final String BLUE_BACKGROUND = "\u001b[34m"; - public static final String MAGENTA_BACKGROUND = "\u001b[35m"; - public static final String CYAN_BACKGROUND = "\u001b[36m"; - public static final String WHITE_BACKGROUND = "\u001b[37m"; - - /*public static final String BLACK_BACKGROUND = "\u001b[30m"; - public static final String RED_BACKGROUND = "\u001b[31m"; - public static final String GREEN_BACKGROUND = "\u001b[32m"; - public static final String YELLOW_BACKGROUND = "\u001b[33m"; - public static final String BLUE_BACKGROUND = "\u001b[34m"; - public static final String MAGENTA_BACKGROUND = "\u001b[35m"; - public static final String CYAN_BACKGROUND = "\u001b[36m"; - public static final String WHITE_BACKGROUND = "\u001b[37m";*/ -} diff --git a/api/src/main/java/org/geysermc/api/Geyser.java b/api/src/main/java/org/geysermc/api/Geyser.java deleted file mode 100644 index 2fc9c190e..000000000 --- a/api/src/main/java/org/geysermc/api/Geyser.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2019 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.api; - -import org.geysermc.api.command.CommandMap; -import org.geysermc.api.logger.Logger; -import org.geysermc.api.plugin.PluginManager; - -import java.util.Collection; -import java.util.concurrent.ScheduledExecutorService; - -public class Geyser { - - private static Connector connector; - - /** - * Returns the connector instance for Geyser - * - * @return the connector instance for Geyser - */ - public static Connector getConnector() { - return connector; - } - - /** - * Sets the connector instance for Geyser - * - * @param connector the connector instance - */ - public static void setConnector(Connector connector) { - Geyser.connector = connector; - } - - /** - * Returns the logger - * - * @return the logger - */ - public static Logger getLogger() { - return connector.getLogger(); - } - - /** - * Returns the plugin manager - * - * @return the plugin manager - */ - public static PluginManager getPluginManager() { - return connector.getPluginManager(); - } - - /** - * Returns the command map - * - * @return the command map - */ - public static CommandMap getCommandMap() { - return connector.getCommandMap(); - } - - public static ScheduledExecutorService getGeneralThreadPool() { - return connector.getGeneralThreadPool(); - } - - /** - * @return the amount of online players - */ - public static int getPlayerCount() { - return connector.getConnectedPlayers().size(); - } - - /** - * Returns a collection of the connected players - * - * @return a collection of the connected players - */ - public static Collection getConnectedPlayers() { - return connector.getConnectedPlayers(); - } -} diff --git a/api/src/main/java/org/geysermc/api/Player.java b/api/src/main/java/org/geysermc/api/Player.java deleted file mode 100644 index f8107cb1d..000000000 --- a/api/src/main/java/org/geysermc/api/Player.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2019 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.api; - -import org.geysermc.api.command.CommandSender; -import org.geysermc.api.session.AuthData; -import org.geysermc.api.window.FormWindow; - -import java.net.InetSocketAddress; - -public interface Player extends CommandSender { - - /** - * Connects the player to the remote server - * - * @param remoteServer the remote server to connect to - */ - void connect(RemoteServer remoteServer); - - /** - * Disconnect the player for the specified reason - * - * @param reason the reason to disconnect the player for - */ - void disconnect(String reason); - - /** - * Returns the authentication data of the player. This is not the - * player's Minecraft credentials; it's simply what is given to the server - * (Name, UUID, Xbox UUID) to verify the player can/actually exists. - * - * @return the authentication data of the player - */ - AuthData getAuthenticationData(); - - /** - * Sends a form window - * - * @param window the window form to send - */ - void sendForm(FormWindow window); - - /** - * Sends a form window with the given ID - * - * @param window the window to send - * @param id the id of the window - */ - void sendForm(FormWindow window, int id); - - /** - * Returns the current hostname and port the player is connected with. - * - * @return player's socket address. - */ - InetSocketAddress getSocketAddress(); -} diff --git a/api/src/main/java/org/geysermc/api/command/Command.java b/api/src/main/java/org/geysermc/api/command/Command.java deleted file mode 100644 index ed9daf649..000000000 --- a/api/src/main/java/org/geysermc/api/command/Command.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2019 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.api.command; - -import java.util.List; - -public interface Command { - - /** - * Returns the name of this command - * - * @return the name of this command - */ - String getName(); - - /** - * Returns the description of this command - * - * @return the description of this command - */ - String getDescription(); - - /** - * Returns the aliases of this command - * - * @return the aliases of this command - */ - List getAliases(); - - /** - * Sets the aliases of this command - * - * @param aliases the a liases of the command - */ - void setAliases(List aliases); - - /** - * Executes the command - * - * @param sender the sender of the command - * @param args the arguments of the command - */ - void execute(CommandSender sender, String[] args); -} diff --git a/api/src/main/java/org/geysermc/api/command/CommandMap.java b/api/src/main/java/org/geysermc/api/command/CommandMap.java deleted file mode 100644 index d9dd098c6..000000000 --- a/api/src/main/java/org/geysermc/api/command/CommandMap.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2019 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.api.command; - -import java.util.Map; - -public interface CommandMap { - - /** - * Registers a new command - * - * @param command the command to register - */ - void registerCommand(Command command); - - /** - * Runs a command for the given command sender - * - * @param sender the sender to run the command for - * @param command the command to run - */ - void runCommand(CommandSender sender, String command); - - /** - * Returns a map of the commands - * - * @return a map of the commands - */ - Map getCommands(); -} diff --git a/api/src/main/java/org/geysermc/api/command/CommandSender.java b/api/src/main/java/org/geysermc/api/command/CommandSender.java deleted file mode 100644 index 77f397f7f..000000000 --- a/api/src/main/java/org/geysermc/api/command/CommandSender.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2019 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.api.command; - -public interface CommandSender { - - /** - * Returns the name of the sender - * - * @return the name of the sender - */ - String getName(); - - /** - * Sends a message to the command sender - * - * @param message the message to be sent - */ - void sendMessage(String message); - - /** - * Sends multiple messages to the command sender - * - * @param messages the messages to be sent - */ - void sendMessage(String[] messages); -} diff --git a/api/src/main/java/org/geysermc/api/command/ConsoleCommandSender.java b/api/src/main/java/org/geysermc/api/command/ConsoleCommandSender.java deleted file mode 100644 index b04f0999e..000000000 --- a/api/src/main/java/org/geysermc/api/command/ConsoleCommandSender.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2019 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.api.command; - -public interface ConsoleCommandSender extends CommandSender { - -} diff --git a/api/src/main/java/org/geysermc/api/events/EventHandler.java b/api/src/main/java/org/geysermc/api/events/EventHandler.java deleted file mode 100644 index d25c14ff1..000000000 --- a/api/src/main/java/org/geysermc/api/events/EventHandler.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2019 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.api.events; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * The annotation to put on all methods that are events. - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -public @interface EventHandler { - - /** - * @return the order to execute events. - * @see EventPriority - */ - EventPriority value() default EventPriority.NORMAL; - - /** - * When an eventHandler should be run. - * The names mostly explain. - */ - enum EventPriority { - FIRST, - NORMAL, - LAST, - READ_ONLY; - } -} diff --git a/api/src/main/java/org/geysermc/api/events/Listener.java b/api/src/main/java/org/geysermc/api/events/Listener.java deleted file mode 100644 index 3288c6821..000000000 --- a/api/src/main/java/org/geysermc/api/events/Listener.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2019 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.api.events; - -/** - * A marker class which says that a specific class uses events. - * @see EventHandler - */ -public interface Listener { -} diff --git a/api/src/main/java/org/geysermc/api/events/PingEvent.java b/api/src/main/java/org/geysermc/api/events/PingEvent.java deleted file mode 100644 index 541657d81..000000000 --- a/api/src/main/java/org/geysermc/api/events/PingEvent.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2019 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.api.events; - -import lombok.Getter; -import lombok.Setter; - -import java.net.InetSocketAddress; - -@Getter -@Setter -public class PingEvent { - - public PingEvent(InetSocketAddress address) { - this.address = address; - } - - private InetSocketAddress address; - - private String edition; - private String motd; - private int protocolVersion; - private String version; - private int playerCount; - private int maximumPlayerCount; - private long serverId; - private String subMotd; - private String gameType; - private boolean nintendoLimited; -} diff --git a/api/src/main/java/org/geysermc/api/events/player/PlayerEvent.java b/api/src/main/java/org/geysermc/api/events/player/PlayerEvent.java deleted file mode 100644 index ab4e98a61..000000000 --- a/api/src/main/java/org/geysermc/api/events/player/PlayerEvent.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2019 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.api.events.player; - -import lombok.Getter; -import org.geysermc.api.Player; - -public class PlayerEvent { - - @Getter - private Player player; - - public PlayerEvent(Player player) { - this.player = player; - } -} diff --git a/api/src/main/java/org/geysermc/api/events/player/PlayerFormResponseEvent.java b/api/src/main/java/org/geysermc/api/events/player/PlayerFormResponseEvent.java deleted file mode 100644 index b68170b2a..000000000 --- a/api/src/main/java/org/geysermc/api/events/player/PlayerFormResponseEvent.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2019 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.api.events.player; - -import lombok.Getter; -import org.geysermc.api.Player; -import org.geysermc.api.window.FormWindow; -import org.geysermc.api.window.response.FormResponse; - -/** - * Called when a player interacts with a form - */ -public class PlayerFormResponseEvent extends PlayerEvent { - - @Getter - private int formID; - - @Getter - private FormWindow window; - - /** - * Constructs a new PlayerFormResponseEvent instance - * - * @param player the player interacting with the form - * @param formID the id of the form - * @param window the window - */ - public PlayerFormResponseEvent(Player player, int formID, FormWindow window) { - super(player); - - this.formID = formID; - this.window = window; - } - - /** - * Returns the response of the window, can be null - * if the player closed the window - * - * @return the response of the window - */ - public FormResponse getResponse() { - return window.getResponse(); - } - - /** - * Returns if the window is closed - * - * @return if the window is closed - */ - public boolean isClosed() { - return window.isClosed(); - } -} diff --git a/api/src/main/java/org/geysermc/api/plugin/Plugin.java b/api/src/main/java/org/geysermc/api/plugin/Plugin.java deleted file mode 100644 index 8209cade0..000000000 --- a/api/src/main/java/org/geysermc/api/plugin/Plugin.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2019 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.api.plugin; - -import lombok.Getter; -import lombok.Setter; - -/** - * The class that any main plugin class should extend. - * The first init point is the constructor, followed by onLoad, and finally onEnable. - */ -public class Plugin { - protected String name; - protected String version; - - /** - * Returns if the plugin is enabled - * - * @return if the plugin is enabled - */ - @Getter - @Setter - private boolean enabled = true; - - /** - * Called when a plugin is enabled - */ - public void onEnable() { - - } - - /** - * Called when a plugin is disabled - */ - public void onDisable() { - - } - - /** - * Called when a plugin is loaded - */ - public void onLoad() { - - } - - /** - * Called when the server is reloaded - */ - public void onReload() { - - } - - public final String getName() { - return name; - } - - @Override - public final String toString() { - return getName(); - } -} diff --git a/api/src/main/java/org/geysermc/api/plugin/PluginManager.java b/api/src/main/java/org/geysermc/api/plugin/PluginManager.java deleted file mode 100644 index 2cc183046..000000000 --- a/api/src/main/java/org/geysermc/api/plugin/PluginManager.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2019 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.api.plugin; - -import org.geysermc.api.events.Listener; - -import java.util.Set; - -public interface PluginManager { - - /** - * Loads a plugin and all its class files - * - * @param plugin the plugin to load - */ - void loadPlugin(Plugin plugin); - - /** - * Enables a plugin - * - * @param plugin the plugin to enable - */ - void enablePlugin(Plugin plugin); - - /** - * Disables a plugin - * - * @param plugin the plugin to disable - */ - void disablePlugin(Plugin plugin); - - /** - * Unloads a plugin - * - * @param plugin the plugin to unload - */ - void unloadPlugin(Plugin plugin); - - /** - * Returns a set of the loaded plugins - * - * @return a set of the loaded plugins - */ - Set getPlugins(); - - /** - * @param name The name of the plugin you want to get. - * @return The plugin with the String name in the parameters. - */ - Plugin getPluginByName(String name); - - /** - * Registers a listener to be run when an event is executed - * @param plugin the plugin registering the listener - * @param listener the listener which will contain the event methods - */ - void registerEventListener(Plugin plugin, Listener listener); - - /** - * Run an event - * @param o the event object. - */ - void runEvent(Object o); -} diff --git a/api/src/main/java/org/geysermc/api/session/AuthData.java b/api/src/main/java/org/geysermc/api/session/AuthData.java deleted file mode 100644 index a095886e5..000000000 --- a/api/src/main/java/org/geysermc/api/session/AuthData.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2019 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.api.session; - -import java.util.UUID; - -public interface AuthData { - - String getName(); - - UUID getUUID(); - - String getXboxUUID(); -} diff --git a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitLogger.java b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitLogger.java index 12fadc6cc..95214972f 100644 --- a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitLogger.java +++ b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitLogger.java @@ -25,10 +25,12 @@ package org.geysermc.platform.bukkit; +import org.geysermc.common.logger.IGeyserLogger; + import java.util.logging.Level; import java.util.logging.Logger; -public class GeyserBukkitLogger implements org.geysermc.api.logger.Logger { +public class GeyserBukkitLogger implements IGeyserLogger { private Logger logger; private boolean debugMode; diff --git a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitPlugin.java b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitPlugin.java index 86dfadbb6..d3b87e8c3 100644 --- a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitPlugin.java +++ b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitPlugin.java @@ -49,7 +49,7 @@ public class GeyserBukkitPlugin extends JavaPlugin implements IGeyserBootstrap { geyserLogger = new GeyserBukkitLogger(getLogger(), geyserConfig.isDebugMode()); - GeyserConnector.start(this, false); + GeyserConnector.start(this); } @Override diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeLogger.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeLogger.java index 671f055de..2ebc069b1 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeLogger.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeLogger.java @@ -25,10 +25,12 @@ package org.geysermc.platform.bungeecord; +import org.geysermc.common.logger.IGeyserLogger; + import java.util.logging.Level; import java.util.logging.Logger; -public class GeyserBungeeLogger implements org.geysermc.api.logger.Logger { +public class GeyserBungeeLogger implements IGeyserLogger { private Logger logger; private boolean debugMode; diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java index fd0248fd7..4cbf88326 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java @@ -86,7 +86,7 @@ public class GeyserBungeePlugin extends Plugin implements IGeyserBootstrap { geyserLogger = new GeyserBungeeLogger(getLogger(), geyserConfig.isDebugMode()); - GeyserConnector.start(this, false); + GeyserConnector.start(this); } @Override diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java index 8424fd634..45d71bd6f 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java @@ -62,7 +62,7 @@ public class GeyserBootstrap implements IGeyserBootstrap { System.exit(0); } - GeyserConnector connector = GeyserConnector.start(this, false); + GeyserConnector connector = GeyserConnector.start(this); ConsoleCommandReader consoleReader = new ConsoleCommandReader(connector); consoleReader.startConsole(); diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/ConsoleCommandReader.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/ConsoleCommandReader.java index 8396228c5..978c413c3 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/ConsoleCommandReader.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/ConsoleCommandReader.java @@ -26,7 +26,7 @@ package org.geysermc.platform.standalone.console; import net.minecrell.terminalconsole.TerminalConsoleAppender; -import org.geysermc.api.command.ConsoleCommandSender; + import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.command.GeyserConsoleCommandSender; import org.jline.reader.EndOfFileException; @@ -82,7 +82,7 @@ public class ConsoleCommandReader { try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) { String line; while ((line = reader.readLine()) != null) { - ConsoleCommandSender sender = new GeyserConsoleCommandSender(); + GeyserConsoleCommandSender sender = new GeyserConsoleCommandSender(); connector.getCommandMap().runCommand(sender, line); } } catch (IOException ex) { diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java index 0e7af4298..886b0d137 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java @@ -26,14 +26,16 @@ package org.geysermc.platform.standalone.console; import io.sentry.Sentry; -import org.geysermc.api.ChatColor; + +import org.geysermc.common.ChatColor; +import org.geysermc.common.logger.IGeyserLogger; import java.io.File; import java.io.IOException; import java.util.Date; import java.util.logging.*; -public class GeyserLogger implements org.geysermc.api.logger.Logger { +public class GeyserLogger implements IGeyserLogger { private boolean colored = true; private boolean debug = false; diff --git a/common/pom.xml b/common/pom.xml index a7f0f2588..1f6c20b7e 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -13,9 +13,9 @@ 1.0-SNAPSHOT - org.geysermc - api - 1.0-SNAPSHOT + com.google.code.gson + gson + 2.8.2 compile diff --git a/api/src/main/java/org/geysermc/api/ChatColor.java b/common/src/main/java/org/geysermc/common/ChatColor.java similarity index 99% rename from api/src/main/java/org/geysermc/api/ChatColor.java rename to common/src/main/java/org/geysermc/common/ChatColor.java index abf82167e..20632770c 100644 --- a/api/src/main/java/org/geysermc/api/ChatColor.java +++ b/common/src/main/java/org/geysermc/common/ChatColor.java @@ -23,7 +23,7 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.api; +package org.geysermc.common; public class ChatColor { @@ -84,4 +84,4 @@ public class ChatColor { public static String stripColors(String message) { return message = message.replaceAll("(&([a-fk-or0-9]))","").replaceAll("(§([a-fk-or0-9]))","").replaceAll("s/\\x1b\\[[0-9;]*[a-zA-Z]//g",""); } -} +} \ No newline at end of file diff --git a/common/src/main/java/org/geysermc/common/bootstrap/IGeyserBootstrap.java b/common/src/main/java/org/geysermc/common/bootstrap/IGeyserBootstrap.java index f41d0a1da..cf4b3991e 100644 --- a/common/src/main/java/org/geysermc/common/bootstrap/IGeyserBootstrap.java +++ b/common/src/main/java/org/geysermc/common/bootstrap/IGeyserBootstrap.java @@ -25,8 +25,8 @@ package org.geysermc.common.bootstrap; -import org.geysermc.api.logger.Logger; import org.geysermc.common.IGeyserConfiguration; +import org.geysermc.common.logger.IGeyserLogger; public interface IGeyserBootstrap { @@ -36,5 +36,5 @@ public interface IGeyserBootstrap { IGeyserConfiguration getGeyserConfig(); - Logger getGeyserLogger(); + IGeyserLogger getGeyserLogger(); } diff --git a/api/src/main/java/org/geysermc/api/logger/Logger.java b/common/src/main/java/org/geysermc/common/logger/IGeyserLogger.java similarity index 97% rename from api/src/main/java/org/geysermc/api/logger/Logger.java rename to common/src/main/java/org/geysermc/common/logger/IGeyserLogger.java index d6227c817..b4d143e43 100644 --- a/api/src/main/java/org/geysermc/api/logger/Logger.java +++ b/common/src/main/java/org/geysermc/common/logger/IGeyserLogger.java @@ -23,9 +23,9 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.api.logger; +package org.geysermc.common.logger; -public interface Logger { +public interface IGeyserLogger { /** * Logs a severe message to console diff --git a/api/src/main/java/org/geysermc/api/window/CustomFormBuilder.java b/common/src/main/java/org/geysermc/common/window/CustomFormBuilder.java similarity index 88% rename from api/src/main/java/org/geysermc/api/window/CustomFormBuilder.java rename to common/src/main/java/org/geysermc/common/window/CustomFormBuilder.java index 094ed5f44..fb6794120 100644 --- a/api/src/main/java/org/geysermc/api/window/CustomFormBuilder.java +++ b/common/src/main/java/org/geysermc/common/window/CustomFormBuilder.java @@ -23,12 +23,13 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.api.window; +package org.geysermc.common.window; import lombok.Getter; -import org.geysermc.api.window.button.FormImage; -import org.geysermc.api.window.component.FormComponent; -import org.geysermc.api.window.response.CustomFormResponse; +import org.geysermc.common.window.CustomFormWindow; +import org.geysermc.common.window.button.FormImage; +import org.geysermc.common.window.component.FormComponent; +import org.geysermc.common.window.response.CustomFormResponse; public class CustomFormBuilder { diff --git a/api/src/main/java/org/geysermc/api/window/CustomFormWindow.java b/common/src/main/java/org/geysermc/common/window/CustomFormWindow.java similarity index 90% rename from api/src/main/java/org/geysermc/api/window/CustomFormWindow.java rename to common/src/main/java/org/geysermc/common/window/CustomFormWindow.java index 66efd850e..a6bc72781 100644 --- a/api/src/main/java/org/geysermc/api/window/CustomFormWindow.java +++ b/common/src/main/java/org/geysermc/common/window/CustomFormWindow.java @@ -23,22 +23,16 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.api.window; +package org.geysermc.common.window; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import lombok.Getter; import lombok.Setter; -import org.geysermc.api.window.button.FormImage; -import org.geysermc.api.window.component.DropdownComponent; -import org.geysermc.api.window.component.FormComponent; -import org.geysermc.api.window.component.InputComponent; -import org.geysermc.api.window.component.LabelComponent; -import org.geysermc.api.window.component.SliderComponent; -import org.geysermc.api.window.component.StepSliderComponent; -import org.geysermc.api.window.component.ToggleComponent; -import org.geysermc.api.window.response.CustomFormResponse; -import org.geysermc.api.window.response.FormResponseData; +import org.geysermc.common.window.button.FormImage; +import org.geysermc.common.window.component.*; +import org.geysermc.common.window.response.CustomFormResponse; +import org.geysermc.common.window.response.FormResponseData; import java.util.ArrayList; import java.util.HashMap; diff --git a/api/src/main/java/org/geysermc/api/window/FormWindow.java b/common/src/main/java/org/geysermc/common/window/FormWindow.java similarity index 94% rename from api/src/main/java/org/geysermc/api/window/FormWindow.java rename to common/src/main/java/org/geysermc/common/window/FormWindow.java index d193950ca..968d9349d 100644 --- a/api/src/main/java/org/geysermc/api/window/FormWindow.java +++ b/common/src/main/java/org/geysermc/common/window/FormWindow.java @@ -23,11 +23,11 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.api.window; +package org.geysermc.common.window; import lombok.Getter; import lombok.Setter; -import org.geysermc.api.window.response.FormResponse; +import org.geysermc.common.window.response.FormResponse; public abstract class FormWindow { diff --git a/api/src/main/java/org/geysermc/api/window/ModalFormWindow.java b/common/src/main/java/org/geysermc/common/window/ModalFormWindow.java similarity index 95% rename from api/src/main/java/org/geysermc/api/window/ModalFormWindow.java rename to common/src/main/java/org/geysermc/common/window/ModalFormWindow.java index 6a419775c..934660395 100644 --- a/api/src/main/java/org/geysermc/api/window/ModalFormWindow.java +++ b/common/src/main/java/org/geysermc/common/window/ModalFormWindow.java @@ -23,12 +23,12 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.api.window; +package org.geysermc.common.window; import com.google.gson.Gson; import lombok.Getter; import lombok.Setter; -import org.geysermc.api.window.response.ModalFormResponse; +import org.geysermc.common.window.response.ModalFormResponse; public class ModalFormWindow extends FormWindow { diff --git a/api/src/main/java/org/geysermc/api/window/SimpleFormWindow.java b/common/src/main/java/org/geysermc/common/window/SimpleFormWindow.java similarity index 94% rename from api/src/main/java/org/geysermc/api/window/SimpleFormWindow.java rename to common/src/main/java/org/geysermc/common/window/SimpleFormWindow.java index 4a46aaf43..cc31f061a 100644 --- a/api/src/main/java/org/geysermc/api/window/SimpleFormWindow.java +++ b/common/src/main/java/org/geysermc/common/window/SimpleFormWindow.java @@ -23,13 +23,13 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.api.window; +package org.geysermc.common.window; import com.google.gson.Gson; import lombok.Getter; import lombok.Setter; -import org.geysermc.api.window.button.FormButton; -import org.geysermc.api.window.response.SimpleFormResponse; +import org.geysermc.common.window.button.FormButton; +import org.geysermc.common.window.response.SimpleFormResponse; import java.util.ArrayList; import java.util.List; diff --git a/api/src/main/java/org/geysermc/api/window/button/FormButton.java b/common/src/main/java/org/geysermc/common/window/button/FormButton.java similarity index 97% rename from api/src/main/java/org/geysermc/api/window/button/FormButton.java rename to common/src/main/java/org/geysermc/common/window/button/FormButton.java index 859bf9382..4f710d483 100644 --- a/api/src/main/java/org/geysermc/api/window/button/FormButton.java +++ b/common/src/main/java/org/geysermc/common/window/button/FormButton.java @@ -23,7 +23,7 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.api.window.button; +package org.geysermc.common.window.button; import lombok.Getter; import lombok.Setter; diff --git a/api/src/main/java/org/geysermc/api/window/button/FormImage.java b/common/src/main/java/org/geysermc/common/window/button/FormImage.java similarity index 97% rename from api/src/main/java/org/geysermc/api/window/button/FormImage.java rename to common/src/main/java/org/geysermc/common/window/button/FormImage.java index 17c472306..a3f83a0c5 100644 --- a/api/src/main/java/org/geysermc/api/window/button/FormImage.java +++ b/common/src/main/java/org/geysermc/common/window/button/FormImage.java @@ -23,7 +23,7 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.api.window.button; +package org.geysermc.common.window.button; import lombok.Getter; import lombok.Setter; diff --git a/api/src/main/java/org/geysermc/api/window/component/DropdownComponent.java b/common/src/main/java/org/geysermc/common/window/component/DropdownComponent.java similarity index 97% rename from api/src/main/java/org/geysermc/api/window/component/DropdownComponent.java rename to common/src/main/java/org/geysermc/common/window/component/DropdownComponent.java index 99e1bca62..8abe72ff8 100644 --- a/api/src/main/java/org/geysermc/api/window/component/DropdownComponent.java +++ b/common/src/main/java/org/geysermc/common/window/component/DropdownComponent.java @@ -23,7 +23,7 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.api.window.component; +package org.geysermc.common.window.component; import lombok.Getter; import lombok.Setter; diff --git a/api/src/main/java/org/geysermc/api/window/component/FormComponent.java b/common/src/main/java/org/geysermc/common/window/component/FormComponent.java similarity index 96% rename from api/src/main/java/org/geysermc/api/window/component/FormComponent.java rename to common/src/main/java/org/geysermc/common/window/component/FormComponent.java index 506cae687..fb5b9d18c 100644 --- a/api/src/main/java/org/geysermc/api/window/component/FormComponent.java +++ b/common/src/main/java/org/geysermc/common/window/component/FormComponent.java @@ -23,7 +23,7 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.api.window.component; +package org.geysermc.common.window.component; import lombok.Getter; diff --git a/api/src/main/java/org/geysermc/api/window/component/InputComponent.java b/common/src/main/java/org/geysermc/common/window/component/InputComponent.java similarity index 97% rename from api/src/main/java/org/geysermc/api/window/component/InputComponent.java rename to common/src/main/java/org/geysermc/common/window/component/InputComponent.java index 12af18268..53ec2b5eb 100644 --- a/api/src/main/java/org/geysermc/api/window/component/InputComponent.java +++ b/common/src/main/java/org/geysermc/common/window/component/InputComponent.java @@ -23,7 +23,7 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.api.window.component; +package org.geysermc.common.window.component; import lombok.Getter; import lombok.Setter; diff --git a/api/src/main/java/org/geysermc/api/window/component/LabelComponent.java b/common/src/main/java/org/geysermc/common/window/component/LabelComponent.java similarity index 96% rename from api/src/main/java/org/geysermc/api/window/component/LabelComponent.java rename to common/src/main/java/org/geysermc/common/window/component/LabelComponent.java index 9ba68ee4a..7d2aaa420 100644 --- a/api/src/main/java/org/geysermc/api/window/component/LabelComponent.java +++ b/common/src/main/java/org/geysermc/common/window/component/LabelComponent.java @@ -23,7 +23,7 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.api.window.component; +package org.geysermc.common.window.component; import lombok.Getter; import lombok.Setter; diff --git a/api/src/main/java/org/geysermc/api/window/component/SliderComponent.java b/common/src/main/java/org/geysermc/common/window/component/SliderComponent.java similarity index 95% rename from api/src/main/java/org/geysermc/api/window/component/SliderComponent.java rename to common/src/main/java/org/geysermc/common/window/component/SliderComponent.java index 468b700ec..fd82b3e26 100644 --- a/api/src/main/java/org/geysermc/api/window/component/SliderComponent.java +++ b/common/src/main/java/org/geysermc/common/window/component/SliderComponent.java @@ -23,7 +23,7 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.api.window.component; +package org.geysermc.common.window.component; import lombok.Getter; import lombok.Setter; @@ -54,7 +54,7 @@ public class SliderComponent extends FormComponent { super("slider"); this.text = text; - this.min = min < 0f ? 0f : min; + this.min = Math.max(min, 0f); this.max = max > this.min ? max : this.min; if (step != -1f && step > 0) this.step = step; diff --git a/api/src/main/java/org/geysermc/api/window/component/StepSliderComponent.java b/common/src/main/java/org/geysermc/common/window/component/StepSliderComponent.java similarity index 97% rename from api/src/main/java/org/geysermc/api/window/component/StepSliderComponent.java rename to common/src/main/java/org/geysermc/common/window/component/StepSliderComponent.java index aa934f062..b61e416d0 100644 --- a/api/src/main/java/org/geysermc/api/window/component/StepSliderComponent.java +++ b/common/src/main/java/org/geysermc/common/window/component/StepSliderComponent.java @@ -23,7 +23,7 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.api.window.component; +package org.geysermc.common.window.component; import lombok.Getter; import lombok.Setter; diff --git a/api/src/main/java/org/geysermc/api/window/component/ToggleComponent.java b/common/src/main/java/org/geysermc/common/window/component/ToggleComponent.java similarity index 97% rename from api/src/main/java/org/geysermc/api/window/component/ToggleComponent.java rename to common/src/main/java/org/geysermc/common/window/component/ToggleComponent.java index 41b292a61..614ecf8fb 100644 --- a/api/src/main/java/org/geysermc/api/window/component/ToggleComponent.java +++ b/common/src/main/java/org/geysermc/common/window/component/ToggleComponent.java @@ -23,7 +23,7 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.api.window.component; +package org.geysermc.common.window.component; public class ToggleComponent extends FormComponent { diff --git a/api/src/main/java/org/geysermc/api/window/response/CustomFormResponse.java b/common/src/main/java/org/geysermc/common/window/response/CustomFormResponse.java similarity index 91% rename from api/src/main/java/org/geysermc/api/window/response/CustomFormResponse.java rename to common/src/main/java/org/geysermc/common/window/response/CustomFormResponse.java index f32c43462..36b2922f9 100644 --- a/api/src/main/java/org/geysermc/api/window/response/CustomFormResponse.java +++ b/common/src/main/java/org/geysermc/common/window/response/CustomFormResponse.java @@ -23,10 +23,12 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.api.window.response; +package org.geysermc.common.window.response; import lombok.AllArgsConstructor; import lombok.Getter; +import org.geysermc.common.window.response.FormResponse; +import org.geysermc.common.window.response.FormResponseData; import java.util.Map; diff --git a/api/src/main/java/org/geysermc/api/window/response/FormResponse.java b/common/src/main/java/org/geysermc/common/window/response/FormResponse.java similarity index 96% rename from api/src/main/java/org/geysermc/api/window/response/FormResponse.java rename to common/src/main/java/org/geysermc/common/window/response/FormResponse.java index 0286bef1a..58c8c8e87 100644 --- a/api/src/main/java/org/geysermc/api/window/response/FormResponse.java +++ b/common/src/main/java/org/geysermc/common/window/response/FormResponse.java @@ -23,7 +23,7 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.api.window.response; +package org.geysermc.common.window.response; public interface FormResponse { } diff --git a/api/src/main/java/org/geysermc/api/window/response/FormResponseData.java b/common/src/main/java/org/geysermc/common/window/response/FormResponseData.java similarity index 96% rename from api/src/main/java/org/geysermc/api/window/response/FormResponseData.java rename to common/src/main/java/org/geysermc/common/window/response/FormResponseData.java index b97fb0521..826aba208 100644 --- a/api/src/main/java/org/geysermc/api/window/response/FormResponseData.java +++ b/common/src/main/java/org/geysermc/common/window/response/FormResponseData.java @@ -23,7 +23,7 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.api.window.response; +package org.geysermc.common.window.response; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/api/src/main/java/org/geysermc/api/window/response/ModalFormResponse.java b/common/src/main/java/org/geysermc/common/window/response/ModalFormResponse.java similarity index 93% rename from api/src/main/java/org/geysermc/api/window/response/ModalFormResponse.java rename to common/src/main/java/org/geysermc/common/window/response/ModalFormResponse.java index a62953b0d..844c9a5b8 100644 --- a/api/src/main/java/org/geysermc/api/window/response/ModalFormResponse.java +++ b/common/src/main/java/org/geysermc/common/window/response/ModalFormResponse.java @@ -23,10 +23,11 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.api.window.response; +package org.geysermc.common.window.response; import lombok.AllArgsConstructor; import lombok.Getter; +import org.geysermc.common.window.response.FormResponse; @Getter @AllArgsConstructor diff --git a/api/src/main/java/org/geysermc/api/window/response/SimpleFormResponse.java b/common/src/main/java/org/geysermc/common/window/response/SimpleFormResponse.java similarity index 90% rename from api/src/main/java/org/geysermc/api/window/response/SimpleFormResponse.java rename to common/src/main/java/org/geysermc/common/window/response/SimpleFormResponse.java index 4271d7546..5a53d0423 100644 --- a/api/src/main/java/org/geysermc/api/window/response/SimpleFormResponse.java +++ b/common/src/main/java/org/geysermc/common/window/response/SimpleFormResponse.java @@ -23,11 +23,12 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.api.window.response; +package org.geysermc.common.window.response; import lombok.AllArgsConstructor; import lombok.Getter; -import org.geysermc.api.window.button.FormButton; +import org.geysermc.common.window.button.FormButton; +import org.geysermc.common.window.response.FormResponse; @Getter @AllArgsConstructor diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index b50185b8f..821c84a97 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -30,29 +30,21 @@ import com.nukkitx.protocol.bedrock.BedrockServer; import com.nukkitx.protocol.bedrock.v388.Bedrock_v388; import lombok.Getter; -import org.geysermc.api.Connector; -import org.geysermc.api.Geyser; -import org.geysermc.api.Player; -import org.geysermc.api.command.CommandMap; -import org.geysermc.api.logger.Logger; -import org.geysermc.api.plugin.Plugin; + import org.geysermc.common.bootstrap.IGeyserBootstrap; +import org.geysermc.common.logger.IGeyserLogger; import org.geysermc.connector.command.GeyserCommandMap; -import org.geysermc.connector.console.GeyserLogger; import org.geysermc.connector.metrics.Metrics; import org.geysermc.connector.network.ConnectorServerEventHandler; -import org.geysermc.connector.network.remote.RemoteJavaServer; +import org.geysermc.connector.network.remote.RemoteServer; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.TranslatorsInit; -import org.geysermc.connector.plugin.GeyserPluginLoader; -import org.geysermc.connector.plugin.GeyserPluginManager; import org.geysermc.connector.thread.PingPassthroughThread; import org.geysermc.connector.utils.Toolbox; import org.geysermc.common.IGeyserConfiguration; import java.net.InetSocketAddress; import java.text.DecimalFormat; -import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.concurrent.Executors; @@ -60,7 +52,7 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @Getter -public class GeyserConnector implements Connector { +public class GeyserConnector { public static final BedrockPacketCodec BEDROCK_PACKET_CODEC = Bedrock_v388.V388_CODEC; public static final int BEDROCK_1_14_PROTOCOL_VERSION = 389; @@ -72,14 +64,12 @@ public class GeyserConnector implements Connector { private static GeyserConnector instance; - private RemoteJavaServer remoteServer; - - private Logger logger; - - private CommandMap commandMap; + private RemoteServer remoteServer; + private IGeyserLogger logger; private IGeyserConfiguration config; - private GeyserPluginManager pluginManager; + + private GeyserCommandMap commandMap; private boolean shuttingDown = false; @@ -88,13 +78,12 @@ public class GeyserConnector implements Connector { private Metrics metrics; - private GeyserConnector(IGeyserConfiguration config, Logger logger, boolean loadPlugins) { + private GeyserConnector(IGeyserConfiguration config, IGeyserLogger logger) { long startupTime = System.currentTimeMillis(); instance = this; this.logger = logger; - GeyserLogger.setLogger(logger); logger.info("******************************************"); logger.info(""); @@ -103,7 +92,6 @@ public class GeyserConnector implements Connector { logger.info("******************************************"); this.config = config; - this.generalThreadPool = Executors.newScheduledThreadPool(config.getGeneralThreadPool()); logger.setDebug(config.isDebugMode()); @@ -112,13 +100,7 @@ public class GeyserConnector implements Connector { TranslatorsInit.start(); commandMap = new GeyserCommandMap(this); - remoteServer = new RemoteJavaServer(config.getRemote().getAddress(), config.getRemote().getPort()); - - Geyser.setConnector(this); - - pluginManager = new GeyserPluginManager(new GeyserPluginLoader(this)); - if (loadPlugins) - pluginManager.getLoader().loadPlugins(); + remoteServer = new RemoteServer(config.getRemote().getAddress(), config.getRemote().getPort()); passthroughThread = new PingPassthroughThread(this); if (config.isPingPassthrough()) @@ -136,9 +118,9 @@ public class GeyserConnector implements Connector { }).join(); if (config.getMetrics().isEnabled()) { - metrics = new Metrics("GeyserMC", config.getMetrics().getUniqueId(), false, java.util.logging.Logger.getLogger("")); + metrics = new Metrics(this, "GeyserMC", config.getMetrics().getUniqueId(), false, java.util.logging.Logger.getLogger("")); metrics.addCustomChart(new Metrics.SingleLineChart("servers", () -> 1)); - metrics.addCustomChart(new Metrics.SingleLineChart("players", Geyser::getPlayerCount)); + metrics.addCustomChart(new Metrics.SingleLineChart("players", players::size)); metrics.addCustomChart(new Metrics.SimplePie("authMode", config.getRemote()::getAuthType)); } @@ -146,40 +128,34 @@ public class GeyserConnector implements Connector { logger.info(String.format("Done (%ss)! Run /help for help!", new DecimalFormat("#.###").format(completeTime))); } - @Override - public Collection getConnectedPlayers() { - return players.values(); - } - public void shutdown() { logger.info("Shutting down connector."); - for (Plugin plugin : pluginManager.getPlugins()) { - pluginManager.disablePlugin(plugin); - pluginManager.unloadPlugin(plugin); - } - shuttingDown = true; generalThreadPool.shutdown(); } public void addPlayer(GeyserSession player) { - players.put(player.getAuthenticationData().getName(), player); - players.put(player.getAuthenticationData().getUUID(), player); + players.put(player.getAuthData().getName(), player); + players.put(player.getAuthData().getUUID(), player); players.put(player.getSocketAddress(), player); } public void removePlayer(GeyserSession player) { - players.remove(player.getAuthenticationData().getName()); - players.remove(player.getAuthenticationData().getUUID()); + players.remove(player.getAuthData().getName()); + players.remove(player.getAuthData().getUUID()); players.remove(player.getSocketAddress()); } - public static GeyserConnector start(IGeyserBootstrap bootstrap, boolean loadPlugins) { - return new GeyserConnector(bootstrap.getGeyserConfig(), bootstrap.getGeyserLogger(), loadPlugins); + public static GeyserConnector start(IGeyserBootstrap bootstrap) { + return new GeyserConnector(bootstrap.getGeyserConfig(), bootstrap.getGeyserLogger()); } public static void stop() { instance.shutdown(); } + + public static GeyserConnector getInstance() { + return instance; + } } diff --git a/connector/src/main/java/org/geysermc/connector/command/CommandSender.java b/connector/src/main/java/org/geysermc/connector/command/CommandSender.java new file mode 100644 index 000000000..eb69010d1 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/command/CommandSender.java @@ -0,0 +1,14 @@ +package org.geysermc.connector.command; + +public interface CommandSender { + + String getName(); + + default void sendMessage(String[] messages) { + for (String message : messages) { + sendMessage(message); + } + } + + void sendMessage(String message); +} diff --git a/connector/src/main/java/org/geysermc/connector/command/GeyserCommand.java b/connector/src/main/java/org/geysermc/connector/command/GeyserCommand.java index a5c11c468..4e1e784c2 100644 --- a/connector/src/main/java/org/geysermc/connector/command/GeyserCommand.java +++ b/connector/src/main/java/org/geysermc/connector/command/GeyserCommand.java @@ -25,18 +25,24 @@ package org.geysermc.connector.command; -import org.geysermc.api.command.Command; -import org.geysermc.api.command.CommandSender; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; +import java.util.ArrayList; import java.util.List; -public abstract class GeyserCommand implements Command { +@Getter +@Setter +public abstract class GeyserCommand { private String name; private String description; + + @Setter(AccessLevel.NONE) private GeyserCommandMap commandMap; - private List aliases; + private List aliases = new ArrayList<>(); public GeyserCommand(String name) { this(name, "A geyser command."); @@ -47,38 +53,5 @@ public abstract class GeyserCommand implements Command { this.description = description; } - @Override - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - @Override - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @Override - public List getAliases() { - return aliases; - } - - @Override - public void setAliases(List aliases) { - this.aliases = aliases; - } - - @Override public abstract void execute(CommandSender sender, String[] args); - - public GeyserCommandMap getCommandMap() { - return commandMap; - } } diff --git a/connector/src/main/java/org/geysermc/connector/command/GeyserCommandMap.java b/connector/src/main/java/org/geysermc/connector/command/GeyserCommandMap.java index a1e7bcaaa..58b98d2d0 100644 --- a/connector/src/main/java/org/geysermc/connector/command/GeyserCommandMap.java +++ b/connector/src/main/java/org/geysermc/connector/command/GeyserCommandMap.java @@ -25,9 +25,6 @@ package org.geysermc.connector.command; -import org.geysermc.api.command.Command; -import org.geysermc.api.command.CommandMap; -import org.geysermc.api.command.CommandSender; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.command.defaults.HelpCommand; import org.geysermc.connector.command.defaults.StopCommand; @@ -36,9 +33,9 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -public class GeyserCommandMap implements CommandMap { +public class GeyserCommandMap { - private final Map commandMap = Collections.synchronizedMap(new HashMap()); + private final Map commandMap = Collections.synchronizedMap(new HashMap<>()); private GeyserConnector connector; public GeyserCommandMap(GeyserConnector connector) { @@ -52,11 +49,11 @@ public class GeyserCommandMap implements CommandMap { registerCommand(new StopCommand(connector, "stop", "Shut down Geyser.")); } - public void registerCommand(Command command) { + public void registerCommand(GeyserCommand command) { commandMap.put(command.getName(), command); connector.getLogger().debug("Registered command " + command.getName()); - if (command.getAliases() == null || command.getAliases().isEmpty()) + if (command.getAliases().isEmpty()) return; for (String alias : command.getAliases()) @@ -64,25 +61,24 @@ public class GeyserCommandMap implements CommandMap { } public void runCommand(CommandSender sender, String command) { - String trim = command.trim(); - String label = null; - String[] args = null; + if (!command.startsWith("/geyser ")) + return; - if (!trim.contains(" ")) { - label = trim.toLowerCase(); + command = command.trim(); + command = command.replace("geyser ", ""); + String label; + String[] args; + + if (!command.contains(" ")) { + label = command.toLowerCase(); args = new String[0]; } else { - label = trim.substring(0, trim.indexOf(" ")).toLowerCase(); - String argLine = trim.substring(trim.indexOf(" " + 1)); + label = command.substring(0, command.indexOf(" ")).toLowerCase(); + String argLine = command.substring(command.indexOf(" " + 1)); args = argLine.contains(" ") ? argLine.split(" ") : new String[] { argLine }; } - if (label == null) { - connector.getLogger().warning("Invalid Command! Try /help for a list of commands."); - return; - } - - Command cmd = commandMap.get(label); + GeyserCommand cmd = commandMap.get(label); if (cmd == null) { connector.getLogger().warning("Invalid Command! Try /help for a list of commands."); return; @@ -91,7 +87,7 @@ public class GeyserCommandMap implements CommandMap { cmd.execute(sender, args); } - public Map getCommands() { + public Map getCommands() { return commandMap; } } diff --git a/connector/src/main/java/org/geysermc/connector/command/GeyserConsoleCommandSender.java b/connector/src/main/java/org/geysermc/connector/command/GeyserConsoleCommandSender.java index 453a61ffd..8bef62ea6 100644 --- a/connector/src/main/java/org/geysermc/connector/command/GeyserConsoleCommandSender.java +++ b/connector/src/main/java/org/geysermc/connector/command/GeyserConsoleCommandSender.java @@ -25,10 +25,9 @@ package org.geysermc.connector.command; -import org.geysermc.api.command.ConsoleCommandSender; -import org.geysermc.connector.console.GeyserLogger; +import org.geysermc.common.ChatColor; -public class GeyserConsoleCommandSender implements ConsoleCommandSender { +public class GeyserConsoleCommandSender implements CommandSender { @Override public String getName() { @@ -37,13 +36,6 @@ public class GeyserConsoleCommandSender implements ConsoleCommandSender { @Override public void sendMessage(String message) { - System.out.println(GeyserLogger.printConsole(message, true)); - } - - @Override - public void sendMessage(String[] messages) { - for (String message : messages) { - sendMessage(message); - } + System.out.println(ChatColor.toANSI(message + ChatColor.RESET)); } } diff --git a/connector/src/main/java/org/geysermc/connector/command/defaults/HelpCommand.java b/connector/src/main/java/org/geysermc/connector/command/defaults/HelpCommand.java index 165485b34..acdfc5d87 100644 --- a/connector/src/main/java/org/geysermc/connector/command/defaults/HelpCommand.java +++ b/connector/src/main/java/org/geysermc/connector/command/defaults/HelpCommand.java @@ -25,17 +25,12 @@ package org.geysermc.connector.command.defaults; -import org.geysermc.api.ChatColor; -import org.geysermc.api.command.Command; -import org.geysermc.api.command.CommandSender; +import org.geysermc.common.ChatColor; import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.command.CommandSender; import org.geysermc.connector.command.GeyserCommand; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map; +import java.util.*; public class HelpCommand extends GeyserCommand { @@ -45,15 +40,15 @@ public class HelpCommand extends GeyserCommand { super(name, description); this.connector = connector; - this.setAliases(Arrays.asList("?")); + this.setAliases(Collections.singletonList("?")); } @Override public void execute(CommandSender sender, String[] args) { sender.sendMessage("---- Showing Help For: Geyser (Page 1/1) ----"); - Map cmds = connector.getCommandMap().getCommands(); + Map cmds = connector.getCommandMap().getCommands(); - List commands = new ArrayList(cmds.keySet()); + List commands = new ArrayList<>(cmds.keySet()); Collections.sort(commands); for (String cmd : commands) { diff --git a/connector/src/main/java/org/geysermc/connector/command/defaults/StopCommand.java b/connector/src/main/java/org/geysermc/connector/command/defaults/StopCommand.java index 2c5449a46..cc433cd35 100644 --- a/connector/src/main/java/org/geysermc/connector/command/defaults/StopCommand.java +++ b/connector/src/main/java/org/geysermc/connector/command/defaults/StopCommand.java @@ -25,11 +25,11 @@ package org.geysermc.connector.command.defaults; -import org.geysermc.api.command.CommandSender; import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.command.CommandSender; import org.geysermc.connector.command.GeyserCommand; -import java.util.Arrays; +import java.util.Collections; public class StopCommand extends GeyserCommand { @@ -39,7 +39,7 @@ public class StopCommand extends GeyserCommand { super(name, description); this.connector = connector; - this.setAliases(Arrays.asList("shutdown")); + this.setAliases(Collections.singletonList("shutdown")); } @Override diff --git a/connector/src/main/java/org/geysermc/connector/console/GeyserLogger.java b/connector/src/main/java/org/geysermc/connector/console/GeyserLogger.java deleted file mode 100644 index 719667c75..000000000 --- a/connector/src/main/java/org/geysermc/connector/console/GeyserLogger.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 2019 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.connector.console; - -import io.sentry.Sentry; -import org.geysermc.api.ChatColor; -import org.geysermc.api.logger.Logger; - -import java.io.File; -import java.io.IOException; -import java.util.Date; -import java.util.logging.*; - -public class GeyserLogger { - - public static Logger DEFAULT; - - /* - private boolean colored = true; - private boolean debug = false; - - private GeyserLogger() { - ConsoleHandler consoleHandler = new ConsoleHandler(); - consoleHandler.setLevel(Level.INFO); - consoleHandler.setFormatter(new SimpleFormatter() { - private static final String format = "[%1$tT][%2$-5s] %3$s %n"; - - @Override - public synchronized String format(LogRecord lr) { - return String.format(format, - new Date(lr.getMillis()), - lr.getLevel().getLocalizedName(), - lr.getMessage() - ); - } - }); - - try { - File logDir = new File("logs"); - logDir.mkdir(); - File logFile = new File(logDir, "latest.log"); - int maxLogFileSize = 20;//Mo - if (logFile.exists() && (logFile.length()) > maxLogFileSize * 1024L * 1024L) - this.warning("Your log file is larger than " + maxLogFileSize + "Mo, you should backup and clean it !"); - FileHandler fileHandler = new FileHandler(logFile.getCanonicalPath(), true); - fileHandler.setLevel(Level.INFO); - fileHandler.setFormatter(new SimpleFormatter() { - private static final String format = "[%1$tF %1$tT][%2$-5s] %3$s %n"; - - @Override - public synchronized String format(LogRecord lr) { - return String.format(format, - new Date(lr.getMillis()), - lr.getLevel().getLocalizedName(), - lr.getMessage() - ); - } - }); - } catch (IOException | SecurityException ex) { - Logger.getLogger(GeyserLogger.class.getName()).log(Level.SEVERE, null, ex); - } - - if (System.getenv().containsKey("DP_SENTRY_CLIENT_KEY")) { - Handler sentryHandler = new io.sentry.jul.SentryHandler(); - sentryHandler.setLevel(Level.SEVERE); - Sentry.init(System.getenv().get("DP_SENTRY_CLIENT_KEY")); - } - } - - @Override - public void severe(String message) { - System.out.println(printConsole(ChatColor.DARK_RED + message, colored)); - } - - @Override - public void severe(String message, Throwable error) { - System.out.println(printConsole(ChatColor.DARK_RED + message + "\n" + error.getMessage(), colored)); - } - - @Override - public void error(String message) { - System.out.println(printConsole(ChatColor.RED + message, colored)); - } - - @Override - public void error(String message, Throwable error) { - System.out.println(printConsole(ChatColor.RED + message + "\n" + error, colored)); - } - - @Override - public void warning(String message) { - System.out.println(printConsole(ChatColor.YELLOW + message, colored)); - } - - @Override - public void info(String message) { - System.out.println(printConsole(ChatColor.WHITE + message, colored)); - } - - @Override - public void debug(String message) { - if (debug) - System.out.println(printConsole(ChatColor.GRAY + message, colored)); - } - - public static String printConsole(String message, boolean colors) { - return colors ? ChatColor.toANSI(message + ChatColor.RESET) : ChatColor.stripColors(message + ChatColor.RESET); - } - - @Override - public void setDebug(boolean debug) { - this.debug = debug; - } - - */ - - public static String printConsole(String message, boolean colors) { - return colors ? ChatColor.toANSI(message + ChatColor.RESET) : ChatColor.stripColors(message + ChatColor.RESET); - } - - public static void setLogger(Logger logger) { - DEFAULT = logger; - } -} diff --git a/connector/src/main/java/org/geysermc/connector/entity/Entity.java b/connector/src/main/java/org/geysermc/connector/entity/Entity.java index e348e1aa7..aeb2d3351 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/Entity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/Entity.java @@ -34,11 +34,13 @@ import com.nukkitx.protocol.bedrock.data.EntityDataDictionary; import com.nukkitx.protocol.bedrock.data.EntityFlag; import com.nukkitx.protocol.bedrock.data.EntityFlags; import com.nukkitx.protocol.bedrock.packet.*; + import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import it.unimi.dsi.fastutil.longs.LongSet; + import lombok.Getter; import lombok.Setter; -import org.geysermc.connector.console.GeyserLogger; + import org.geysermc.connector.entity.attribute.Attribute; import org.geysermc.connector.entity.attribute.AttributeType; import org.geysermc.connector.entity.type.EntityType; @@ -115,7 +117,7 @@ public class Entity { valid = true; session.getUpstream().sendPacket(addEntityPacket); - GeyserLogger.DEFAULT.debug("Spawned entity " + entityType + " at location " + position + " with id " + geyserId + " (java id " + entityId + ")"); + session.getConnector().getLogger().debug("Spawned entity " + entityType + " at location " + position + " with id " + geyserId + " (java id " + entityId + ")"); } /** diff --git a/connector/src/main/java/org/geysermc/connector/entity/PaintingEntity.java b/connector/src/main/java/org/geysermc/connector/entity/PaintingEntity.java index b598b9bf3..77b05b535 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/PaintingEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/PaintingEntity.java @@ -27,10 +27,11 @@ package org.geysermc.connector.entity; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.packet.AddPaintingPacket; + import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; -import org.geysermc.connector.console.GeyserLogger; + import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.utils.PaintingType; @@ -58,7 +59,7 @@ public class PaintingEntity extends Entity { valid = true; - GeyserLogger.DEFAULT.debug("Spawned painting on " + position); + session.getConnector().getLogger().debug("Spawned painting on " + position); } public Vector3f fixOffset(boolean toBedrock) { diff --git a/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java index afcc45052..ca7343787 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java @@ -29,9 +29,11 @@ import com.github.steveice10.mc.auth.data.GameProfile; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.packet.AddPlayerPacket; import com.nukkitx.protocol.bedrock.packet.PlayerListPacket; + import lombok.Getter; import lombok.Setter; -import org.geysermc.api.Geyser; + +import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.utils.SkinUtils; @@ -105,7 +107,7 @@ public class PlayerEntity extends LivingEntity { if (!playerList) { // remove from playerlist if player isn't on playerlist - Geyser.getGeneralThreadPool().execute(() -> { + GeyserConnector.getInstance().getGeneralThreadPool().execute(() -> { PlayerListPacket playerList = new PlayerListPacket(); playerList.setType(PlayerListPacket.Type.REMOVE); playerList.getEntries().add(new PlayerListPacket.Entry(uuid)); diff --git a/connector/src/main/java/org/geysermc/connector/metrics/Metrics.java b/connector/src/main/java/org/geysermc/connector/metrics/Metrics.java index 9b149ba12..b0a9c237e 100644 --- a/connector/src/main/java/org/geysermc/connector/metrics/Metrics.java +++ b/connector/src/main/java/org/geysermc/connector/metrics/Metrics.java @@ -2,7 +2,6 @@ package org.geysermc.connector.metrics; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import org.geysermc.api.Geyser; import org.geysermc.connector.GeyserConnector; import javax.net.ssl.HttpsURLConnection; @@ -47,15 +46,19 @@ public class Metrics { // A list with all custom charts private final List charts = new ArrayList<>(); + private GeyserConnector connector; + /** * Class constructor. * + * @param connector The GeyserConnector instance * @param name The name of the server software. * @param serverUUID The uuid of the server. * @param logFailedRequests Whether failed requests should be logged or not. * @param logger The logger for the failed requests. */ - public Metrics(String name, String serverUUID, boolean logFailedRequests, Logger logger) { + public Metrics(GeyserConnector connector, String name, String serverUUID, boolean logFailedRequests, Logger logger) { + this.connector = connector; this.name = name; this.serverUUID = serverUUID; Metrics.logFailedRequests = logFailedRequests; @@ -81,7 +84,7 @@ public class Metrics { * Starts the Scheduler which submits our data every 30 minutes. */ private void startSubmitting() { - Geyser.getGeneralThreadPool().scheduleAtFixedRate(this::submitData, 1, 30, TimeUnit.MINUTES); + connector.getGeneralThreadPool().scheduleAtFixedRate(this::submitData, 1, 30, TimeUnit.MINUTES); // Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start // WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted! // WARNING: Just don't do it! @@ -119,7 +122,7 @@ public class Metrics { */ private JsonObject getServerData() { // OS specific data - int playerAmount = Geyser.getPlayerCount(); + int playerAmount = connector.getPlayers().size(); String osName = System.getProperty("os.name"); String osArch = System.getProperty("os.arch"); diff --git a/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java b/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java index 34d36a216..e8d0d9d10 100644 --- a/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java @@ -29,10 +29,9 @@ import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo; import com.nukkitx.protocol.bedrock.BedrockPong; import com.nukkitx.protocol.bedrock.BedrockServerEventHandler; import com.nukkitx.protocol.bedrock.BedrockServerSession; -import org.geysermc.api.events.PingEvent; + import org.geysermc.common.IGeyserConfiguration; import org.geysermc.connector.GeyserConnector; -import org.geysermc.connector.console.GeyserLogger; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.utils.MessageUtils; @@ -48,50 +47,35 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler { @Override public boolean onConnectionRequest(InetSocketAddress inetSocketAddress) { - GeyserLogger.DEFAULT.info(inetSocketAddress + " tried to connect!"); + connector.getLogger().info(inetSocketAddress + " tried to connect!"); return true; } @Override public BedrockPong onQuery(InetSocketAddress inetSocketAddress) { - GeyserLogger.DEFAULT.debug(inetSocketAddress + " has pinged you!"); + connector.getLogger().debug(inetSocketAddress + " has pinged you!"); + IGeyserConfiguration config = connector.getConfig(); - PingEvent pongEvent = new PingEvent(inetSocketAddress); - pongEvent.setEdition("MCPE"); - pongEvent.setGameType("Default"); - pongEvent.setNintendoLimited(false); - pongEvent.setProtocolVersion(GeyserConnector.BEDROCK_PACKET_CODEC.getProtocolVersion()); - pongEvent.setVersion(GeyserConnector.BEDROCK_PACKET_CODEC.getMinecraftVersion()); - - connector.getPluginManager().runEvent(pongEvent); - if (connector.getConfig().isPingPassthrough()) { - ServerStatusInfo serverInfo = connector.getPassthroughThread().getInfo(); - - if (serverInfo != null) { - pongEvent.setMotd(MessageUtils.getBedrockMessage(serverInfo.getDescription())); - pongEvent.setSubMotd(config.getBedrock().getMotd2()); - pongEvent.setPlayerCount(serverInfo.getPlayerInfo().getOnlinePlayers()); - pongEvent.setMaximumPlayerCount(serverInfo.getPlayerInfo().getMaxPlayers()); - } - } else { - pongEvent.setPlayerCount(1); - pongEvent.setMaximumPlayerCount(config.getMaxPlayers()); - pongEvent.setMotd(config.getBedrock().getMotd1()); - pongEvent.setSubMotd(config.getBedrock().getMotd2()); - } + ServerStatusInfo serverInfo = connector.getPassthroughThread().getInfo(); BedrockPong pong = new BedrockPong(); - pong.setEdition(pongEvent.getEdition()); - pong.setGameType(pongEvent.getGameType()); - pong.setNintendoLimited(pongEvent.isNintendoLimited()); - pong.setProtocolVersion(pongEvent.getProtocolVersion()); - pong.setVersion(pongEvent.getVersion()); - pong.setMotd(pongEvent.getMotd()); - pong.setSubMotd(pongEvent.getSubMotd()); - pong.setPlayerCount(pongEvent.getPlayerCount()); - pong.setMaximumPlayerCount(pongEvent.getMaximumPlayerCount()); + pong.setEdition("MCPE"); + pong.setGameType("Default"); + pong.setNintendoLimited(false); + pong.setProtocolVersion(GeyserConnector.BEDROCK_1_14_PROTOCOL_VERSION); + pong.setVersion(GeyserConnector.BEDROCK_PACKET_CODEC.getMinecraftVersion()); pong.setIpv4Port(config.getBedrock().getPort()); - + if (connector.getConfig().isPingPassthrough()) { + pong.setMotd(MessageUtils.getBedrockMessage(serverInfo.getDescription())); + pong.setSubMotd(config.getBedrock().getMotd2()); + pong.setPlayerCount(serverInfo.getPlayerInfo().getOnlinePlayers()); + pong.setMaximumPlayerCount(serverInfo.getPlayerInfo().getMaxPlayers()); + } else { + pong.setPlayerCount(connector.getPlayers().size()); + pong.setMaximumPlayerCount(config.getMaxPlayers()); + pong.setMotd(config.getBedrock().getMotd1()); + pong.setMotd(config.getBedrock().getMotd2()); + } return pong; } @@ -100,7 +84,7 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler { bedrockServerSession.setLogging(true); bedrockServerSession.setPacketHandler(new UpstreamPacketHandler(connector, new GeyserSession(connector, bedrockServerSession))); bedrockServerSession.addDisconnectHandler(disconnectReason -> { - GeyserLogger.DEFAULT.info("Bedrock user with ip: " + bedrockServerSession.getAddress().getAddress() + " has disconnected for reason " + disconnectReason); + connector.getLogger().info("Bedrock user with ip: " + bedrockServerSession.getAddress().getAddress() + " has disconnected for reason " + disconnectReason); GeyserSession player = connector.getPlayers().get(bedrockServerSession.getAddress()); if (player != null) { diff --git a/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java b/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java index 6e9e291c5..2c267d733 100644 --- a/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java @@ -66,7 +66,7 @@ public class UpstreamPacketHandler extends LoggingPacketHandler { switch (packet.getStatus()) { case COMPLETED: session.connect(connector.getRemoteServer()); - connector.getLogger().info("Player connected with username " + session.getAuthenticationData().getName()); + connector.getLogger().info("Player connected with username " + session.getAuthData().getName()); break; case HAVE_ALL_PACKS: ResourcePackStackPacket stack = new ResourcePackStackPacket(); @@ -93,7 +93,7 @@ public class UpstreamPacketHandler extends LoggingPacketHandler { IGeyserConfiguration.IUserAuthenticationInfo info = connector.getConfig().getUserAuths().get(bedrockUsername); if (info != null) { - connector.getLogger().info("using stored credentials for bedrock user " + session.getAuthenticationData().getName()); + connector.getLogger().info("using stored credentials for bedrock user " + session.getAuthData().getName()); session.authenticate(info.getEmail(), info.getPassword()); // TODO send a message to bedrock user telling them they are connected (if nothing like a motd @@ -109,7 +109,7 @@ public class UpstreamPacketHandler extends LoggingPacketHandler { public boolean handle(MovePlayerPacket packet) { if (!session.isLoggedIn() && !session.isLoggingIn()) { // TODO it is safer to key authentication on something that won't change (UUID, not username) - if (!couldLoginUserByName(session.getAuthenticationData().getName())) { + if (!couldLoginUserByName(session.getAuthData().getName())) { LoginEncryptionUtils.showLoginWindow(session); } // else we were able to log the user in diff --git a/connector/src/main/java/org/geysermc/connector/network/remote/RemoteJavaServer.java b/connector/src/main/java/org/geysermc/connector/network/remote/RemoteJavaServer.java deleted file mode 100644 index d335ba946..000000000 --- a/connector/src/main/java/org/geysermc/connector/network/remote/RemoteJavaServer.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2019 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.connector.network.remote; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import org.geysermc.api.RemoteServer; - -@Getter -@AllArgsConstructor -public class RemoteJavaServer implements RemoteServer { - - private String address; - private int port; -} \ No newline at end of file diff --git a/api/src/main/java/org/geysermc/api/RemoteServer.java b/connector/src/main/java/org/geysermc/connector/network/remote/RemoteServer.java similarity index 77% rename from api/src/main/java/org/geysermc/api/RemoteServer.java rename to connector/src/main/java/org/geysermc/connector/network/remote/RemoteServer.java index 8004cbd16..b2662fdb7 100644 --- a/api/src/main/java/org/geysermc/api/RemoteServer.java +++ b/connector/src/main/java/org/geysermc/connector/network/remote/RemoteServer.java @@ -23,21 +23,15 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.api; +package org.geysermc.connector.network.remote; -public interface RemoteServer { +import lombok.AllArgsConstructor; +import lombok.Getter; - /** - * Returns the IP address of the remote server - * - * @return the IP address of the remote server - */ - String getAddress(); +@Getter +@AllArgsConstructor +public class RemoteServer { - /** - * Returns the port of the remote server - * - * @return the port of the remote server - */ - int getPort(); -} + private String address; + private int port; +} \ No newline at end of file diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index 8fedc583a..0b036ea06 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -45,15 +45,17 @@ import com.nukkitx.protocol.bedrock.BedrockServerSession; import com.nukkitx.protocol.bedrock.data.GamePublishSetting; import com.nukkitx.protocol.bedrock.data.GameRule; import com.nukkitx.protocol.bedrock.packet.*; + import lombok.Getter; import lombok.Setter; -import org.geysermc.api.Player; -import org.geysermc.api.RemoteServer; -import org.geysermc.api.session.AuthData; -import org.geysermc.api.window.FormWindow; + +import org.geysermc.common.window.FormWindow; import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.command.CommandSender; import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.inventory.PlayerInventory; +import org.geysermc.connector.network.remote.RemoteServer; +import org.geysermc.connector.network.session.auth.AuthData; import org.geysermc.connector.network.session.cache.*; import org.geysermc.connector.network.translators.Registry; import org.geysermc.connector.network.translators.TranslatorsInit; @@ -63,13 +65,13 @@ import java.net.InetSocketAddress; import java.util.UUID; @Getter -public class GeyserSession implements Player { +public class GeyserSession implements CommandSender { private final GeyserConnector connector; private final UpstreamSession upstream; private RemoteServer remoteServer; private Client downstream; - private AuthData authenticationData; + private AuthData authData; private PlayerEntity playerEntity; private PlayerInventory inventory; @@ -123,7 +125,7 @@ public class GeyserSession implements Player { this.remoteServer = remoteServer; if (!(connector.getConfig().getRemote().getAuthType().hashCode() == "online".hashCode())) { connector.getLogger().info("Attempting to login using offline mode... authentication is disabled."); - authenticate(authenticationData.getName()); + authenticate(authData.getName()); } Vector3f pos = Vector3f.ZERO; @@ -182,7 +184,7 @@ public class GeyserSession implements Player { public void connected(ConnectedEvent event) { loggingIn = false; loggedIn = true; - connector.getLogger().info(authenticationData.getName() + " (logged in as: " + protocol.getProfile().getName() + ")" + " has connected to remote java server on address " + remoteServer.getAddress()); + connector.getLogger().info(authData.getName() + " (logged in as: " + protocol.getProfile().getName() + ")" + " has connected to remote java server on address " + remoteServer.getAddress()); playerEntity.setUuid(protocol.getProfile().getId()); playerEntity.setUsername(protocol.getProfile().getName()); } @@ -191,7 +193,7 @@ public class GeyserSession implements Player { public void disconnected(DisconnectedEvent event) { loggingIn = false; loggedIn = false; - connector.getLogger().info(authenticationData.getName() + " has disconnected from remote java server on address " + remoteServer.getAddress() + " because of " + event.getReason()); + connector.getLogger().info(authData.getName() + " has disconnected from remote java server on address " + remoteServer.getAddress() + " because of " + event.getReason()); upstream.disconnect(event.getReason()); } @@ -234,12 +236,12 @@ public class GeyserSession implements Player { } public void setAuthenticationData(AuthData authData) { - authenticationData = authData; + this.authData = authData; } @Override public String getName() { - return authenticationData.getName(); + return authData.getName(); } @Override @@ -255,18 +257,10 @@ public class GeyserSession implements Player { upstream.sendPacket(textPacket); } - @Override - public void sendMessage(String[] messages) { - for (String message : messages) { - sendMessage(message); - } - } - public void sendForm(FormWindow window, int id) { windowCache.showWindow(window, id); } - @Override public InetSocketAddress getSocketAddress() { return this.upstream.getAddress(); } diff --git a/connector/src/main/java/org/geysermc/connector/network/session/auth/BedrockAuthData.java b/connector/src/main/java/org/geysermc/connector/network/session/auth/AuthData.java similarity index 72% rename from connector/src/main/java/org/geysermc/connector/network/session/auth/BedrockAuthData.java rename to connector/src/main/java/org/geysermc/connector/network/session/auth/AuthData.java index 47d79ed85..9674f8db2 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/auth/BedrockAuthData.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/auth/AuthData.java @@ -2,13 +2,12 @@ package org.geysermc.connector.network.session.auth; import lombok.AllArgsConstructor; import lombok.Getter; -import org.geysermc.api.session.AuthData; import java.util.UUID; @Getter @AllArgsConstructor -public class BedrockAuthData implements AuthData { +public class AuthData { private String name; private UUID UUID; diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/WindowCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/WindowCache.java index 5d21c55ca..68945bfee 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/cache/WindowCache.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/WindowCache.java @@ -26,14 +26,14 @@ package org.geysermc.connector.network.session.cache; import com.nukkitx.protocol.bedrock.packet.ModalFormRequestPacket; + import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -import lombok.Getter; -import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.api.window.FormWindow; -import java.util.HashMap; -import java.util.Map; +import lombok.Getter; + +import org.geysermc.common.window.FormWindow; +import org.geysermc.connector.network.session.GeyserSession; public class WindowCache { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/Registry.java b/connector/src/main/java/org/geysermc/connector/network/translators/Registry.java index 3867c8b52..fd6830255 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/Registry.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/Registry.java @@ -27,7 +27,7 @@ package org.geysermc.connector.network.translators; import com.github.steveice10.packetlib.packet.Packet; import com.nukkitx.protocol.bedrock.BedrockPacket; -import org.geysermc.connector.console.GeyserLogger; +import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.network.session.GeyserSession; import java.util.HashMap; @@ -55,7 +55,7 @@ public class Registry { return true; } } catch (Throwable ex) { - GeyserLogger.DEFAULT.error("Could not translate packet " + packet.getClass().getSimpleName(), ex); + GeyserConnector.getInstance().getLogger().error("Could not translate packet " + packet.getClass().getSimpleName(), ex); ex.printStackTrace(); } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java index cc2ab4d07..dd69fdf3e 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java @@ -27,7 +27,8 @@ package org.geysermc.connector.network.translators.bedrock; import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket; import com.nukkitx.protocol.bedrock.packet.CommandRequestPacket; -import org.geysermc.api.Geyser; + +import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; @@ -36,8 +37,8 @@ public class BedrockCommandRequestTranslator extends PacketTranslator { TextPacket textPacket = new TextPacket(); textPacket.setPlatformChatId(""); textPacket.setSourceName(""); - textPacket.setXuid(session.getAuthenticationData().getXboxUUID()); + textPacket.setXuid(session.getAuthData().getXboxUUID()); switch (packet.getType()) { case CHAT: textPacket.setType(TextPacket.Type.CHAT); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java index 0eb150803..e7eb10843 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java @@ -30,7 +30,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.Serv import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket; import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket; -import org.geysermc.connector.console.GeyserLogger; + import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; @@ -66,7 +66,7 @@ public class JavaPlayerPositionRotationTranslator extends PacketTranslator { // #slowdownbrother, just don't execute it directly + GeyserConnector.getInstance().getGeneralThreadPool().execute(() -> { // #slowdownbrother, just don't execute it directly PaintingEntity entity = new PaintingEntity( packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPlayerTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPlayerTranslator.java index 660cac2ec..e0c7de854 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPlayerTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPlayerTranslator.java @@ -27,7 +27,8 @@ package org.geysermc.connector.network.translators.java.entity.spawn; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPlayerPacket; import com.nukkitx.math.vector.Vector3f; -import org.geysermc.api.Geyser; + +import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; @@ -43,7 +44,7 @@ public class JavaSpawnPlayerTranslator extends PacketTranslator { @Override public void translate(ServerTeamPacket packet, GeyserSession session) { - Geyser.getLogger().debug("Team packet " + packet.getTeamName() + " " + packet.getAction()+" "+ Arrays.toString(packet.getPlayers())); + GeyserConnector.getInstance().getLogger().debug("Team packet " + packet.getTeamName() + " " + packet.getAction()+" "+ Arrays.toString(packet.getPlayers())); Scoreboard scoreboard = session.getScoreboardCache().getScoreboard(); switch (packet.getAction()) { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaUpdateScoreTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaUpdateScoreTranslator.java index 7d21deaf0..0baa368ce 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaUpdateScoreTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaUpdateScoreTranslator.java @@ -27,7 +27,8 @@ package org.geysermc.connector.network.translators.java.scoreboard; import com.github.steveice10.mc.protocol.data.game.scoreboard.ScoreboardAction; import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerUpdateScorePacket; -import org.geysermc.api.Geyser; + +import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.scoreboard.Objective; @@ -42,7 +43,7 @@ public class JavaUpdateScoreTranslator extends PacketTranslator { + GeyserConnector.getInstance().getGeneralThreadPool().execute(() -> { Vector2i chunkPos = session.getLastChunkPosition(); Vector3f position = session.getPlayerEntity().getPosition(); Vector2i newChunkPos = Vector2i.from(position.getFloorX() >> 4, position.getFloorZ() >> 4); diff --git a/connector/src/main/java/org/geysermc/connector/plugin/GeyserPluginLoader.java b/connector/src/main/java/org/geysermc/connector/plugin/GeyserPluginLoader.java deleted file mode 100644 index 894b34475..000000000 --- a/connector/src/main/java/org/geysermc/connector/plugin/GeyserPluginLoader.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2019 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.connector.plugin; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.nukkitx.protocol.bedrock.handler.BedrockPacketHandler; -import org.geysermc.api.Connector; -import org.geysermc.api.plugin.Plugin; -import java.io.File; -import java.io.InputStream; -import java.lang.reflect.Field; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -public class GeyserPluginLoader extends ClassLoader { - - private Connector connector; - - public GeyserPluginLoader(Connector connector) { - this.connector = connector; - } - - public void loadPlugins() { - File dir = new File("plugins"); - - if (!dir.exists()) { - dir.mkdir(); - } - - for (File f : dir.listFiles()) { - if (!f.getName().toLowerCase().endsWith(".jar")) - continue; - - try { - ZipFile file = new ZipFile(f); - ZipEntry e = file.getEntry("plugin.yml"); - - if (e == null || e.isDirectory()) { - connector.getLogger().severe("Plugin " + f.getName() + " has no valid plugin.yml!"); - continue; - } - - file.stream().forEach((x) -> { - if (x.getName().endsWith(".class")) { - try { - InputStream is = file.getInputStream(x); - byte[] b = new byte[is.available()]; - is.read(b); - this.defineClass(x.getName().replace(".class", "").replaceAll("/", "."), b, 0, b.length); - is.close(); - } catch (Exception e1) { - e1.printStackTrace(); - } - } - }); - - ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); - InputStream is = file.getInputStream(e); - - PluginYML yml = mapper.readValue(is, PluginYML.class); - is.close(); - Plugin plugin = (Plugin) Class.forName(yml.main, true, this).newInstance(); - - Class cl = Plugin.class; - - Field name = cl.getDeclaredField("name"); - name.setAccessible(true); - - Field version = cl.getDeclaredField("version"); - version.setAccessible(true); - - name.set(plugin, yml.name); - - version.set(plugin, yml.version); - - connector.getLogger().info("Loading plugin " + yml.name + " version " + yml.version); - connector.getPluginManager().loadPlugin(plugin); - } catch (Exception e) { - connector.getLogger().severe("Error loading plugin " + f.getName()); - e.printStackTrace(); - } - } - - for (Plugin plugin : connector.getPluginManager().getPlugins()) { - connector.getPluginManager().enablePlugin(plugin); - } - } - - public void loadPlugin(Plugin plugin) { - plugin.onLoad(); - } - - public void enablePlugin(Plugin plugin) { - plugin.setEnabled(true); - plugin.onEnable(); - } - - public void disablePlugin(Plugin plugin) { - plugin.setEnabled(false); - plugin.onDisable(); - } -} diff --git a/connector/src/main/java/org/geysermc/connector/plugin/GeyserPluginManager.java b/connector/src/main/java/org/geysermc/connector/plugin/GeyserPluginManager.java deleted file mode 100644 index 470dd23e0..000000000 --- a/connector/src/main/java/org/geysermc/connector/plugin/GeyserPluginManager.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2019 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.connector.plugin; - -import lombok.Getter; -import org.geysermc.api.events.EventHandler; -import org.geysermc.api.events.Listener; -import org.geysermc.api.plugin.Plugin; -import org.geysermc.api.plugin.PluginManager; - -import java.awt.*; -import java.lang.reflect.Method; -import java.util.*; -import java.util.List; - -public class GeyserPluginManager implements PluginManager { - private final List EVENTS = new ArrayList<>(); - - @Getter - private GeyserPluginLoader loader; - - private Map plugins = new HashMap<>(); - - public GeyserPluginManager(GeyserPluginLoader loader) { - this.loader = loader; - } - - public void loadPlugin(Plugin plugin) { - loader.loadPlugin(plugin); - plugins.put(plugin.getName(), plugin); - } - - public void unloadPlugin(Plugin plugin) { - plugins.remove(plugin); - } - - public void enablePlugin(Plugin plugin) { - loader.enablePlugin(plugin); - } - - public void disablePlugin(Plugin plugin) { - loader.disablePlugin(plugin); - } - - public Set getPlugins() { - return new HashSet<>(plugins.values()); - } - - @Override - public void registerEventListener(Plugin p, Listener l) { - try { - Class clazz = l.getClass(); - - for(Method m : clazz.getMethods()) { - if(m.getAnnotation(EventHandler.class) != null) { - PluginListener listener = new PluginListener(); - - listener.plugin = p; - listener.listener = l; - listener.clazz = m.getParameterTypes()[0]; - listener.priority = m.getAnnotation(EventHandler.class).value(); - listener.run = m; - EVENTS.add(listener); - } - } - } catch (Exception e) { - // - } - } - - @Override - public void runEvent(Object o) { - for(EventHandler.EventPriority p : EventHandler.EventPriority.values()) { - for (PluginListener listener : EVENTS) { - listener.runIfNeeded(p, o); - } - } - } - - @Override - public Plugin getPluginByName(String name) { - return plugins.get(name); - } -} \ No newline at end of file diff --git a/connector/src/main/java/org/geysermc/connector/plugin/PluginListener.java b/connector/src/main/java/org/geysermc/connector/plugin/PluginListener.java deleted file mode 100644 index 605572f19..000000000 --- a/connector/src/main/java/org/geysermc/connector/plugin/PluginListener.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.geysermc.connector.plugin; - -import org.geysermc.api.events.EventHandler; -import org.geysermc.api.events.Listener; -import org.geysermc.api.plugin.Plugin; -import org.geysermc.connector.console.GeyserLogger; - -import java.lang.reflect.Method; - -public class PluginListener { - Method run; - Plugin plugin; - Listener listener; - Class clazz; - EventHandler.EventPriority priority; - - void runIfNeeded(EventHandler.EventPriority p, Object o) { - if(p.equals(priority) && clazz.isInstance(o)) { - try { - run.invoke(listener, o); - } catch (ReflectiveOperationException ex) { - GeyserLogger.DEFAULT.severe("Exception while trying to run event! Contact the maintainer of " + plugin.getName()); - - ex.printStackTrace(); - } - } - } -} diff --git a/connector/src/main/java/org/geysermc/connector/plugin/PluginYML.java b/connector/src/main/java/org/geysermc/connector/plugin/PluginYML.java deleted file mode 100644 index 154253692..000000000 --- a/connector/src/main/java/org/geysermc/connector/plugin/PluginYML.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2019 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.connector.plugin; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class PluginYML { - - @JsonProperty("name") - String name; - - @JsonProperty("version") - String version; - - @JsonProperty("main") - String main; -} diff --git a/connector/src/main/java/org/geysermc/connector/scoreboard/Scoreboard.java b/connector/src/main/java/org/geysermc/connector/scoreboard/Scoreboard.java index bb014ad4f..5bcebfb51 100644 --- a/connector/src/main/java/org/geysermc/connector/scoreboard/Scoreboard.java +++ b/connector/src/main/java/org/geysermc/connector/scoreboard/Scoreboard.java @@ -31,7 +31,7 @@ import com.nukkitx.protocol.bedrock.packet.RemoveObjectivePacket; import com.nukkitx.protocol.bedrock.packet.SetDisplayObjectivePacket; import com.nukkitx.protocol.bedrock.packet.SetScorePacket; import lombok.Getter; -import org.geysermc.api.Geyser; + import org.geysermc.connector.network.session.GeyserSession; import java.util.*; @@ -77,7 +77,7 @@ public class Scoreboard { public Team registerNewTeam(String teamName, Set players) { if (teams.containsKey(teamName)) { - Geyser.getLogger().info("Ignoring team " + teamName + ". It overrides without removing old team."); + session.getConnector().getLogger().info("Ignoring team " + teamName + ". It overrides without removing old team."); return getTeam(teamName); } @@ -120,7 +120,7 @@ public class Scoreboard { for (String objectiveId : new ArrayList<>(objectives.keySet())) { Objective objective = objectives.get(objectiveId); if (objective.isTemp()) { - Geyser.getLogger().debug("Ignoring temp Scoreboard Objective '"+ objectiveId +'\''); + session.getConnector().getLogger().debug("Ignoring temp Scoreboard Objective '"+ objectiveId +'\''); continue; } diff --git a/connector/src/main/java/org/geysermc/connector/utils/InventoryUtils.java b/connector/src/main/java/org/geysermc/connector/utils/InventoryUtils.java index a56b6ed7f..037bff4be 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/InventoryUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/InventoryUtils.java @@ -9,7 +9,7 @@ import com.github.steveice10.packetlib.packet.Packet; import com.nukkitx.protocol.bedrock.data.ContainerId; import com.nukkitx.protocol.bedrock.data.ItemData; import com.nukkitx.protocol.bedrock.packet.InventoryContentPacket; -import org.geysermc.api.Geyser; +import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.inventory.Inventory; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.TranslatorsInit; @@ -51,7 +51,7 @@ public class InventoryUtils { InventoryTranslator translator = TranslatorsInit.getInventoryTranslator(); translator.prepareInventory(session, inventory); - Geyser.getGeneralThreadPool().schedule(() -> { + GeyserConnector.getInstance().getGeneralThreadPool().schedule(() -> { List packets = session.getInventoryCache().getCachedPackets().get(inventory.getId()); packets.forEach(itemPacket -> { if (itemPacket != null) { diff --git a/connector/src/main/java/org/geysermc/connector/utils/LoginEncryptionUtils.java b/connector/src/main/java/org/geysermc/connector/utils/LoginEncryptionUtils.java index b94f13cdc..ea799df66 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/LoginEncryptionUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/LoginEncryptionUtils.java @@ -9,17 +9,18 @@ import com.nukkitx.network.util.Preconditions; import com.nukkitx.protocol.bedrock.packet.LoginPacket; import com.nukkitx.protocol.bedrock.packet.ServerToClientHandshakePacket; import com.nukkitx.protocol.bedrock.util.EncryptionUtils; + import net.minidev.json.JSONObject; -import org.geysermc.api.events.player.PlayerFormResponseEvent; -import org.geysermc.api.window.CustomFormBuilder; -import org.geysermc.api.window.CustomFormWindow; -import org.geysermc.api.window.FormWindow; -import org.geysermc.api.window.component.InputComponent; -import org.geysermc.api.window.component.LabelComponent; -import org.geysermc.api.window.response.CustomFormResponse; + +import org.geysermc.common.window.CustomFormBuilder; +import org.geysermc.common.window.CustomFormWindow; +import org.geysermc.common.window.FormWindow; +import org.geysermc.common.window.component.InputComponent; +import org.geysermc.common.window.component.LabelComponent; +import org.geysermc.common.window.response.CustomFormResponse; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.session.auth.BedrockAuthData; +import org.geysermc.connector.network.session.auth.AuthData; import org.geysermc.connector.network.session.cache.WindowCache; import javax.crypto.SecretKey; @@ -86,7 +87,7 @@ public class LoginEncryptionUtils { } JSONObject extraData = (JSONObject) jwt.getPayload().toJSONObject().get("extraData"); - session.setAuthenticationData(new BedrockAuthData(extraData.getAsString("displayName"), UUID.fromString(extraData.getAsString("identity")), extraData.getAsString("XUID"))); + session.setAuthenticationData(new AuthData(extraData.getAsString("displayName"), UUID.fromString(extraData.getAsString("identity")), extraData.getAsString("XUID"))); if (payload.get("identityPublicKey").getNodeType() != JsonNodeType.STRING) { throw new RuntimeException("Identity Public Key was not found!"); @@ -140,17 +141,13 @@ public class LoginEncryptionUtils { FormWindow window = windowCache.getWindows().remove(AUTH_FORM_ID); window.setResponse(formData.trim()); - if (session.isLoggedIn()) { - PlayerFormResponseEvent event = new PlayerFormResponseEvent(session, AUTH_FORM_ID, window); - connector.getPluginManager().runEvent(event); - } else { + if (!session.isLoggedIn()) { if (window instanceof CustomFormWindow) { CustomFormWindow customFormWindow = (CustomFormWindow) window; if (!customFormWindow.getTitle().equals("Login")) return false; CustomFormResponse response = (CustomFormResponse) customFormWindow.getResponse(); - if (response != null) { String email = response.getInputResponses().get(2); String password = response.getInputResponses().get(3); @@ -158,7 +155,6 @@ public class LoginEncryptionUtils { session.authenticate(email, password); } - // TODO should we clear the window cache in all cases or just if not already logged in? // Clear windows so authentication data isn't accidentally cached windowCache.getWindows().clear(); } diff --git a/connector/src/main/java/org/geysermc/connector/utils/SkinProvider.java b/connector/src/main/java/org/geysermc/connector/utils/SkinProvider.java index f3bb4319d..05703301a 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/SkinProvider.java +++ b/connector/src/main/java/org/geysermc/connector/utils/SkinProvider.java @@ -2,16 +2,16 @@ package org.geysermc.connector.utils; import com.google.gson.Gson; import com.google.gson.GsonBuilder; + import lombok.AllArgsConstructor; import lombok.Getter; -import org.geysermc.api.Geyser; + import org.geysermc.connector.GeyserConnector; import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; -import java.io.IOException; import java.net.URL; import java.util.Map; import java.util.UUID; @@ -19,7 +19,7 @@ import java.util.concurrent.*; public class SkinProvider { public static final Gson GSON = new GsonBuilder().create(); - public static final boolean ALLOW_THIRD_PARTY_CAPES = ((GeyserConnector)Geyser.getConnector()).getConfig().isAllowThirdPartyCapes(); + public static final boolean ALLOW_THIRD_PARTY_CAPES = GeyserConnector.getInstance().getConfig().isAllowThirdPartyCapes(); private static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(ALLOW_THIRD_PARTY_CAPES ? 21 : 14); public static final byte[] STEVE_SKIN = new ProvidedSkin("bedrock/skin/skin_steve.png").getSkin(); @@ -58,7 +58,7 @@ public class SkinProvider { getOrDefault(requestCape(capeUrl, false), EMPTY_CAPE, 5) ); - Geyser.getLogger().debug("Took " + (System.currentTimeMillis() - time) + "ms for " + playerId); + GeyserConnector.getInstance().getLogger().debug("Took " + (System.currentTimeMillis() - time) + "ms for " + playerId); return skinAndCape; }, EXECUTOR_SERVICE); } @@ -162,7 +162,7 @@ public class SkinProvider { private static byte[] requestImage(String imageUrl, boolean cape) throws Exception { BufferedImage image = ImageIO.read(new URL(imageUrl)); - Geyser.getLogger().debug("Downloaded " + imageUrl); + GeyserConnector.getInstance().getLogger().debug("Downloaded " + imageUrl); if (cape) { image = image.getWidth() > 64 ? scale(image) : image; @@ -173,8 +173,7 @@ public class SkinProvider { image = newImage; } - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(image.getWidth() * 4 + image.getHeight() * 4); - try { + try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(image.getWidth() * 4 + image.getHeight() * 4)) { for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { int rgba = image.getRGB(x, y); @@ -186,10 +185,6 @@ public class SkinProvider { } image.flush(); return outputStream.toByteArray(); - } finally { - try { - outputStream.close(); - } catch (IOException ignored) {} } } diff --git a/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java b/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java index 91910c961..3d3e27fef 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java @@ -5,9 +5,10 @@ import com.google.gson.JsonObject; import com.nukkitx.protocol.bedrock.data.ImageData; import com.nukkitx.protocol.bedrock.data.SerializedSkin; import com.nukkitx.protocol.bedrock.packet.PlayerListPacket; + import lombok.AllArgsConstructor; import lombok.Getter; -import org.geysermc.api.Geyser; + import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.network.session.GeyserSession; @@ -96,8 +97,8 @@ public class SkinUtils { return new GameProfileData(skinUrl, capeUrl, isAlex); } catch (Exception exception) { - if (!((GeyserConnector) Geyser.getConnector()).getConfig().getRemote().getAuthType().equals("offline")) { - Geyser.getLogger().debug("Got invalid texture data for " + profile.getName() + " " + exception.getMessage()); + if (!GeyserConnector.getInstance().getConfig().getRemote().getAuthType().equals("offline")) { + GeyserConnector.getInstance().getLogger().debug("Got invalid texture data for " + profile.getName() + " " + exception.getMessage()); } // return default skin with default cape when texture data is invalid return new GameProfileData(SkinProvider.EMPTY_SKIN.getTextureUrl(), SkinProvider.EMPTY_CAPE.getTextureUrl(), false); @@ -107,7 +108,7 @@ public class SkinUtils { public static void requestAndHandleSkinAndCape(PlayerEntity entity, GeyserSession session, Consumer skinAndCapeConsumer) { - Geyser.getGeneralThreadPool().execute(() -> { + GeyserConnector.getInstance().getGeneralThreadPool().execute(() -> { GameProfileData data = GameProfileData.from(entity.getProfile()); SkinProvider.requestSkinAndCape(entity.getUuid(), data.getSkinUrl(), data.getCapeUrl()) @@ -151,7 +152,7 @@ public class SkinUtils { } } } catch (Exception e) { - Geyser.getLogger().error("Failed getting skin for " + entity.getUuid(), e); + GeyserConnector.getInstance().getLogger().error("Failed getting skin for " + entity.getUuid(), e); } if (skinAndCapeConsumer != null) skinAndCapeConsumer.accept(skinAndCape); diff --git a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java index 74a1be96f..1b1ab6b22 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java +++ b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java @@ -9,8 +9,8 @@ import com.nukkitx.protocol.bedrock.packet.StartGamePacket; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; + import org.geysermc.connector.GeyserConnector; -import org.geysermc.connector.console.GeyserLogger; import org.geysermc.connector.network.translators.block.BlockEntry; import org.geysermc.connector.network.translators.item.ItemEntry; import org.geysermc.connector.world.GlobalBlockPalette; @@ -40,7 +40,7 @@ public class Toolbox { blocksTag = (ListTag) nbtInputStream.readTag(); nbtInputStream.close(); } catch (Exception ex) { - GeyserLogger.DEFAULT.warning("Failed to get blocks from runtime block states, please report this error!"); + GeyserConnector.getInstance().getLogger().warning("Failed to get blocks from runtime block states, please report this error!"); throw new AssertionError(ex); } @@ -100,7 +100,7 @@ public class Toolbox { int blockIndex = 0; for (Map.Entry> itemEntry : blocks.entrySet()) { if (!blockIdToIdentifier.containsKey(itemEntry.getValue().get("bedrock_identifier"))) { - GeyserLogger.DEFAULT.debug("Mapping " + itemEntry.getValue().get("bedrock_identifier") + " was not found for bedrock edition!"); + GeyserConnector.getInstance().getLogger().debug("Mapping " + itemEntry.getValue().get("bedrock_identifier") + " was not found for bedrock edition!"); BLOCK_ENTRIES.put(blockIndex, new BlockEntry(itemEntry.getKey(), blockIndex, 248, 0)); // update block } else { BLOCK_ENTRIES.put(blockIndex, new BlockEntry(itemEntry.getKey(), blockIndex, blockIdToIdentifier.get(itemEntry.getValue().get("bedrock_identifier")), (int) itemEntry.getValue().get("bedrock_data"))); diff --git a/pom.xml b/pom.xml index 2f0908c50..fc1ead33b 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,6 @@ - api bootstrap common connector From 0960ab2365a1fd19b9426ff7459de6caf64065dd Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sat, 21 Dec 2019 11:38:45 -0600 Subject: [PATCH 20/45] Close bedrock server upon shutdown --- .../main/java/org/geysermc/connector/GeyserConnector.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index 821c84a97..87337f63c 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -76,6 +76,8 @@ public class GeyserConnector { private final ScheduledExecutorService generalThreadPool; private PingPassthroughThread passthroughThread; + private BedrockServer bedrockServer; + private Metrics metrics; private GeyserConnector(IGeyserConfiguration config, IGeyserLogger logger) { @@ -106,7 +108,7 @@ public class GeyserConnector { if (config.isPingPassthrough()) generalThreadPool.scheduleAtFixedRate(passthroughThread, 1, 1, TimeUnit.SECONDS); - BedrockServer bedrockServer = new BedrockServer(new InetSocketAddress(config.getBedrock().getAddress(), config.getBedrock().getPort())); + bedrockServer = new BedrockServer(new InetSocketAddress(config.getBedrock().getAddress(), config.getBedrock().getPort())); bedrockServer.setHandler(new ConnectorServerEventHandler(this)); bedrockServer.bind().whenComplete((avoid, throwable) -> { if (throwable == null) { @@ -129,10 +131,11 @@ public class GeyserConnector { } public void shutdown() { - logger.info("Shutting down connector."); + logger.info("Shutting down Geyser."); shuttingDown = true; generalThreadPool.shutdown(); + bedrockServer.close(); } public void addPlayer(GeyserSession player) { From 1fbbb876893e2acfacc35b39bd65881138b8aed1 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sat, 21 Dec 2019 11:53:19 -0600 Subject: [PATCH 21/45] Add PlatformType enum and add bStats platform chart --- .../platform/bukkit/GeyserBukkitPlugin.java | 3 ++- .../platform/bungeecord/GeyserBungeePlugin.java | 3 ++- .../platform/standalone/GeyserBootstrap.java | 3 ++- .../java/org/geysermc/common/PlatformType.java | 17 +++++++++++++++++ .../org/geysermc/connector/GeyserConnector.java | 10 +++++++--- 5 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 common/src/main/java/org/geysermc/common/PlatformType.java diff --git a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitPlugin.java b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitPlugin.java index d3b87e8c3..6bb77df1a 100644 --- a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitPlugin.java +++ b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitPlugin.java @@ -26,6 +26,7 @@ package org.geysermc.platform.bukkit; import org.bukkit.plugin.java.JavaPlugin; +import org.geysermc.common.PlatformType; import org.geysermc.connector.GeyserConnector; import org.geysermc.common.bootstrap.IGeyserBootstrap; @@ -49,7 +50,7 @@ public class GeyserBukkitPlugin extends JavaPlugin implements IGeyserBootstrap { geyserLogger = new GeyserBukkitLogger(getLogger(), geyserConfig.isDebugMode()); - GeyserConnector.start(this); + GeyserConnector.start(PlatformType.BUKKIT, this); } @Override diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java index 4cbf88326..bf7cfff8a 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java @@ -30,6 +30,7 @@ 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.GeyserConnector; import org.geysermc.common.bootstrap.IGeyserBootstrap; @@ -86,7 +87,7 @@ public class GeyserBungeePlugin extends Plugin implements IGeyserBootstrap { geyserLogger = new GeyserBungeeLogger(getLogger(), geyserConfig.isDebugMode()); - GeyserConnector.start(this); + GeyserConnector.start(PlatformType.BUNGEECORD, this); } @Override diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java index 45d71bd6f..a99b2434e 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java @@ -26,6 +26,7 @@ package org.geysermc.platform.standalone; import org.fusesource.jansi.AnsiConsole; +import org.geysermc.common.PlatformType; import org.geysermc.common.bootstrap.IGeyserBootstrap; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.utils.FileUtils; @@ -62,7 +63,7 @@ public class GeyserBootstrap implements IGeyserBootstrap { System.exit(0); } - GeyserConnector connector = GeyserConnector.start(this); + GeyserConnector connector = GeyserConnector.start(PlatformType.STANDALONE, this); ConsoleCommandReader consoleReader = new ConsoleCommandReader(connector); consoleReader.startConsole(); diff --git a/common/src/main/java/org/geysermc/common/PlatformType.java b/common/src/main/java/org/geysermc/common/PlatformType.java new file mode 100644 index 000000000..fa6f57fda --- /dev/null +++ b/common/src/main/java/org/geysermc/common/PlatformType.java @@ -0,0 +1,17 @@ +package org.geysermc.common; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum PlatformType { + + BUKKIT("Bukkit"), + BUNGEECORD("BungeeCord"), + SPONGE("Sponge"), + STANDALONE("Standalone"), + VELOCITY("Velocity"); + + private String platformName; +} diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index 87337f63c..004afe506 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -31,6 +31,7 @@ import com.nukkitx.protocol.bedrock.v388.Bedrock_v388; import lombok.Getter; +import org.geysermc.common.PlatformType; import org.geysermc.common.bootstrap.IGeyserBootstrap; import org.geysermc.common.logger.IGeyserLogger; import org.geysermc.connector.command.GeyserCommandMap; @@ -77,15 +78,17 @@ public class GeyserConnector { private PingPassthroughThread passthroughThread; private BedrockServer bedrockServer; + private PlatformType platformType; private Metrics metrics; - private GeyserConnector(IGeyserConfiguration config, IGeyserLogger logger) { + private GeyserConnector(PlatformType platformType, IGeyserConfiguration config, IGeyserLogger logger) { long startupTime = System.currentTimeMillis(); instance = this; this.logger = logger; + this.platformType = platformType; logger.info("******************************************"); logger.info(""); @@ -124,6 +127,7 @@ public class GeyserConnector { metrics.addCustomChart(new Metrics.SingleLineChart("servers", () -> 1)); metrics.addCustomChart(new Metrics.SingleLineChart("players", players::size)); metrics.addCustomChart(new Metrics.SimplePie("authMode", config.getRemote()::getAuthType)); + metrics.addCustomChart(new Metrics.SimplePie("platform", platformType::getPlatformName)); } double completeTime = (System.currentTimeMillis() - startupTime) / 1000D; @@ -150,8 +154,8 @@ public class GeyserConnector { players.remove(player.getSocketAddress()); } - public static GeyserConnector start(IGeyserBootstrap bootstrap) { - return new GeyserConnector(bootstrap.getGeyserConfig(), bootstrap.getGeyserLogger()); + public static GeyserConnector start(PlatformType platformType, IGeyserBootstrap bootstrap) { + return new GeyserConnector(platformType, bootstrap.getGeyserConfig(), bootstrap.getGeyserLogger()); } public static void stop() { From 70fd9867f54139dbace6ee3d99c92d68b83df456 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sat, 21 Dec 2019 16:18:34 -0600 Subject: [PATCH 22/45] Add Sponge platform bootstrap --- .../platform/bukkit/GeyserBukkitLogger.java | 8 +- bootstrap/pom.xml | 2 +- bootstrap/sponge/pom.xml | 84 +++++++++ .../sponge/GeyserSpongeConfiguration.java | 161 ++++++++++++++++++ .../platform/sponge/GeyserSpongeLogger.java | 54 ++++++ .../platform/sponge/GeyserSpongePlugin.java | 87 ++++++++++ .../geysermc/connector/utils/FileUtils.java | 9 +- 7 files changed, 396 insertions(+), 9 deletions(-) create mode 100644 bootstrap/sponge/pom.xml create mode 100644 bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java create mode 100644 bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeLogger.java create mode 100644 bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongePlugin.java diff --git a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitLogger.java b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitLogger.java index 95214972f..05fd2c6c8 100644 --- a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitLogger.java +++ b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitLogger.java @@ -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); diff --git a/bootstrap/pom.xml b/bootstrap/pom.xml index 7cc7e2ba6..b826f61ac 100644 --- a/bootstrap/pom.xml +++ b/bootstrap/pom.xml @@ -33,7 +33,7 @@ bukkit bungeecord - + sponge standalone diff --git a/bootstrap/sponge/pom.xml b/bootstrap/sponge/pom.xml new file mode 100644 index 000000000..0e8222730 --- /dev/null +++ b/bootstrap/sponge/pom.xml @@ -0,0 +1,84 @@ + + + 4.0.0 + + org.geysermc + bootstrap-parent + 1.0-SNAPSHOT + ../ + + bootstrap-sponge + + + org.geysermc + connector + 1.0-SNAPSHOT + compile + + + org.spongepowered + spongeapi + 7.1.0 + provided + + + + ${outputName}-Sponge + ../../target + + + src/main/resources/ + true + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 + + + package + + shade + + + + + com.fasterxml.jackson + org.geysermc.platform.sponge.shaded.jackson + + + io.netty + org.geysermc.platform.sponge.shaded.netty + + + true + + + + + + + *:* + + META-INF/* + + + + + + com.google.code.gson:* + org.yaml:* + com.nukkitx:fastutil-lite:* + org.slf4j:* + org.ow2.asm:* + + + + + + + \ No newline at end of file diff --git a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java new file mode 100644 index 000000000..8ae4c31df --- /dev/null +++ b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java @@ -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 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) 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 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"); + } + } +} diff --git a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeLogger.java b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeLogger.java new file mode 100644 index 000000000..b183d4586 --- /dev/null +++ b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeLogger.java @@ -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; + } +} diff --git a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongePlugin.java b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongePlugin.java new file mode 100644 index 000000000..76a89cfb6 --- /dev/null +++ b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongePlugin.java @@ -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(); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/utils/FileUtils.java b/connector/src/main/java/org/geysermc/connector/utils/FileUtils.java index e28e3662a..ff3793f35 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/FileUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/FileUtils.java @@ -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 loadConfig(File src, Class valueType) throws IOException { ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory()); return objectMapper.readValue(src, valueType); } public static File fileOrCopiedFromResource(String name, Function s) throws IOException { - File file = new File(name); + return fileOrCopiedFromResource(new File(name), name, s); + } + + public static File fileOrCopiedFromResource(File file, String name, Function 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; } - - } From 7354819451548b4add4b32ea859eabdb5391cfb9 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sat, 21 Dec 2019 16:19:04 -0600 Subject: [PATCH 23/45] Add license headers to Sponge classes --- .../sponge/GeyserSpongeConfiguration.java | 25 +++++++++++++++++++ .../platform/sponge/GeyserSpongeLogger.java | 25 +++++++++++++++++++ .../platform/sponge/GeyserSpongePlugin.java | 25 +++++++++++++++++++ 3 files changed, 75 insertions(+) diff --git a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java index 8ae4c31df..9bb8a3668 100644 --- a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java +++ b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java @@ -1,3 +1,28 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + package org.geysermc.platform.sponge; import lombok.AllArgsConstructor; diff --git a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeLogger.java b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeLogger.java index b183d4586..1df7fbf9b 100644 --- a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeLogger.java +++ b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeLogger.java @@ -1,3 +1,28 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + package org.geysermc.platform.sponge; import lombok.AllArgsConstructor; diff --git a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongePlugin.java b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongePlugin.java index 76a89cfb6..ecac6353c 100644 --- a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongePlugin.java +++ b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongePlugin.java @@ -1,3 +1,28 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + package org.geysermc.platform.sponge; import com.google.inject.Inject; From b70edac3cc64db53a7d65fb73d18e98d55c88b74 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sat, 21 Dec 2019 16:19:32 -0600 Subject: [PATCH 24/45] Update Geyser help command message on startup --- .../src/main/java/org/geysermc/connector/GeyserConnector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index 004afe506..b82808235 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -131,7 +131,7 @@ public class GeyserConnector { } double completeTime = (System.currentTimeMillis() - startupTime) / 1000D; - logger.info(String.format("Done (%ss)! Run /help for help!", new DecimalFormat("#.###").format(completeTime))); + logger.info(String.format("Done (%ss)! Run /geyser help for help!", new DecimalFormat("#.###").format(completeTime))); } public void shutdown() { From 145784b18d811aba3e3868c3c5a9eababaadbe30 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Tue, 31 Dec 2019 17:00:06 -0600 Subject: [PATCH 25/45] Shade in netty with BungeeCord module --- bootstrap/bungeecord/pom.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bootstrap/bungeecord/pom.xml b/bootstrap/bungeecord/pom.xml index 58525b64c..01757ff5c 100644 --- a/bootstrap/bungeecord/pom.xml +++ b/bootstrap/bungeecord/pom.xml @@ -50,6 +50,10 @@ net.md_5.bungee.jni org.geysermc.platform.bungeecord.shaded.jni + + io.netty + org.geysermc.platform.bungeecord.shaded.netty + true @@ -68,7 +72,6 @@ com.google.code.gson:* org.yaml:* - io.netty:* From 7d14d079eff8c2f9924fe6478b2246565cabcacb Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Thu, 2 Jan 2020 12:37:30 -0600 Subject: [PATCH 26/45] Fix NPE with ServerInfo being null for ping passthrough --- .../geysermc/connector/network/ConnectorServerEventHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java b/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java index e8d0d9d10..d460f585a 100644 --- a/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java @@ -65,7 +65,7 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler { pong.setProtocolVersion(GeyserConnector.BEDROCK_1_14_PROTOCOL_VERSION); pong.setVersion(GeyserConnector.BEDROCK_PACKET_CODEC.getMinecraftVersion()); pong.setIpv4Port(config.getBedrock().getPort()); - if (connector.getConfig().isPingPassthrough()) { + if (connector.getConfig().isPingPassthrough() && serverInfo != null) { pong.setMotd(MessageUtils.getBedrockMessage(serverInfo.getDescription())); pong.setSubMotd(config.getBedrock().getMotd2()); pong.setPlayerCount(serverInfo.getPlayerInfo().getOnlinePlayers()); From 5c7755b772dba5a1f306336a9748c4df1fc2401a Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sat, 18 Jan 2020 16:38:40 -0600 Subject: [PATCH 27/45] Shade netty into Bukkit jar --- bootstrap/bukkit/pom.xml | 7 ++++++- connector/src/main/resources/mappings | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/bootstrap/bukkit/pom.xml b/bootstrap/bukkit/pom.xml index 46e7a14e9..0b091a543 100644 --- a/bootstrap/bukkit/pom.xml +++ b/bootstrap/bukkit/pom.xml @@ -45,6 +45,12 @@ shade + + + io.netty + org.geysermc.platform.bukkit.shaded.netty + + true @@ -62,7 +68,6 @@ com.google.code.gson:* org.yaml:* - io.netty:* diff --git a/connector/src/main/resources/mappings b/connector/src/main/resources/mappings index b9308a646..1ad8a1941 160000 --- a/connector/src/main/resources/mappings +++ b/connector/src/main/resources/mappings @@ -1 +1 @@ -Subproject commit b9308a64699fabb7510a05d3b270ccd6dd52b635 +Subproject commit 1ad8a19417391710d34d72214e3aa430f84740cd From 88fc3cf8437b45fa1b629e34e0f860295af44311 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sat, 18 Jan 2020 16:48:46 -0600 Subject: [PATCH 28/45] Fix building --- .../translators/bedrock/BedrockPlayerInitializedTranslator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java index e30ef2d77..3a00d8ea2 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java @@ -40,7 +40,7 @@ public class BedrockPlayerInitializedTranslator extends PacketTranslator Date: Sat, 18 Jan 2020 16:50:17 -0600 Subject: [PATCH 29/45] Fix auth type check from merge conflict --- .../bedrock/BedrockPlayerInitializedTranslator.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java index 3a00d8ea2..32697f0ea 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java @@ -26,6 +26,8 @@ package org.geysermc.connector.network.translators.bedrock; import com.nukkitx.protocol.bedrock.packet.SetLocalPlayerAsInitializedPacket; + +import org.geysermc.common.AuthType; import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; @@ -38,7 +40,7 @@ public class BedrockPlayerInitializedTranslator extends PacketTranslator Date: Sat, 18 Jan 2020 17:28:27 -0600 Subject: [PATCH 30/45] Attempt to archive all artifacts for Jenkins --- Jenkinsfile | 2 +- bootstrap/bukkit/pom.xml | 1 - bootstrap/bungeecord/pom.xml | 1 - bootstrap/sponge/pom.xml | 1 - bootstrap/standalone/pom.xml | 1 - 5 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1b908bdf0..3556720a7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -15,7 +15,7 @@ pipeline { } post { success { - archiveArtifacts artifacts: 'target/*.jar', fingerprint: true + archiveArtifacts artifacts: 'target/*.jar, bootstrap/bukkit/target/*.jar, bootstrap/bungeecord/target/*.jar, bootstrap/sponge/target/*.jar, bootstrap/standalone/target/*.jar', fingerprint: true } } } diff --git a/bootstrap/bukkit/pom.xml b/bootstrap/bukkit/pom.xml index 0b091a543..0f4d32885 100644 --- a/bootstrap/bukkit/pom.xml +++ b/bootstrap/bukkit/pom.xml @@ -26,7 +26,6 @@ ${outputName}-Bukkit - ../../target src/main/resources/ diff --git a/bootstrap/bungeecord/pom.xml b/bootstrap/bungeecord/pom.xml index 01757ff5c..317e80cb5 100644 --- a/bootstrap/bungeecord/pom.xml +++ b/bootstrap/bungeecord/pom.xml @@ -26,7 +26,6 @@ ${outputName}-BungeeCord - ../../target src/main/resources/ diff --git a/bootstrap/sponge/pom.xml b/bootstrap/sponge/pom.xml index 0e8222730..1b1dd8e94 100644 --- a/bootstrap/sponge/pom.xml +++ b/bootstrap/sponge/pom.xml @@ -26,7 +26,6 @@ ${outputName}-Sponge - ../../target src/main/resources/ diff --git a/bootstrap/standalone/pom.xml b/bootstrap/standalone/pom.xml index 05e63ad73..2e767de5e 100644 --- a/bootstrap/standalone/pom.xml +++ b/bootstrap/standalone/pom.xml @@ -45,7 +45,6 @@ ${outputName} - ../../target org.apache.maven.plugins From ba724bb7d67f01c7b90d6abea0f23922204f51da Mon Sep 17 00:00:00 2001 From: Tim203 Date: Sat, 25 Jan 2020 13:10:58 +0100 Subject: [PATCH 31/45] Added the Nintendo Switch as DeviceOS --- .../connector/network/session/auth/BedrockClientData.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/auth/BedrockClientData.java b/connector/src/main/java/org/geysermc/connector/network/session/auth/BedrockClientData.java index 574ba5447..3793e5227 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/auth/BedrockClientData.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/auth/BedrockClientData.java @@ -78,7 +78,8 @@ public class BedrockClientData { WIN32, DEDICATED, ORBIS, - NX + NX, + SWITCH } public enum InputMode { From cc3cf702572ca81707e129f0172ad39810e0540e Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sat, 25 Jan 2020 22:59:00 -0600 Subject: [PATCH 32/45] Search for key in Geyser plugin folder in plugin versions --- .../platform/bukkit/GeyserBukkitConfiguration.java | 9 ++++++--- .../org/geysermc/platform/bukkit/GeyserBukkitPlugin.java | 2 +- .../platform/bungeecord/GeyserBungeeConfiguration.java | 9 ++++++--- .../geysermc/platform/bungeecord/GeyserBungeePlugin.java | 2 +- .../platform/sponge/GeyserSpongeConfiguration.java | 9 ++++++--- .../org/geysermc/platform/sponge/GeyserSpongePlugin.java | 2 +- .../java/org/geysermc/common/IGeyserConfiguration.java | 3 ++- .../connector/network/session/GeyserSession.java | 2 +- 8 files changed, 24 insertions(+), 14 deletions(-) diff --git a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java index 8a2a7a9a0..f4c4b008c 100644 --- a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java +++ b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java @@ -28,12 +28,14 @@ package org.geysermc.platform.bukkit; import org.bukkit.configuration.file.FileConfiguration; import org.geysermc.common.IGeyserConfiguration; +import java.io.File; import java.util.HashMap; import java.util.Map; public class GeyserBukkitConfiguration implements IGeyserConfiguration { private FileConfiguration config; + private File dataFolder; private BukkitBedrockConfiguration bedrockConfig; private BukkitRemoteConfiguration remoteConfig; @@ -41,7 +43,8 @@ public class GeyserBukkitConfiguration implements IGeyserConfiguration { private Map userAuthInfo = new HashMap<>(); - public GeyserBukkitConfiguration(FileConfiguration config) { + public GeyserBukkitConfiguration(File dataFolder, FileConfiguration config) { + this.dataFolder = dataFolder; this.config = config; bedrockConfig = new BukkitBedrockConfiguration(); @@ -97,8 +100,8 @@ public class GeyserBukkitConfiguration implements IGeyserConfiguration { } @Override - public String getFloodgateKeyFile() { - return config.getString("floodgate-key-file", "public-key.pem"); + public File getFloodgateKeyFile() { + return new File(dataFolder.toString() + config.getString("floodgate-key-file", "public-key.pem")); } @Override diff --git a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitPlugin.java b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitPlugin.java index 6bb77df1a..21f130da3 100644 --- a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitPlugin.java +++ b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitPlugin.java @@ -41,7 +41,7 @@ public class GeyserBukkitPlugin extends JavaPlugin implements IGeyserBootstrap { public void onEnable() { saveDefaultConfig(); - geyserConfig = new GeyserBukkitConfiguration(getConfig()); + geyserConfig = new GeyserBukkitConfiguration(getDataFolder(), getConfig()); if (geyserConfig.getMetrics().getUniqueId().equals("generateduuid")) { getConfig().set("metrics.uuid", UUID.randomUUID().toString()); diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java index 43c77733b..0aaf714b3 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java @@ -29,11 +29,13 @@ import net.md_5.bungee.config.Configuration; import org.geysermc.common.IGeyserConfiguration; +import java.io.File; import java.util.HashMap; import java.util.Map; public class GeyserBungeeConfiguration implements IGeyserConfiguration { + private File dataFolder; private Configuration config; private BungeeBedrockConfiguration bedrockConfig; @@ -42,7 +44,8 @@ public class GeyserBungeeConfiguration implements IGeyserConfiguration { private Map userAuthInfo = new HashMap<>(); - public GeyserBungeeConfiguration(Configuration config) { + public GeyserBungeeConfiguration(File dataFolder, Configuration config) { + this.dataFolder = dataFolder; this.config = config; bedrockConfig = new BungeeBedrockConfiguration(); @@ -98,8 +101,8 @@ public class GeyserBungeeConfiguration implements IGeyserConfiguration { } @Override - public String getFloodgateKeyFile() { - return config.getString("floodgate-key-file", "public-key.pem"); + public File getFloodgateKeyFile() { + return new File(dataFolder, config.getString("floodgate-key-file", "public-key.pem")); } @Override diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java index bf7cfff8a..b396ede5d 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java @@ -73,7 +73,7 @@ public class GeyserBungeePlugin extends Plugin implements IGeyserBootstrap { return; } - geyserConfig = new GeyserBungeeConfiguration(configuration); + geyserConfig = new GeyserBungeeConfiguration(getDataFolder(), configuration); if (geyserConfig.getMetrics().getUniqueId().equals("generateduuid")) { configuration.set("metrics.uuid", UUID.randomUUID().toString()); diff --git a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java index 1b30c4393..86b3ef342 100644 --- a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java +++ b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java @@ -31,12 +31,14 @@ import ninja.leaping.configurate.ConfigurationNode; import org.geysermc.common.IGeyserConfiguration; +import java.io.File; import java.util.HashMap; import java.util.List; import java.util.Map; public class GeyserSpongeConfiguration implements IGeyserConfiguration { + private File dataFolder; private ConfigurationNode node; private SpongeBedrockConfiguration bedrockConfig; @@ -45,7 +47,8 @@ public class GeyserSpongeConfiguration implements IGeyserConfiguration { private Map userAuthInfo = new HashMap<>(); - public GeyserSpongeConfiguration(ConfigurationNode node) { + public GeyserSpongeConfiguration(File dataFolder, ConfigurationNode node) { + this.dataFolder = dataFolder; this.node = node; this.bedrockConfig = new SpongeBedrockConfiguration(node.getNode("bedrock")); @@ -101,8 +104,8 @@ public class GeyserSpongeConfiguration implements IGeyserConfiguration { } @Override - public String getFloodgateKeyFile() { - return node.getNode("floodgate-key-file").getString("public-key.pem"); + public File getFloodgateKeyFile() { + return new File(dataFolder, node.getNode("floodgate-key-file").getString("public-key.pem")); } @Override diff --git a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongePlugin.java b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongePlugin.java index ecac6353c..15ab0d1fe 100644 --- a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongePlugin.java +++ b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongePlugin.java @@ -73,7 +73,7 @@ public class GeyserSpongePlugin implements IGeyserBootstrap { ConfigurationLoader loader = YAMLConfigurationLoader.builder().setPath(configFile.toPath()).build(); try { - this.geyserConfig = new GeyserSpongeConfiguration(loader.load()); + this.geyserConfig = new GeyserSpongeConfiguration(configDir, loader.load()); } catch (IOException ex) { logger.warn("Failed to load config.yml!"); ex.printStackTrace(); diff --git a/common/src/main/java/org/geysermc/common/IGeyserConfiguration.java b/common/src/main/java/org/geysermc/common/IGeyserConfiguration.java index 1414e6c21..0a1da2d35 100644 --- a/common/src/main/java/org/geysermc/common/IGeyserConfiguration.java +++ b/common/src/main/java/org/geysermc/common/IGeyserConfiguration.java @@ -25,6 +25,7 @@ package org.geysermc.common; +import java.io.File; import java.util.Map; public interface IGeyserConfiguration { @@ -45,7 +46,7 @@ public interface IGeyserConfiguration { boolean isAllowThirdPartyCapes(); - String getFloodgateKeyFile(); + File getFloodgateKeyFile(); IMetricsInfo getMetrics(); diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index 54577296a..f38e810d4 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -190,7 +190,7 @@ public class GeyserSession implements CommandSender { PublicKey key = null; try { key = EncryptionUtil.getKeyFromFile( - Paths.get(connector.getConfig().getFloodgateKeyFile()), + Paths.get(connector.getConfig().getFloodgateKeyFile().getPath()), PublicKey.class ); } catch (IOException | InvalidKeySpecException | NoSuchAlgorithmException e) { From 240f41ff03a3b3bee345b6dcc2773a0914326150 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sun, 26 Jan 2020 11:22:21 -0600 Subject: [PATCH 33/45] Use Path instead of File for floodgate key file in config ...and fix related issues with the file not being found. --- .../platform/bukkit/GeyserBukkitConfiguration.java | 6 ++++-- .../platform/bungeecord/GeyserBungeeConfiguration.java | 6 ++++-- .../platform/sponge/GeyserSpongeConfiguration.java | 6 ++++-- .../platform/standalone/GeyserConfiguration.java | 9 ++++++--- .../java/org/geysermc/common/IGeyserConfiguration.java | 4 ++-- .../connector/network/session/GeyserSession.java | 3 +-- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java index f4c4b008c..e38a982db 100644 --- a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java +++ b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java @@ -29,6 +29,8 @@ import org.bukkit.configuration.file.FileConfiguration; import org.geysermc.common.IGeyserConfiguration; import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; @@ -100,8 +102,8 @@ public class GeyserBukkitConfiguration implements IGeyserConfiguration { } @Override - public File getFloodgateKeyFile() { - return new File(dataFolder.toString() + config.getString("floodgate-key-file", "public-key.pem")); + public Path getFloodgateKeyFile() { + return Paths.get(dataFolder.toString(), config.getString("floodgate-key-file", "public-key.pem")); } @Override diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java index 0aaf714b3..94580e583 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java @@ -30,6 +30,8 @@ import net.md_5.bungee.config.Configuration; import org.geysermc.common.IGeyserConfiguration; import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; @@ -101,8 +103,8 @@ public class GeyserBungeeConfiguration implements IGeyserConfiguration { } @Override - public File getFloodgateKeyFile() { - return new File(dataFolder, config.getString("floodgate-key-file", "public-key.pem")); + public Path getFloodgateKeyFile() { + return Paths.get(dataFolder.toString(), config.getString("floodgate-key-file", "public-key.pem")); } @Override diff --git a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java index 86b3ef342..dbc83fbea 100644 --- a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java +++ b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java @@ -32,6 +32,8 @@ import ninja.leaping.configurate.ConfigurationNode; import org.geysermc.common.IGeyserConfiguration; import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -104,8 +106,8 @@ public class GeyserSpongeConfiguration implements IGeyserConfiguration { } @Override - public File getFloodgateKeyFile() { - return new File(dataFolder, node.getNode("floodgate-key-file").getString("public-key.pem")); + public Path getFloodgateKeyFile() { + return Paths.get(dataFolder.toString(), node.getNode("floodgate-key-file").getString("public-key.pem")); } @Override diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserConfiguration.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserConfiguration.java index 6f4837f8f..06cb711c1 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserConfiguration.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserConfiguration.java @@ -27,10 +27,13 @@ package org.geysermc.platform.standalone; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; + import lombok.Getter; + import org.geysermc.common.IGeyserConfiguration; -import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Map; @JsonIgnoreProperties(ignoreUnknown = true) @@ -63,8 +66,8 @@ public class GeyserConfiguration implements IGeyserConfiguration { private MetricsInfo metrics; @Override - public File getFloodgateKeyFile() { - return new File(floodgateKeyFile); + public Path getFloodgateKeyFile() { + return Paths.get(floodgateKeyFile); } @Getter diff --git a/common/src/main/java/org/geysermc/common/IGeyserConfiguration.java b/common/src/main/java/org/geysermc/common/IGeyserConfiguration.java index 0a1da2d35..db5d831b1 100644 --- a/common/src/main/java/org/geysermc/common/IGeyserConfiguration.java +++ b/common/src/main/java/org/geysermc/common/IGeyserConfiguration.java @@ -25,7 +25,7 @@ package org.geysermc.common; -import java.io.File; +import java.nio.file.Path; import java.util.Map; public interface IGeyserConfiguration { @@ -46,7 +46,7 @@ public interface IGeyserConfiguration { boolean isAllowThirdPartyCapes(); - File getFloodgateKeyFile(); + Path getFloodgateKeyFile(); IMetricsInfo getMetrics(); diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index f38e810d4..3ddc3bd43 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -66,7 +66,6 @@ import org.geysermc.floodgate.util.EncryptionUtil; import java.io.IOException; import java.net.InetSocketAddress; -import java.nio.file.Paths; import java.security.NoSuchAlgorithmException; import java.security.PublicKey; import java.security.spec.InvalidKeySpecException; @@ -190,7 +189,7 @@ public class GeyserSession implements CommandSender { PublicKey key = null; try { key = EncryptionUtil.getKeyFromFile( - Paths.get(connector.getConfig().getFloodgateKeyFile().getPath()), + connector.getConfig().getFloodgateKeyFile(), PublicKey.class ); } catch (IOException | InvalidKeySpecException | NoSuchAlgorithmException e) { From 3e4fd618e5d7aca75f349abc9145716798cc2e02 Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Tue, 28 Jan 2020 23:28:23 -0900 Subject: [PATCH 34/45] Fix offline auth bug Handled in GeyserSession#connect --- .../bedrock/BedrockPlayerInitializedTranslator.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java index 32697f0ea..a2422d342 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java @@ -40,11 +40,6 @@ public class BedrockPlayerInitializedTranslator extends PacketTranslator Date: Sat, 8 Feb 2020 13:43:25 -0600 Subject: [PATCH 35/45] Add velocity platform support --- bootstrap/pom.xml | 6 +- bootstrap/velocity/pom.xml | 72 ++++++++++++ .../velocity/GeyserVelocityConfiguration.java | 110 ++++++++++++++++++ .../velocity/GeyserVelocityLogger.java | 79 +++++++++++++ .../velocity/GeyserVelocityPlugin.java | 96 +++++++++++++++ .../geysermc/connector/utils/FileUtils.java | 1 + 6 files changed, 363 insertions(+), 1 deletion(-) create mode 100644 bootstrap/velocity/pom.xml create mode 100644 bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityConfiguration.java create mode 100644 bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityLogger.java create mode 100644 bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityPlugin.java diff --git a/bootstrap/pom.xml b/bootstrap/pom.xml index b826f61ac..6d12b6732 100644 --- a/bootstrap/pom.xml +++ b/bootstrap/pom.xml @@ -29,12 +29,16 @@ bungeecord-repo https://oss.sonatype.org/content/repositories/snapshots + + velocity-repo + https://repo.velocitypowered.com/snapshots/ + bukkit bungeecord sponge standalone - + velocity \ No newline at end of file diff --git a/bootstrap/velocity/pom.xml b/bootstrap/velocity/pom.xml new file mode 100644 index 000000000..22fe92115 --- /dev/null +++ b/bootstrap/velocity/pom.xml @@ -0,0 +1,72 @@ + + + 4.0.0 + + org.geysermc + bootstrap-parent + 1.0-SNAPSHOT + ../ + + bootstrap-velocity + + + org.geysermc + connector + 1.0-SNAPSHOT + compile + + + com.velocitypowered + velocity-api + 1.0.0-SNAPSHOT + provided + + + + ${outputName}-Velocity + + + src/main/resources/ + true + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 + + + package + + shade + + + true + + + + + + + *:* + + META-INF/* + + + + + + com.google.code.gson:* + io.netty:* + org.slf4j:* + org.ow2.asm:* + + + + + + + \ No newline at end of file diff --git a/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityConfiguration.java b/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityConfiguration.java new file mode 100644 index 000000000..2fab448d9 --- /dev/null +++ b/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityConfiguration.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2019-2020 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.platform.velocity; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.Getter; + +import org.geysermc.common.IGeyserConfiguration; + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Map; + +@JsonIgnoreProperties(ignoreUnknown = true) +@Getter +public class GeyserVelocityConfiguration implements IGeyserConfiguration { + + private BedrockConfiguration bedrock; + private RemoteConfiguration remote; + + @JsonProperty("floodgate-key-file") + private String floodgateKeyFile; + + private Map userAuths; + + @JsonProperty("ping-passthrough") + private boolean pingPassthrough; + + @JsonProperty("max-players") + private int maxPlayers; + + @JsonProperty("debug-mode") + private boolean debugMode; + + @JsonProperty("general-thread-pool") + private int generalThreadPool; + + @JsonProperty("allow-third-party-capes") + private boolean allowThirdPartyCapes; + + private MetricsInfo metrics; + + @Override + public Path getFloodgateKeyFile() { + return Paths.get(floodgateKeyFile); + } + + @Getter + public static class BedrockConfiguration implements IBedrockConfiguration { + + private String address; + private int port; + + private String motd1; + private String motd2; + } + + @Getter + public static class RemoteConfiguration implements IRemoteConfiguration { + + private String address; + private int port; + + private String motd1; + private String motd2; + + @JsonProperty("auth-type") + private String authType; + } + + @Getter + public static class UserAuthenticationInfo implements IUserAuthenticationInfo { + private String email; + private String password; + } + + @Getter + public static class MetricsInfo implements IMetricsInfo { + + private boolean enabled; + + @JsonProperty("uuid") + private String uniqueId; + } +} diff --git a/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityLogger.java b/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityLogger.java new file mode 100644 index 000000000..623c6481e --- /dev/null +++ b/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityLogger.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2019-2020 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.platform.velocity; + +import lombok.AllArgsConstructor; + +import org.geysermc.common.logger.IGeyserLogger; +import org.slf4j.Logger; + +@AllArgsConstructor +public class GeyserVelocityLogger 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; + } +} \ No newline at end of file diff --git a/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityPlugin.java b/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityPlugin.java new file mode 100644 index 000000000..4020b81e4 --- /dev/null +++ b/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityPlugin.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2019-2020 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.platform.velocity; + +import com.google.inject.Inject; + +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; +import com.velocitypowered.api.event.proxy.ProxyShutdownEvent; +import com.velocitypowered.api.plugin.Plugin; + +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 java.io.File; +import java.io.IOException; +import java.util.UUID; + +@Plugin(id = "geyser", name = GeyserConnector.NAME + "-Velocity", version = GeyserConnector.VERSION, url = "https://geysermc.org", authors = "GeyserMC") +public class GeyserVelocityPlugin implements IGeyserBootstrap { + + @Inject + private Logger logger; + + private GeyserVelocityConfiguration geyserConfig; + private GeyserVelocityLogger geyserLogger; + + + @Override + public void onEnable() { + try { + File configDir = new File("plugins/" + GeyserConnector.NAME + "-Velocity/"); + if (!configDir.exists()) + configDir.mkdir(); + File configFile = FileUtils.fileOrCopiedFromResource(new File(configDir, "config.yml"), "config.yml", (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString())); + geyserConfig = FileUtils.loadConfig(configFile, GeyserVelocityConfiguration.class); + } catch (IOException ex) { + logger.warn("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex); + ex.printStackTrace(); + } + + this.geyserLogger = new GeyserVelocityLogger(logger, geyserConfig.isDebugMode()); + GeyserConnector.start(PlatformType.VELOCITY, this); + } + + @Override + public void onDisable() { + GeyserConnector.stop(); + } + + @Override + public GeyserVelocityConfiguration getGeyserConfig() { + return geyserConfig; + } + + @Override + public GeyserVelocityLogger getGeyserLogger() { + return geyserLogger; + } + + @Subscribe + public void onInit(ProxyInitializeEvent event) { + onEnable(); + } + + @Subscribe + public void onShutdown(ProxyShutdownEvent event) { + onDisable(); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/utils/FileUtils.java b/connector/src/main/java/org/geysermc/connector/utils/FileUtils.java index e07724643..3070e743d 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/FileUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/FileUtils.java @@ -46,6 +46,7 @@ public class FileUtils { public static File fileOrCopiedFromResource(File file, String name, Function s) throws IOException { if (!file.exists()) { + file.createNewFile(); FileOutputStream fos = new FileOutputStream(file); InputStream input = GeyserConnector.class.getResourceAsStream("/" + name); // resources need leading "/" prefix From 81ca0ca69a2c6957a86b378fde2f3ff4884ad4c4 Mon Sep 17 00:00:00 2001 From: Redned Date: Sun, 9 Feb 2020 19:19:42 -0600 Subject: [PATCH 36/45] Include velocity jar on Jenkins --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3556720a7..64e9878fc 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -15,7 +15,7 @@ pipeline { } post { success { - archiveArtifacts artifacts: 'target/*.jar, bootstrap/bukkit/target/*.jar, bootstrap/bungeecord/target/*.jar, bootstrap/sponge/target/*.jar, bootstrap/standalone/target/*.jar', fingerprint: true + archiveArtifacts artifacts: 'target/*.jar, bootstrap/bukkit/target/*.jar, bootstrap/bungeecord/target/*.jar, bootstrap/sponge/target/*.jar, bootstrap/standalone/target/*.jar, bootstrap/bukkit/velocity/*.jar', fingerprint: true } } } From 18ac2815dd4d07c229f53632a4d6466d7c322f80 Mon Sep 17 00:00:00 2001 From: Redned Date: Thu, 13 Feb 2020 13:58:42 -0600 Subject: [PATCH 37/45] Velocity target is not in Bukkit folder... --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 64e9878fc..6a25e5202 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -15,7 +15,7 @@ pipeline { } post { success { - archiveArtifacts artifacts: 'target/*.jar, bootstrap/bukkit/target/*.jar, bootstrap/bungeecord/target/*.jar, bootstrap/sponge/target/*.jar, bootstrap/standalone/target/*.jar, bootstrap/bukkit/velocity/*.jar', fingerprint: true + archiveArtifacts artifacts: 'target/*.jar, bootstrap/bukkit/target/*.jar, bootstrap/bungeecord/target/*.jar, bootstrap/sponge/target/*.jar, bootstrap/standalone/target/*.jar, bootstrap/velocity/target/*.jar', fingerprint: true } } } From 5fa2defdbcfde592b470dd3fbd78f8584e6e7aec Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Thu, 13 Feb 2020 20:55:04 +0000 Subject: [PATCH 38/45] Exclude original jars. --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6a25e5202..b2baa119e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -15,7 +15,7 @@ pipeline { } post { success { - archiveArtifacts artifacts: 'target/*.jar, bootstrap/bukkit/target/*.jar, bootstrap/bungeecord/target/*.jar, bootstrap/sponge/target/*.jar, bootstrap/standalone/target/*.jar, bootstrap/velocity/target/*.jar', fingerprint: true + archiveArtifacts artifacts: 'bootstrap/**/target/*.jar', excludes: 'bootstrap/**/target/original-*.jar', fingerprint: true } } } From b97fa2b1c8341964af4ff5e896e0d6d9ee278353 Mon Sep 17 00:00:00 2001 From: Tim203 Date: Wed, 26 Feb 2020 23:53:26 +0100 Subject: [PATCH 39/45] Added a response to the PluginMessage packet in the Login state --- .../network/translators/TranslatorsInit.java | 3 +++ .../java/JavaLoginPluginMessageTranslator.java | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 connector/src/main/java/org/geysermc/connector/network/translators/java/JavaLoginPluginMessageTranslator.java diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java b/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java index 2abeebb8e..f4ab1684b 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java @@ -40,6 +40,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenW import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerSetSlotPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerWindowItemsPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.world.*; +import com.github.steveice10.mc.protocol.packet.login.server.LoginPluginRequestPacket; import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.NbtUtils; import com.nukkitx.nbt.stream.NBTOutputStream; @@ -94,6 +95,8 @@ public class TranslatorsInit { } public static void start() { + Registry.registerJava(LoginPluginRequestPacket.class, new JavaLoginPluginMessageTranslator()); + Registry.registerJava(ServerJoinGamePacket.class, new JavaJoinGameTranslator()); Registry.registerJava(ServerPluginMessagePacket.class, new JavaPluginMessageTranslator()); Registry.registerJava(ServerChatPacket.class, new JavaChatTranslator()); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaLoginPluginMessageTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaLoginPluginMessageTranslator.java new file mode 100644 index 000000000..f92fca9f9 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaLoginPluginMessageTranslator.java @@ -0,0 +1,16 @@ +package org.geysermc.connector.network.translators.java; + +import com.github.steveice10.mc.protocol.packet.login.client.LoginPluginResponsePacket; +import com.github.steveice10.mc.protocol.packet.login.server.LoginPluginRequestPacket; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; + +public class JavaLoginPluginMessageTranslator extends PacketTranslator { + @Override + public void translate(LoginPluginRequestPacket packet, GeyserSession session) { + // A vanilla client doesn't know any PluginMessage in the Login state, so we don't know any either. + session.getDownstream().getSession().send( + new LoginPluginResponsePacket(packet.getMessageId(), null) + ); + } +} From e52a461a73adf56bb16393454cff102790903153 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sun, 1 Mar 2020 10:48:49 -0600 Subject: [PATCH 40/45] Attempt to get log4j2 working --- bootstrap/standalone/pom.xml | 58 ++++++++--- .../platform/standalone/GeyserBootstrap.java | 13 +-- .../console/ConsoleCommandReader.java | 96 ------------------- .../standalone/console/GeyserLogger.java | 39 ++++++-- .../resources/log4j2.component.properties | 1 + .../standalone/src/main/resources/log4j2.yml | 20 ++++ connector/pom.xml | 2 +- 7 files changed, 98 insertions(+), 131 deletions(-) delete mode 100644 bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/ConsoleCommandReader.java create mode 100644 bootstrap/standalone/src/main/resources/log4j2.component.properties create mode 100644 bootstrap/standalone/src/main/resources/log4j2.yml diff --git a/bootstrap/standalone/pom.xml b/bootstrap/standalone/pom.xml index 2e767de5e..800a79c3e 100644 --- a/bootstrap/standalone/pom.xml +++ b/bootstrap/standalone/pom.xml @@ -20,27 +20,55 @@ net.minecrell terminalconsoleappender - 1.0.0 - jar - compile + 1.1.1 + + + org.apache.logging.log4j + log4j-core + + + org.jline + jline-reader + + + org.jline + jline-terminal-jna + + + org.jline + jline-terminal + + - org.slf4j - slf4j-api - 1.7.5 - compile + org.jline + jline-terminal + 3.9.0 - org.slf4j - slf4j-simple - 1.6.4 - compile + org.jline + jline-terminal-jna + 3.9.0 - org.fusesource.jansi - jansi - 1.18 - compile + org.jline + jline-reader + 3.9.0 + + + org.apache.logging.log4j + log4j-api + 2.13.1 + + + org.apache.logging.log4j + log4j-core + 2.13.1 + + + org.apache.logging.log4j + log4j-slf4j18-impl + 2.13.1 diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java index a99b2434e..199745388 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserBootstrap.java @@ -25,12 +25,10 @@ package org.geysermc.platform.standalone; -import org.fusesource.jansi.AnsiConsole; import org.geysermc.common.PlatformType; import org.geysermc.common.bootstrap.IGeyserBootstrap; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.utils.FileUtils; -import org.geysermc.platform.standalone.console.ConsoleCommandReader; import org.geysermc.platform.standalone.console.GeyserLogger; import java.io.File; @@ -48,11 +46,6 @@ public class GeyserBootstrap implements IGeyserBootstrap { @Override public void onEnable() { - // Metric - if (!(System.console() == null) && System.getProperty("os.name", "Windows 10").toLowerCase().contains("windows")) { - AnsiConsole.systemInstall(); - } - geyserLogger = new GeyserLogger(); try { @@ -63,10 +56,8 @@ public class GeyserBootstrap implements IGeyserBootstrap { System.exit(0); } - GeyserConnector connector = GeyserConnector.start(PlatformType.STANDALONE, this); - - ConsoleCommandReader consoleReader = new ConsoleCommandReader(connector); - consoleReader.startConsole(); + GeyserConnector.start(PlatformType.STANDALONE, this); + geyserLogger.start(); } @Override diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/ConsoleCommandReader.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/ConsoleCommandReader.java deleted file mode 100644 index ff6cff798..000000000 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/ConsoleCommandReader.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2019-2020 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.platform.standalone.console; - -import net.minecrell.terminalconsole.TerminalConsoleAppender; - -import org.geysermc.connector.GeyserConnector; -import org.geysermc.connector.command.GeyserConsoleCommandSender; -import org.jline.reader.EndOfFileException; -import org.jline.reader.LineReader; -import org.jline.reader.LineReaderBuilder; -import org.jline.reader.UserInterruptException; -import org.jline.terminal.Terminal; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.logging.Level; -import java.util.logging.Logger; - -public class ConsoleCommandReader { - - private GeyserConnector connector; - private Terminal terminal; - - public ConsoleCommandReader(GeyserConnector connector) { - this.connector = connector; - this.terminal = TerminalConsoleAppender.getTerminal(); - } - - public void startConsole() { - Thread thread = new Thread(() -> { - if (terminal != null) { - LineReader lineReader = LineReaderBuilder.builder() - .appName("Geyser") - .terminal(terminal) - .build(); - TerminalConsoleAppender.setReader(lineReader); - - try { - String line; - - while (true) { - try { - line = lineReader.readLine("> "); - } catch (EndOfFileException ignored) { - continue; - } - - if (line == null) - break; - } - } catch (UserInterruptException ignore) { - /* do nothing */ - } finally { - TerminalConsoleAppender.setReader(null); - } - } else { - try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) { - String line; - while ((line = reader.readLine()) != null) { - GeyserConsoleCommandSender sender = new GeyserConsoleCommandSender(); - connector.getCommandMap().runCommand(sender, line); - } - } catch (IOException ex) { - Logger.getLogger("Geyser").log(Level.SEVERE, null, ex); - } - } - }); - - thread.setName("ConsoleCommandThread"); - } -} diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java index 35347e7ae..3ec11cc07 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java @@ -27,15 +27,22 @@ package org.geysermc.platform.standalone.console; import io.sentry.Sentry; +import lombok.extern.log4j.Log4j2; + +import net.minecrell.terminalconsole.SimpleTerminalConsole; + import org.geysermc.common.ChatColor; import org.geysermc.common.logger.IGeyserLogger; +import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.command.GeyserConsoleCommandSender; import java.io.File; import java.io.IOException; import java.util.Date; import java.util.logging.*; -public class GeyserLogger implements IGeyserLogger { +@Log4j2 +public class GeyserLogger extends SimpleTerminalConsole implements IGeyserLogger { private boolean colored = true; private boolean debug = false; @@ -88,40 +95,56 @@ public class GeyserLogger implements IGeyserLogger { } } + @Override + protected boolean isRunning() { + return !GeyserConnector.getInstance().isShuttingDown(); + } + + @Override + protected void runCommand(String line) { + GeyserConsoleCommandSender sender = new GeyserConsoleCommandSender(); + GeyserConnector.getInstance().getCommandMap().runCommand(sender, line); + } + + @Override + protected void shutdown() { + GeyserConnector.getInstance().shutdown(); + } + @Override public void severe(String message) { - System.out.println(printConsole(ChatColor.DARK_RED + message, colored)); + log.fatal(printConsole(ChatColor.DARK_RED + message, colored)); } @Override public void severe(String message, Throwable error) { - System.out.println(printConsole(ChatColor.DARK_RED + message + "\n" + error.getMessage(), colored)); + log.fatal(printConsole(ChatColor.DARK_RED + message, colored), error); } @Override public void error(String message) { - System.out.println(printConsole(ChatColor.RED + message, colored)); + log.error(printConsole(ChatColor.RED + message, colored)); } @Override public void error(String message, Throwable error) { - System.out.println(printConsole(ChatColor.RED + message + "\n" + error, colored)); + log.error(printConsole(ChatColor.RED + message, colored), error); } @Override public void warning(String message) { - System.out.println(printConsole(ChatColor.YELLOW + message, colored)); + log.warn(printConsole(ChatColor.YELLOW + message, colored)); } @Override public void info(String message) { - System.out.println(printConsole(ChatColor.WHITE + message, colored)); + log.info(printConsole(ChatColor.WHITE + message, colored)); } @Override public void debug(String message) { if (debug) - System.out.println(printConsole(ChatColor.GRAY + message, colored)); + log.info(printConsole(ChatColor.GRAY + message, colored)); } public static String printConsole(String message, boolean colors) { diff --git a/bootstrap/standalone/src/main/resources/log4j2.component.properties b/bootstrap/standalone/src/main/resources/log4j2.component.properties new file mode 100644 index 000000000..ed03a2b82 --- /dev/null +++ b/bootstrap/standalone/src/main/resources/log4j2.component.properties @@ -0,0 +1 @@ +log4j2.contextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector \ No newline at end of file diff --git a/bootstrap/standalone/src/main/resources/log4j2.yml b/bootstrap/standalone/src/main/resources/log4j2.yml new file mode 100644 index 000000000..c839ef8dc --- /dev/null +++ b/bootstrap/standalone/src/main/resources/log4j2.yml @@ -0,0 +1,20 @@ +Configuration: + Appenders: + TerminalConsole: + PatternLayout: + pattern: "%cyan{%d{HH:mm:ss}} [%style{%highlight{%-5level}{STYLE=Logback}}] %minecraftFormatting{%msg}%n" + name: Console + RollingRandomAccessFile: + PatternLayout: + pattern: "%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level - %msg%n" + Policies: + TimeBasedTriggeringPolicy: "" + OnStartupTriggeringPolicy: "" + name: File + fileName: "logs/server.log" + filePattern: "logs/%d{yyyy-MM-dd}-%i.log.gz" + Loggers: + Root: + level: error + AppenderRef: + ref: Console \ No newline at end of file diff --git a/connector/pom.xml b/connector/pom.xml index 31bbcc4b6..e9de81e64 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -57,7 +57,7 @@ com.github.steveice10 packetlib - 1.4-SNAPSHOT + 1.5-SNAPSHOT compile From bcf77f10980dd371b145e801bdd2af50d1f7abd2 Mon Sep 17 00:00:00 2001 From: Redned Date: Sun, 1 Mar 2020 13:30:51 -0600 Subject: [PATCH 41/45] Bump packetlib version to 1.5-SNAPSHOT --- connector/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/pom.xml b/connector/pom.xml index 31bbcc4b6..e9de81e64 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -57,7 +57,7 @@ com.github.steveice10 packetlib - 1.4-SNAPSHOT + 1.5-SNAPSHOT compile From 936cbad67d918d27b17643fbf4c85a3e6f0d547d Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Wed, 4 Mar 2020 20:35:23 -0600 Subject: [PATCH 42/45] Get log4j2 working and fix commands --- bootstrap/standalone/pom.xml | 28 ++++++- .../standalone/console/GeyserLogger.java | 79 ++++--------------- .../resources/log4j2.component.properties | 1 - .../standalone/src/main/resources/log4j2.xml | 21 +++++ .../standalone/src/main/resources/log4j2.yml | 20 ----- .../connector/command/GeyserCommandMap.java | 4 +- .../command/GeyserConsoleCommandSender.java | 41 ---------- .../command/defaults/HelpCommand.java | 2 +- 8 files changed, 67 insertions(+), 129 deletions(-) delete mode 100644 bootstrap/standalone/src/main/resources/log4j2.component.properties create mode 100644 bootstrap/standalone/src/main/resources/log4j2.xml delete mode 100644 bootstrap/standalone/src/main/resources/log4j2.yml delete mode 100644 connector/src/main/java/org/geysermc/connector/command/GeyserConsoleCommandSender.java diff --git a/bootstrap/standalone/pom.xml b/bootstrap/standalone/pom.xml index 800a79c3e..7c271339a 100644 --- a/bootstrap/standalone/pom.xml +++ b/bootstrap/standalone/pom.xml @@ -90,6 +90,13 @@ org.apache.maven.plugins maven-shade-plugin 3.2.1 + + + com.github.edwgiz + maven-shade-plugin.log4j2-cachefile-transformer + 2.8.1 + + package @@ -97,10 +104,29 @@ shade - true + false + + + + *:* + + META-INF/versions/9/module-info.class + + + + + + org.geysermc.platform.standalone.GeyserBootstrap + + + + + ${project.build.directory}/dependency-reduced-pom.xml + diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java index 3ec11cc07..cac40b563 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java @@ -25,75 +25,20 @@ package org.geysermc.platform.standalone.console; -import io.sentry.Sentry; - import lombok.extern.log4j.Log4j2; import net.minecrell.terminalconsole.SimpleTerminalConsole; +import org.apache.logging.log4j.core.config.Configurator; import org.geysermc.common.ChatColor; import org.geysermc.common.logger.IGeyserLogger; import org.geysermc.connector.GeyserConnector; -import org.geysermc.connector.command.GeyserConsoleCommandSender; - -import java.io.File; -import java.io.IOException; -import java.util.Date; -import java.util.logging.*; +import org.geysermc.connector.command.CommandSender; @Log4j2 -public class GeyserLogger extends SimpleTerminalConsole implements IGeyserLogger { +public class GeyserLogger extends SimpleTerminalConsole implements IGeyserLogger, CommandSender { private boolean colored = true; - private boolean debug = false; - - public GeyserLogger() { - ConsoleHandler consoleHandler = new ConsoleHandler(); - consoleHandler.setLevel(Level.INFO); - consoleHandler.setFormatter(new SimpleFormatter() { - private static final String format = "[%1$tT][%2$-5s] %3$s %n"; - - @Override - public synchronized String format(LogRecord lr) { - return String.format(format, - new Date(lr.getMillis()), - lr.getLevel().getLocalizedName(), - lr.getMessage() - ); - } - }); - - try { - File logDir = new File("logs"); - logDir.mkdir(); - File logFile = new File(logDir, "latest.log"); - int maxLogFileSize = 20;//Mo - if (logFile.exists() && (logFile.length()) > maxLogFileSize * 1024L * 1024L) - this.warning("Your log file is larger than " + maxLogFileSize + "Mo, you should backup and clean it !"); - FileHandler fileHandler = new FileHandler(logFile.getCanonicalPath(), true); - fileHandler.setLevel(Level.INFO); - fileHandler.setFormatter(new SimpleFormatter() { - private static final String format = "[%1$tF %1$tT][%2$-5s] %3$s %n"; - - @Override - public synchronized String format(LogRecord lr) { - return String.format(format, - new Date(lr.getMillis()), - lr.getLevel().getLocalizedName(), - lr.getMessage() - ); - } - }); - } catch (IOException | SecurityException ex) { - Logger.getLogger(GeyserLogger.class.getName()).log(Level.SEVERE, null, ex); - } - - if (System.getenv().containsKey("DP_SENTRY_CLIENT_KEY")) { - Handler sentryHandler = new io.sentry.jul.SentryHandler(); - sentryHandler.setLevel(Level.SEVERE); - Sentry.init(System.getenv().get("DP_SENTRY_CLIENT_KEY")); - } - } @Override protected boolean isRunning() { @@ -102,8 +47,7 @@ public class GeyserLogger extends SimpleTerminalConsole implements IGeyserLogger @Override protected void runCommand(String line) { - GeyserConsoleCommandSender sender = new GeyserConsoleCommandSender(); - GeyserConnector.getInstance().getCommandMap().runCommand(sender, line); + GeyserConnector.getInstance().getCommandMap().runCommand(this, line); } @Override @@ -143,8 +87,7 @@ public class GeyserLogger extends SimpleTerminalConsole implements IGeyserLogger @Override public void debug(String message) { - if (debug) - log.info(printConsole(ChatColor.GRAY + message, colored)); + log.debug(printConsole(ChatColor.GRAY + message, colored)); } public static String printConsole(String message, boolean colors) { @@ -153,6 +96,16 @@ public class GeyserLogger extends SimpleTerminalConsole implements IGeyserLogger @Override public void setDebug(boolean debug) { - this.debug = debug; + Configurator.setLevel(log.getName(), debug ? org.apache.logging.log4j.Level.DEBUG : log.getLevel()); + } + + @Override + public String getName() { + return "CONSOLE"; + } + + @Override + public void sendMessage(String message) { + info(message); } } diff --git a/bootstrap/standalone/src/main/resources/log4j2.component.properties b/bootstrap/standalone/src/main/resources/log4j2.component.properties deleted file mode 100644 index ed03a2b82..000000000 --- a/bootstrap/standalone/src/main/resources/log4j2.component.properties +++ /dev/null @@ -1 +0,0 @@ -log4j2.contextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector \ No newline at end of file diff --git a/bootstrap/standalone/src/main/resources/log4j2.xml b/bootstrap/standalone/src/main/resources/log4j2.xml new file mode 100644 index 000000000..957415405 --- /dev/null +++ b/bootstrap/standalone/src/main/resources/log4j2.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/bootstrap/standalone/src/main/resources/log4j2.yml b/bootstrap/standalone/src/main/resources/log4j2.yml deleted file mode 100644 index c839ef8dc..000000000 --- a/bootstrap/standalone/src/main/resources/log4j2.yml +++ /dev/null @@ -1,20 +0,0 @@ -Configuration: - Appenders: - TerminalConsole: - PatternLayout: - pattern: "%cyan{%d{HH:mm:ss}} [%style{%highlight{%-5level}{STYLE=Logback}}] %minecraftFormatting{%msg}%n" - name: Console - RollingRandomAccessFile: - PatternLayout: - pattern: "%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level - %msg%n" - Policies: - TimeBasedTriggeringPolicy: "" - OnStartupTriggeringPolicy: "" - name: File - fileName: "logs/server.log" - filePattern: "logs/%d{yyyy-MM-dd}-%i.log.gz" - Loggers: - Root: - level: error - AppenderRef: - ref: Console \ No newline at end of file diff --git a/connector/src/main/java/org/geysermc/connector/command/GeyserCommandMap.java b/connector/src/main/java/org/geysermc/connector/command/GeyserCommandMap.java index 6a8e16808..7172622c3 100644 --- a/connector/src/main/java/org/geysermc/connector/command/GeyserCommandMap.java +++ b/connector/src/main/java/org/geysermc/connector/command/GeyserCommandMap.java @@ -61,7 +61,7 @@ public class GeyserCommandMap { } public void runCommand(CommandSender sender, String command) { - if (!command.startsWith("/geyser ")) + if (!command.startsWith("geyser ")) return; command = command.trim(); @@ -80,7 +80,7 @@ public class GeyserCommandMap { GeyserCommand cmd = commandMap.get(label); if (cmd == null) { - connector.getLogger().warning("Invalid Command! Try /help for a list of commands."); + connector.getLogger().error("Invalid Command! Try /geyser help for a list of commands."); return; } diff --git a/connector/src/main/java/org/geysermc/connector/command/GeyserConsoleCommandSender.java b/connector/src/main/java/org/geysermc/connector/command/GeyserConsoleCommandSender.java deleted file mode 100644 index 20b2f9739..000000000 --- a/connector/src/main/java/org/geysermc/connector/command/GeyserConsoleCommandSender.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2019-2020 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.connector.command; - -import org.geysermc.common.ChatColor; - -public class GeyserConsoleCommandSender implements CommandSender { - - @Override - public String getName() { - return "CONSOLE"; - } - - @Override - public void sendMessage(String message) { - System.out.println(ChatColor.toANSI(message + ChatColor.RESET)); - } -} diff --git a/connector/src/main/java/org/geysermc/connector/command/defaults/HelpCommand.java b/connector/src/main/java/org/geysermc/connector/command/defaults/HelpCommand.java index 6964b9a33..4fa0068ae 100644 --- a/connector/src/main/java/org/geysermc/connector/command/defaults/HelpCommand.java +++ b/connector/src/main/java/org/geysermc/connector/command/defaults/HelpCommand.java @@ -52,7 +52,7 @@ public class HelpCommand extends GeyserCommand { Collections.sort(commands); for (String cmd : commands) { - sender.sendMessage(ChatColor.YELLOW + "/" + cmd + ChatColor.WHITE + ": " + cmds.get(cmd).getDescription()); + sender.sendMessage(ChatColor.YELLOW + "/geyser " + cmd + ChatColor.WHITE + ": " + cmds.get(cmd).getDescription()); } } } From 1670c77672c9f8de5d2c0dda68cab29fce745942 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Wed, 4 Mar 2020 20:44:42 -0600 Subject: [PATCH 43/45] Only allow console to shut down Geyser with a command --- .../geysermc/platform/standalone/console/GeyserLogger.java | 5 +++++ .../java/org/geysermc/connector/command/CommandSender.java | 2 ++ .../org/geysermc/connector/command/defaults/StopCommand.java | 3 +++ .../geysermc/connector/network/session/GeyserSession.java | 5 +++++ 4 files changed, 15 insertions(+) diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java index cac40b563..7df8a4efb 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java @@ -108,4 +108,9 @@ public class GeyserLogger extends SimpleTerminalConsole implements IGeyserLogger public void sendMessage(String message) { info(message); } + + @Override + public boolean isConsole() { + return true; + } } diff --git a/connector/src/main/java/org/geysermc/connector/command/CommandSender.java b/connector/src/main/java/org/geysermc/connector/command/CommandSender.java index eb69010d1..9e4f020bd 100644 --- a/connector/src/main/java/org/geysermc/connector/command/CommandSender.java +++ b/connector/src/main/java/org/geysermc/connector/command/CommandSender.java @@ -11,4 +11,6 @@ public interface CommandSender { } void sendMessage(String message); + + boolean isConsole(); } diff --git a/connector/src/main/java/org/geysermc/connector/command/defaults/StopCommand.java b/connector/src/main/java/org/geysermc/connector/command/defaults/StopCommand.java index c54d48c5c..25034f1ad 100644 --- a/connector/src/main/java/org/geysermc/connector/command/defaults/StopCommand.java +++ b/connector/src/main/java/org/geysermc/connector/command/defaults/StopCommand.java @@ -44,6 +44,9 @@ public class StopCommand extends GeyserCommand { @Override public void execute(CommandSender sender, String[] args) { + if (!sender.isConsole()) + return; + connector.shutdown(); } } diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index 330ef0ac5..a2d8a7263 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -324,6 +324,11 @@ public class GeyserSession implements CommandSender { upstream.sendPacket(textPacket); } + @Override + public boolean isConsole() { + return false; + } + public void sendForm(FormWindow window, int id) { windowCache.showWindow(window, id); } From 73284b724823695cd1b1d4f5fd6bff9c4e1e5637 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Wed, 4 Mar 2020 20:48:22 -0600 Subject: [PATCH 44/45] Remove 'Support to be Ran as a Plugin' from whats left in README --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 07bc30ce3..1cd56040d 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,6 @@ Take a look [here](https://github.com/GeyserMC/Geyser/wiki#Setup) for how to set - Block Particles - Block Entities ([`block-entities`](https://github.com/GeyserMC/Geyser/tree/block-entities)) - Some Entity Flags -- Support to be Ran as a Plugin ([`plugin`](https://github.com/GeyserMC/Geyser/tree/plugin)) ## Compiling 1. Clone the repo to your computer From a51611733de45c447a6379fd95c58863fcefef3c Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Wed, 4 Mar 2020 20:56:08 -0600 Subject: [PATCH 45/45] Update workflow path --- .github/workflows/pullrequest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml index bf5972f2f..ce6d76461 100644 --- a/.github/workflows/pullrequest.yml +++ b/.github/workflows/pullrequest.yml @@ -28,4 +28,4 @@ jobs: if: success() with: name: Geyser - path: target/Geyser.jar + path: bootstrap/standalone/target/Geyser.jar