Skip to content

Commit

Permalink
Finally get the extension updated
Browse files Browse the repository at this point in the history
  • Loading branch information
rtm516 committed Feb 24, 2023
1 parent 24cf4c6 commit bc3c2df
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
4 changes: 2 additions & 2 deletions bootstrap/geyser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.2</version>
<version>2.14.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.13.2</version>
<version>2.14.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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()];

Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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();
}

Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion bootstrap/geyser/src/main/resources/extension.yml
Original file line number Diff line number Diff line change
@@ -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" ]
10 changes: 9 additions & 1 deletion bootstrap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>sonatype-oss-snapshots1</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -50,7 +58,7 @@
</dependencies>

<modules>
<!-- <module>geyser</module>-->
<module>geyser</module>
<module>standalone</module>
</modules>
</project>
6 changes: 3 additions & 3 deletions bootstrap/standalone/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.2</version>
<version>2.14.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.13.2</version>
<version>2.14.0</version>
<scope>compile</scope>
</dependency>
<!-- For pinging servers -->
<dependency>
<groupId>com.nukkitx.protocol</groupId>
<artifactId>bedrock-common</artifactId>
<version>2.9.4</version>
<version>2.9.17-20230217.002312-1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.2.1</version>
<version>2.14.0</version>
</dependency>
<dependency>
<groupId>com.nimbusds</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 + ")");
}

/**
Expand Down

0 comments on commit bc3c2df

Please sign in to comment.