Guest User

Untitled

a guest
Dec 14th, 2019
96
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class InventoryListener implements Listener {
  2.  
  3. @EventHandler
  4. public void onInventoryClose(InventoryCloseEvent event) {
  5. CTF.getInstance().getInventoryManager().closedInventory(event.getPlayer());
  6. }
  7.  
  8. @EventHandler
  9. public void onInventoryClick(InventoryClickEvent event) {
  10. Player player = (Player) event.getWhoClicked();
  11.  
  12. if (event.getClickedInventory() == null) {
  13. return;
  14. }
  15.  
  16. // testing for interactive inventory
  17. Inventory top = event.getView().getTopInventory();
  18.  
  19. if (top == null) {
  20. return;
  21. }
  22.  
  23. if (!event.getClickedInventory().equals(top)) {
  24. return;
  25. }
  26.  
  27. ItemStack is = event.getCurrentItem();
  28.  
  29. if (is == null) {
  30. return;
  31. }
  32.  
  33. String title = event.getView().getTitle();
  34.  
  35. String[] invTitles = new String[] {InventoryManager.mapSelectorTitle};
  36. for(String t : invTitles) {
  37. if(t.equals(title)) {
  38. if(!event.isCancelled()) {
  39. event.setCancelled(true);
  40. break;
  41. }
  42. }
  43. }
  44.  
  45.  
  46. if (title.equals(InventoryManager.mapSelectorTitle)) {
  47. InventoryManager im = CTF.getInstance().getInventoryManager();
  48. String mapName = Strings.stripColor(is.getItemMeta().getDisplayName());
  49. Map map = null;
  50. for (Map m : CTF.getInstance().getMapManager().getMaps()) {
  51. if (m.getName().equals(mapName)) {
  52. map = m;
  53. break;
  54. }
  55. }
  56.  
  57. Game game = im.getGameAndRemoveFromMapInventories(player);
  58. //can close inventory from here, since their game value has already been deleted
  59. player.closeInventory();
  60.  
  61. if (map == null) {
  62. Messenger.message(player, "&cSomehow, that map wasn't found.");
  63. }
  64.  
  65. game.setMap(map);
  66. game.initialize();
  67.  
  68. CTF.getInstance().getGameManager().saveGame(game);
  69.  
  70. if(!game.getArena().isPresent()) {
  71. Messenger.message(player, "&cUnable to initialize that arena.");
  72. CTF.getInstance().getGameManager().stopGame(game);
  73. return;
  74. }
  75.  
  76.  
  77. UnjoinableReason reason = CTF.getInstance().getGameManager().joinGame(player, game,
  78. Authenticator.hasPermission(player, Permissions.overrideMaxPlayers),
  79. Authenticator.hasPermission(player, Permissions.overrideGameState));
  80.  
  81. if(reason != UnjoinableReason.NONE) {
  82. Optional<Team> t = CTF.getInstance().getGameManager().getTeam(game, player);
  83. Messenger.message(player, "&6Joined team: " + t.get().getChatColor() + t.get().getName());
  84. } else {
  85. Messenger.message(player, reason.getReason());
  86. CTF.getInstance().getGameManager().stopGame(game);
  87. }
  88.  
  89. }
  90.  
  91. return;
  92. }
  93.  
  94. }
RAW Paste Data