Fix paper in inventory
Deploy / Build (push) Successful in 2m23s
Deploy / Deploy (push) Successful in 11s

This commit is contained in:
2026-06-12 15:07:46 +02:00
parent 9efe35fe0d
commit 796e154c1c
2 changed files with 14 additions and 70 deletions
@@ -1,5 +1,6 @@
package net.wesjd.anvilgui;
import lombok.Getter;
import lombok.NonNull;
import net.md_5.bungee.api.chat.BaseComponent;
import net.wesjd.anvilgui.version.VersionWrapper;
@@ -76,10 +77,7 @@ public class AnvilGUI {
* A state that decides where the anvil GUI is able to get closed by the user
*/
private final boolean preventClose;
/**
* A state that decides whether compatibility with Geyser software is enabled
*/
private final boolean geyserCompatibility;
/**
* A set of slot numbers that are permitted to be interacted with by the user. An interactable
* slot is one that is able to be minipulated by the player, i.e. clicking and picking up an item,
@@ -102,6 +100,7 @@ public class AnvilGUI {
/**
* The inventory that is used on the Bukkit side of things
*/
@Getter
private Inventory inventory;
/**
* The listener holder class
@@ -127,7 +126,6 @@ public class AnvilGUI {
* @param titleComponent What to have the text already set to
* @param initialContents The initial contents of the inventory
* @param preventClose Whether to prevent the inventory from closing
* @param geyserCompatibility Whether to enable compatibility with Geyser software
* @param closeListener A {@link Consumer} when the inventory closes
* @param concurrentClickHandlerExecution Flag to allow concurrent execution of the click handler
* @param clickHandler A {@link ClickHandler} that is called when the player clicks a slot
@@ -139,7 +137,6 @@ public class AnvilGUI {
Object titleComponent,
ItemStack[] initialContents,
boolean preventClose,
boolean geyserCompatibility,
Set<Integer> interactableSlots,
Consumer<StateSnapshot> closeListener,
boolean concurrentClickHandlerExecution,
@@ -150,7 +147,6 @@ public class AnvilGUI {
this.titleComponent = titleComponent;
this.initialContents = initialContents;
this.preventClose = preventClose;
this.geyserCompatibility = geyserCompatibility;
this.interactableSlots = Collections.unmodifiableSet(interactableSlots);
this.closeListener = closeListener;
this.concurrentClickHandlerExecution = concurrentClickHandlerExecution;
@@ -181,11 +177,6 @@ public class AnvilGUI {
WRAPPER.setActiveContainerId(container, containerId);
WRAPPER.addActiveContainerSlotListener(container, player);
// Primitive Geyser Check!
if (player.getName().startsWith(".")) {
WRAPPER.sendPacketExperienceChange(player, 20);
}
open = true;
}
@@ -210,15 +201,20 @@ public class AnvilGUI {
HandlerList.unregisterAll(listener);
inventory = container.getBukkitInventory();
// We need to use setItem instead of setContents because a Minecraft ContainerAnvil
// contains two separate inventories: the result inventory and the ingredients inventory.
// The setContents method only updates the ingredients inventory unfortunately,
// but setItem handles the index going into the result inventory.
for (int i = 0; i < initialContents.length; i++) {
inventory.setItem(i, new ItemStack(Material.AIR));
}
if (sendClosePacket) {
WRAPPER.handleInventoryCloseEvent(player);
WRAPPER.setActiveContainerDefault(player);
WRAPPER.sendPacketCloseWindow(player, containerId);
}
// Primitive Geyser Check!
if (player.getName().startsWith(".")) {
WRAPPER.sendPacketExperienceChange(player, player.getLevel());
}
if (closeListener != null) {
closeListener.accept(StateSnapshot.fromAnvilGUI(this));
@@ -256,9 +252,6 @@ public class AnvilGUI {
* @param preserveRenameText Whether to preserve the entered rename text
*/
private void setTitle(Object title, boolean preserveRenameText) {
if (!true) {
return;
}
String renameText = container.getRenameText();
WRAPPER.sendPacketOpenWindow(player, containerId, title);
if (preserveRenameText) {
@@ -267,15 +260,6 @@ public class AnvilGUI {
}
}
/**
* Returns the Bukkit inventory for this anvil gui
*
* @return the {@link Inventory} for this anvil gui
*/
public Inventory getInventory() {
return inventory;
}
/**
* Simply holds the listeners for the GUI
*/
@@ -324,7 +308,7 @@ public class AnvilGUI {
}
if (rawSlot < 3 && rawSlot >= 0 || event.getAction().equals(InventoryAction.MOVE_TO_OTHER_INVENTORY)) {
event.setCancelled(!interactableSlots.contains(rawSlot));
event.setCancelled(true);
if (clickHandlerRunning && !concurrentClickHandlerExecution) {
// A click handler is running, don't launch another one
return;
@@ -368,12 +352,7 @@ public class AnvilGUI {
@EventHandler
public void onInventoryDrag(InventoryDragEvent event) {
if (event.getInventory().equals(inventory)) {
for (int slot : Slot.values()) {
if (event.getRawSlots().contains(slot)) {
event.setCancelled(!interactableSlots.contains(slot));
break;
}
}
event.setCancelled(true);
}
}
@@ -401,8 +380,6 @@ public class AnvilGUI {
private ClickHandler clickHandler;
/** A state that decides where the anvil GUI is able to be closed by the user */
private boolean preventClose = false;
/** A state that determines whether support for Geyser software is enabled */
private boolean geyserCompatibility = true;
/** A set of integers containing the slot numbers that should be modifiable by the user. */
private Set<Integer> interactableSlots = Collections.emptySet();
/** The {@link Plugin} that this anvil GUI is associated with */
@@ -440,14 +417,6 @@ public class AnvilGUI {
return this;
}
/**
* Disables compatibility with Geyser software
*/
public Builder disableGeyserCompat() {
geyserCompatibility = false;
return this;
}
/**
* Permit the user to modify (take items in and out) the slot numbers provided.
*
@@ -653,7 +622,6 @@ public class AnvilGUI {
titleComponent,
new ItemStack[] {itemLeft, itemRight, itemOutput},
preventClose,
geyserCompatibility,
interactableSlots,
closeListener,
concurrentClickHandlerExecution,
@@ -7,8 +7,6 @@ import net.minecraft.network.protocol.game.ClientboundContainerClosePacket;
import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket;
import net.minecraft.network.protocol.game.ClientboundSetExperiencePacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.Container;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.inventory.AnvilMenu;
import net.minecraft.world.inventory.ContainerLevelAccess;
import net.minecraft.world.inventory.MenuType;
@@ -21,8 +19,6 @@ import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import java.lang.reflect.Method;
public final class VersionWrapper {
public static final VersionWrapper INSTANCE = new VersionWrapper();
@@ -69,26 +65,6 @@ public final class VersionWrapper {
setTitle(guiTitle);
}
public void l() {
// If the output is empty copy the left input into the output
Slot output = this.getSlot(2);
if (!output.hasItem()) {
output.set(this.getSlot(0).getItem().copy());
}
this.cost.set(0);
// Sync to the client
this.sendAllDataToRemote();
this.broadcastChanges();
}
public void a(LivingEntity player) {
}
protected void a(LivingEntity player, Container container) {
}
public int getContainerId() {
return this.containerId;
}