Java Code Examples for org.bukkit.event.inventory.InventoryCloseEvent#getInventory()

The following examples show how to use org.bukkit.event.inventory.InventoryCloseEvent#getInventory() . 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: PlayerInteractListener.java    From SkyWarsReloaded with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler 
  public void onInventoryClose(InventoryCloseEvent e) {
  	Inventory inv = e.getInventory();
InventoryView inView = e.getPlayer().getOpenInventory();
  	if (inView.getTitle().equals(new Messaging.MessageFormatter().format("event.crateInv"))) {
  		for (GameMap gMap: GameMap.getPlayableArenas(GameType.ALL)) {
  			for (Crate crate: gMap.getCrates()) {
  				if(crate.getInventory().equals(inv) && inv.getViewers().size() <= 1) {
				if (SkyWarsReloaded.getNMS().getVersion() < 9) {
					e.getPlayer().getWorld().playSound(e.getPlayer().getLocation(), Sound.valueOf("CHEST_CLOSE"), 1, 1);
				} else {
					e.getPlayer().getWorld().playSound(e.getPlayer().getLocation(), Sound.BLOCK_CHEST_CLOSE, 1, 1);
				}
  					SkyWarsReloaded.getNMS().playEnderChestAction(e.getPlayer().getWorld().getBlockAt(crate.getLocation()), false);
  					return;
  				}
  			}
  		}
  	} else if (inView.getTitle().contains("chest.yml")) {
  		SkyWarsReloaded.getCM().save(inView.getTitle());
}
  	
  }
 
Example 2
Source File: CutCleanListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void closeInventoryEvent(InventoryCloseEvent e){
    if (!unlimitedLapis) return;

    if (e.getInventory() instanceof EnchantingInventory){
        e.getInventory().setItem(1, null);
    }
}
 
Example 3
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);
        }
    }
}
 
Example 4
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 5
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 6
Source File: EventExecutor.java    From PlayerSQL with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler
public void handle(InventoryCloseEvent e) {
    Inventory inventory = e.getInventory();
    if (CustomInventory.isInstance(inventory)) {
        CustomInventory.close(inventory);
    }
}
 
Example 7
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 8
Source File: DuctSettingsInventory.java    From Transport-Pipes with MIT License 4 votes vote down vote up
@EventHandler
public void onClose(InventoryCloseEvent e) {
    if (e.getInventory() != null && e.getInventory().equals(inv) && e.getPlayer() instanceof Player) {
        save((Player) e.getPlayer());
    }
}
 
Example 9
Source File: PlayerSettingsInventory.java    From Transport-Pipes with MIT License 4 votes vote down vote up
@EventHandler
public void onInvClose(InventoryCloseEvent e) {
    if (e.getInventory() != null && inventories.contains(e.getInventory()) && e.getPlayer() instanceof Player) {
        inventories.remove(e.getInventory());
    }
}
 
Example 10
Source File: Cosmic.java    From Crazy-Crates with MIT License 4 votes vote down vote up
@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 11
Source File: ATM.java    From TimeIsMoney with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onClose(InventoryCloseEvent e) {
	if (e.getInventory() != null)
		openATMs.remove(e.getInventory());
}