forked from git-mirrors/GeyserConnect
Support Geyser 2.1.1
This commit is contained in:
parent
a933ae0463
commit
0c2304e662
4 changed files with 39 additions and 10 deletions
|
@ -30,12 +30,12 @@ dependencies {
|
|||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
|
||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
|
||||
|
||||
compileOnly 'org.geysermc.geyser:api:2.1.0-SNAPSHOT'
|
||||
compileOnly('org.geysermc.geyser:core:2.1.0-SNAPSHOT') {
|
||||
compileOnly 'org.geysermc.geyser:api:2.1.1-SNAPSHOT'
|
||||
compileOnly('org.geysermc.geyser:core:2.1.1-SNAPSHOT') {
|
||||
exclude group: 'io.netty'
|
||||
}
|
||||
|
||||
implementation 'org.xerial:sqlite-jdbc:3.41.2.1'
|
||||
implementation 'org.xerial:sqlite-jdbc:3.41.2.2'
|
||||
implementation 'com.mysql:mysql-connector-j:8.0.33'
|
||||
}
|
||||
|
||||
|
|
|
@ -41,13 +41,14 @@ import org.geysermc.geyser.api.connection.GeyserConnection;
|
|||
import org.geysermc.geyser.api.event.bedrock.SessionInitializeEvent;
|
||||
import org.geysermc.geyser.api.event.lifecycle.GeyserDefineCommandsEvent;
|
||||
import org.geysermc.geyser.api.event.lifecycle.GeyserPostInitializeEvent;
|
||||
import org.geysermc.geyser.api.event.lifecycle.GeyserPreInitializeEvent;
|
||||
import org.geysermc.geyser.api.extension.Extension;
|
||||
import org.geysermc.geyser.api.network.AuthType;
|
||||
import org.geysermc.geyser.api.util.PlatformType;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GeyserConnect implements Extension {
|
||||
|
@ -71,6 +72,14 @@ public class GeyserConnect implements Extension {
|
|||
return storageManager;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onPreInitialize(GeyserPreInitializeEvent event) {
|
||||
if (this.geyserApi().platformType() != PlatformType.STANDALONE) {
|
||||
this.logger().severe("GeyserConnect is only supported on standalone Geyser instances!");
|
||||
this.disable();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onPostInitialize(GeyserPostInitializeEvent event) {
|
||||
config = ConfigLoader.load(this, GeyserConnect.class, Config.class);
|
||||
|
@ -89,16 +98,22 @@ public class GeyserConnect implements Extension {
|
|||
}
|
||||
|
||||
storageManager.setupStorage();
|
||||
|
||||
GeyserImpl geyserInstance = (GeyserImpl) this.geyserApi();
|
||||
|
||||
// Remove all saved logins to prevent issues connecting
|
||||
// Maybe worth adding support for this later
|
||||
geyserInstance.getConfig().getSavedUserLogins().clear();
|
||||
|
||||
if (geyserInstance.getConfig().isPassthroughMotd() || geyserInstance.getConfig().isPassthroughPlayerCounts()) {
|
||||
this.logger().warning("Either `passthrough-motd` or `passthrough-player-counts` is enabled in the config, this will likely produce errors");
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onSessionInitialize(SessionInitializeEvent event) {
|
||||
GeyserSession session = (GeyserSession) event.connection();
|
||||
|
||||
// Remove all saved logins to prevent issues connecting
|
||||
// Maybe worth adding support for this later
|
||||
session.getGeyser().getConfig().getSavedUserLogins().clear();
|
||||
|
||||
// Change the packet handler to our own
|
||||
BedrockPacketHandler packetHandler = session.getUpstream().getSession().getPacketHandler();
|
||||
session.getUpstream().getSession().setPacketHandler(new PacketHandler(this, session, packetHandler));
|
||||
|
|
|
@ -35,7 +35,6 @@ import org.geysermc.cumulus.form.CustomForm;
|
|||
import org.geysermc.cumulus.form.ModalForm;
|
||||
import org.geysermc.cumulus.form.SimpleForm;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.util.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -55,7 +54,7 @@ public class UIHandler {
|
|||
String message = "";
|
||||
try {
|
||||
File messageFile = Utils.fileOrCopiedFromResource(GeyserConnect.instance().config().welcomeFile(), "welcome.txt");
|
||||
message = new String(FileUtils.readAllBytes(messageFile), StandardCharsets.UTF_8);
|
||||
message = new String(Utils.readAllBytes(messageFile), StandardCharsets.UTF_8);
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.geysermc.connect.extension.GeyserConnect;
|
|||
import org.geysermc.geyser.session.GeyserSession;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -111,4 +112,18 @@ public class Utils {
|
|||
originalPacketHandler.handle(initializedPacket);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read all bytes from a file
|
||||
*
|
||||
* @param file File to read bytes of
|
||||
* @return The byte array of the file
|
||||
*/
|
||||
public static byte[] readAllBytes(File file) {
|
||||
try (InputStream stream = new FileInputStream(file)) {
|
||||
return stream.readAllBytes();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Cannot read " + file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue