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

Reject requests that are unavailable spaces; other things

Dieser Commit ist enthalten in:
Camotoy 2021-03-08 14:17:31 -05:00
Ursprung 7e3d51f9ad
Commit 44e9dba759
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
7 geänderte Dateien mit 40 neuen und 17 gelöschten Zeilen

Datei anzeigen

@ -418,8 +418,6 @@ public class GeyserSession implements CommandSender {
this.spawned = false;
this.loggedIn = false;
connector.getPlayers().forEach(player -> this.emotes.addAll(player.getEmotes()));
// Make a copy to prevent ConcurrentModificationException
final List<GeyserSession> tmpPlayers = new ArrayList<>(connector.getPlayers());
tmpPlayers.forEach(player -> this.emotes.addAll(player.getEmotes()));

Datei anzeigen

@ -121,7 +121,8 @@ public abstract class InventoryTranslator {
*
* @return true if this transfer should be rejected
*/
public boolean shouldRejectItemPlace(GeyserSession session, Inventory inventory, int javaSourceSlot, int javaDestinationSlot) {
public boolean shouldRejectItemPlace(GeyserSession session, Inventory inventory, ContainerSlotType bedrockSourceContainer,
int javaSourceSlot, ContainerSlotType bedrockDestinationContainer, int javaDestinationSlot) {
return false;
}
@ -201,8 +202,9 @@ public abstract class InventoryTranslator {
int sourceSlot = bedrockSlotToJava(transferAction.getSource());
int destSlot = bedrockSlotToJava(transferAction.getDestination());
if (shouldRejectItemPlace(session, inventory, isCursor(transferAction.getSource()) ? -1 : sourceSlot,
isCursor(transferAction.getDestination()) ? -1 : destSlot)) {
if (shouldRejectItemPlace(session, inventory, transferAction.getSource().getContainer(),
isCursor(transferAction.getSource()) ? -1 : sourceSlot,
transferAction.getDestination().getContainer(), isCursor(transferAction.getDestination()) ? -1 : destSlot)) {
// This item would not be here in Java
return rejectRequest(request, false);
}
@ -273,7 +275,7 @@ public abstract class InventoryTranslator {
}
break;
}
case SWAP: { //TODO
case SWAP: {
SwapStackRequestActionData swapAction = (SwapStackRequestActionData) action;
if (!(checkNetId(session, inventory, swapAction.getSource()) && checkNetId(session, inventory, swapAction.getDestination()))) {
session.getConnector().getLogger().error("DEBUG: About to reject SWAP request made by " + session.getName());
@ -284,23 +286,31 @@ public abstract class InventoryTranslator {
return rejectRequest(request);
}
if (isCursor(swapAction.getSource()) && isCursor(swapAction.getDestination())) { //???
int sourceSlot = bedrockSlotToJava(swapAction.getSource());
int destSlot = bedrockSlotToJava(swapAction.getDestination());
boolean isSourceCursor = isCursor(swapAction.getSource());
boolean isDestCursor = isCursor(swapAction.getDestination());
if (shouldRejectItemPlace(session, inventory, swapAction.getSource().getContainer(),
isSourceCursor ? -1 : sourceSlot,
swapAction.getDestination().getContainer(), isDestCursor ? -1 : destSlot)) {
// This item would not be here in Java
return rejectRequest(request, false);
}
if (isSourceCursor && isDestCursor) { //???
return rejectRequest(request);
} else if (isCursor(swapAction.getSource())) { //swap cursor
int destSlot = bedrockSlotToJava(swapAction.getDestination());
} else if (isSourceCursor) { //swap cursor
if (InventoryUtils.canStack(cursor, plan.getItem(destSlot))) { //TODO: cannot simply swap if cursor stacks with slot (temp slot)
return rejectRequest(request);
}
plan.add(Click.LEFT, destSlot);
} else if (isCursor(swapAction.getDestination())) { //swap cursor
int sourceSlot = bedrockSlotToJava(swapAction.getSource());
} else if (isDestCursor) { //swap cursor
if (InventoryUtils.canStack(cursor, plan.getItem(sourceSlot))) { //TODO
return rejectRequest(request);
}
plan.add(Click.LEFT, sourceSlot);
} else {
int sourceSlot = bedrockSlotToJava(swapAction.getSource());
int destSlot = bedrockSlotToJava(swapAction.getDestination());
if (!cursor.isEmpty()) { //TODO: (temp slot)
return rejectRequest(request);
}

Datei anzeigen

@ -43,7 +43,8 @@ public class CartographyInventoryTranslator extends AbstractBlockInventoryTransl
}
@Override
public boolean shouldRejectItemPlace(GeyserSession session, Inventory inventory, int javaSourceSlot, int javaDestinationSlot) {
public boolean shouldRejectItemPlace(GeyserSession session, Inventory inventory, ContainerSlotType bedrockSourceContainer,
int javaSourceSlot, ContainerSlotType bedrockDestinationContainer, int javaDestinationSlot) {
if (javaDestinationSlot == 0) {
// Bedrock Edition can use paper in slot 0
GeyserItemStack itemStack = javaSourceSlot == -1 ? session.getPlayerInventory().getCursor() : inventory.getItem(javaSourceSlot);

Datei anzeigen

@ -100,7 +100,8 @@ public class LoomInventoryTranslator extends AbstractBlockInventoryTranslator {
}
@Override
public boolean shouldRejectItemPlace(GeyserSession session, Inventory inventory, int javaSourceSlot, int javaDestinationSlot) {
public boolean shouldRejectItemPlace(GeyserSession session, Inventory inventory, ContainerSlotType bedrockSourceContainer,
int javaSourceSlot, ContainerSlotType bedrockDestinationContainer, int javaDestinationSlot) {
if (javaDestinationSlot != 1) {
return false;
}

Datei anzeigen

@ -30,7 +30,9 @@ import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityDataMap;
import com.nukkitx.protocol.bedrock.data.entity.EntityLinkData;
import com.nukkitx.protocol.bedrock.data.inventory.*;
import com.nukkitx.protocol.bedrock.data.inventory.ContainerSlotType;
import com.nukkitx.protocol.bedrock.data.inventory.ItemStackRequest;
import com.nukkitx.protocol.bedrock.data.inventory.StackRequestSlotInfoData;
import com.nukkitx.protocol.bedrock.packet.ItemStackResponsePacket;
import com.nukkitx.protocol.bedrock.packet.SetEntityLinkPacket;
import org.geysermc.connector.entity.Entity;
@ -128,6 +130,7 @@ public class MerchantInventoryTranslator extends BaseInventoryTranslator {
@Override
public void openInventory(GeyserSession session, Inventory inventory) {
//Handled in JavaTradeListTranslator
//TODO: send a blank inventory here in case the villager doesn't send a TradeList packet
}
@Override

Datei anzeigen

@ -41,6 +41,16 @@ public abstract class ChestInventoryTranslator extends BaseInventoryTranslator {
this.updater = new ChestInventoryUpdater(paddedSize);
}
@Override
public boolean shouldRejectItemPlace(GeyserSession session, Inventory inventory, ContainerSlotType bedrockSourceContainer,
int javaSourceSlot, ContainerSlotType bedrockDestinationContainer, int javaDestinationSlot) {
// Reject any item placements that occur in the unusable inventory space
if (bedrockSourceContainer == ContainerSlotType.CONTAINER && javaSourceSlot >= this.size) {
return true;
}
return bedrockDestinationContainer == ContainerSlotType.CONTAINER && javaDestinationSlot >= this.size;
}
@Override
public void updateInventory(GeyserSession session, Inventory inventory) {
updater.updateInventory(this, session, inventory);

Datei anzeigen

@ -61,7 +61,7 @@ public class JavaOpenHorseWindowTranslator extends PacketTranslator<ServerOpenHo
String[] acceptedHorseArmorIdentifiers = new String[] {"minecraft:horsearmorleather", "minecraft:horsearmoriron",
"minecraft:horsearmorgold", "minecraft:horsearmordiamond"};
NbtMapBuilder armorBuilder = NbtMap.builder();
List<NbtMap> acceptedArmors = new ArrayList<>();
List<NbtMap> acceptedArmors = new ArrayList<>(4);
for (String identifier : acceptedHorseArmorIdentifiers) {
NbtMapBuilder acceptedItemBuilder = NbtMap.builder()
.putShort("Aux", Short.MAX_VALUE)