From 266d3741675ed509a6752a82d40ccad556a699b8 Mon Sep 17 00:00:00 2001 From: EOT3000 <43685885+EOT3000@users.noreply.github.com> Date: Sat, 13 Jul 2019 15:00:51 -0400 Subject: [PATCH] completely re-do console --- .../main/java/org/geysermc/api/ChatColor.java | 4 +- .../java/org/geysermc/api/ConsoleColors.java | 69 +++++++++++++++++++ .../main/java/org/geysermc/api/GeyserAPI.java | 4 ++ .../java/org/geysermc/api/logger/Logger.java | 21 ++++-- .../java/org/geysermc/api/plugin/Plugin.java | 11 +++ connector/pom.xml | 6 ++ .../geysermc/connector/GeyserConnector.java | 24 +++++-- .../connector/console/GeyserLogger.java | 55 ++++++--------- .../console/LoggingOutputStream.java | 66 ------------------ .../network/ConnectorServerEventHandler.java | 7 +- .../network/UpstreamPacketHandler.java | 6 ++ .../network/session/GeyserSession.java | 7 +- .../network/translators/Registry.java | 11 +-- .../network/translators/TranslatorsInit.java | 59 ++++++++++++++-- .../connector/plugin/GeyserPluginLoader.java | 1 + 15 files changed, 225 insertions(+), 126 deletions(-) create mode 100644 api/src/main/java/org/geysermc/api/ConsoleColors.java create mode 100644 api/src/main/java/org/geysermc/api/GeyserAPI.java delete mode 100644 connector/src/main/java/org/geysermc/connector/console/LoggingOutputStream.java diff --git a/api/src/main/java/org/geysermc/api/ChatColor.java b/api/src/main/java/org/geysermc/api/ChatColor.java index 5edac6481..abf82167e 100644 --- a/api/src/main/java/org/geysermc/api/ChatColor.java +++ b/api/src/main/java/org/geysermc/api/ChatColor.java @@ -52,8 +52,8 @@ public class ChatColor { public static final String RESET = ESCAPE + "r"; public static String toANSI(String string) { - string = string.replace(BOLD, ""); - string = string.replace(OBFUSCATED, (char) 0x1b + "[6m"); + string = string.replace(BOLD, (char) 0x1b + "[1m"); + string = string.replace(OBFUSCATED, (char) 0x1b + "[5m"); string = string.replace(ITALIC, (char) 0x1b + "[3m"); string = string.replace(UNDERLINE, (char) 0x1b + "[4m"); string = string.replace(STRIKETHROUGH, (char) 0x1b + "[9m"); diff --git a/api/src/main/java/org/geysermc/api/ConsoleColors.java b/api/src/main/java/org/geysermc/api/ConsoleColors.java new file mode 100644 index 000000000..a59512275 --- /dev/null +++ b/api/src/main/java/org/geysermc/api/ConsoleColors.java @@ -0,0 +1,69 @@ +/* + * 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/GeyserAPI.java b/api/src/main/java/org/geysermc/api/GeyserAPI.java new file mode 100644 index 000000000..ba4405852 --- /dev/null +++ b/api/src/main/java/org/geysermc/api/GeyserAPI.java @@ -0,0 +1,4 @@ +package org.geysermc.api; + +public class GeyserAPI { +} diff --git a/api/src/main/java/org/geysermc/api/logger/Logger.java b/api/src/main/java/org/geysermc/api/logger/Logger.java index 8a953728c..de836d6ad 100644 --- a/api/src/main/java/org/geysermc/api/logger/Logger.java +++ b/api/src/main/java/org/geysermc/api/logger/Logger.java @@ -27,13 +27,6 @@ package org.geysermc.api.logger; public interface Logger { - /** - * Logs an info message to console - * - * @param message the message to log - */ - void info(String message); - /** * Logs a severe message to console * @@ -41,6 +34,13 @@ public interface Logger { */ void severe(String message); + /** + * Logs an error message to console + * + * @param message the message to log + */ + void error(String message); + /** * Logs a warning message to console * @@ -48,6 +48,13 @@ public interface Logger { */ void warning(String message); + /** + * Logs an info message to console + * + * @param message the message to log + */ + void info(String message); + /** * Logs a debug message to console * diff --git a/api/src/main/java/org/geysermc/api/plugin/Plugin.java b/api/src/main/java/org/geysermc/api/plugin/Plugin.java index 848001a54..1cc995d35 100644 --- a/api/src/main/java/org/geysermc/api/plugin/Plugin.java +++ b/api/src/main/java/org/geysermc/api/plugin/Plugin.java @@ -28,6 +28,10 @@ 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 { @Getter @@ -54,4 +58,11 @@ public class Plugin { public void onLoad() { } + + /** + * Called when th server is reloaded + */ + public void onReload() { + + } } diff --git a/connector/pom.xml b/connector/pom.xml index da48bff87..cab4b8629 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -65,6 +65,12 @@ 2.1.0 compile + + org.fusesource.jansi + jansi + 1.18 + compile + com.nukkitx.protocol bedrock-v354 diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index a78ab433f..443b6ad5e 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -27,12 +27,20 @@ package org.geysermc.connector; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import com.nukkitx.network.raknet.RakNetServer; +import com.nukkitx.network.raknet.RakNetServerListener; +import com.nukkitx.network.raknet.RakNetServerSession; import com.nukkitx.protocol.bedrock.BedrockPacketCodec; import com.nukkitx.protocol.bedrock.BedrockServer; import com.nukkitx.protocol.bedrock.v361.Bedrock_v361; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.socket.DatagramPacket; import lombok.Getter; +import org.apache.logging.log4j.core.filter.Filterable; +import org.fusesource.jansi.AnsiConsole; import org.geysermc.api.ChatColor; import org.geysermc.api.Connector; +import org.geysermc.api.ConsoleColors; import org.geysermc.api.Geyser; import org.geysermc.api.command.CommandMap; import org.geysermc.api.logger.Logger; @@ -48,10 +56,8 @@ import org.geysermc.connector.plugin.GeyserPluginLoader; import org.geysermc.connector.plugin.GeyserPluginManager; import org.geysermc.connector.utils.Toolbox; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; +import java.lang.reflect.Field; import java.net.InetSocketAddress; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -91,15 +97,21 @@ public class GeyserConnector implements Connector { } private GeyserConnector() { + if(!(System.console() == null) && System.getProperty("os.name", "Windows 10").toLowerCase().contains("windows")) { + AnsiConsole.systemInstall(); + } instance = this; this.generalThreadPool = Executors.newScheduledThreadPool(32); //TODO: Make configurable value - this.logger = new GeyserLogger(this); + + this.logger = GeyserLogger.DEFAULT; + ConsoleCommandReader consoleReader = new ConsoleCommandReader(this); + consoleReader.startConsole(); - logger.info(ChatColor.AQUA + "******************************************"); + logger.info("******************************************"); logger.info(""); logger.info("Loading " + NAME + " vesion " + VERSION); logger.info(""); 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 c2ff16b57..a57d95538 100644 --- a/connector/src/main/java/org/geysermc/connector/console/GeyserLogger.java +++ b/connector/src/main/java/org/geysermc/connector/console/GeyserLogger.java @@ -29,32 +29,19 @@ import org.geysermc.api.ChatColor; import org.geysermc.connector.GeyserConnector; import io.sentry.Sentry; -import java.io.File; -import java.io.IOException; -import java.io.PrintStream; +import java.io.*; +import java.lang.reflect.Field; import java.util.Date; -import java.util.logging.ConsoleHandler; -import java.util.logging.FileHandler; -import java.util.logging.Handler; -import java.util.logging.Level; -import java.util.logging.LogRecord; -import java.util.logging.Logger; -import java.util.logging.SimpleFormatter; +import java.util.logging.*; public class GeyserLogger implements org.geysermc.api.logger.Logger { - private Logger logger; - private boolean colored = true; private boolean debug = true; - public GeyserLogger(GeyserConnector connector) { - this.logger = Logger.getLogger(connector.getClass().getName()); + public static final GeyserLogger DEFAULT = new GeyserLogger(); - logger.setUseParentHandlers(false); - logger.setLevel(Level.ALL); - - System.setOut(new PrintStream(new LoggingOutputStream(this.logger, Level.INFO), true)); + private GeyserLogger() { ConsoleHandler consoleHandler = new ConsoleHandler(); consoleHandler.setLevel(Level.INFO); @@ -71,15 +58,13 @@ public class GeyserLogger implements org.geysermc.api.logger.Logger { } }); - logger.addHandler(consoleHandler); - 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) - logger.warning("Your log file is larger than " + maxLogFileSize + "Mo, you should backup and clean it !"); + 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() { @@ -94,7 +79,6 @@ public class GeyserLogger implements org.geysermc.api.logger.Logger { ); } }); - logger.addHandler(fileHandler); } catch (IOException | SecurityException ex) { Logger.getLogger(GeyserLogger.class.getName()).log(Level.SEVERE, null, ex); } @@ -102,31 +86,36 @@ public class GeyserLogger implements org.geysermc.api.logger.Logger { if (System.getenv().containsKey("DP_SENTRY_CLIENT_KEY")) { Handler sentryHandler = new io.sentry.jul.SentryHandler(); sentryHandler.setLevel(Level.SEVERE); - logger.addHandler(sentryHandler); Sentry.init(System.getenv().get("DP_SENTRY_CLIENT_KEY")); } } - public void info(String message) { - logger.info(printConsole(message, colored)); - } - + @Override public void severe(String message) { - logger.severe(printConsole(message, colored)); + System.out.println(printConsole(ChatColor.DARK_RED + message, colored)); } + @Override + public void error(String message) { + System.out.println(printConsole(ChatColor.RED + message, colored)); + } + + @Override public void warning(String message) { - logger.warning(printConsole(message, colored)); + 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) - info(message); + System.out.println(printConsole(ChatColor.GRAY + message, colored)); } public void stop() { - for (Handler handler : logger.getHandlers()) - handler.close(); } public static String printConsole(String message, boolean colors) { diff --git a/connector/src/main/java/org/geysermc/connector/console/LoggingOutputStream.java b/connector/src/main/java/org/geysermc/connector/console/LoggingOutputStream.java deleted file mode 100644 index 3a3c532f3..000000000 --- a/connector/src/main/java/org/geysermc/connector/console/LoggingOutputStream.java +++ /dev/null @@ -1,66 +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 java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.nio.charset.StandardCharsets; -import java.util.logging.Level; -import java.util.logging.Logger; - -public class LoggingOutputStream extends ByteArrayOutputStream { - - private Logger logger; - private Level level; - - public LoggingOutputStream(Logger logger, Level level) { - this.logger = logger; - this.level = level; - } - - @Override - public synchronized void write(int b) { - super.write(b); - - try { - String contents = toString(StandardCharsets.UTF_8.name()); - if (!contents.isEmpty() && !contents.equals(System.getProperty("line.separator"))) - logger.logp(level, "", "", contents); - } catch (UnsupportedEncodingException ex) { - Logger.getLogger(LoggingOutputStream.class.getName()).log(Level.SEVERE, null, ex); - } - } - - @Override - public synchronized void flush() throws IOException { - String contents = toString(StandardCharsets.UTF_8.name()); - super.reset(); - - if (!contents.isEmpty() && !contents.equals(System.getProperty("line.separator"))) - logger.logp(level, "", "", contents); - } -} 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 84719bb6f..44b80b5da 100644 --- a/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java @@ -51,16 +51,18 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler { @Override public BedrockPong onQuery(InetSocketAddress inetSocketAddress) { + System.out.println(inetSocketAddress + " has pinged you!"); GeyserConfiguration config = connector.getConfig(); BedrockPong pong = new BedrockPong(); pong.setEdition("MCPE"); pong.setMotd(config.getBedrock().getMotd1()); pong.setSubMotd(config.getBedrock().getMotd2()); - pong.setPlayerCount(1); + pong.setPlayerCount(2); pong.setMaximumPlayerCount(config.getMaxPlayers()); pong.setGameType("Default"); pong.setNintendoLimited(false); pong.setProtocolVersion(GeyserConnector.BEDROCK_PACKET_CODEC.getProtocolVersion()); + pong.setVersion("1.12.0"); return pong; } @@ -69,7 +71,10 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler { public void onSessionCreation(BedrockServerSession bedrockServerSession) { bedrockServerSession.setLogging(true); bedrockServerSession.setPacketHandler(new UpstreamPacketHandler(connector, new GeyserSession(connector, bedrockServerSession))); + bedrockServerSession.addDisconnectHandler((x) -> System.out.println("Bedrock user with ip: " + bedrockServerSession.getAddress().getAddress() + " has disconected for reason " + x)); bedrockServerSession.setPacketCodec(Bedrock_v361.V361_CODEC); } + + } \ No newline at end of file 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 d557b7037..059c2aa88 100644 --- a/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java @@ -52,6 +52,7 @@ public class UpstreamPacketHandler implements BedrockPacketHandler { System.err.println("Handled " + loginPacket.getClass().getSimpleName()); // TODO: Implement support for multiple protocols if (loginPacket.getProtocolVersion() != GeyserConnector.BEDROCK_PACKET_CODEC.getProtocolVersion()) { + System.out.println("unsupported"); session.getUpstream().disconnect("Unsupported Bedrock version. Are you running an outdated version?"); return true; } @@ -74,8 +75,12 @@ public class UpstreamPacketHandler implements BedrockPacketHandler { return true; } + + PlayStatusPacket playStatus = new PlayStatusPacket(); + playStatus.setStatus(PlayStatusPacket.Status.LOGIN_SUCCESS); + session.getUpstream().sendPacketImmediately(playStatus); ResourcePacksInfoPacket resourcePacksInfo = new ResourcePacksInfoPacket(); @@ -101,6 +106,7 @@ public class UpstreamPacketHandler implements BedrockPacketHandler { session.getUpstream().disconnect("disconnectionScreen.resourcePack"); break; } + return true; } 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 1422b6c12..42f965479 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 @@ -31,6 +31,7 @@ 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.packet.Packet; import com.github.steveice10.packetlib.tcp.TcpSessionFactory; import com.nukkitx.network.util.DisconnectReason; import com.nukkitx.protocol.PlayerSession; @@ -56,6 +57,8 @@ public class GeyserSession implements PlayerSession { @Getter private Client downstream; + private final GeyserSession THIS = this; + @Getter private AuthenticationData authenticationData; @@ -78,13 +81,13 @@ public class GeyserSession implements PlayerSession { @Override public void disconnected(DisconnectedEvent event) { - connector.getLogger().info(authenticationData.getName() + " has disconnected from remote java server on address " + remoteServer.getAddress()); + connector.getLogger().info(authenticationData.getName() + " has disconnected from remote java server on address " + remoteServer.getAddress() + " because of " + event.getReason()); upstream.disconnect(event.getReason()); } @Override public void packetReceived(PacketReceivedEvent event) { - Registry.JAVA.translate(event.getPacket().getClass(), event.getPacket()); + Registry.JAVA.translate(event.getPacket().getClass(), event.getPacket(), THIS); } }); 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 4d4dc1803..de10204aa 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 @@ -1,23 +1,26 @@ package org.geysermc.connector.network.translators; import com.github.steveice10.packetlib.packet.Packet; +import org.geysermc.api.Geyser; +import org.geysermc.connector.network.session.GeyserSession; import java.util.HashMap; import java.util.Map; +import java.util.function.BiConsumer; import java.util.function.Consumer; public class Registry { - private final Map, Consumer> MAP = new HashMap<>(); + private final Map, BiConsumer> MAP = new HashMap<>(); public static final Registry JAVA = new Registry<>(); - public static void add(Class clazz, Consumer translator) { + public static void add(Class clazz, BiConsumer translator) { JAVA.MAP.put(clazz, translator); } - public

void translate(Class

clazz, P p) { + public

void translate(Class

clazz, P p, GeyserSession s) { try { - ((Consumer

) JAVA.MAP.get(clazz)).accept(p); + ((BiConsumer) JAVA.MAP.get(clazz)).accept(p, s); } catch (NullPointerException e) { System.err.println("could not translate packet" + p.getClass().getSimpleName()); } 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 0c50411c2..7498c8a70 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 @@ -4,23 +4,34 @@ import com.flowpowered.math.vector.Vector2f; import com.flowpowered.math.vector.Vector3f; import com.flowpowered.math.vector.Vector3i; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerAbilitiesPacket; import com.nukkitx.protocol.bedrock.data.GamePublishSetting; import com.nukkitx.protocol.bedrock.data.GameRule; -import com.nukkitx.protocol.bedrock.packet.StartGamePacket; +import com.nukkitx.protocol.bedrock.packet.*; +import com.nukkitx.protocol.bedrock.v340.serializer.FullChunkDataSerializer_v340; +import com.nukkitx.protocol.bedrock.v340.serializer.ResourcePackChunkDataSerializer_v340; import org.geysermc.connector.utils.Toolbox; public class TranslatorsInit { public static void start() { - + addLoginPackets(); } private static void addLoginPackets() { - Registry.add(ServerJoinGamePacket.class, (x) -> { + Registry.add(ServerJoinGamePacket.class, (x, y) -> { + AdventureSettingsPacket bedrockPacket = new AdventureSettingsPacket(); + + bedrockPacket.setUniqueEntityId(x.getEntityId()); + + y.getUpstream().sendPacketImmediately(bedrockPacket); + + System.out.println(y.getUpstream().isClosed()); + StartGamePacket startGamePacket = new StartGamePacket(); startGamePacket.setUniqueEntityId(x.getEntityId()); startGamePacket.setRuntimeEntityId(x.getEntityId()); startGamePacket.setPlayerGamemode(x.getGameMode().ordinal()); - startGamePacket.setPlayerPosition(new Vector3f(-249, 67, -275)); + startGamePacket.setPlayerPosition(new Vector3f(0, 0, 0)); startGamePacket.setRotation(new Vector2f(1, 1)); startGamePacket.setSeed(1111); @@ -28,7 +39,7 @@ public class TranslatorsInit { startGamePacket.setGeneratorId(0); startGamePacket.setLevelGamemode(x.getGameMode().ordinal()); startGamePacket.setDifficulty(1); - startGamePacket.setDefaultSpawn(new Vector3i(-249, 67, -275)); + startGamePacket.setDefaultSpawn(new Vector3i(0, 0, 0)); startGamePacket.setAcheivementsDisabled(true); startGamePacket.setTime(1300); startGamePacket.setEduLevel(false); @@ -61,6 +72,44 @@ public class TranslatorsInit { startGamePacket.setEnchantmentSeed(1); startGamePacket.setMultiplayerCorrelationId(""); startGamePacket.setCachedPalette(Toolbox.CACHED_PALLETE); + + y.getUpstream().sendPacketImmediately(startGamePacket); + + System.out.println(y.getUpstream().isClosed()); + + Vector3f pos = new Vector3f(0, 0, 0); + + int chunkX = pos.getFloorX() >> 4; + + int chunkZ = pos.getFloorX() >> 4; + + for (int x1 = -3; x1 < 3; x1++) { + + for (int z = -3; z < 3; z++) { + + LevelChunkPacket data = new LevelChunkPacket(); + + data.setChunkX(chunkX + x1); + + data.setChunkZ(chunkZ + z); + + data.setData(new byte[0]); + + y.getUpstream().sendPacketImmediately(data); + + System.out.println(y.getUpstream().isClosed()); + + } + + } + + PlayStatusPacket packet = new PlayStatusPacket(); + + packet.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN); + + y.getUpstream().sendPacket(packet); + + System.out.println(y.getUpstream().isClosed()); }); } } diff --git a/connector/src/main/java/org/geysermc/connector/plugin/GeyserPluginLoader.java b/connector/src/main/java/org/geysermc/connector/plugin/GeyserPluginLoader.java index c0d9e0d97..7df06ee88 100644 --- a/connector/src/main/java/org/geysermc/connector/plugin/GeyserPluginLoader.java +++ b/connector/src/main/java/org/geysermc/connector/plugin/GeyserPluginLoader.java @@ -27,6 +27,7 @@ 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;