Bug appears when i open inventory for player. I tried my own code and code from docs. But, they all also cause an error.
Error
java.lang.IllegalArgumentException: Listener already listening
at net.minecraft.server.v1_12_R1.Container.addSlotListener(Container.java:56) ~[spigot.jar:git-Spigot-dcd1643-e60fc34]
at net.minecraft.server.v1_12_R1.EntityPlayer.syncInventory(EntityPlayer.java:236) ~[spigot.jar:git-Spigot-dcd1643-e60fc34]
at net.minecraft.server.v1_12_R1.PlayerList.a(PlayerList.java:219) ~[spigot.jar:git-Spigot-dcd1643-e60fc34]
at net.minecraft.server.v1_12_R1.LoginListener.b(LoginListener.java:159) ~[spigot.jar:git-Spigot-dcd1643-e60fc34]
at net.minecraft.server.v1_12_R1.LoginListener.e(LoginListener.java:57) ~[spigot.jar:git-Spigot-dcd1643-e60fc34]
at net.minecraft.server.v1_12_R1.NetworkManager.a(NetworkManager.java:233) ~[spigot.jar:git-Spigot-dcd1643-e60fc34]
at net.minecraft.server.v1_12_R1.ServerConnection.c(ServerConnection.java:140) [spigot.jar:git-Spigot-dcd1643-e60fc34]
at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:845) [spigot.jar:git-Spigot-dcd1643-e60fc34]
at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [spigot.jar:git-Spigot-dcd1643-e60fc34]
at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [spigot.jar:git-Spigot-dcd1643-e60fc34]
at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [spigot.jar:git-Spigot-dcd1643-e60fc34]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_275]
My code
Provider:
public class SelectionProvider implements InventoryProvider {
public static final SmartInventory INVENTORY = SmartInventory.builder()
.id("myInventory")
.provider(new SelectionProvider())
.size(3, 9)
.title(ChatColor.BLUE + "My Awesome Inventory!")
.build();
private final Random random = new Random();
@Override
public void init(Player player, InventoryContents contents) {
contents.fillBorders(ClickableItem.empty(new ItemStack(Material.STAINED_GLASS_PANE)));
contents.set(1, 1, ClickableItem.of(new ItemStack(Material.CARROT_ITEM),
e -> player.sendMessage(ChatColor.GOLD + "You clicked on a potato.")));
contents.set(1, 7, ClickableItem.of(new ItemStack(Material.BARRIER),
e -> player.closeInventory()));
}
@Override
public void update(Player player, InventoryContents contents) {
int state = contents.property("state", 0);
contents.setProperty("state", state + 1);
if(state % 5 != 0)
return;
short durability = (short) random.nextInt(15);
ItemStack glass = new ItemStack(Material.STAINED_GLASS_PANE, 1, durability);
contents.fillBorders(ClickableItem.empty(glass));
}
}
When the bug appears
Bug appears when i open inventory for player. I tried my own code and code from docs. But, they all also cause an error.
Error
My code
Provider:
Fragment of listener code, that opens menu.