org.bukkit.event.inventory.InventoryCloseEvent Java Examples

The following examples show how to use org.bukkit.event.inventory.InventoryCloseEvent. 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: CEListener.java    From ce with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #2
Source File: ListenerMenuClose.java    From TrMenu with MIT License 6 votes vote down vote up
@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 #3
Source File: PlayerListener.java    From QuickShop-Reremake with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryClose(InventoryCloseEvent e) {
    Location location;
    try {
        location = e.getInventory().getLocation();
    } catch (NullPointerException ex) {
        //for strange NPE from spigot API fix
        return;
    }
    if (location == null) {
        return; /// ignored as workaround, GH-303
    }
    final Shop shop = plugin.getShopManager().getShopIncludeAttached(location);
    if (shop != null) {
        shop.setSignText();
    }
}
 
Example #4
Source File: InventoryClose.java    From StaffPlus with GNU General Public License v3.0 6 votes vote down vote up
@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 #5
Source File: StoreListener.java    From skRayFall with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Remove the store/unstore event possibility when an inventory is closed.
 *
 * @param evt The InventoryCloseEvent used to remove the possibility of a store/unstore
 *            event
 */
@EventHandler
public void onClose(InventoryCloseEvent evt) {
    if (evt.getView().getBottomInventory().getType() == InventoryType.PLAYER
            && (evt.getView().getTopInventory().getType() == InventoryType.CHEST
            || evt.getView().getTopInventory().getType() == InventoryType.ENDER_CHEST
            || evt.getView().getTopInventory().getType() == InventoryType.HOPPER
            || evt.getView().getTopInventory().getType() == InventoryType.DISPENSER
            || evt.getView().getTopInventory().getType() == InventoryType.DROPPER)) {
        if (storePossible.contains(evt.getPlayer())) {
            storePossible.remove(evt.getPlayer());
        } else if (unstorePossible.contains(evt.getPlayer())) {
            unstorePossible.remove(evt.getPlayer());
        }
    }
}
 
Example #6
Source File: SilentOpenChest.java    From SuperVanish with Mozilla Public License 2.0 6 votes vote down vote up
@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 #7
Source File: ItemFlagGui.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
void onInventoryClose(InventoryCloseEvent event) {
    if (!event.getView().getPlayer().equals(this.player)) {
        return;
    }

    StringBuilder str = new StringBuilder();
    Arrays.stream(event.getInventory().getContents())
            .filter(item -> item != null && !item.getType().equals(Material.AIR))
            .map(item -> item.getType().name()).distinct()
            .forEach(item -> str.append(item).append(","));

    if (str.length() > 0) {
        region.setFlag(event.getPlayer(), flag, str.toString().substring(0, str.toString().length() - 1));
        RedProtect.get().lang.sendMessage(player, RedProtect.get().lang.get("cmdmanager.region.flag.set").replace("{flag}", "'" + flag + "'") + " " + region.getFlagString(flag));
        RedProtect.get().logger.addLog("(World " + region.getWorld() + ") Player " + player.getName() + " SET FLAG " + flag + " of region " + region.getName() + " to " + region.getFlagString(flag));
    } else {
        region.removeFlag(flag);
        RedProtect.get().lang.sendMessage(player, RedProtect.get().lang.get("cmdmanager.region.flag.removed").replace("{flag}", flag).replace("{region}", region.getName()));
        RedProtect.get().logger.addLog("(World " + region.getWorld() + ") Player " + player.getName() + " REMOVED FLAG " + flag + " of region " + region.getName());
    }

    close(false);
}
 
Example #8
Source File: InventoryGui.java    From InventoryGui with MIT License 6 votes vote down vote up
@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 #9
Source File: UnitMaterial.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onInventoryClose(InventoryCloseEvent event) {
	ItemStack foundStack = null;
	for (ItemStack stack : event.getPlayer().getInventory().getContents()) {
		if (stack == null) {
			continue;
		}
		
		if (LoreMaterial.isCustom(stack)) {
			if (LoreMaterial.getMaterial(stack) instanceof UnitMaterial) {
				if (foundStack == null) {
					foundStack = stack;
				} else {
					event.getPlayer().getWorld().dropItem(event.getPlayer().getLocation(), stack);
					event.getPlayer().getInventory().remove(stack);
				}
			}
		}
		
	}
}
 
Example #10
Source File: WorthListener.java    From factions-top with MIT License 6 votes vote down vote up
@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 #11
Source File: FlagGui.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
void onInventoryClose(InventoryCloseEvent event) {
    if (!event.getPlayer().equals(this.player)) {
        return;
    }

    if (this.editable) {
        for (int i = 0; i < this.size; i++) {
            try {
                String flag = this.inv.getItem(i).getItemMeta().getLore().get(1).replace("ยง0", "");
                if (RedProtect.get().config.getDefFlags().contains(flag)) {
                    RedProtect.get().config.setGuiSlot(/*this.inv.getItem(i).getType().name(),*/ flag, i);
                }
            } catch (Exception e) {
                RedProtect.get().lang.sendMessage(this.player, "gui.edit.error");
                close(false);
                return;
            }
        }
        RedProtect.get().config.saveGui();
        RedProtect.get().lang.sendMessage(this.player, "gui.edit.ok");
    }

    close(false);
}
 
Example #12
Source File: SentinelEventHandler.java    From Sentinel with MIT License 6 votes vote down vote up
/**
 * Called when an inventory is closed.
 */
@EventHandler
public void onInvClose(InventoryCloseEvent event) {
    String invTitle = SentinelUtilities.getInventoryTitle(event);
    if (invTitle.startsWith(InvPrefix)) {
        int id = Integer.parseInt(invTitle.substring(InvPrefix.length()));
        NPC npc = CitizensAPI.getNPCRegistry().getById(id);
        if (npc != null && npc.hasTrait(SentinelTrait.class)) {
            ArrayList<ItemStack> its = npc.getTrait(SentinelTrait.class).drops;
            its.clear();
            for (ItemStack it : event.getInventory().getContents()) {
                if (it != null && it.getType() != Material.AIR) {
                    its.add(it);
                }
            }
        }
    }
}
 
Example #13
Source File: ChestGUIListener.java    From NovaGuilds with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onInventoryClose(InventoryCloseEvent event) {
	final NovaPlayer nPlayer = PlayerManager.getPlayer(event.getPlayer());
	if(nPlayer.getGuiInventory() != null && !ChestGUIUtils.guiContinueList.contains(nPlayer)) {
		if(nPlayer.getGuiInventoryHistory().size() == 1) {
			nPlayer.setGuiInventory(null);
		}
		else {
			nPlayer.removeLastGUIInventoryHistory();

			NovaGuilds.runTask(new Runnable() {
				@Override
				public void run() {
					nPlayer.getGuiInventory().open(nPlayer);
				}
			});
		}
	}
}
 
Example #14
Source File: InventoryForPassengers.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void inventoryClose(InventoryCloseEvent event) {
	ArrayList<EntityNBT> passagers = new ArrayList<EntityNBT>(54);
	for (ItemStack item : getContents()) {
		if (BookOfSouls.isValidBook(item)) {
			passagers.add(BookOfSouls.bookToEntityNBT(item));
		}
	}
	_variable.setPassengers(passagers.toArray(new EntityNBT[passagers.size()]));
	super.inventoryClose(event);
}
 
Example #15
Source File: IconMenuController.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@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 #16
Source File: BackpackEventListener.java    From Minepacks with GNU General Public License v3.0 5 votes vote down vote up
@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 #17
Source File: TestBackpackListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testCloseBackpack() throws InterruptedException {
    Player player = server.addPlayer();
    PlayerBackpack backpack = openMockBackpack(player, "TEST_CLOSE_BACKPACK", 27);
    listener.onClose(new InventoryCloseEvent(player.getOpenInventory()));

    Assertions.assertTrue(backpack.getOwner().isDirty());
}
 
Example #18
Source File: BackpackListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onClose(InventoryCloseEvent e) {
    Player p = ((Player) e.getPlayer());
    ItemStack backpack = backpacks.remove(p.getUniqueId());

    if (backpack != null) {
        p.playSound(p.getLocation(), Sound.ENTITY_HORSE_ARMOR, 1F, 1F);
        PlayerProfile.getBackpack(backpack, PlayerBackpack::markDirty);
    }
}
 
Example #19
Source File: SignEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@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 #20
Source File: CreativeModeListener.java    From ShopChest with MIT License 5 votes vote down vote up
@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 #21
Source File: GUIListeners.java    From CratesPlus with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onInventoryClose(InventoryCloseEvent event) {
    if (GUI.ignoreClosing.contains(event.getPlayer().getUniqueId())) {
        GUI.ignoreClosing.remove(event.getPlayer().getUniqueId());
        return;
    }
    if (GUI.guis.containsKey(event.getPlayer().getUniqueId()))
        GUI.guis.remove(event.getPlayer().getUniqueId());
    if (GUI.pageTracker.containsKey(event.getPlayer().getUniqueId()))
        GUI.pageTracker.remove(event.getPlayer().getUniqueId());
}
 
Example #22
Source File: AnvilGUI.java    From AnvilGUI with MIT License 5 votes vote down vote up
@EventHandler
public void onInventoryClose(InventoryCloseEvent event) {
	if (open && event.getInventory().equals(inventory)) {
		closeInventory();
		if(preventClose) {
			Bukkit.getScheduler().runTask(plugin, AnvilGUI.this::openInventory);
		}
	}
}
 
Example #23
Source File: InventoryConvIO.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onClose(InventoryCloseEvent event) {
    if (!(event.getPlayer() instanceof Player)) {
        return;
    }
    if (!event.getPlayer().equals(player)) {
        return;
    }

    // allow for closing previous option inventory
    if (switching) {
        return;
    }
    // allow closing when the conversation has finished
    if (allowClose) {
        HandlerList.unregisterAll(this);
        return;
    }
    if (conv.isMovementBlock()) {
        new BukkitRunnable() {
            public void run() {
                player.teleport(loc);
                player.openInventory(inv);
            }
        }.runTask(BetonQuest.getInstance());
    } else {
        conv.endConversation();
        HandlerList.unregisterAll(this);
    }
}
 
Example #24
Source File: ExcessChestListener.java    From TradePlus with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onClose(InventoryCloseEvent event) {
  Inventory closed = event.getInventory();

  if (pl.getExcessChests().contains(closed)) {
    for (ItemStack i : event.getInventory()) {
      if (i == null || i.getType() == Material.AIR) continue;
      event
          .getPlayer()
          .getWorld()
          .dropItemNaturally(event.getPlayer().getLocation(), i);
    }
    pl.getExcessChests().remove(closed);
  }
}
 
Example #25
Source File: MapListener.java    From CS-CoreLib with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onClose(InventoryCloseEvent e) {
	if (Maps.getInstance().menus.containsKey(e.getPlayer().getUniqueId())) {
		Maps.getInstance().menus.get(e.getPlayer().getUniqueId()).getMenuCloseHandler().onClose((Player) e.getPlayer());
		Maps.getInstance().menus.remove(e.getPlayer().getUniqueId());
	}
	if (Maps.getInstance().inv.containsKey(e.getPlayer().getUniqueId())) Maps.getInstance().inv.remove(e.getPlayer().getUniqueId());
	if (Maps.getInstance().sounds.containsKey(e.getPlayer().getUniqueId())) {
		((Player) e.getPlayer()).playSound(e.getPlayer().getLocation(), Maps.getInstance().sounds.get(e.getPlayer().getUniqueId()).getClosingSound(), 1F, 1F);
		Maps.getInstance().sounds.remove(e.getPlayer().getUniqueId());
	}
}
 
Example #26
Source File: SentinelUtilities.java    From Sentinel with MIT License 5 votes vote down vote up
/**
 * Gets the title of an inventory in an InventoryCloseEvent (compensates for code change between Spigot versions).
 */
public static String getInventoryTitle(InventoryCloseEvent event) {
    if (SentinelVersionCompat.v1_10) {
        return event.getView().getTitle();
    }
    try {
        Object inventory = event.getInventory();
        return (String) inventory.getClass().getMethod("getTitle").invoke(inventory);
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #27
Source File: War.java    From Crazy-Crates with MIT License 5 votes vote down vote up
@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 #28
Source File: DataUpdaterEvents.java    From AACAdditionPro with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onInventoryClose(final InventoryCloseEvent event)
{
    final User user = UserManager.getUser(event.getPlayer().getUniqueId());

    if (user != null) {
        user.getTimestampMap().nullifyTimeStamp(TimestampKey.INVENTORY_OPENED);
    }
}
 
Example #29
Source File: Inventory.java    From AACAdditionPro with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onInventoryClose(final InventoryCloseEvent event)
{
    final User user = UserManager.getUser(event.getPlayer().getUniqueId());

    // Not bypassed
    if (User.isUserInvalid(user, this.getModuleType())) {
        return;
    }

    vlManager.flag(user.getPlayer(), perfectExitPattern.apply(user, event), 0, () -> {}, () -> {});
}
 
Example #30
Source File: GUI.java    From Crazy-Auctions with MIT License 5 votes vote down vote up
@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);
        }
    }
}