Cannot get chest inventory !

Discussion in 'Spigot Plugin Development' started by Arest, Jul 6, 2015.

  1. So i have made a plugin that place a chest when ever a player die and i want to add those items from player inventory to that chest but i get an error here is the code

    Code (Text):
    package me.Arest.re;

    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.material.Chest;
    import org.bukkit.plugin.java.JavaPlugin;

    public class re extends JavaPlugin implements Listener {
        public void onEnable() {
            Bukkit.getServer().getLogger().info("Resurrection v1.0 Enabled !");
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
        }
        public void onDisable() {
            Bukkit.getServer().getLogger().info("Resurrection v1.0 Disabled !");
        }
        @EventHandler
            public void onPlayerDeathEvent(PlayerDeathEvent e) {
                if(!(e.getEntity() instanceof Player )) return;
                Player p = e.getEntity();
                Location pl = p.getLocation();
                World world = p.getWorld();
                Location playerChestplace = new Location(world, pl.getX()+2,pl.getY(),pl.getZ());
                playerChestplace.getBlock().setType(Material.CHEST);
                Chest chest = (Chest) playerChestplace.getBlock().getState();
               
                ItemStack[] pinventory = p.getInventory().getContents();
                ItemStack[] chestInventory = new ItemStack[pinventory.length];
               
               
                }
           
           
        }
     
    And from there i dont know what to do next someone help me please :)
     
  2. to get the inventory, you do chest.getBlockInventory(); in there you can set the contents or get the contents and stuff like that.
     
  3. Use seperate classes for events and commands and anything inbetween! Only use the main class to set up everything as the plugin is loaded!
     
  4. Code (Text):
    if(!(e.getEntity() instanceof Player )) return;
    Code (Text):
    Player p = e.getEntity();
    [​IMG]
     
    • Funny Funny x 2