How do you create an CraftingInventory?

Discussion in 'Plugin Development' started by ChrisixStudios, Apr 9, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    ChrisixStudios

    Hello Bukkit Community :)

    I am trying to create a CraftingInventory object for my viewer so I can access the setResult(ItemStack result) method. Here is the code I have.

    Code:java
    1. CraftingInventory top = (CraftingInventory) Bukkit.createInventory(p, InventoryType.WORKBENCH);

    The value p is a Player which is part of the constructor. For me this seems like It should work but i get a ClassCastException CraftInventoryCustome to CraftingInventory. I know this is part of the craftbukkit.jar but I like to stay away and just use the API in the bukkit.jar. So how do you go about Creating a CraftingInventory? Thanks for any help :)
     
  2. Offline

    chasechocolate

    I believe it has to be done with packets. Check out http://wiki.vg/Protocol#Open_Window_.280x64.29
    Code:java
    1. Packet100OpenWindow packet = new Packet100OpenWindow(1, 1, "Crafting", 9, true); //Title will get overridden
    2. ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
     
  3. Offline

    tylersyme

    Ok, so I know this is a tad old but I tried the code you used and got an importing error that I've never seen before

    Caused by: java.lang.ClassNotFoundException: net.minecraft.server.v1_5_R2.Packet
    at org.bukkit.plugin.java.PluginClassLoader.findClass0(PluginClassLoader.java:70)
    Is this a simple fix?

    oh, and this is what I imported (everything worked before I imported this and added that code)

    import net.minecraft.server.v1_5_R2.Packet100OpenWindow;

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  4. Offline

    chasechocolate

    tylersyme you have to be building against CraftBukkit, not Bukkit.
     
  5. Offline

    tylersyme

    Yes, I am. I'm using CraftBukkit beta build and there are no errors until I attempt to run my plugin, then I get this whole error
    Code:
    11:49:25 [SEVERE] Could not load 'plugins/ExaItems.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.NoClassDefFoundError: net/minecraft/server/v1_5_R2/Packet
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:184)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
        at org.bukkit.craftbukkit.v1_5_R3.CraftServer.loadPlugins(CraftServer.java:239)
        at org.bukkit.craftbukkit.v1_5_R3.CraftServer.reload(CraftServer.java:603)
        at org.bukkit.Bukkit.reload(Bukkit.java:185)
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:23)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:189)
        at org.bukkit.craftbukkit.v1_5_R3.CraftServer.dispatchCommand(CraftServer.java:523)
        at org.bukkit.craftbukkit.v1_5_R3.CraftServer.dispatchServerCommand(CraftServer.java:512)
        at net.minecraft.server.v1_5_R3.DedicatedServer.an(DedicatedServer.java:262)
        at net.minecraft.server.v1_5_R3.DedicatedServer.r(DedicatedServer.java:227)
        at net.minecraft.server.v1_5_R3.MinecraftServer.q(MinecraftServer.java:477)
        at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java:410)
        at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:573)
    Caused by: java.lang.NoClassDefFoundError: net/minecraft/server/v1_5_R2/Packet
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:247)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:173)
        ... 14 more
    Caused by: java.lang.ClassNotFoundException: net.minecraft.server.v1_5_R2.Packet
        at org.bukkit.plugin.java.PluginClassLoader.findClass0(PluginClassLoader.java:70)
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:53)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        ... 17 more
    11:49:25 [INFO] Server permissions file permissions.yml is empty, ignoring it
    11:49:25 [INFO] CONSOLE: Reload complete.
    
    Now, it was caused by that import: Caused by: java.lang.ClassNotFoundException: net.minecraft.server.v1_5_R2.Packet

    So there are no errors showing in eclipse but when I run it, there is. I'm using
    craftbukkit-1.5.1-R0.3-20130418.060238-5.jar as my library
     
  6. getPlayer().openWorkbench(Location location, boolean force);
     
Thread Status:
Not open for further replies.

Share This Page