Put items in chest!

LucGamesHD

Developer
Hey i found a methode to put items in chests :D
P.S This is a Code from a Test plugin xD

Java:
@EventHandler
	public void onTest(BlockPlaceEvent e){
		Player p = e.getPlayer();
		Block block = e.getBlock();
		
		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);
		
		
	}
 
Last edited:
Top