Advertisement
stoi2m1

Untitled

Jan 11th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. @EventHandler(priority = EventPriority.HIGH)
  2. public void onChestOpen(InventoryOpenEvent event) {
  3. Player player = (Player) event.getPlayer();
  4. Inventory inventory = event.getInventory();
  5. InventoryType invtype = inventory.getType();
  6. Inventory lootChest = Bukkit.createInventory(null, inventory.getSize(), "Chest Loot"); // create a new inventory to display content to player
  7.  
  8. if ( protectedRegion ) {
  9. System.out.println("exiting chest open event because region is protected");
  10. return;
  11. }
  12.  
  13. if ( loadingLoot )
  14. return;
  15.  
  16. loadingLoot = true;
  17.  
  18. if( player != null && player == event.getPlayer() ) {
  19. if( invtype == InventoryType.CHEST ) {
  20.  
  21. if ( worthy ) {
  22. player.sendMessage("Loading NEW loot!");
  23. //player.sendMessage("chest size is" + size);
  24.  
  25. // lets make sure the lootConfig is loaded with the lootFile
  26. if ( lootConfig == null ) {
  27. //player.sendMessage("lootConfig is null");
  28. try {
  29. lootConfig = loadYaml(lootConfig, lootFile);
  30. } catch (Exception e) {
  31. e.printStackTrace();
  32. }
  33. }
  34.  
  35. // load loot table into a list strings
  36. @SuppressWarnings("unchecked")
  37. List<Object> items = (List<Object>) lootConfig.get("loot.items");
  38.  
  39. // clear chest
  40. event.getInventory().clear();
  41.  
  42. event.setCancelled(true);
  43. player.playSound(player.getLocation(), Sound.CHEST_OPEN, 1, 1);
  44.  
  45. // load the chest
  46. set_item(player, items, lootChest);
  47.  
  48. } else {
  49.  
  50. player.sendMessage("Loading OLD loot!");
  51. String displayName = player.getName();
  52.  
  53. @SuppressWarnings("unchecked")
  54. List<Block> loot = (List<Block>) chestConfig.get("player."+displayName+".loot");
  55. ItemStack[] chestLoot = loot.toArray(new ItemStack[loot.size()]);
  56. lootChest.setContents(chestLoot);
  57.  
  58. event.setCancelled(true);
  59. player.playSound(player.getLocation(), Sound.CHEST_OPEN, 10, 1);
  60. player.openInventory(lootChest);
  61. }
  62. }
  63. }
  64.  
  65. loadingLoot = false;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement