Java Code Examples for org.bukkit.event.inventory.InventoryCloseEvent#getPlayer()
The following examples show how to use
org.bukkit.event.inventory.InventoryCloseEvent#getPlayer() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ListenerMenuClose.java From TrMenu with MIT License | 6 votes |
@EventHandler public void onClose(InventoryCloseEvent e) { if (!(e.getInventory().getHolder() instanceof MenuHolder)) { return; } Player p = (Player) e.getPlayer(); Menu menu = ((MenuHolder) e.getInventory().getHolder()).getMenu(); if (!Strings.isBlank(menu.getCloseRequirement()) && !Boolean.parseBoolean(String.valueOf(JavaScript.run(p, menu.getCloseRequirement())))) { TrAction.runActions(menu.getCloseDenyActions(), p); return; } if (menu.getCloseActions() != null && !p.hasMetadata("TrMenu.Force-Close")) { menu.getCloseActions().forEach(action -> action.run(p)); } if (ArgsCache.getHeldSlot().containsKey(p.getUniqueId())) { p.getInventory().setHeldItemSlot(ArgsCache.getHeldSlot().get(p.getUniqueId())); ArgsCache.getHeldSlot().remove(p.getUniqueId()); } menu.getButtons().keySet().forEach(b -> { b.getDefIcon().getItem().resetIndex(p); b.getIcons().forEach(i -> i.getItem().resetIndex(p)); }); }
Example 2
Source File: InventoryGui.java From InventoryGui with MIT License | 6 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onInventoryClose(InventoryCloseEvent event) { Inventory inventory = getInventory(event.getPlayer()); if (event.getInventory().equals(inventory)) { // go back. that checks if the player is in gui and has history if (gui.equals(getOpen(event.getPlayer()))) { if (closeAction == null || closeAction.onClose(new Close(event.getPlayer(), gui, event))) { goBack(event.getPlayer()); } else { clearHistory(event.getPlayer()); } } if (inventories.size() <= 1) { destroy(false); } else { inventory.clear(); for (HumanEntity viewer : inventory.getViewers()) { if (viewer != event.getPlayer()) { viewer.closeInventory(); } } inventories.remove(event.getPlayer().getUniqueId()); } } }
Example 3
Source File: CEListener.java From ce with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void inventoryClose(InventoryCloseEvent event) { if (event.getInventory().getName() .equals(ChatColor.LIGHT_PURPLE + "" + ChatColor.MAGIC + "abc" + ChatColor.RESET + ChatColor.DARK_PURPLE + " Runecrafting " + ChatColor.LIGHT_PURPLE + "" + ChatColor.MAGIC + "cba")) { ItemStack[] contents = event.getInventory().getContents(); HumanEntity p = event.getPlayer(); Location loc = p.getLocation().add(0, 1.25, 0); Vector velocity = loc.getDirection().multiply(0.25); if (contents[0] != null && !contents[0].getType().equals(Material.AIR)) if (p.getInventory().firstEmpty() == -1) p.getWorld().dropItem(loc, contents[0]).setVelocity(velocity); else p.getInventory().addItem(contents[0]); if (contents[1] != null && !contents[1].getType().equals(Material.AIR)) if (p.getInventory().firstEmpty() == -1) p.getWorld().dropItem(loc, contents[1]).setVelocity(velocity); else p.getInventory().addItem(contents[1]); } }
Example 4
Source File: SilentOpenChest.java From SuperVanish with Mozilla Public License 2.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onChestClose(InventoryCloseEvent e) { if (!(e.getPlayer() instanceof Player)) return; final Player p = (Player) e.getPlayer(); if (!playerStateInfoMap.containsKey(p)) return; if (!(p.getInventory().getType() == InventoryType.CHEST || plugin.getVersionUtil().isOneDotXOrHigher(11) && isShulkerBox(p.getInventory()))) { return; } new BukkitRunnable() { @Override public void run() { StateInfo stateInfo = playerStateInfoMap.get(p); if (stateInfo == null) return; restoreState(stateInfo, p); playerStateInfoMap.remove(p); } }.runTaskLater(plugin, 1); }
Example 5
Source File: InventoryClose.java From StaffPlus with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onClose(InventoryCloseEvent event) { final Player player = (Player) event.getPlayer(); User user = userManager.get(player.getUniqueId()); if(user.isFrozen() && options.modeFreezePrompt) { new BukkitRunnable() { @Override public void run() { new FreezeGui(player, options.modeFreezePromptTitle); } }.runTaskLater(StaffPlus.get(), 1L); return; }else if(user.getCurrentGui() != null) { user.setCurrentGui(null); } }
Example 6
Source File: WorthListener.java From factions-top with MIT License | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void updateWorth(InventoryCloseEvent event) { // Do nothing if a player did not close the inventory or if chest // events are disabled. if (!(event.getPlayer() instanceof Player) || plugin.getSettings().isDisableChestEvents()) { return; } // Get cached values from when chest was opened and add the difference // to the worth manager. if (event.getInventory().getHolder() instanceof DoubleChest) { DoubleChest chest = (DoubleChest) event.getInventory().getHolder(); updateWorth((Chest) chest.getLeftSide()); updateWorth((Chest) chest.getRightSide()); } if (event.getInventory().getHolder() instanceof Chest) { updateWorth((Chest) event.getInventory().getHolder()); } }
Example 7
Source File: BackpackEventListener.java From Minepacks with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onClose(InventoryCloseEvent event) { if (event.getInventory() != null && event.getInventory().getHolder() instanceof Backpack && event.getPlayer() instanceof Player) { Backpack backpack = (Backpack)event.getInventory().getHolder(); Player closer = (Player)event.getPlayer(); if(backpack.canEdit(closer)) { backpack.save(); } backpack.close(closer); if(event.getPlayer().getUniqueId().equals(backpack.getOwner().getUniqueId())) { messageOwnBackpackClose.send(closer); } else { OfflinePlayer owner = backpack.getOwner(); messageOtherBackpackClose.send(closer, owner.getName(), owner.isOnline() ? owner.getPlayer().getDisplayName() : ChatColor.GRAY + owner.getName()); } if(closeSound != null) { closer.getWorld().playSound(closer.getLocation(), closeSound, 1, 0); } } }
Example 8
Source File: SignEvents.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onChestClosed(InventoryCloseEvent e) { if (e.getPlayer() == null || e.getPlayer().getLocation() == null || !plugin.getWorldManager().isSkyAssociatedWorld(e.getPlayer().getLocation().getWorld()) || e.getInventory().getType() != InventoryType.CHEST ) { return; } Location loc = e.getInventory().getLocation(); if (loc != null) { logic.updateSignsOnContainer(loc); } }
Example 9
Source File: CreativeModeListener.java From ShopChest with MIT License | 5 votes |
@EventHandler public void onPlayerCloseInventory(InventoryCloseEvent e) { HumanEntity entity = e.getPlayer(); if (!(entity instanceof Player)) return; Player p = (Player) entity; ClickType clickType = ClickType.getPlayerClickType(p); if (!(clickType instanceof SelectClickType)) return; ClickType.removePlayerClickType(p); p.sendMessage(LanguageUtils.getMessage(Message.CREATION_CANCELLED)); }
Example 10
Source File: IconMenuController.java From SkyWarsReloaded with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onInventoryClose(InventoryCloseEvent event) { if (event.getPlayer() instanceof Player && menu.containsKey(event.getPlayer())) { new BukkitRunnable() { @Override public void run() { if (menu.get(event.getPlayer()).getInventories().contains(event.getPlayer().getOpenInventory())) { destroy(((Player) event.getPlayer())); } } }.runTaskLater(SkyWarsReloaded.get(), 5); } }
Example 11
Source File: War.java From Crazy-Crates with MIT License | 5 votes |
@EventHandler public void onInventoryClose(InventoryCloseEvent e) { Player player = (Player) e.getPlayer(); if (canClose.containsKey(player) && canClose.get(player)) { for (Crate crate : cc.getCrates()) { if (crate.getCrateType() == CrateType.WAR && e.getView().getTitle().equalsIgnoreCase(Methods.sanitizeColor(crate.getFile().getString(crateNameString)))) { canClose.remove(player); if (cc.hasCrateTask(player)) { cc.endCrate(player); } } } } }
Example 12
Source File: GUI.java From Crazy-Auctions with MIT License | 5 votes |
@EventHandler public void onInvClose(InventoryCloseEvent e) { FileConfiguration config = Files.CONFIG.getFile(); Inventory inv = e.getInventory(); Player player = (Player) e.getPlayer(); if (inv != null) { if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Bidding-On-Item")))) { bidding.remove(player); } } }
Example 13
Source File: MenuHandler.java From EnchantmentsEnhance with GNU General Public License v3.0 | 5 votes |
/** * Removes current item placed on the enhancing slot. * * @param e */ @EventHandler(priority = EventPriority.MONITOR) public void onInventoryClose(InventoryCloseEvent e) { Player player = (Player) e.getPlayer(); if (MainMenu.inProgress.containsKey(player.getName())) { MainMenu.inProgress.get(player.getName()).cancel(); } MainMenu.clearPlayer(player.getName()); }
Example 14
Source File: UIListener.java From Shopkeepers with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.NORMAL) void onInventoryClose(InventoryCloseEvent event) { if (event.getPlayer().getType() != EntityType.PLAYER) return; Player player = (Player) event.getPlayer(); UISession session = uiManager.getSession(player); if (session != null) { Log.debug("Player " + player.getName() + " closed " + session.getUIType().getIdentifier()); // inform uiManager so that it can cleanup player data: uiManager.onInventoryClose(player); // inform uiHandler so that it can react to it: if (session.getUIHandler().isWindow(event.getInventory())) { session.getUIHandler().onInventoryClose(event, player); } } }
Example 15
Source File: PlayerEventListener.java From Hawk with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onInventoryCloseServerSide(InventoryCloseEvent e) { HumanEntity hE = e.getPlayer(); if(!(hE instanceof Player)) return; HawkPlayer pp = hawk.getHawkPlayer((Player) hE); pp.sendSimulatedAction(new Runnable() { @Override public void run() { pp.setInventoryOpen((byte)0); } }); }
Example 16
Source File: Cosmic.java From Crazy-Crates with MIT License | 4 votes |
@EventHandler public void onInvClose(InventoryCloseEvent e) { Inventory inv = e.getInventory(); Player player = (Player) e.getPlayer(); Crate crate = cc.getOpeningCrate(player); if (cc.isInOpeningList(player)) { if (crate.getFile() == null) { return; } else { if (!crate.getFile().getString("Crate.CrateType").equalsIgnoreCase("Cosmic")) { return; } } } else { return; } if (e.getView().getTitle().equals(Methods.sanitizeColor(crate.getFile().getString("Crate.CrateName") + " - Prizes"))) { boolean playSound = false; for (int i : picks.get(player)) { if (inv.getItem(i) != null) { Tier tier = getTier(crate, inv.getItem(i)); if (tier != null) { Prize prize = crate.pickPrize(player, tier); for (int stop = 0; prize == null && stop <= 2000; stop++) { prize = crate.pickPrize(player, tier); } cc.givePrize(player, prize); playSound = true; } } } if (playSound) { player.playSound(player.getLocation(), cc.getSound("UI_BUTTON_CLICK", "CLICK"), 1, 1); } cc.removePlayerFromOpeningList(player); cc.removePlayerKeyType(player); if (glass.containsKey(player)) { picks.put(player, glass.get(player)); glass.remove(player); } checkHands.remove(player); } if (cc.isInOpeningList(player) && e.getView().getTitle().equals(Methods.sanitizeColor(crate.getFile().getString("Crate.CrateName") + " - Choose"))) { if (!glass.containsKey(player) || glass.get(player).size() < 4) { cc.removePlayerFromOpeningList(player); cc.removePlayerKeyType(player); } if (glass.containsKey(player)) { picks.put(player, glass.get(player)); glass.remove(player); } checkHands.remove(player); } }
Example 17
Source File: GUIListener.java From EnchantmentsEnhance with GNU General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onClose(InventoryCloseEvent e) { Player player = (Player) e.getPlayer(); String playerName = player.getName(); GUIManager.getMap().remove(playerName); }
Example 18
Source File: IconMenuController.java From SkyWarsReloaded with GNU General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onInventoryClose(InventoryCloseEvent event) { if (event.getPlayer() instanceof Player && menu.containsKey(event.getPlayer())) { destroy((Player) event.getPlayer()); } }
Example 19
Source File: PlayerSettingsInventory.java From Transport-Pipes with MIT License | 4 votes |
@EventHandler public void onInvClose(InventoryCloseEvent e) { if (e.getInventory() != null && inventories.contains(e.getInventory()) && e.getPlayer() instanceof Player) { inventories.remove(e.getInventory()); } }
Example 20
Source File: DuctSettingsInventory.java From Transport-Pipes with MIT License | 4 votes |
@EventHandler public void onClose(InventoryCloseEvent e) { if (e.getInventory() != null && e.getInventory().equals(inv) && e.getPlayer() instanceof Player) { save((Player) e.getPlayer()); } }