Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-20 06:50:09 +01:00
More formatting fixes
Dieser Commit ist enthalten in:
Ursprung
1cdd66ae0b
Commit
48aa586b21
@ -235,6 +235,7 @@ public class GeyserSpigotWorldManager extends GeyserWorldManager {
|
|||||||
NbtMap blockEntityTag = lecternTag.build();
|
NbtMap blockEntityTag = lecternTag.build();
|
||||||
BlockEntityUtils.updateBlockEntity(session, blockEntityTag, Vector3i.from(x, y, z));
|
BlockEntityUtils.updateBlockEntity(session, blockEntityTag, Vector3i.from(x, y, z));
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isChunkLoad) {
|
if (isChunkLoad) {
|
||||||
// Delay to ensure the chunk is sent first, and then the lectern data
|
// Delay to ensure the chunk is sent first, and then the lectern data
|
||||||
Bukkit.getScheduler().runTaskLater(this.plugin, lecternInfoGet, 5);
|
Bukkit.getScheduler().runTaskLater(this.plugin, lecternInfoGet, 5);
|
||||||
|
@ -62,6 +62,10 @@ public class GeyserItemStack {
|
|||||||
this.netId = netId;
|
this.netId = netId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static GeyserItemStack from(ItemStack itemStack) {
|
||||||
|
return itemStack == null ? EMPTY : new GeyserItemStack(itemStack.getId(), itemStack.getAmount(), itemStack.getNbt());
|
||||||
|
}
|
||||||
|
|
||||||
public int getJavaId() {
|
public int getJavaId() {
|
||||||
return isEmpty() ? 0 : javaId;
|
return isEmpty() ? 0 : javaId;
|
||||||
}
|
}
|
||||||
@ -74,10 +78,6 @@ public class GeyserItemStack {
|
|||||||
return isEmpty() ? null : nbt;
|
return isEmpty() ? null : nbt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNetId(int netId) {
|
|
||||||
this.netId = netId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNetId() {
|
public int getNetId() {
|
||||||
return isEmpty() ? 0 : netId;
|
return isEmpty() ? 0 : netId;
|
||||||
}
|
}
|
||||||
@ -90,10 +90,6 @@ public class GeyserItemStack {
|
|||||||
amount -= sub;
|
amount -= sub;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GeyserItemStack from(ItemStack itemStack) {
|
|
||||||
return itemStack == null ? EMPTY : new GeyserItemStack(itemStack.getId(), itemStack.getAmount(), itemStack.getNbt());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack getItemStack() {
|
public ItemStack getItemStack() {
|
||||||
return getItemStack(amount);
|
return getItemStack(amount);
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,7 @@ public class BedrockLecternUpdateTranslator extends PacketTranslator<LecternUpda
|
|||||||
session.getConnector().getLogger().debug("Expected lectern but it wasn't open!");
|
session.getConnector().getLogger().debug("Expected lectern but it wasn't open!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LecternContainer lecternContainer = (LecternContainer) session.getOpenInventory();
|
LecternContainer lecternContainer = (LecternContainer) session.getOpenInventory();
|
||||||
if (lecternContainer.getCurrentBedrockPage() == packet.getPage()) {
|
if (lecternContainer.getCurrentBedrockPage() == packet.getPage()) {
|
||||||
// The same page means Bedrock is closing the window
|
// 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)
|
// 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 newJavaPage = (packet.getPage() * 2);
|
||||||
int currentJavaPage = (lecternContainer.getCurrentBedrockPage() * 2);
|
int currentJavaPage = (lecternContainer.getCurrentBedrockPage() * 2);
|
||||||
|
|
||||||
// Send as many click button packets as we need to
|
// 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
|
// 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
|
// is a byte when transmitted over the network and therefore this stops us at 128
|
||||||
|
@ -39,6 +39,7 @@ import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.*;
|
|||||||
import com.nukkitx.protocol.bedrock.packet.ItemStackResponsePacket;
|
import com.nukkitx.protocol.bedrock.packet.ItemStackResponsePacket;
|
||||||
import it.unimi.dsi.fastutil.ints.*;
|
import it.unimi.dsi.fastutil.ints.*;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.geysermc.connector.GeyserConnector;
|
||||||
import org.geysermc.connector.inventory.*;
|
import org.geysermc.connector.inventory.*;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.inventory.click.Click;
|
import org.geysermc.connector.network.translators.inventory.click.Click;
|
||||||
@ -171,9 +172,12 @@ public abstract class InventoryTranslator {
|
|||||||
} else {
|
} else {
|
||||||
response = rejectRequest(request);
|
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;
|
refresh = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
responsePacket.getEntries().add(response);
|
responsePacket.getEntries().add(response);
|
||||||
}
|
}
|
||||||
session.sendUpstreamPacket(responsePacket);
|
session.sendUpstreamPacket(responsePacket);
|
||||||
@ -198,11 +202,10 @@ public abstract class InventoryTranslator {
|
|||||||
transferAction.getSource().getSlot() >= 28 && transferAction.getSource().getSlot() <= 31) {
|
transferAction.getSource().getSlot() >= 28 && transferAction.getSource().getSlot() <= 31) {
|
||||||
return rejectRequest(request, false);
|
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("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()));
|
dumpStackRequestDetails(session, inventory, transferAction.getSource(), transferAction.getDestination());
|
||||||
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())));
|
|
||||||
return rejectRequest(request);
|
return rejectRequest(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,11 +288,10 @@ public abstract class InventoryTranslator {
|
|||||||
case SWAP: {
|
case SWAP: {
|
||||||
SwapStackRequestActionData swapAction = (SwapStackRequestActionData) action;
|
SwapStackRequestActionData swapAction = (SwapStackRequestActionData) action;
|
||||||
if (!(checkNetId(session, inventory, swapAction.getSource()) && checkNetId(session, inventory, swapAction.getDestination()))) {
|
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("DEBUG: About to reject SWAP request made by " + session.getName());
|
||||||
session.getConnector().getLogger().error("Source: " + swapAction.getSource().toString() + " Result: " + checkNetId(session, inventory, swapAction.getSource()));
|
dumpStackRequestDetails(session, inventory, swapAction.getSource(), swapAction.getDestination());
|
||||||
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())));
|
|
||||||
return rejectRequest(request);
|
return rejectRequest(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -756,13 +758,22 @@ public abstract class InventoryTranslator {
|
|||||||
* as bad (false).
|
* as bad (false).
|
||||||
*/
|
*/
|
||||||
public static ItemStackResponsePacket.Response rejectRequest(ItemStackRequest request, boolean throwError) {
|
public static ItemStackResponsePacket.Response rejectRequest(ItemStackRequest request, boolean throwError) {
|
||||||
if (throwError) {
|
if (throwError && GeyserConnector.getInstance().getConfig().isDebugMode()) {
|
||||||
// Currently for debugging, but might be worth it to keep in the future if something goes terribly wrong.
|
|
||||||
new Throwable("DEBUGGING: ItemStackRequest rejected " + request.toString()).printStackTrace();
|
new Throwable("DEBUGGING: ItemStackRequest rejected " + request.toString()).printStackTrace();
|
||||||
}
|
}
|
||||||
return new ItemStackResponsePacket.Response(ItemStackResponsePacket.ResponseStatus.ERROR, request.getRequestId(), Collections.emptyList());
|
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) {
|
public boolean checkNetId(GeyserSession session, Inventory inventory, StackRequestSlotInfoData slotInfoData) {
|
||||||
int netId = slotInfoData.getStackNetworkId();
|
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.
|
// "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.
|
||||||
|
@ -39,8 +39,9 @@ public class CraftingInventoryTranslator extends AbstractBlockInventoryTranslato
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SlotType getSlotType(int javaSlot) {
|
public SlotType getSlotType(int javaSlot) {
|
||||||
if (javaSlot == 0)
|
if (javaSlot == 0) {
|
||||||
return SlotType.OUTPUT;
|
return SlotType.OUTPUT;
|
||||||
|
}
|
||||||
return SlotType.NORMAL;
|
return SlotType.NORMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,5 +64,4 @@ public class HorseInventoryUpdater extends InventoryUpdater {
|
|||||||
session.sendUpstreamPacket(slotPacket);
|
session.sendUpstreamPacket(slotPacket);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren