org.bukkit.event.inventory.ClickType Java Examples

The following examples show how to use org.bukkit.event.inventory.ClickType. 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: EnhancedItemListener.java    From EnchantmentsEnhance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Prevents enhanced item from storing.
 *
 * @param e
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onInventoryClick(InventoryClickEvent e) {
    if ((e.getInventory().getType() != InventoryType.CRAFTING) && (e.getInventory().getType() != InventoryType.PLAYER)) {
        if ((e.getClick().equals(ClickType.NUMBER_KEY)) && (e.getWhoClicked().getInventory().getItem(e.getHotbarButton()) != null)) {
            ItemStack itemMoved = e.getWhoClicked().getInventory().getItem(e.getHotbarButton());
            if ((itemMoved.hasItemMeta()) && (itemMoved.getItemMeta().hasLore())) {
                if (itemMoved.getItemMeta().getLore().contains(Util.UNIQUEID + Util.toColor(SettingsManager.lang.getString("lore.untradeableLore")))) {
                    e.setCancelled(true);
                    Util.sendMessage(SettingsManager.lang.getString("messages.noStorage"), e.getWhoClicked());
                }
            }
        }
        if (e.getCurrentItem() != null) {
            if ((e.getCurrentItem().hasItemMeta()) && (e.getCurrentItem().getItemMeta().hasLore())) {
                if (e.getCurrentItem().getItemMeta().getLore().contains(Util.UNIQUEID + Util.toColor(SettingsManager.lang.getString("lore.untradeableLore")))) {
                    e.setCancelled(true);
                    Util.sendMessage(SettingsManager.lang.getString("messages.noStorage"), e.getWhoClicked());
                }
            }
        }
    }
}
 
Example #2
Source File: ViewInventoryMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void showInventories(final ObserverInteractEvent event) {
    if(event.getClickType() != ClickType.RIGHT) return;
    if(event.getPlayer().isDead()) return;

    if(event.getClickedParticipant() != null) {
        event.setCancelled(true);
        if(canPreviewInventory(event.getPlayer(), event.getClickedParticipant())) {
            this.previewPlayerInventory(event.getPlayer().getBukkit(), event.getClickedParticipant().getInventory());
        }
    } else if(event.getClickedEntity() instanceof InventoryHolder && !(event.getClickedEntity() instanceof Player)) {
        event.setCancelled(true);
        this.previewInventory(event.getPlayer().getBukkit(), ((InventoryHolder) event.getClickedEntity()).getInventory());
    } else if(event.getClickedBlockState() instanceof InventoryHolder) {
        event.setCancelled(true);
        this.previewInventory(event.getPlayer().getBukkit(), ((InventoryHolder) event.getClickedBlockState()).getInventory());
    }
}
 
Example #3
Source File: EventFilterMatchModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onInteract(final PlayerInteractEvent event) {
  if (cancelUnlessInteracting(event, event.getPlayer())) {
    // Allow the how-to book to be read
    if (event.getMaterial() == Material.WRITTEN_BOOK) {
      event.setUseItemInHand(Event.Result.ALLOW);
    }

    MatchPlayer player = match.getPlayer(event.getPlayer());
    if (player == null) return;

    ClickType clickType = convertClick(event.getAction(), event.getPlayer());
    if (clickType == null) return;

    match.callEvent(
        new ObserverInteractEvent(
            player, clickType, event.getClickedBlock(), null, event.getItem()));
  }
}
 
Example #4
Source File: PickerMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler
public void rightClickIcon(final ObserverInteractEvent event) {
    if(event.getClickType() != ClickType.RIGHT) return;

    MatchPlayer player = event.getPlayer();
    if(!canUse(player)) return;

    ItemStack hand = event.getClickedItem();
    if(ItemUtils.isNothing(hand)) return;

    String displayName = hand.getItemMeta().getDisplayName();
    if(displayName == null) return;

    if(hand.getType() == Button.JOIN.material) {
        event.setCancelled(true);
        if(canOpenWindow(player)) {
            showWindow(player);
        } else {
            // If there is nothing to pick, just join immediately
            jmm.requestJoin(player, JoinRequest.user());
        }
    } else if(hand.getType() == Button.LEAVE.material) {
        event.setCancelled(true);
        jmm.requestObserve(player);
    }
}
 
Example #5
Source File: EventFilterMatchModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onDamage(final EntityDamageEvent event) {
  cancelUnlessInteracting(event, event.getEntity());
  if (event instanceof EntityDamageByEntityEvent) {
    EntityDamageByEntityEvent entityEvent = (EntityDamageByEntityEvent) event;
    if (cancelUnlessInteracting(event, entityEvent.getDamager())) {
      MatchPlayer player = match.getPlayer(entityEvent.getDamager());
      if (player == null) return;

      match.callEvent(
          new ObserverInteractEvent(
              player,
              ClickType.LEFT,
              null,
              event.getEntity(),
              player.getInventory().getItemInHand()));
    }
  }
}
 
Example #6
Source File: Icon.java    From TrMenu with MIT License 6 votes vote down vote up
public void onClick(Player player, Button button, ClickType clickType, InventoryClickEvent event) {
    List<AbstractAction> actions = getActions().getOrDefault(clickType, new ArrayList<>());
    Notifys.debug(player, "ClickType: {0}, Actions: {1}. &8{2}", clickType.name(), actions.size(), actions);

    ArgsCache.getEvent().put(player.getUniqueId(), event);
    ArgsCache.getClickedItem().put(player.getUniqueId(), item);
    ArgsCache.getClickedButtons().put(player.getUniqueId(), button);

    TrAction.runActions(actions, player);
    if (getActions().get(null) != null) {
        TrAction.runActions(getActions().get(null), player);
    }

    ArgsCache.clear(player);
    button.refreshConditionalIcon(player, event);
}
 
Example #7
Source File: GUIs.java    From MineTinker with GNU General Public License v3.0 6 votes vote down vote up
public static void addNavigationButtons(GUI.Window currentPage) {
	ItemMeta forwardMeta = forwardStack.getItemMeta();
	if (forwardMeta != null) {
		forwardMeta.setDisplayName(ChatColor.GREEN + LanguageManager.getString("GUIs.Forward"));
		forwardStack.setItemMeta(forwardMeta);
	}

	ItemMeta backMeta = backStack.getItemMeta();
	if (backMeta != null) {
		backMeta.setDisplayName(ChatColor.RED + LanguageManager.getString("GUIs.Back"));
		backStack.setItemMeta(backMeta);
	}

	GUI.Window.Button back = currentPage.addButton(0, 5, backStack);
	back.addAction(ClickType.LEFT, new ButtonAction.PAGE_DOWN(back));

	GUI.Window.Button forward = currentPage.addButton(8, 5, forwardStack);
	forward.addAction(ClickType.LEFT, new ButtonAction.PAGE_UP(forward));
}
 
Example #8
Source File: SimpleSlot.java    From helper with MIT License 5 votes vote down vote up
@Nonnull
@Override
public Slot bind(@Nonnull ClickType type, @Nonnull Runnable handler) {
    Objects.requireNonNull(type, "type");
    Objects.requireNonNull(handler, "handler");
    this.handlers.computeIfAbsent(type, t -> ConcurrentHashMap.newKeySet()).add(Item.transformRunnable(handler));
    return this;
}
 
Example #9
Source File: Item.java    From helper with MIT License 5 votes vote down vote up
@Nonnull
public Builder bind(@Nullable Consumer<InventoryClickEvent> handler, @Nonnull ClickType... types) {
    for (ClickType type : types) {
        bind(type, handler);
    }
    return this;
}
 
Example #10
Source File: DuctSettingsInventory.java    From Transport-Pipes with 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 #11
Source File: SimpleSlot.java    From helper with MIT License 5 votes vote down vote up
@Nonnull
@Override
public <T extends Consumer<InventoryClickEvent>> Slot bindAllConsumers(@Nonnull Iterable<Map.Entry<ClickType, T>> handlers) {
    Objects.requireNonNull(handlers, "handlers");
    for (Map.Entry<ClickType, T> handler : handlers) {
        bind(handler.getKey(), handler.getValue());
    }
    return this;
}
 
Example #12
Source File: SimpleSlot.java    From helper with MIT License 5 votes vote down vote up
@Nonnull
@Override
public <T extends Runnable> Slot bindAllRunnables(@Nonnull Iterable<Map.Entry<ClickType, T>> handlers) {
    Objects.requireNonNull(handlers, "handlers");
    for (Map.Entry<ClickType, T> handler : handlers) {
        bind(handler.getKey(), handler.getValue());
    }
    return this;
}
 
Example #13
Source File: TestBackpackListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private boolean isAllowed(String id, ItemStack item) throws InterruptedException {
    Player player = server.addPlayer();
    Inventory inv = openMockBackpack(player, id, 9).getInventory();

    int slot = 7;
    inv.setItem(slot, item);
    InventoryClickEvent event = new InventoryClickEvent(player.getOpenInventory(), SlotType.CONTAINER, slot, ClickType.LEFT, InventoryAction.PICKUP_ONE);
    listener.onClick(event);
    return !event.isCancelled();
}
 
Example #14
Source File: Item.java    From helper with MIT License 5 votes vote down vote up
@Nonnull
public <T extends Runnable> Builder bindAllRunnables(@Nonnull Iterable<Map.Entry<ClickType, T>> handlers) {
    Objects.requireNonNull(handlers, "handlers");
    for (Map.Entry<ClickType, T> handler : handlers) {
        bind(handler.getKey(), handler.getValue());
    }
    return this;
}
 
Example #15
Source File: SimpleSlot.java    From helper with MIT License 5 votes vote down vote up
@Nonnull
@Override
public Slot bind(@Nonnull ClickType type, @Nonnull Consumer<InventoryClickEvent> handler) {
    Objects.requireNonNull(type, "type");
    Objects.requireNonNull(handler, "handler");
    this.handlers.computeIfAbsent(type, t -> ConcurrentHashMap.newKeySet()).add(handler);
    return this;
}
 
Example #16
Source File: SimpleSlot.java    From helper with MIT License 5 votes vote down vote up
/**
 * Clears all bindings on this slot for a given click type.
 *
 * @return this slot
 */
@Nonnull
@Override
public Slot clearBindings(ClickType type) {
    this.handlers.remove(type);
    return this;
}
 
Example #17
Source File: TestVanillaMachinesListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private InventoryClickEvent mockGrindStoneEvent(ItemStack item) {
    Player player = server.addPlayer();
    Inventory inv = TestUtilities.mockInventory(InventoryType.GRINDSTONE, item, null);
    InventoryView view = player.openInventory(inv);
    InventoryClickEvent event = new InventoryClickEvent(view, SlotType.CONTAINER, 2, ClickType.LEFT, InventoryAction.PICKUP_ONE);

    listener.onGrindstone(event);
    return event;
}
 
Example #18
Source File: EventFilterMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
void callObserverInteractEvent(PlayerInteractEntityEvent event) {
  MatchPlayer player = match.getPlayer(event.getPlayer());
  if (player == null) return;

  match.callEvent(
      new ObserverInteractEvent(
          player,
          convertClick(ClickType.RIGHT, event.getPlayer()),
          null,
          event.getRightClicked(),
          event.getPlayer().getItemInHand()));
}
 
Example #19
Source File: Item.java    From helper with MIT License 5 votes vote down vote up
@Nonnull
public Builder bind(@Nullable Runnable handler, @Nonnull ClickType... types) {
    for (ClickType type : types) {
        bind(type, handler);
    }
    return this;
}
 
Example #20
Source File: VisitGUI.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler
@Override
public void onInventoryClick(InventoryClickEvent e) {
    if (e.getInventory().equals(getInventory())) {
        e.setCancelled(true);
        if (e.getClickedInventory() == null || !e.getClickedInventory().equals(getInventory())) return;
        if (islands.containsKey(e.getSlot())) {
            Island island = IridiumSkyblock.getIslandManager().getIslandViaId(islands.get(e.getSlot()));
            User u = User.getUser((OfflinePlayer) e.getWhoClicked());
            if (island.isVisit() || u.bypassing) {
                if (e.getClick() == ClickType.RIGHT) {
                    if (island.hasVoted(u)) {
                        island.removeVote(u);
                    } else {
                        island.addVote(u);
                    }
                } else {
                    e.getWhoClicked().closeInventory();
                    island.teleportHome((Player) e.getWhoClicked());
                }
            } else {
                e.getWhoClicked().sendMessage(Utils.color(IridiumSkyblock.getMessages().playersIslandIsPrivate.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
            }
        } else if (e.getSlot() == getInventory().getSize() - 7) {
            if (IridiumSkyblock.visitGUI.containsKey(page - 1))
                e.getWhoClicked().openInventory(IridiumSkyblock.visitGUI.get(page - 1).getInventory());
        } else if (e.getSlot() == getInventory().getSize() - 3) {
            if (IridiumSkyblock.visitGUI.containsKey(page + 1))
                e.getWhoClicked().openInventory(IridiumSkyblock.visitGUI.get(page + 1).getInventory());
        }
    }
}
 
Example #21
Source File: Item.java    From helper with MIT License 5 votes vote down vote up
@Nonnull
public <T extends Consumer<InventoryClickEvent>> Builder bindAllConsumers(@Nonnull Iterable<Map.Entry<ClickType, T>> handlers) {
    Objects.requireNonNull(handlers, "handlers");
    for (Map.Entry<ClickType, T> handler : handlers) {
        bind(handler.getKey(), handler.getValue());
    }
    return this;
}
 
Example #22
Source File: NavigatorInterface.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public boolean buttonClicked(ItemStack stack, Player clicker, ClickType clickType, Event event) {
    if(connector.isConnectable()) {
        windowManager.closeWindow(clicker);
        connector.teleport(clicker);
    }
    return true;
}
 
Example #23
Source File: GUIListener.java    From EnchantmentsEnhance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Prevents item glitched into menu.
 *
 * @param e
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onInventoryClick(InventoryClickEvent e) {
    if ((e.getInventory().getType() != InventoryType.CRAFTING) && (e.getInventory().getType() != InventoryType.PLAYER)) {
        if ((e.getClick().equals(ClickType.NUMBER_KEY)) && (e.getWhoClicked().getInventory().getItem(e.getHotbarButton()) != null)) {
            Player player = (Player) e.getWhoClicked();
            String playerName = player.getName();
            GUIAbstract gui = GUIManager.getMap().get(playerName);
            if (gui != null && gui.getInventory().equals(e.getInventory())) {
                e.setCancelled(true);
            }
        }
    }
}
 
Example #24
Source File: EventFilterMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
ClickType convertClick(ClickType clickType, Player player) {
    if(clickType == ClickType.RIGHT && player.isSneaking()) {
        return ClickType.SHIFT_RIGHT;
    } else {
        return clickType;
    }
}
 
Example #25
Source File: EventFilterMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@Nullable ClickType convertClick(Action action, Player player) {
    switch(action) {
        case LEFT_CLICK_BLOCK:
        case LEFT_CLICK_AIR:
            return ClickType.LEFT;

        case RIGHT_CLICK_BLOCK:
        case RIGHT_CLICK_AIR:
            return convertClick(ClickType.RIGHT, player);

        default:
            return null;
    }
}
 
Example #26
Source File: EventFilterMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onAttack(final PlayerAttackEntityEvent event) {
    if(cancelUnlessInteracting(event, event.getPlayer())) {
        final MatchPlayer attacker = getMatch().getPlayer(event.getPlayer());
        if(attacker == null || attacker.isSpawned()) return;
        getMatch().callEvent(new ObserverInteractEvent(attacker, ClickType.LEFT, null, event.getLeftClicked(), event.getPlayer().getInventory().getItemInMainHand()));
    }
}
 
Example #27
Source File: IntegerEditMenu.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onClick(InventoryClickEvent event) {
    if (!(event.getInventory().getHolder() instanceof UltimateHolder) ||
            ((UltimateHolder) event.getInventory().getHolder()).getTitle() == null ||
            !stripFormatting(((UltimateHolder) event.getInventory().getHolder()).getTitle()).contains(stripFormatting(getTitle()))) {
        return false;
    }
    if (event.getSlotType() != InventoryType.SlotType.CONTAINER) {
        return true;
    }
    Player player = (Player) event.getWhoClicked();
    Inventory menu = event.getInventory();
    ItemStack returnItem = menu.getItem(getIndex(5, 0));
    String configName = returnItem.getItemMeta().getLore().get(0);
    String path = returnItem.getItemMeta().getLore().get(1);
    int page = getPage(returnItem.getItemMeta().getLore().get(2));
    int slot = event.getSlot();
    int row = slot / 9;
    int col = slot % 9;
    ItemStack clickedItem = event.getCurrentItem();
    if (slot >= getIndex(3, 0) && slot <= getIndex(3, 8)) {
        // increment buttons
        YmlConfiguration config = FileUtil.getYmlConfiguration(configName);
        int value = config.getInt(path, 0);
        int increment = getDisplayNameAsInt(clickedItem);
        if (event.getClick() == ClickType.LEFT) {
            value += increment;
        } else if (event.getClick() == ClickType.RIGHT) {
            value = increment;
        }
        config.set(path, value);
        config.set("dirty", true);
    }
    if (slot != getIndex(5,0)) {
        player.openInventory(createEditMenu(configName, path, page));
    } else {
        player.openInventory(parent.createEditMenu(configName, path, page));
    }
    return true;
}
 
Example #28
Source File: IconMenu.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
OptionClickEvent(Player player, String name, ClickType clickType, ItemStack itemStack, int slot) {
    this.player = player;
    this.name = name;
    this.clickType = clickType;
    this.item = itemStack;
    this.slot = slot;
}
 
Example #29
Source File: TestVanillaMachinesListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private InventoryClickEvent mockAnvilEvent(ItemStack item) {
    Player player = server.addPlayer();
    Inventory inv = TestUtilities.mockInventory(InventoryType.ANVIL, item, null, new ItemStack(Material.IRON_CHESTPLATE));
    InventoryView view = player.openInventory(inv);
    InventoryClickEvent event = new InventoryClickEvent(view, SlotType.CONTAINER, 2, ClickType.LEFT, InventoryAction.PICKUP_ONE);

    listener.onAnvil(event);
    return event;
}
 
Example #30
Source File: BrewObjective.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onIngredientPut(InventoryClickEvent event) {
    if (event.getInventory().getType() != InventoryType.BREWING)
        return;
    if (event.getRawSlot() == 3 || event.getClick().equals(ClickType.SHIFT_LEFT)) {
        String playerID = PlayerConverter.getID((Player) event.getWhoClicked());
        if (!containsPlayer(playerID))
            return;
        locations.put(((BrewingStand) event.getInventory().getHolder()).getLocation(), playerID);
    }
}