Java Code Examples for org.bukkit.event.inventory.InventoryClickEvent

The following examples show how to use org.bukkit.event.inventory.InventoryClickEvent. These examples are extracted from open source projects. 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
@EventHandler(priority = EventPriority.LOW)
public void onInventoryClick(final InventoryClickEvent event)
{
    final User user = UserManager.getUser(event.getWhoClicked().getUniqueId());

    if (user != null &&
        // Quickbar actions can be performed outside the inventory.
        event.getSlotType() != InventoryType.SlotType.QUICKBAR)
    {
        // Only update if the inventory is currently closed to not interfere with opening time checks.
        if (!user.hasOpenInventory()) {
            user.getTimestampMap().updateTimeStamp(TimestampKey.INVENTORY_OPENED);
        }

        user.getTimestampMap().updateTimeStamp(TimestampKey.LAST_INVENTORY_CLICK);
        if (event.getCurrentItem() != null) {
            user.getTimestampMap().updateTimeStamp(TimestampKey.LAST_INVENTORY_CLICK_ON_ITEM);
        }

        user.getDataMap().setValue(DataKey.LAST_RAW_SLOT_CLICKED, event.getRawSlot());
        user.getDataMap().setValue(DataKey.LAST_MATERIAL_CLICKED, event.getCurrentItem() == null ?
                                                                  Material.AIR :
                                                                  event.getCurrentItem().getType());
    }
}
 
Example 2
@Override
protected int process(User user, InventoryClickEvent event)
{
    // Flight may trigger this
    if (!user.getPlayer().getAllowFlight() &&
        // Not using an Elytra
        !EntityUtil.isFlyingWithElytra(user.getPlayer()) &&
        // Sprinting and Sneaking as detection
        (user.getPlayer().isSprinting() || user.getPlayer().isSneaking()) &&
        // The player opened the inventory at least a quarter second ago
        user.notRecentlyOpenedInventory(250) &&
        // Is the player moving
        user.hasMovedRecently(TimestampKey.LAST_HEAD_OR_OTHER_MOVEMENT, 1000))
    {
        message = "Inventory-Verbose | Player: " + user.getPlayer().getName() + " interacted with an inventory while sprinting or sneaking.";
        return 20;
    }
    return 0;
}
 
Example 3
@EventHandler(ignoreCancelled = true)
public void onGrindstone(InventoryClickEvent e) {
    // The Grindstone was only ever added in MC 1.14
    MinecraftVersion minecraftVersion = SlimefunPlugin.getMinecraftVersion();
    if (!minecraftVersion.isAtLeast(MinecraftVersion.MINECRAFT_1_14)) {
        return;
    }

    if (e.getRawSlot() == 2 && e.getWhoClicked() instanceof Player && e.getInventory().getType() == InventoryType.GRINDSTONE) {
        ItemStack item1 = e.getInventory().getContents()[0];
        ItemStack item2 = e.getInventory().getContents()[1];

        if (checkForUnallowedItems(item1, item2)) {
            e.setResult(Result.DENY);
        }
    }

}
 
Example 4
@EventHandler
public void onMainMenuClick(InventoryClickEvent event) {

    if (!(event.getWhoClicked() instanceof Player)) return;
    if (!event.getInventory().getName().equalsIgnoreCase("Adventurer's guild")) return;
    if (event.getCurrentItem() == null || event.getCurrentItem().getType().equals(Material.AIR)) return;
    if (event.getCurrentItem().equals(difficulty))
        difficultyMenu((Player) event.getWhoClicked());
    if (event.getCurrentItem().equals(quest)) {
        event.getWhoClicked().closeInventory();
        event.getWhoClicked().sendMessage("Coming soon!");
    }

    event.setCancelled(true);

}
 
Example 5
Source Project: UHC   Source File: IconInventory.java    License: MIT License 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void on(InventoryClickEvent event) {
    final Inventory inventory = event.getInventory();
    if (!inventory.getTitle().equals(title)) return;

    event.setCancelled(true);

    final int slot = event.getRawSlot();

    if (slot < 0 || slot >= inventory.getSize() || slot >= icons.size()) return;

    // call event
    final IconStack icon = icons.get(slot);

    if (icon != null) {
        icon.onClick((Player) event.getWhoClicked());
    }
}
 
Example 6
@EventHandler(priority = EventPriority.LOWEST)
public void onInventoryClick(final InventoryClickEvent event) {
  if (event.getCurrentItem() == null
      || event.getCurrentItem().getItemMeta() == null
      || event.getCurrentItem().getItemMeta().getDisplayName() == null) return;

  if (event.getWhoClicked() instanceof Player) {
    MatchPlayer player = match.getPlayer(event.getWhoClicked());
    if (menu.isViewing(player)) {
      ItemStack clicked = event.getCurrentItem();
      menu.getTools()
          .forEach(
              tool -> {
                if (clicked.getType().equals(tool.getMaterial(player))) {
                  tool.onInventoryClick(menu, player, event.getClick());
                }
              });
    }
  }
}
 
Example 7
Source Project: UhcCore   Source File: CutCleanListener.java    License: GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onInventoryClick(InventoryClickEvent e){
    Inventory inv = e.getInventory();
    ItemStack item = e.getCurrentItem();
    if (!unlimitedLapis) return;
    if (inv == null || item == null) return;

    if (inv instanceof EnchantingInventory){

        if (item.getType().equals(lapis.getType())){
            e.setCancelled(true);
        }else {
            e.getInventory().setItem(1, lapis);
        }
    }
}
 
Example 8
Source Project: civcraft   Source File: LoreGuiItemListener.java    License: GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void OnInventoryClickSecondPhase(InventoryClickEvent event) {
	if (event.isCancelled()) {
		return;
	}
	
	if (event.getRawSlot() < event.getView().getTopInventory().getSize()) {
		if (guiInventories.containsKey(event.getView().getTopInventory().getName())) {
			event.setCancelled(true);
			return;
		}
	} else if (event.isShiftClick()) {
		if (guiInventories.containsKey(event.getView().getTopInventory().getName())) {
			event.setCancelled(true);
			return;
		}			
	}
	
}
 
Example 9
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
    if (event.isCancelled()) {
        return;
    }

    if (event.getClickedInventory() == null) {
        return;
    }

    if (event.getClickedInventory().getType() == InventoryType.PLAYER) {
        Player p = (Player) event.getWhoClicked();
        if (Main.isPlayerInGame(p)) {
            GamePlayer gPlayer = Main.getPlayerGameProfile(p);
            Game game = gPlayer.getGame();
            if (game.getStatus() == GameStatus.WAITING || gPlayer.isSpectator) {
                event.setCancelled(true);
            }
        }
    }
}
 
Example 10
Source Project: CratesPlus   Source File: BlockListeners.java    License: GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
    if (!cratesPlus.getConfigHandler().isDisableKeySwapping() || event.getView().getTitle().equals("Claim Crate Keys"))
        return;
    if (!event.getInventory().getType().toString().contains("PLAYER") && event.getCurrentItem() != null) {
        String title;
        ItemStack item = event.getCurrentItem();
        for (Map.Entry<String, Crate> crate : cratesPlus.getConfigHandler().getCrates().entrySet()) {
            if (!(crate.getValue() instanceof KeyCrate)) {
                continue;
            }
            KeyCrate keyCrate = (KeyCrate) crate.getValue();
            Key key = keyCrate.getKey();
            if (key == null)
                continue;
            title = key.getName();

            if (item.hasItemMeta() && item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().contains(title)) {
                // Send message?
                event.setCancelled(true);
                return;
            }
        }
    }
}
 
Example 11
Source Project: Shopkeepers   Source File: PlayerShopkeeper.java    License: GNU General Public License v3.0 6 votes vote down vote up
protected void handleUpdateItemAmountOnClick(InventoryClickEvent event, int minAmount) {
	// cancel event:
	event.setCancelled(true);
	// ignore in certain situations:
	ItemStack clickedItem = event.getCurrentItem();
	if (Utils.isEmpty(clickedItem)) return;

	// get new item amount:
	int currentItemAmount = clickedItem.getAmount();
	if (minAmount <= 0) minAmount = 0;
	int newItemAmount = this.getNewAmountAfterEditorClick(event, currentItemAmount, minAmount, clickedItem.getMaxStackSize());
	assert newItemAmount >= minAmount;
	assert newItemAmount <= clickedItem.getMaxStackSize();

	// update item in inventory:
	if (newItemAmount == 0) {
		// empty item slot:
		event.setCurrentItem(null);
	} else {
		clickedItem.setAmount(newItemAmount);
	}
}
 
Example 12
Source Project: MineableSpawners   Source File: AnvilRenameListener.java    License: MIT License 6 votes vote down vote up
@EventHandler (ignoreCancelled = true)
public void onAnvilRename(InventoryClickEvent e) {
  if (e.getInventory() == null || e.getInventory().getType() == null) {
    return;
  }

  if (e.getCurrentItem() == null || e.getCurrentItem().getType() == null) {
    return;
  }

  if (e.getInventory().getType() != InventoryType.ANVIL || e.getCurrentItem().getType() != XMaterial.SPAWNER.parseMaterial()) {
    return;
  }

  if (!plugin.getConfigurationHandler().getBoolean("anvil", "prevent-anvil")) {
    return;
  }

  Player player = (Player) e.getWhoClicked();
  e.setCancelled(true);
  player.sendMessage(plugin.getConfigurationHandler().getMessage("anvil", "prevented"));
}
 
Example 13
Source Project: Civs   Source File: CivilianTests.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Test(expected = SuccessException.class)
    @Ignore
    public void inventoryClickOnUnownedCivItemShouldBeCancelled() {
        InventoryClickEvent event = mock(InventoryClickEvent.class);
        ItemStack is = TestUtil.createUniqueItemStack(Material.CHEST, "Civs Cobble");
        when(event.getCurrentItem()).thenReturn(is);
        Inventory inventory = mock(Inventory.class);
        when(event.getClickedInventory()).thenReturn(inventory);
        Player player = mock(Player.class);
        UUID uuid = new UUID(1,8);
        when(player.getUniqueId()).thenReturn(uuid);
        when(event.getWhoClicked()).thenReturn(player);
        doThrow(new SuccessException()).when(event).setCancelled(true);

        CivilianListener civilianListener = new CivilianListener();
//        civilianListener.onInventoryMoveEvent(event);
        fail("set cancelled not called");
    }
 
Example 14
@EventHandler(ignoreCancelled = true)
public void onItemMove(InventoryClickEvent event) {
    ItemStack currentItem = event.getCurrentItem();
    if (currentItem == null || currentItem.getType() == Material.AIR) return;
    NBTItem nbtItem = new NBTItem(currentItem);
    if (!nbtItem.hasKey("HubBasics")) return;

    CustomItem item = HubBasics.getInstance().getItemManager().get(nbtItem.getString("HubBasics"));
    if (item == null) {
        currentItem.setType(Material.AIR); // Destroy old item
        return;
    }
    if (item.getRunOnInventory()) {
        item.onCommand((Player) event.getWhoClicked());
    }
    if (!item.getAllowMove())
        event.setCancelled(true); // Call setCancelled only when needed to not conflict with other plugins
}
 
Example 15
Source Project: AnnihilationPro   Source File: KitLoading.java    License: MIT License 6 votes vote down vote up
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
public void StopClicking(InventoryClickEvent event)
{
    HumanEntity entity = event.getWhoClicked();
    ItemStack stack = event.getCurrentItem();
    InventoryType top = event.getView().getTopInventory().getType();
    
    if (stack != null && (entity instanceof Player)) 
    {
    	if (top == InventoryType.PLAYER || top == InventoryType.WORKBENCH || top == InventoryType.CRAFTING) 
    		return;

    	if(KitUtils.isSoulbound(stack))
          event.setCancelled(true); 
    }
 }
 
Example 16
Source Project: AnvilGUI   Source File: AnvilGUI.java    License: MIT License 6 votes vote down vote up
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
	if (
		((event.getInventory().equals(inventory)) && (event.getRawSlot() < 3)) ||
		(event.getAction().equals(InventoryAction.MOVE_TO_OTHER_INVENTORY)) ||
		((event.getRawSlot() < 3) && ((event.getAction().equals(InventoryAction.PLACE_ALL)) || (event.getAction().equals(InventoryAction.PLACE_ONE)) || (event.getAction().equals(InventoryAction.PLACE_SOME)) || (event.getCursor() != null)))
	){
		event.setCancelled(true);
		final Player clicker = (Player) event.getWhoClicked();
		if (event.getRawSlot() == Slot.OUTPUT) {
			final ItemStack clicked = inventory.getItem(Slot.OUTPUT);
			if (clicked == null || clicked.getType() == Material.AIR) return;

			final Response response = completeFunction.apply(clicker, clicked.hasItemMeta() ? clicked.getItemMeta().getDisplayName() : "");
			if(response.getText() != null) {
				final ItemMeta meta = clicked.getItemMeta();
				meta.setDisplayName(response.getText());
				clicked.setItemMeta(meta);
				inventory.setItem(Slot.INPUT_LEFT, clicked);
			} else {
				closeInventory();
			}
		}
	}
}
 
Example 17
@Override
protected void inventoryClick(InventoryClickEvent event) {
	super.inventoryClick(event);
	ItemStack item = event.getCurrentItem();
	if (item != null && item.getType() != Material.AIR) {
		Player player = (Player) event.getWhoClicked();
		if (item.equals(((EntityNBT) _wrapper)._bos.getBook())) {
			event.setCancelled(true);
		} else if (!BookOfSouls.isValidBook(item)) {
			event.setCancelled(true);
			player.sendMessage("§cYou can only put Books of Souls.");
		} else {
			EntityNBT entityNbt = BookOfSouls.bookToEntityNBT(item);
			if (entityNbt == null) {
				player.sendMessage("§cThat Book of Souls is corrupted!");
				event.setCancelled(true);
			}
		}
	}
}
 
Example 18
Source Project: Minepacks   Source File: ItemFilter.java    License: GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onItemClick(InventoryClickEvent event)
{
	if(!(event.getWhoClicked() instanceof Player)) return;
	if(event.getInventory().getHolder() instanceof Backpack)
	{
		Player player = (Player) event.getWhoClicked();
		if(event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY && checkIsBlockedAndShowMessage(player, event.getCurrentItem()))
		{
			event.setCancelled(true);
		}
		else if((event.getAction() == InventoryAction.HOTBAR_MOVE_AND_READD || event.getAction() == InventoryAction.HOTBAR_SWAP) && event.getHotbarButton() != -1)
		{
			ItemStack item = event.getWhoClicked().getInventory().getItem(event.getHotbarButton());
			if(checkIsBlockedAndShowMessage(player, item))
			{
				event.setCancelled(true);
			}
		}
		else if(!player.getInventory().equals(event.getClickedInventory()) && checkIsBlockedAndShowMessage(player, event.getCursor()))
		{
			event.setCancelled(true);
		}
	}
}
 
Example 19
Source Project: civcraft   Source File: BuildStructureList.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
	public void performAction(InventoryClickEvent event, ItemStack stack) {
//		Player player = (Player)event.getWhoClicked();
//		Resident resident = CivGlobal.getResident(player);
//		Inventory guiInventory = Bukkit.getServer().createInventory(player, LoreGuiItem.MAX_INV_SIZE, "Pick Structure To Build");
//		
//		for (ConfigBuildableInfo info : CivSettings.structures.values()) {
//			int type = ItemManager.getId(Material.ANVIL);
//			if (info.itemTypeId != 0) {
//				type = info.itemTypeId;
//			}
//			
//			ItemStack is;
//			if (!resident.hasTown()) {
//				is = LoreGuiItem.build(info.displayName, ItemManager.getId(Material.BEDROCK), 0, CivColor.Rose+"Must belong to a town to build structures.");
//			} else {
//				if (!resident.getCiv().hasTechnology(info.require_tech)) {
//					ConfigTech tech = CivSettings.techs.get(info.require_tech);
//					is = LoreGuiItem.build(info.displayName, ItemManager.getId(Material.BEDROCK), 0, CivColor.Rose+"Requires: "+tech.name);
//				} else {
//					is = LoreGuiItem.build(info.displayName, type, info.itemData, CivColor.Gold+"<Click To Build>");
//					is = LoreGuiItem.setAction(is, "BuildChooseTemplate");
//					is = LoreGuiItem.setActionData(is, "info", info.id);
//				}
//			}
//			
//			guiInventory.addItem(is);
//		}
//		
//		
//		LoreGuiItemListener.guiInventories.put(guiInventory.getName(), guiInventory);		
//		TaskMaster.syncTask(new OpenInventoryTask(player, guiInventory));
	}
 
Example 20
Source Project: uSkyBlock   Source File: SkyBlockMenu.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void onClickPartyMenu(InventoryClickEvent event, ItemStack currentItem, Player p, ItemMeta meta, SkullMeta skull, int slotIndex) {
    event.setCancelled(true);
    if (slotIndex < 0 || slotIndex > 35) {
        return;
    }
    if (meta == null || currentItem.getType() == SIGN_MATERIAL) {
        p.closeInventory();
        p.performCommand("island");
    } else if (skull != null && plugin.getIslandInfo(p).isLeader(p)) {
        p.closeInventory();
        p.openInventory(displayPartyPlayerGUI(p, skull.getOwner()));
    }
}
 
Example 21
Source Project: uSkyBlock   Source File: MenuEventsTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testOnGuiClick_regularMenu() {
    UltimateHolder holder = new UltimateHolder(getFakePlayer(), "Island GUI menu", MenuType.DEFAULT);
    InventoryClickEvent event = getEvent(holder);

    menuEvents.guiClick(event);
    verify(fakeConfigMenu, times(0)).onClick(any());
    verify(fakeMenu).onClick(event);
}
 
Example 22
Source Project: Transport-Pipes   Source File: DuctSettingsInventory.java    License: MIT License 5 votes vote down vote up
@EventHandler
public void onInvClick(InventoryClickEvent e) {
    if (e.getInventory() != null && e.getInventory().equals(inv) && e.getWhoClicked() instanceof Player) {
        if (itemService.isItemWildcardOrBarrier(e.getCurrentItem())) {
            e.setCancelled(true);
            return;
        }
        //don't call click method when double clicked, because before a double click, left click was already registered twice
        if (e.getClick() != ClickType.DOUBLE_CLICK && click((Player) e.getWhoClicked(), e.getRawSlot(), e.getClick())) {
            e.setCancelled(true);
        } else if (e.getClick() == ClickType.DOUBLE_CLICK && e.getAction() == InventoryAction.COLLECT_TO_CURSOR && collect_to_cursor((Player) e.getWhoClicked(), e.getCursor(), e.getRawSlot())) {
            e.setCancelled(true);
        }
    }
}
 
Example 23
@EventHandler
public void onInventoryClick(final InventoryClickEvent event) {
	if (event.getWhoClicked() instanceof Player) {
    	GameMap gMap = MatchManager.get().getPlayerMap((Player) event.getWhoClicked());
    	if (gMap == null) {
    		ItemStack item;
    		ItemStack item2;
    		if (event.getClick().equals(ClickType.NUMBER_KEY)) {
    			item = event.getWhoClicked().getInventory().getItem(event.getHotbarButton());
    			item2 = event.getCurrentItem();
    		} else {
    			item = event.getCurrentItem();
    			item2 = event.getCurrentItem();
    		}
    		
    		if (item != null && (item.equals(SkyWarsReloaded.getIM().getItem("optionselect")) 
    				|| item.equals(SkyWarsReloaded.getIM().getItem("joinselect")) 
    				|| item.equals(SkyWarsReloaded.getIM().getItem("spectateselect"))) 
    				|| item2 != null && (item2.equals(SkyWarsReloaded.getIM().getItem("optionselect")) 
            		|| item2.equals(SkyWarsReloaded.getIM().getItem("joinselect")) 
            		|| item2.equals(SkyWarsReloaded.getIM().getItem("spectateselect"))) ) {
    			event.setCancelled(true);
    		}
    	} else {
    		if (gMap.getMatchState().equals(MatchState.WAITINGSTART) || gMap.getMatchState().equals(MatchState.ENDING)) {
    			event.setCancelled(true);
    		}
    	}
	}

}
 
Example 24
/**
 * Gets clicked inventory
 * For API older than 1.8
 *
 * @param event inventory click event
 * @return inventory
 */
public static Inventory getClickedInventory(InventoryClickEvent event) {
	int slot = event.getRawSlot();
	InventoryView view = event.getView();

	if(slot < 0) {
		return null;
	}
	else if(view.getTopInventory() != null && slot < view.getTopInventory().getSize()) {
		return view.getTopInventory();
	}
	else {
		return view.getBottomInventory();
	}
}
 
Example 25
Source Project: factions-top   Source File: GuiListener.java    License: MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void registerClick(InventoryClickEvent event) {
    GuiContext context = plugin.getGuiManager().getContext(event.getClickedInventory());
    if (context == null) {
        return;
    }

    event.setCancelled(true);

    if (context.getSlots().size() >= event.getSlot()) {
        context.getSlots().get(event.getSlot()).handleClick(context);
    }
}
 
Example 26
Source Project: SuperVanish   Source File: SilentOpenChest.java    License: Mozilla Public License 2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onSpectatorClick(InventoryClickEvent e) {
    if (!(e.getWhoClicked() instanceof Player))
        return;
    Player p = (Player) e.getWhoClicked();
    if (!plugin.getVanishStateMgr().isVanished(p.getUniqueId())) return;
    if (!playerStateInfoMap.containsKey(p)) return;
    if (p.getGameMode() != GameMode.SURVIVAL && p.getGameMode() != GameMode.ADVENTURE
            && p.getGameMode() != GameMode.CREATIVE) {
        e.setCancelled(false);
    }
}
 
Example 27
Source Project: IridiumSkyblock   Source File: WarpGUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
@EventHandler
@Override
public void onInventoryClick(InventoryClickEvent e) {
    if (e.getInventory().equals(getInventory())) {
        Player p = (Player) e.getWhoClicked();
        User u = User.getUser(p);
        e.setCancelled(true);
        if (e.getClickedInventory() == null || !e.getClickedInventory().equals(getInventory())) return;
        if (warps.containsKey(e.getSlot())) {
            Island.Warp warp = warps.get(e.getSlot());
            if (e.getClick().equals(ClickType.RIGHT)) {
                u.getIsland().removeWarp(warps.get(e.getSlot()));
                getInventory().clear();
                addContent();
            } else {
                if (warp.getPassword().isEmpty()) {
                    p.teleport(warp.getLocation());
                    p.sendMessage(Utils.color(IridiumSkyblock.getMessages().teleporting.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
                } else {
                    p.sendMessage(Utils.color(IridiumSkyblock.getMessages().enterPassword.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
                    u.warp = warp;
                }
            }
            p.closeInventory();
        }
    }
}
 
Example 28
Source Project: uSkyBlock   Source File: SkyBlockMenu.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void onClickPermissionMenu(InventoryClickEvent event, ItemStack currentItem, Player p, String inventoryName, int slotIndex) {
    event.setCancelled(true);
    if (slotIndex < 0 || slotIndex > 35) {
        return;
    }
    IslandInfo islandInfo = plugin.getIslandInfo(p);
    if (!plugin.getIslandInfo(p).isLeader(p)) {
        p.closeInventory();
        p.openInventory(displayPartyGUI(p));
    }
    String[] playerPerm = inventoryName.split(" ");
    String pname = playerPerm[0];
    ItemStack skullItem = event.getInventory().getItem(1);
    if (skullItem != null && skullItem.getType().equals(Material.PLAYER_HEAD)) {
        ItemMeta meta = skullItem.getItemMeta();
        if (meta instanceof SkullMeta) {
            pname = ((SkullMeta) meta).getOwner();
        }
    }
    for (PartyPermissionMenuItem item : permissionMenuItems) {
        if (currentItem.getType() == item.getIcon().getType()) {
            p.closeInventory();
            islandInfo.togglePerm(pname, item.getPerm());
            p.openInventory(displayPartyPlayerGUI(p, pname));
            return;
        }
    }
    if (currentItem.getType() == SIGN_MATERIAL) {
        p.closeInventory();
        p.openInventory(displayPartyGUI(p));
    } else {
        p.closeInventory();
        p.openInventory(displayPartyPlayerGUI(p, pname));
    }
}
 
Example 29
Source Project: GriefDefender   Source File: PlayerEventHandler.java    License: MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerInteractInventoryClick(InventoryClickEvent event) {
    final HumanEntity player = event.getWhoClicked();
    GDCauseStackManager.getInstance().pushCause(player);
    if (!GDFlags.INTERACT_INVENTORY_CLICK || event.getClickedInventory() == null || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUID())) {
        return;
    }

    GDTimings.PLAYER_INTERACT_INVENTORY_CLICK_EVENT.startTiming();
    final Location location = player.getLocation();
    final GDClaim claim = this.dataStore.getClaimAt(location);
    final ItemStack cursorItem = event.getCursor();
    final Inventory source = event.getInventory();
    final ItemStack target = event.getCurrentItem();

    if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.INTERACT_INVENTORY_CLICK.getName(), target, player.getWorld().getUID())) {
        GDTimings.PLAYER_INTERACT_INVENTORY_CLICK_EVENT.stopTiming();
        return;
    }

    final GDPermissionUser user = PermissionHolderCache.getInstance().getOrCreateUser(player.getUniqueId());
    final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.INTERACT_INVENTORY_CLICK, source, target, user, TrustTypes.CONTAINER, true);
    if (result == Tristate.FALSE) {
        final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.PERMISSION_INTERACT_ITEM,
                ImmutableMap.of(
                "player", claim.getOwnerDisplayName(),
                "item", ItemTypeRegistryModule.getInstance().getNMSKey(target)));
        GriefDefenderPlugin.sendClaimDenyMessage(claim, player, message);
        event.setCancelled(true);
    }
    GDTimings.PLAYER_INTERACT_INVENTORY_CLICK_EVENT.stopTiming();
}
 
Example 30
Source Project: PGM   Source File: SpawnMatchModule.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryClick(final InventoryClickEvent event) {
  MatchPlayer player = match.getPlayer(event.getWhoClicked());
  if (player != null) {
    State state = states.get(player);
    if (state != null) state.onEvent(event);
  }
}