Put items in chest!

Discussion in 'Nukkit discussions and help' started by LucGamesHD, 2/3/16.

  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
Dismiss Notice
We welcome you on our site. This site is devoted to the Nukkit project and all that is connected with him. Here you can communicate, download plugins, also many other things get acquainted! Register the account right now :3
  1. LucGamesHD

    LucGamesHD Developer

    Messages:
    26
    Likes Received:
    10
    Minecraft:
    LucGamesYT
    Hey i found a methode to put items in chests :D
    P.S This is a Code from a Test plugin xD

    Code:
    @EventHandler
    public void onTest(BlockPlaceEvent e){
    Player p = e.getPlayer();
    Block block = e.getBlock();
    
    [pre][code]    if(block.getId() == Block.CHEST){
            double x = e.getBlock().getX();
            double y = e.getBlock().getY();
            double z = e.getBlock().getZ();
            List<String> arenen = cfg.getStringList("Blocks");
            arenen.add(x + "," + y + "," + z);
            cfg.set("Blocks", arenen);
            cfg.save();
            p.sendMessage("Erlfogreich gesetzt!");
        }
    
    }
    
    public void refillChests(Level level){
        if(level instanceof Level){
            List<String> list = cfg.getStringList("Blocks");
            for(String sign : list){
                String[] infos = sign.split(",");
                double x = Double.valueOf(infos[0]);
                double y = Double.valueOf(infos[1]);
                double z = Double.valueOf(infos[2]);
    
                if(level.getBlockEntity(new Vector3(x, y, z)) instanceof BlockEntityChest){
                    BlockEntityChest chest = (BlockEntityChest) level.getBlockEntity(new Vector3(x, y, z));
                    addStuff(chest);
                }
    
            }
        }
    
    }
    
    public void addStuff(BlockEntityChest chest){
        ChestInventory inv = null;
        if(chest.isPaired()){
            inv = (ChestInventory) chest.getInventory();
        }else{
            inv = (ChestInventory) chest.getRealInventory();
        }
        Item item = Item.get(Item.IRON_AXE);
    
        inv.addItem(item);
    
    }
    
    [/code][/pre]
     
    Last edited: 2/3/16
    fromgate and M4Gn1T like this.
  2. fromgate

    fromgate Administrator

    Messages:
    665
    Likes Received:
    186
    Great! Thank you! :)
     
    LucGamesHD likes this.
  3. LucGamesHD

    LucGamesHD Developer

    Messages:
    26
    Likes Received:
    10
    Minecraft:
    LucGamesYT
    :)
     

Share This Page