From bc3c2df17ef04b2d02934d923b08a99b112eff57 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Fri, 24 Feb 2023 22:35:05 +0000 Subject: [PATCH] Finally get the extension updated --- README.md | 2 +- bootstrap/geyser/pom.xml | 4 +-- .../geyser/MCXboxBroadcastExtension.java | 25 +++++++++++-------- .../geyser/src/main/resources/extension.yml | 3 ++- bootstrap/pom.xml | 10 +++++++- bootstrap/standalone/pom.xml | 6 ++--- core/pom.xml | 2 +- .../core/RtaWebsocketClient.java | 2 +- 8 files changed, 34 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 8d54180..383d85b 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ You use this project at your own risk, the contributors are not responsible for ## Features - Syncing of MOTD and other server details - Automatic friend list management - - ~~Easy Geyser integration (as an extension)~~ (Currently not working due to API limitations) + - Easy Geyser integration (as an extension) ## Pterodactyl Panel There is an egg for easy instance creation supplied for [Pterodactyl Panel](https://pterodactyl.io/), this being `egg-m-c-xbox-broadcast.json` diff --git a/bootstrap/geyser/pom.xml b/bootstrap/geyser/pom.xml index 70edfce..c748eea 100644 --- a/bootstrap/geyser/pom.xml +++ b/bootstrap/geyser/pom.xml @@ -38,13 +38,13 @@ com.fasterxml.jackson.core jackson-core - 2.13.2 + 2.14.0 compile com.fasterxml.jackson.dataformat jackson-dataformat-yaml - 2.13.2 + 2.14.0 compile diff --git a/bootstrap/geyser/src/main/java/com/rtm516/mcxboxbroadcast/bootstrap/geyser/MCXboxBroadcastExtension.java b/bootstrap/geyser/src/main/java/com/rtm516/mcxboxbroadcast/bootstrap/geyser/MCXboxBroadcastExtension.java index 93859ed..0e9b910 100644 --- a/bootstrap/geyser/src/main/java/com/rtm516/mcxboxbroadcast/bootstrap/geyser/MCXboxBroadcastExtension.java +++ b/bootstrap/geyser/src/main/java/com/rtm516/mcxboxbroadcast/bootstrap/geyser/MCXboxBroadcastExtension.java @@ -8,11 +8,13 @@ import com.rtm516.mcxboxbroadcast.core.exceptions.SessionCreationException; import com.rtm516.mcxboxbroadcast.core.exceptions.SessionUpdateException; import com.rtm516.mcxboxbroadcast.core.exceptions.XboxFriendsException; +import com.rtm516.mcxboxbroadcast.core.models.FollowerResponse; +import org.geysermc.api.Geyser; import org.geysermc.common.PlatformType; +import org.geysermc.event.subscribe.Subscribe; import org.geysermc.floodgate.util.Utils; import org.geysermc.floodgate.util.WhitelistUtils; import org.geysermc.geyser.GeyserImpl; -import org.geysermc.geyser.api.event.Subscribe; import org.geysermc.geyser.api.event.lifecycle.GeyserPostInitializeEvent; import org.geysermc.geyser.api.extension.Extension; import org.geysermc.geyser.api.network.AuthType; @@ -24,9 +26,12 @@ import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; +import java.net.URISyntaxException; import java.net.UnknownHostException; import java.nio.file.FileSystem; +import java.nio.file.FileSystems; import java.nio.file.Files; +import java.util.Collections; import java.util.concurrent.TimeUnit; public class MCXboxBroadcastExtension implements Extension { @@ -45,7 +50,7 @@ public void onPostInitialize(GeyserPostInitializeEvent event) { // Create the config file if it doesn't exist if (!configFile.exists()) { try (FileWriter writer = new FileWriter(configFile)) { - try (FileSystem fileSystem = this.fileSystem()) { + try (FileSystem fileSystem = FileSystems.newFileSystem(new File(MCXboxBroadcastExtension.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toPath(), Collections.emptyMap())) { try (InputStream input = Files.newInputStream(fileSystem.getPath("config.yml"))) { byte[] bytes = new byte[input.available()]; @@ -56,7 +61,7 @@ public void onPostInitialize(GeyserPostInitializeEvent event) { writer.flush(); } } - } catch (IOException e) { + } catch (IOException | URISyntaxException e) { logger.error("Failed to create config", e); return; } @@ -105,7 +110,7 @@ public void onPostInitialize(GeyserPostInitializeEvent event) { sessionInfo.setVersion(this.geyserApi().defaultRemoteServer().minecraftVersion()); sessionInfo.setProtocol(this.geyserApi().defaultRemoteServer().protocolVersion()); sessionInfo.setPlayers(this.geyserApi().onlineConnections().size()); - sessionInfo.setMaxPlayers(this.geyserApi().maxPlayers()); + sessionInfo.setMaxPlayers(GeyserImpl.getInstance().getConfig().getMaxPlayers()); // TODO Find API equivalent sessionInfo.setIp(ip); sessionInfo.setPort(port); @@ -120,7 +125,7 @@ public void onPostInitialize(GeyserPostInitializeEvent event) { } // Start the update timer - GeyserImpl.getInstance().getScheduledThread().scheduleWithFixedDelay(this::tick, config.updateInterval, config.updateInterval, TimeUnit.SECONDS); + GeyserImpl.getInstance().getScheduledThread().scheduleWithFixedDelay(this::tick, config.updateInterval, config.updateInterval, TimeUnit.SECONDS); // TODO Find API equivalent }).start(); } @@ -138,13 +143,13 @@ private void tick() { // If we are in spigot, using floodgate authentication and have the config option enabled // get the users friends and whitelist them - if (this.geyserApi().defaultRemoteServer().authType() == AuthType.HYBRID - && GeyserImpl.getInstance().getPlatformType() == PlatformType.SPIGOT + if (this.geyserApi().defaultRemoteServer().authType() == AuthType.FLOODGATE + && GeyserImpl.getInstance().getPlatformType() == PlatformType.SPIGOT // TODO Find API equivalent && config.whitelistFriends) { try { - for (String xuid : sessionManager.getXboxFriends()) { - if (WhitelistUtils.addPlayer(Utils.getJavaUuid(xuid), "unknown")) { - logger.info("Added xbox friend " + xuid + " to whitelist"); + for (FollowerResponse.Person person : sessionManager.getXboxFriends()) { + if (WhitelistUtils.addPlayer(Utils.getJavaUuid(person.xuid), "unknown")) { + logger.info("Added xbox friend " + person.displayName + " to whitelist"); } } } catch (XboxFriendsException e) { diff --git a/bootstrap/geyser/src/main/resources/extension.yml b/bootstrap/geyser/src/main/resources/extension.yml index 4012ca6..6b936f6 100644 --- a/bootstrap/geyser/src/main/resources/extension.yml +++ b/bootstrap/geyser/src/main/resources/extension.yml @@ -1,5 +1,6 @@ +id: mcxboxbroadcast name: MCXboxBroadcast version: 1.0 main: com.rtm516.mcxboxbroadcast.bootstrap.geyser.MCXboxBroadcastExtension -api: "2.0.2" +api: "1.0.1" authors: [ "rtm516" ] diff --git a/bootstrap/pom.xml b/bootstrap/pom.xml index d1e38d9..d0c63c3 100644 --- a/bootstrap/pom.xml +++ b/bootstrap/pom.xml @@ -38,6 +38,14 @@ true + + sonatype-oss-snapshots1 + https://s01.oss.sonatype.org/content/repositories/snapshots/ + + + jitpack.io + https://jitpack.io + @@ -50,7 +58,7 @@ - + geyser standalone \ No newline at end of file diff --git a/bootstrap/standalone/pom.xml b/bootstrap/standalone/pom.xml index 739923d..83a9b4d 100644 --- a/bootstrap/standalone/pom.xml +++ b/bootstrap/standalone/pom.xml @@ -20,20 +20,20 @@ com.fasterxml.jackson.core jackson-core - 2.13.2 + 2.14.0 compile com.fasterxml.jackson.dataformat jackson-dataformat-yaml - 2.13.2 + 2.14.0 compile com.nukkitx.protocol bedrock-common - 2.9.4 + 2.9.17-20230217.002312-1 org.slf4j diff --git a/core/pom.xml b/core/pom.xml index 432097e..ab643af 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -20,7 +20,7 @@ com.fasterxml.jackson.core jackson-databind - 2.13.2.1 + 2.14.0 com.nimbusds diff --git a/core/src/main/java/com/rtm516/mcxboxbroadcast/core/RtaWebsocketClient.java b/core/src/main/java/com/rtm516/mcxboxbroadcast/core/RtaWebsocketClient.java index b9cb8ba..3c118a1 100644 --- a/core/src/main/java/com/rtm516/mcxboxbroadcast/core/RtaWebsocketClient.java +++ b/core/src/main/java/com/rtm516/mcxboxbroadcast/core/RtaWebsocketClient.java @@ -73,7 +73,7 @@ public void onMessage(String message) { */ @Override public void onClose(int code, String reason, boolean remote) { - logger.debug("Websocket disconnected: " + reason + " (" + code + ")"); + logger.debug("Websocket disconnected: " + reason + " (" + code + ")"); } /**