Solved Open *Offline* Players enderchest

Discussion in 'Plugin Development' started by Destroyer7712, Jul 7, 2015.

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

    Destroyer7712

    I know to open an EnderChest you do
    Code:
    player.openInventory(target.getEnderChest());
    But, I haven't been able to figure out how to get an offline players inventory.

    I've tried
    Code:
    target = Bukkit.getOfflinePlayer(targetname);
    but it returns a CraftOfflinePlayer.

    How do I get the Enderchest of an offline player?
     
  2. You need to save it in a file when they disconnect. Something like this:
    Code:
        @EventHandler
        public void playerQuitEvent(PlayerQuitEvent e) {
            Player p = e.getPlayer();
            String uuid = p.getUniqueId().toString();
           
            List<String> contents = new ArrayList<String>();
           
            String format;
            for(ItemStack is : p.getEnderChest().getContents()) {
                format = is.getTypeId()+" "+is.getAmount()+" "+is.getDurability()+" "+is.getData();
            }
           
            getConfig().set(uuid+".enderchest", contents);
            saveConfig();
        }
    And then just make a simple parser that can read it when ever you want to open the player's enderchest
     
    Destroyer7712 likes this.
  3. thats a bad way of doing it. There is actually a built in method to save/read itemstacks from a configuration.
    directly set the itemstack to a path and use config.getItemStack(path) to get it. Or use this resource: http://bukkit.org/threads/saving-inventory-in-config.372202/
     
    Destroyer7712 and adventuretc like this.
  4. Offline

    Destroyer7712

Thread Status:
Not open for further replies.

Share This Page