How to force player to open their crafting inventory?

Discussion in 'Plugin Development' started by ShakyTom, Aug 2, 2013.

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

    ShakyTom

    Hey there.

    I want to be able to force a player to open their own crafting inventory (the one you get when you press e ingame that shows inventory, armour slots etc).

    I have tried the following

    Code:
    player.openInventory(player.getInventory());
    but that just opens up the contents of the players inventory as a chest.

    Any help?
     
  2. Offline

    xTrollxDudex

    ShakyTom
    Create an inventory:
    PHP:
    Inventory inv Bukkit.createInventory(playerInventoryType.PLAYER);
    and open
    PHP:
    player.openInventory(inv);
    Note you will need to add items to your inventory, try
    PHP:
    ItemStack[] is player.getInventory().getContents();
    inv.getInventory().setContents(is);
     
  3. Offline

    ShakyTom


    So I can't get their current inventory and open that? I have to create a new duplicate one first?
     
  4. Offline

    xTrollxDudex

    ShakyTom
    Yes. And about putting items in, my bad it's supposed to be inv.setContents(is);
     
  5. Offline

    ShakyTom

    Gave the code a go anyway, it just does the same as

    Code:
    player.openInventory(player.getInventory());
    which shows
    [​IMG]

    I want to open this inventory:

    [​IMG]

    Thanks for the help :)
     
  6. Offline

    xTrollxDudex

  7. Offline

    ShakyTom


    Code:
    Inventory pInv = plugin.getServer().createInventory(player, InventoryType.PLAYER);
    pInv.setContents(player.getInventory().getContents());
    player.openInventory(pInv);
     
  8. Offline

    xTrollxDudex

    ShakyTom
    Try
    PHP:
    PlayerInventory pInv = (PlayerInventoryplugin.getServer().createInventory(playerInventoryType.PLAYER);
    pInv.setArmorContents(player.getInventory().getArmorContents());
    pInv.setContents(ayer.getInventory().getContents());
    player.openInventory(pInv);
     
  9. Offline

    ShakyTom

    Code:
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_6_R2.inventory.CraftInventoryCustom cannot be cast to org.bukkit.inventory.PlayerInventory
     
  10. Offline

    xTrollxDudex

    ShakyTom
    Dangit. I'm starting to doubt the possibility of this.
     
  11. Offline

    ShakyTom


    Would seem very strange if this is impossible :/
     
  12. Offline

    xTrollxDudex

    ShakyTom
    The inventory opening should be handled client side, since you can switch the key used to open you inventory. What wouldn't make sense is that if it was handled client side, then people can easily give themselves items via client hacks. There are no hacks that can do this(NEI/TMI use the /give command). So it is mixed, and I have no furthur idea.
     
  13. Offline

    ShakyTom


    Thanks for your help anyway, maybe someone else has an idea? :)
     
  14. Offline

    foodyling

    ShakyTom I believe opening their inventory is client side only, however you could always open a plain old crafting bench instead.
     
    Meatiex and xTrollxDudex like this.
Thread Status:
Not open for further replies.

Share This Page