Save config enderchest?

Discussion in 'Plugin Development' started by sum_17427, Nov 24, 2014.

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

    sum_17427

    Here my code:
    Code:
    package me.summc.Backpack;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin implements Listener{
       
        public void onEnable(){
            getServer().getPluginManager().registerEvents(this, this);
        }
       
        @EventHandler
        public void onInventoryClick(PlayerInteractEvent e){
            Player p = e.getPlayer();
            Inventory newcomer = Bukkit.createInventory(null, 18, ChatColor.BLACK + "Backpack");
            Inventory skyman = Bukkit.createInventory(null, 27, ChatColor.BLACK + "Backpack");
            Inventory skyguide = Bukkit.createInventory(null, 36, ChatColor.BLACK + "Backpack");
            ItemStack air = new ItemStack(Material.AIR);
            ItemMeta airMeta = air.getItemMeta();
            air.setItemMeta(airMeta);
            if (p.hasPermission("bp.normal")){
                if ((e.getAction() == Action.LEFT_CLICK_AIR)) {
                    if (p.getItemInHand().getType() == Material.ENDER_CHEST){
                        newcomer.setItem(1, air);
                        p.openInventory(newcomer);
                    }
                }
            }
            if (p.hasPermission("bp.medium")){
                if ((e.getAction() == Action.LEFT_CLICK_AIR)) {
                    if (p.getItemInHand().getType() == Material.ENDER_CHEST){
                        skyman.setItem(1, air);
                        p.openInventory(skyman);
                    }
                }
            }
            if (p.hasPermission("bp.hard")){
                if ((e.getAction() == Action.LEFT_CLICK_AIR)) {
                    if (p.getItemInHand().getType() == Material.ENDER_CHEST){
                        skyguide.setItem(1, air);
                        p.openInventory(skyguide);
                    }
                }
            }
        }
       
        public void onDisable(){
           
        }
    }
    
    When i put item in there then close and open again, the item is gone? Please help me
     
  2. Offline

    mrCookieSlime

    Moved to Plugin Developement.
     
  3. Offline

    JordyPwner

    OFFTOPIC? When did u got Moderator :confused: ALso GG :D

    ONTOPIC: Do you save the items in a config file?
     
  4. Offline

    mrCookieSlime

    JordyPwner
    Please keep this Thread clean. You can talk about things like that on my Profile. And I am mod since 3 days now.

    sum_17427
    You probably want to store the Player's UUID in an ArrayList when they open the Inventory.
    And when they close it, loop through all the Items in the Inventory and store them in a config along with their slot.
    Now when you open the Inventory, instead of setting an Air Block into the first Inventory slot, loop through the size of the Inventory and retrieve the ItemStack from the config using the current slot.
     
  5. Offline

    sum_17427

    mrCookieSlime
    What should i do? Can i have a full code, also im remove the Air Block
     
  6. Offline

    mrCookieSlime

    sum_17427
    I am not going to spoonfeed you.
    I told you what to do, you can just google how to do it.
     
Thread Status:
Not open for further replies.

Share This Page