Java Code Examples for org.bukkit.event.inventory.InventoryClickEvent#setCurrentItem()

The following examples show how to use org.bukkit.event.inventory.InventoryClickEvent#setCurrentItem() . 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: Carried.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void onEvent(InventoryClickEvent event) {
  super.onEvent(event);
  if (this.isCarrier(event.getWhoClicked())
      && event.getSlot() == ArmorType.HELMET.inventorySlot()) {
    event.setCancelled(true);
    event.getView().setCursor(null);
    event.setCurrentItem(null);
    this.flag
        .getMatch()
        .getExecutor(MatchScope.RUNNING)
        .execute(
            () -> {
              if (isCurrent()) dropFlag();
            });
  }
}
 
Example 2
Source File: RepairListener.java    From EnchantmentsEnhance with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onAnvilGUIClick(final InventoryClickEvent event) {
    if (event.getInventory().getType() == InventoryType.ANVIL && event.getWhoClicked() instanceof Player) {
        if (!(event.getInventory() instanceof AnvilInventory)) {
            return;
        }
        final Player player = (Player) event.getWhoClicked();
        final AnvilInventory inv = (AnvilInventory) event.getInventory();
        AnvilTask task = AnvilTask.getTask(inv);
        if (task == null) {
            task = new AnvilTask(inv, player);
        }
        if (event.getRawSlot() == 2) {
            final ItemStack translatedItem = ColorHandler.getTranslatedItem(player, inv, task);
            event.setCurrentItem(translatedItem);
        }
    }
}
 
Example 3
Source File: ExhibitionListener.java    From NyaaUtils with MIT License 6 votes vote down vote up
@EventHandler(priority = HIGHEST, ignoreCancelled = true)
public void onPlayerFetchItem(InventoryClickEvent ev) {
    if (!(ev.getWhoClicked() instanceof Player)) return;
    if (ExhibitionFrame.isFrameInnerItem(ev.getCursor())) {
        plugin.getLogger().warning(
                String.format("Illegal Exhibition Item use: {player: %s, location: %s, item: %s}",
                        ev.getWhoClicked().getName(), ev.getWhoClicked().getLocation().toString(),
                        ev.getCursor().toString()));
        ev.setCancelled(true);
        ev.getView().setCursor(new ItemStack(Material.AIR));
    }
    if (ExhibitionFrame.isFrameInnerItem(ev.getCurrentItem())) {
        plugin.getLogger().warning(
                String.format("Illegal Exhibition Item use: {player: %s, location: %s, item: %s}",
                        ev.getWhoClicked().getName(), ev.getWhoClicked().getLocation().toString(),
                        ev.getCursor().toString()));
        ev.setCancelled(true);
        ev.setCurrentItem(new ItemStack(Material.AIR));
    }
}
 
Example 4
Source File: InventoryForSpecialVariable.java    From NBTEditor with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void inventoryClick(InventoryClickEvent event) {
	int slot = event.getRawSlot();
	if (slot >= 0 && slot < getInventory().getSize()) {
		ItemStack item = _inventory.getItem(slot);
		if (item != null) {
			if (item.equals(_placeholders.get(slot))) {
				event.setCurrentItem(null);
			} else if (item.equals(ITEM_FILLER)) {
				event.setCancelled(true);
			}
		}

	}
	if (!_allowBos && BookOfSouls.isValidBook(event.getCurrentItem())) {
		event.setCancelled(true);
	}
}
 
Example 5
Source File: Carried.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onEvent(InventoryClickEvent event) {
    super.onEvent(event);
    if(this.isCarrier(event.getWhoClicked()) && event.getSlot() == ArmorType.HELMET.inventorySlot()) {
        event.setCancelled(true);
        event.getView().setCursor(null);
        event.setCurrentItem(null);
        this.flag.getMatch().getScheduler(MatchScope.RUNNING).createTask(() -> {
            if(isCurrent()) {
                dropFlag();
            }
        });
    }
}
 
Example 6
Source File: ElytraEnhanceListener.java    From NyaaUtils with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onInventoryClickEvent(InventoryClickEvent event) {
    if (!event.getWhoClicked().isGliding() && event.getCurrentItem() != null && plugin.fuelManager.getFuelID(event.getCurrentItem()) != -1) {
        ItemStack item = event.getCurrentItem();
        int id = plugin.fuelManager.getFuelID(item);
        int durability = plugin.fuelManager.getFuelDurability(item);
        plugin.fuelManager.updateItem(item, id, durability);
        event.setCurrentItem(item);
    }
}
 
Example 7
Source File: FlagObjective.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
    if (isPicker(event.getWhoClicked()) && event.getSlot() == ArmorType.HELMET.getSlot()) {
        event.setCancelled(true);
        event.setCurrentItem(null);
        spawnFlag();
    }
}
 
Example 8
Source File: ItemBuilder.java    From ProRecipes with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler
public void onInventoryClick(InventoryClickEvent event){
	if(event.getInventory() == null || event.getClickedInventory() == null)return;
	if(event.getSlot() == -999)return;
	if(!event.getInventory().getType().equals(InventoryType.WORKBENCH))return;
	if(!event.getWhoClicked().hasMetadata("itemBuilder"))return;
	//////////////////System.out.println("Called");
	//////////////////System.out.println(event.getInventory().getTitle());
	//////////////////System.out.println(event.getAction());
	if(((Player)event.getWhoClicked()).isSneaking()){
		event.setCancelled(true);
		return;
	}
	//////////////////System.out.println(event.getAction());
	String step = event.getWhoClicked().getMetadata("itemBuilder").get(0).asString();
	if(step.equalsIgnoreCase("itemRequest")){
		
		switch(event.getAction()){
		case PLACE_ONE:
		case PLACE_SOME:
		case PLACE_ALL:
		case DROP_ALL_CURSOR:
		case DROP_ALL_SLOT:
		case DROP_ONE_CURSOR:
		case DROP_ONE_SLOT:
		case MOVE_TO_OTHER_INVENTORY:
			event.setCancelled(true);
			ItemStack i = event.getCursor().clone();
			event.setCursor(null);
			if(i == null){
				i = event.getCurrentItem().clone();
				event.setCurrentItem(null);
			}
			event.getInventory().setItem(0, i);
			openInterface((Player)event.getWhoClicked(), true);
		}
	}else if(step.equalsIgnoreCase("itemInterface")){
		if(event.getSlot() == 0){
			
		}else if(event.getSlot() == 1){
			openAddLore((Player)event.getWhoClicked());
		}else if(event.getSlot() == 3){
			openSetDisplayName((Player)event.getWhoClicked());
		}else if(event.getSlot() == 7){
			removeLore((Player)event.getWhoClicked());
		}else if(event.getSlot() == 9){
			finish((Player)event.getWhoClicked());
		}else if(event.getSlot() == 5){
			
		}else if(event.getSlot() == 8){
			
		}
		
		event.setCancelled(true);
	}
	
}
 
Example 9
Source File: ItemSaleEvent.java    From EliteMobs with GNU General Public License v3.0 2 votes vote down vote up
@EventHandler
public void playerSellEvent(InventoryClickEvent event) {

    if (!SharedShopElements.sellInventoryNullPointerPreventer(event)) {

        return;

    }

    if (!event.getInventory().getName().equals(ShopHandler.SHOP_NAME) &&
            !event.getInventory().getName().equals(CustomShopHandler.SHOP_NAME)) {

        return;

    }

    if (event.getClickedInventory().getName().equals(ShopHandler.SHOP_NAME) ||
            event.getClickedInventory().getName().equals(CustomShopHandler.SHOP_NAME)) {

        return;

    }

    if (!ObfuscatedSignatureLoreData.obfuscatedSignatureDetector(event.getCurrentItem())) {

        event.setCancelled(true);
        return;

    }

    Player player = (Player) event.getWhoClicked();
    ItemStack itemStack = event.getCurrentItem();
    String itemDisplayName = itemStack.getItemMeta().getDisplayName();

    double amountDeduced = ItemWorthCalculator.determineResaleWorth(itemStack);

    EconomyHandler.addCurrency(UUIDFilter.guessUUI(player.getName()), amountDeduced);

    if (event.getCurrentItem().getAmount() == 1) {

        event.setCurrentItem(new ItemStack(Material.AIR));

    } else if (event.getCurrentItem().getAmount() > 1) {

        int newAmount = event.getCurrentItem().getAmount() - 1;

        event.getCurrentItem().setAmount(newAmount);

    }

    SharedShopElements.sellMessage(player, itemDisplayName, amountDeduced);

}