3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-25 15:50:14 +01:00

More formatting fixes

Dieser Commit ist enthalten in:
Camotoy 2021-03-13 18:07:43 -05:00
Ursprung 1cdd66ae0b
Commit 48aa586b21
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
7 geänderte Dateien mit 34 neuen und 24 gelöschten Zeilen

Datei anzeigen

@ -235,6 +235,7 @@ public class GeyserSpigotWorldManager extends GeyserWorldManager {
NbtMap blockEntityTag = lecternTag.build();
BlockEntityUtils.updateBlockEntity(session, blockEntityTag, Vector3i.from(x, y, z));
};
if (isChunkLoad) {
// Delay to ensure the chunk is sent first, and then the lectern data
Bukkit.getScheduler().runTaskLater(this.plugin, lecternInfoGet, 5);

Datei anzeigen

@ -62,6 +62,10 @@ public class GeyserItemStack {
this.netId = netId;
}
public static GeyserItemStack from(ItemStack itemStack) {
return itemStack == null ? EMPTY : new GeyserItemStack(itemStack.getId(), itemStack.getAmount(), itemStack.getNbt());
}
public int getJavaId() {
return isEmpty() ? 0 : javaId;
}
@ -74,10 +78,6 @@ public class GeyserItemStack {
return isEmpty() ? null : nbt;
}
public void setNetId(int netId) {
this.netId = netId;
}
public int getNetId() {
return isEmpty() ? 0 : netId;
}
@ -90,10 +90,6 @@ public class GeyserItemStack {
amount -= sub;
}
public static GeyserItemStack from(ItemStack itemStack) {
return itemStack == null ? EMPTY : new GeyserItemStack(itemStack.getId(), itemStack.getAmount(), itemStack.getNbt());
}
public ItemStack getItemStack() {
return getItemStack(amount);
}

Datei anzeigen

@ -65,6 +65,7 @@ public class BedrockLecternUpdateTranslator extends PacketTranslator<LecternUpda
session.getConnector().getLogger().debug("Expected lectern but it wasn't open!");
return;
}
LecternContainer lecternContainer = (LecternContainer) session.getOpenInventory();
if (lecternContainer.getCurrentBedrockPage() == packet.getPage()) {
// The same page means Bedrock is closing the window
@ -76,6 +77,7 @@ public class BedrockLecternUpdateTranslator extends PacketTranslator<LecternUpda
// 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);
// Send as many click button packets as we need to
// Java has the option to specify exact page numbers by adding 100 to the number, but buttonId variable
// is a byte when transmitted over the network and therefore this stops us at 128

Datei anzeigen

@ -367,7 +367,7 @@ public class BedrockInteractTranslator extends PacketTranslator<InteractPacket>
if (ridingEntity instanceof AbstractHorseEntity) {
if (ridingEntity.getMetadata().getFlags().getFlag(EntityFlag.TAMED)) {
// We should request to open the horse inventory instead
ClientPlayerStatePacket openHorseWindowPacket = new ClientPlayerStatePacket((int)session.getPlayerEntity().getEntityId(), PlayerState.OPEN_HORSE_INVENTORY);
ClientPlayerStatePacket openHorseWindowPacket = new ClientPlayerStatePacket((int) session.getPlayerEntity().getEntityId(), PlayerState.OPEN_HORSE_INVENTORY);
session.sendDownstreamPacket(openHorseWindowPacket);
}
} else {

Datei anzeigen

@ -39,6 +39,7 @@ import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.*;
import com.nukkitx.protocol.bedrock.packet.ItemStackResponsePacket;
import it.unimi.dsi.fastutil.ints.*;
import lombok.AllArgsConstructor;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.inventory.*;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.inventory.click.Click;
@ -171,9 +172,12 @@ public abstract class InventoryTranslator {
} else {
response = rejectRequest(request);
}
if (response.getResult() == ItemStackResponsePacket.ResponseStatus.ERROR) {
if (response.getResult() != ItemStackResponsePacket.ResponseStatus.OK) {
// Sync our copy of the inventory with Bedrock's to prevent desyncs
refresh = true;
}
responsePacket.getEntries().add(response);
}
session.sendUpstreamPacket(responsePacket);
@ -198,11 +202,10 @@ public abstract class InventoryTranslator {
transferAction.getSource().getSlot() >= 28 && transferAction.getSource().getSlot() <= 31) {
return rejectRequest(request, false);
}
if (session.getConnector().getConfig().isDebugMode()) {
session.getConnector().getLogger().error("DEBUG: About to reject TAKE/PLACE request made by " + session.getName());
session.getConnector().getLogger().error("Source: " + transferAction.getSource().toString() + " Result: " + checkNetId(session, inventory, transferAction.getSource()));
session.getConnector().getLogger().error("Destination: " + transferAction.getDestination().toString() + " Result: " + checkNetId(session, inventory, transferAction.getDestination()));
session.getConnector().getLogger().error("Geyser's record of source slot: " + inventory.getItem(bedrockSlotToJava(transferAction.getSource())));
session.getConnector().getLogger().error("Geyser's record of destination slot: " + inventory.getItem(bedrockSlotToJava(transferAction.getDestination())));
dumpStackRequestDetails(session, inventory, transferAction.getSource(), transferAction.getDestination());
}
return rejectRequest(request);
}
@ -285,11 +288,10 @@ public abstract class InventoryTranslator {
case SWAP: {
SwapStackRequestActionData swapAction = (SwapStackRequestActionData) action;
if (!(checkNetId(session, inventory, swapAction.getSource()) && checkNetId(session, inventory, swapAction.getDestination()))) {
if (session.getConnector().getConfig().isDebugMode()) {
session.getConnector().getLogger().error("DEBUG: About to reject SWAP request made by " + session.getName());
session.getConnector().getLogger().error("Source: " + swapAction.getSource().toString() + " Result: " + checkNetId(session, inventory, swapAction.getSource()));
session.getConnector().getLogger().error("Destination: " + swapAction.getDestination().toString() + " Result: " + checkNetId(session, inventory, swapAction.getDestination()));
session.getConnector().getLogger().error("Geyser's record of source slot: " + inventory.getItem(bedrockSlotToJava(swapAction.getSource())));
session.getConnector().getLogger().error("Geyser's record of destination slot: " + inventory.getItem(bedrockSlotToJava(swapAction.getDestination())));
dumpStackRequestDetails(session, inventory, swapAction.getSource(), swapAction.getDestination());
}
return rejectRequest(request);
}
@ -756,13 +758,22 @@ public abstract class InventoryTranslator {
* as bad (false).
*/
public static ItemStackResponsePacket.Response rejectRequest(ItemStackRequest request, boolean throwError) {
if (throwError) {
// Currently for debugging, but might be worth it to keep in the future if something goes terribly wrong.
if (throwError && GeyserConnector.getInstance().getConfig().isDebugMode()) {
new Throwable("DEBUGGING: ItemStackRequest rejected " + request.toString()).printStackTrace();
}
return new ItemStackResponsePacket.Response(ItemStackResponsePacket.ResponseStatus.ERROR, request.getRequestId(), Collections.emptyList());
}
/**
* Print out the contents of an ItemStackRequest, should the net ID check fail.
*/
protected void dumpStackRequestDetails(GeyserSession session, Inventory inventory, StackRequestSlotInfoData source, StackRequestSlotInfoData destination) {
session.getConnector().getLogger().error("Source: " + source.toString() + " Result: " + checkNetId(session, inventory, source));
session.getConnector().getLogger().error("Destination: " + destination.toString() + " Result: " + checkNetId(session, inventory, destination));
session.getConnector().getLogger().error("Geyser's record of source slot: " + inventory.getItem(bedrockSlotToJava(source)));
session.getConnector().getLogger().error("Geyser's record of destination slot: " + inventory.getItem(bedrockSlotToJava(destination)));
}
public boolean checkNetId(GeyserSession session, Inventory inventory, StackRequestSlotInfoData slotInfoData) {
int netId = slotInfoData.getStackNetworkId();
// "In my testing, sometimes the client thinks the netId of an item in the crafting grid is 1, even though we never said it was.

Datei anzeigen

@ -39,8 +39,9 @@ public class CraftingInventoryTranslator extends AbstractBlockInventoryTranslato
@Override
public SlotType getSlotType(int javaSlot) {
if (javaSlot == 0)
if (javaSlot == 0) {
return SlotType.OUTPUT;
}
return SlotType.NORMAL;
}

Datei anzeigen

@ -64,5 +64,4 @@ public class HorseInventoryUpdater extends InventoryUpdater {
session.sendUpstreamPacket(slotPacket);
return true;
}
}