Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
* Copyright (c) 2019-2026 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
Expand Down Expand Up @@ -36,7 +36,20 @@ public class BedrockCommandRequestTranslator extends PacketTranslator<CommandReq

@Override
public void translate(GeyserSession session, CommandRequestPacket packet) {
String command = MessageTranslator.convertIncomingToPlainText(packet.getCommand());
session.sendCommand(MessageTranslator.normalizeSpace(command).substring(1));
// Java trims all messages, and then checks for the leading slash
String message = MessageTranslator.convertIncomingToPlainText(
MessageTranslator.normalizeSpace(packet.getCommand())
);

if (message.isBlank()) {
// Java Edition (as of 1.17.1) just doesn't pass on these messages, so... we won't either!
return;
}

if (!message.startsWith("/")) {
return;
}

session.sendCommand(message.substring(1));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
* Copyright (c) 2019-2026 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
Expand Down Expand Up @@ -32,6 +32,7 @@
import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator;
import org.geysermc.geyser.util.InventoryUtils;
import org.geysermc.geyser.util.MathUtils;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundContainerButtonClickPacket;

/**
Expand All @@ -49,15 +50,24 @@ public void translate(GeyserSession session, LecternUpdatePacket packet) {
return;
}

if (lecternContainer.getCurrentBedrockPage() == packet.getPage()) {
// Books on java can only be 100 pages so clamp the page number to that
// This also forces requested pages to be sequential
// This is 25 for showing page 49/50, and 50 for 99/100
int currentPage = lecternContainer.getCurrentBedrockPage();
int requestedPage = packet.getPage();
int page = MathUtils.constrain(MathUtils.constrain(requestedPage, currentPage - 1, currentPage + 1), 0, 50);

if (currentPage == requestedPage) {
// The same page means Bedrock is closing the window
InventoryUtils.sendJavaContainerClose(holder);
InventoryUtils.closeInventory(session, holder, false);
} else if (currentPage == page) {
// The requested page was clamped back to the current page so do nothing
} else {
// Each "page" Bedrock gives to us actually represents two pages (think opening a book and seeing two pages)
// Each "page" on Java is just one page (think a spiral notebook folded back to only show one page)
int newJavaPage = (packet.getPage() * 2);
int currentJavaPage = (lecternContainer.getCurrentBedrockPage() * 2);
int newJavaPage = (page * 2);
int currentJavaPage = (currentPage * 2);
Comment on lines +53 to +70

// So, fun fact: We need to separately handle fake lecterns!
// Since those are not actually a real lectern... the Java server won't respond to our requests.
Expand Down
13 changes: 2 additions & 11 deletions core/src/main/java/org/geysermc/geyser/util/AssetUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
* Copyright (c) 2019-2026 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
Expand Down Expand Up @@ -202,16 +202,7 @@ public static void downloadAndRunClientJarTasks() {

public static void saveFile(Path location, InputStream fileStream) throws IOException {
try (OutputStream outStream = Files.newOutputStream(location)) {

// Write the file to the locale dir
byte[] buf = new byte[fileStream.available()];
int length;
while ((length = fileStream.read(buf)) != -1) {
outStream.write(buf, 0, length);
}

// Flush all changes to disk and cleanup
outStream.flush();
fileStream.transferTo(outStream);
}
}

Expand Down
Loading