Invalid Inventory Size?

Discussion in 'Plugin Development' started by TheHandfish, Jun 20, 2014.

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



    So on my favorite server, there's a Creative server. A lot of people use this client that allows you to get "rare items" and give them to others. However, recently, some people have found a way to jack up the items and make them crash you when you spawn. So, I've got this plugin that has a configurable timeout that is initiated every time you pick up an item, and if you log out during the time, it backs your inventory up into a config (using the InventorySerializer library) and makes it available for access using /restoreinv. Miraculously, the everything up until the /restoreinv command works great. Here is my command sender:

    1. @Override
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    3. {
    4. if (cmd.getName().equalsIgnoreCase("restoreinv"))
    5. {
    6. if(sender instanceof Player)
    7. {
    8. Player p = (Player) sender;
    9. if(plugin.getConfig().contains("CrashResolver." + p.getDisplayName() + ".Contents"))
    10. {
    11. p.sendMessage("§aViewing restored inventory. Take what you need now, it won't stay!");
    12. ItemStack[] lastinv = InventoryStringDeSerializer.StringToInventory(plugin.getConfig().getString("CrashResolver." + p.getDisplayName() + ".Contents")).getContents();
    13. Inventory newinv = Bukkit.createInventory(p, InventoryType.CHEST);
    14. newinv.setContents(lastinv); // Line 81 - ERROR POINT
    15. p.openInventory(newinv);
    16. plugin.getConfig().set("CrashResolver." + p.getDisplayName(), null);
    17. }
    18. else
    19. {
    20. p.sendMessage("§6No saved inventory to view!");
    21. }
    22. return true;
    23. }
    24. }
    25. return false;
    26. }

    (NOTICE: I marked out Line 81: // Line 81 - ERROR POINT)
    I get an error whenever I try /restoreinv.

    So apparently, the problem is that the inventory "newinv" is too small or something. I'm not completely sure to be honest (which I guess is why I'm posting here :p). So, how can I:
    a) Make the restored inventory have 36 slots (enough to fit a full Player inventory) and b) get rid of this error?
  2. Offline


    Use Bukkit.createInventory(p, 36, p.getName()); instead of your current one. Idk why yours isnt working but that one will work.

    Or Bukkit.createInventory(p, InventoryType.PLAYER);

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 9, 2016
  3. Offline


    @ferrargo: Thanks! Your first reply worked for me.
Thread Status:
Not open for further replies.

Share This Page