Loading custom inventory

Discussion in 'Plugin Development' started by Eos, Jul 22, 2015.

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

    Eos

    The players inventory saves to the config, but it doesn't load there inventory for some odd reason.


    Code:
    Player pinv;
    
    Inventory enderchest = Bukkit.createInventory(pinv, 27, ChatColor.GREEN + "Ender Chest");
    HashMap < String, ItemStack[] > invsave = new HashMap < String, ItemStack[] > ();
    
    public void onDisable() {
    
        for (Map.Entry < String, ItemStack[] > userentry: invsave.entrySet()) {
            try {
    
                Config.set(userentry.getKey().toString() + ".enderchest", userentry.getValue());
                Config.save(ConfigFile);
                Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "[Risk] has saved players inventories");
    
    
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    
    @
    EventHandler
    public void customINVDetectClose(InventoryCloseEvent e) {
        try {
            if (e.getInventory().getName().equals(ChatColor.GREEN + "Ender Chest")) {
                invsave.put(e.getPlayer().getUniqueId().toString(), enderchest.getContents());
    
                e.getPlayer().sendMessage("Closes");
    
            }
        } catch (Exception er) {
            er.printStackTrace();
        }
    }
    
    
    @
    EventHandler
    public void customINVDetect(PlayerInteractEvent e) {
        Player p = e.getPlayer();
        ItemStack item = p.getItemInHand();
        if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK) || e.getAction().equals(Action.RIGHT_CLICK_AIR)) {
            if (e.getClickedBlock().getType().equals(Material.ENDER_CHEST)) {
                e.setCancelled(true);
    
                if (invsave.containsKey(p.getUniqueId().toString())) {
                    enderchest.setContents(invsave.get(p.getUniqueId().toString()));
                    p.sendMessage("Debug");
    
                }
                p.openInventory(enderchest);
            }
        }
    }
     
  2. Offline

    Zombie_Striker

    @Eos
    Did you call the Inventory update event?
     
  3. Offline

    Eos

    @Zombie_Striker, No I haven't i'll try that once the minecraft session is back up.

    Edit: Doesn't work.
     
    Last edited: Jul 22, 2015
  4. Offline

    WPM

    Just switch your minecraft localhost server or whatever it is to offline mode.
     
  5. Offline

    SantaClawz69

    @Eos was there like an error message somewhere in the console? You should probably take that out. If none, please post the full code so we can examine what you have maybe done wrong.
     
  6. Offline

    Eos

    No error. No you don't need the full code thats all the code that's related to the inventory.
     
Thread Status:
Not open for further replies.

Share This Page