Error with chests

Discussion in 'Plugin Development' started by CactusComboPvP, Aug 22, 2014.

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

    CactusComboPvP

    Okay so a code im using is this:
    Code:
    private HashMap<UUID, Inventory> backpacks = new HashMap<UUID, Inventory>();
       
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e) {
            Inventory inv = Bukkit.getServer().createInventory(e.getPlayer(), InventoryType.CHEST);
           
            if (getConfig().contains("backpacks." + e.getPlayer().getUniqueId())) {
                for (String item : getConfig().getConfigurationSection("backpacks." + e.getPlayer().getUniqueId()).getKeys(false)) {
                    inv.addItem(loadItem(getConfig().getConfigurationSection("backpacks." + e.getPlayer().getUniqueId() + "." + item)));
                }
            }
           
            backpacks.put(e.getPlayer().getUniqueId(), inv);
        }
       
        @EventHandler
        public void onPlayerLeave(PlayerQuitEvent e) {
            if (!getConfig().contains("backpacks." + e.getPlayer().getUniqueId())) {
                getConfig().createSection("backpacks." + e.getPlayer().getUniqueId());
            }
           
            char c = 'a';
            for (ItemStack itemStack : backpacks.get(e.getPlayer().getUniqueId())) {
                if (itemStack != null) {
                    saveItem(getConfig().createSection("backpacks." + e.getPlayer().getUniqueId() + "." + c++), itemStack);
                }
            }
           
            saveConfig();
        }
       
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            getConfig().options().copyDefaults(true);
            saveConfig();
            saveDefaultConfig();
        }
       
        public void onDisable() {
            for (Entry<UUID, Inventory> entry : backpacks.entrySet()) {
                if (!getConfig().contains("backpacks." + entry.getKey())) {
                    getConfig().createSection("backpacks." + entry.getKey());
                }
               
                char c = 'a';
                for (ItemStack itemStack : entry.getValue()) {
                    if (itemStack != null) {
                        saveItem(getConfig().createSection("backpacks." + entry.getKey() + "." + c++), itemStack);
                    }
                }
               
                saveConfig();
            }
        }
       
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if (!(sender instanceof Player)) {
                sender.sendMessage(ChatColor.RED + "The console cannot have an backpack.");
                return true;
            }
           
            Player p = (Player) sender;
           
            if (cmd.getName().equalsIgnoreCase("backpack")) {
                p.openInventory(backpacks.get(p.getUniqueId()));
            }
           
            return true;
        }
       
        private void saveItem(ConfigurationSection section, ItemStack itemStack) {
            section.set("type", itemStack.getType().name());
            section.set("amount", itemStack.getAmount());
            // Save more information.
        }
       
        private ItemStack loadItem(ConfigurationSection section) {
            return new ItemStack(Material.valueOf(section.getString("type")), section.getInt("amount"));
            // Load more information.
        }

    But when i do /backpack it gives an error on command:
    Code:
    p.openInventory(backpacks.get(p.getUniqueId()));
     
  2. Offline

    Kassestral

    Can we have the error log?
     
Thread Status:
Not open for further replies.

Share This Page