Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @EventHandler(priority = EventPriority.HIGH)
- public void onChestOpen(InventoryOpenEvent event) {
- Player player = (Player) event.getPlayer();
- Inventory inventory = event.getInventory();
- InventoryType invtype = inventory.getType();
- Inventory lootChest = Bukkit.createInventory(null, inventory.getSize(), "Chest Loot"); // create a new inventory to display content to player
- if ( protectedRegion ) {
- System.out.println("exiting chest open event because region is protected");
- return;
- }
- if ( loadingLoot )
- return;
- loadingLoot = true;
- if( player != null && player == event.getPlayer() ) {
- if( invtype == InventoryType.CHEST ) {
- if ( worthy ) {
- player.sendMessage("Loading NEW loot!");
- //player.sendMessage("chest size is" + size);
- // lets make sure the lootConfig is loaded with the lootFile
- if ( lootConfig == null ) {
- //player.sendMessage("lootConfig is null");
- try {
- lootConfig = loadYaml(lootConfig, lootFile);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- // load loot table into a list strings
- @SuppressWarnings("unchecked")
- List<Object> items = (List<Object>) lootConfig.get("loot.items");
- // clear chest
- event.getInventory().clear();
- event.setCancelled(true);
- player.playSound(player.getLocation(), Sound.CHEST_OPEN, 1, 1);
- // load the chest
- set_item(player, items, lootChest);
- } else {
- player.sendMessage("Loading OLD loot!");
- String displayName = player.getName();
- @SuppressWarnings("unchecked")
- List<Block> loot = (List<Block>) chestConfig.get("player."+displayName+".loot");
- ItemStack[] chestLoot = loot.toArray(new ItemStack[loot.size()]);
- lootChest.setContents(chestLoot);
- event.setCancelled(true);
- player.playSound(player.getLocation(), Sound.CHEST_OPEN, 10, 1);
- player.openInventory(lootChest);
- }
- }
- }
- loadingLoot = false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement