1.11.2 Weird error while opening a crafting table inventory

Discussion in 'Spigot Plugin Development' started by sdfqsdfqsdfqsdf, Jan 29, 2020.

  1. Error:
    Code (Text):
    [15:52:32] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'crafter' in plugin AutoCrafter v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[server.jar:git-Spigot-cbd1a1b-009d8af]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) ~[server.jar:git-Spigot-cbd1a1b-009d8af]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.dispatchCommand(CraftServer.java:710) ~[server.jar:git-Spigot-cbd1a1b-009d8af]
            at net.minecraft.server.v1_14_R1.PlayerConnection.handleCommand(PlayerConnection.java:1641) ~[server.jar:git-Spigot-cbd1a1b-009d8af]
            at net.minecraft.server.v1_14_R1.PlayerConnection.a(PlayerConnection.java:1481) ~[server.jar:git-Spigot-cbd1a1b-009d8af]
            at net.minecraft.server.v1_14_R1.PacketPlayInChat.a(PacketPlayInChat.java:47) ~[server.jar:git-Spigot-cbd1a1b-009d8af]
            at net.minecraft.server.v1_14_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) ~[server.jar:git-Spigot-cbd1a1b-009d8af]
            at net.minecraft.server.v1_14_R1.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:19) ~[server.jar:git-Spigot-cbd1a1b-009d8af]
            at net.minecraft.server.v1_14_R1.TickTask.run(SourceFile:18) [server.jar:git-Spigot-cbd1a1b-009d8af]
            at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.executeTask(SourceFile:144) [server.jar:git-Spigot-cbd1a1b-009d8af]
            at net.minecraft.server.v1_14_R1.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) [server.jar:git-Spigot-cbd1a1b-009d8af]
            at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.executeNext(SourceFile:118) [server.jar:git-Spigot-cbd1a1b-009d8af]
            at net.minecraft.server.v1_14_R1.MinecraftServer.aX(MinecraftServer.java:909) [server.jar:git-Spigot-cbd1a1b-009d8af]
            at net.minecraft.server.v1_14_R1.MinecraftServer.executeNext(MinecraftServer.java:902) [server.jar:git-Spigot-cbd1a1b-009d8af]
            at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.awaitTasks(SourceFile:127) [server.jar:git-Spigot-cbd1a1b-009d8af]
            at net.minecraft.server.v1_14_R1.MinecraftServer.sleepForTick(MinecraftServer.java:886) [server.jar:git-Spigot-cbd1a1b-009d8af]
            at net.minecraft.server.v1_14_R1.MinecraftServer.run(MinecraftServer.java:819) [server.jar:git-Spigot-cbd1a1b-009d8af]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_211]
    Caused by: java.lang.IllegalArgumentException: Cannot open an inventory of type CRAFTING
            at org.apache.commons.lang.Validate.isTrue(Validate.java:71) ~[server.jar:git-Spigot-cbd1a1b-009d8af]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.createInventory(CraftServer.java:1533) ~[server.jar:git-Spigot-cbd1a1b-009d8af]
            at fr.snow.autocraft.mainclass.onCommand(mainclass.java:243) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[server.jar:git-Spigot-cbd1a1b-009d8af]
            ... 17 more
    here is the code that is the problem:
    if(args.length == 0)
    {
    sender.sendMessage("§6========== §eCommande §6==========");
    sender.sendMessage("§6/§ecrafter get §6{Player} {Amount} §e: donne un ou plusieurs crafters au joueur ciblé");
    ((Player)sender).openInventory(Bukkit.getServer().createInventory(null, InventoryType.CRAFTING));
    }
     
  2. Use this method instead:
    Code (Java):
    ((Player) sender).openWorkbench(null, true);
     
  3. InventoryType.CRAFTING is the 2x2 crafting-inventory in your "normal" Inventory. If you wish to open that, your only choice is to open the player Inventory.
    I suspect, however, that you want to open the Inventory that is represented by a workbench. Either use @Krymonota's Method, or change the inventory to InventoryType.WORKBENCH
     
  4. Oh and for this question, I am trying to use it to get a craft from a random chest content (shaped)
    do you think I can use this or not ?

    CraftingInventory craft = (CraftingInventory) Bukkit.createInventory(null, InventoryType.WORKBENCH);
    craft.setItem(0, itms.get(0));craft.setItem(1, itms.get(1));craft.setItem(2, itms.get(2));
    craft.setItem(3, itms.get(3));craft.setItem(4, itms.get(4));craft.setItem(5, itms.get(5));
    craft.setItem(6, itms.get(6));craft.setItem(7, itms.get(7));craft.setItem(8, itms.get(8));
    return craft.getResult();
     
  5. Why using CraftInventory thou?
    It seems like a simple Inventory would be sufficient in this case. Also, a loop might just be beneficial here...