@EventHandler public final void __handleInvClick(InventoryClickEvent e) { Inventory clickedInventory = e.getClickedInventory(); ClickType clickType = e.getClick(); Player player = (Player) e.getWhoClicked(); ItemStack clicked = e.getCurrentItem(); if (clickedInventory == null) return; if (clickedInventory == inventory) { e.setCancelled(true); if (clicked != null) { BiConsumer<Player, ClickType> b; if ((b = clicks.get(e.getRawSlot())) != null) { b.accept(player, clickType); if (updateOnClick && ! destroyed) update(); } } } }
@EventHandler public void onInteract(InventoryClickEvent e) { Player player = (Player) e.getWhoClicked(); if(!ChatColor.stripColor(e.getClickedInventory().getTitle()).equalsIgnoreCase("HCRiots Donator Kits")) { return; } if(e.getInventory().getSize() != 45) { return; } if(e.getClick() != ClickType.LEFT) { return; } if(ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()).equalsIgnoreCase("Titanium Kit")) { this.giveTitaniumKit(player); } }
@EventHandler public void onInventoryClick(InventoryClickEvent event) { Player player = (Player) event.getWhoClicked(); ItemStack clicked = event.getCurrentItem(); Inventory inventory = event.getInventory(); if (inventory.getName().equals("Faction Management")) { if (clicked.getType() == Material.SKULL_ITEM) { if (event.getClick() == ClickType.LEFT) { Bukkit.dispatchCommand(player, "f promote " + clicked.getItemMeta().getDisplayName()); event.setCancelled(true); } if (event.getClick() == ClickType.MIDDLE){ Bukkit.dispatchCommand(player, "f leader " + clicked.getItemMeta().getDisplayName()); event.setCancelled(true); } if (event.getClick() == ClickType.RIGHT) { Bukkit.dispatchCommand(player, "f demote " + clicked.getItemMeta().getDisplayName()); event.setCancelled(true); } } } }
@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); } else { event.setUseItemInHand(Event.Result.DENY); event.setUseInteractedBlock(Event.Result.DENY); } MatchPlayer player = getMatch().getPlayer(event.getPlayer()); if(player == null) return; if(!player.isSpawned()) { ClickType clickType = convertClick(event.getAction(), event.getPlayer()); if(clickType == null) return; getMatch().callEvent(new ObserverInteractEvent(player, clickType, event.getClickedBlock(), null, event.getItem())); } // Right-clicking armor will put it on unless we do this event.getPlayer().updateInventory(); } }
@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); } }
@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()); } }
@EventHandler(priority = EventPriority.LOW) public void onInteract(PlayerInteractEvent event) { if(!event.hasItem()) return; final ClickType click; switch(event.getAction()) { case LEFT_CLICK_AIR: case LEFT_CLICK_BLOCK: click = ClickType.LEFT; break; case RIGHT_CLICK_AIR: case RIGHT_CLICK_BLOCK: click = ClickType.RIGHT; break; default: return; } if(onButtonClick(event.getItem(), event.getActor(), click, event)) { event.setUseItemInHand(Event.Result.DENY); event.setUseInteractedBlock(Event.Result.DENY); } }
@Override public void onClick(Player player, ItemStack stack, String action, ClickType clickType) { if (action.equals("craft")) { if (SamaGamesAPI.get().getPlayerManager().getPlayerData(player.getUniqueId()).getPowders() >= 64) { this.hub.getGuiManager().openGui(player, new GuiWellCraft(this.hub, this.parent)); } else { player.sendMessage(Well.TAG + ChatColor.RED + "Vous n'avez pas assez de poussières d'\u272F !"); } } else if (action.equals("back")) { this.hub.getGuiManager().closeGui(player); this.parent.stop(player); } }
@Override public void enableCosmetic(Player player, JukeboxDiskCosmetic cosmetic, ClickType clickType, boolean login) { if (cosmetic.isOwned(player)) { if (cosmetic.getAccessibility().canAccess(player)) { this.play(cosmetic, player); AbstractGui gui = (AbstractGui) this.hub.getGuiManager().getPlayerGui(player); if (gui != null) gui.update(player); } else { player.sendMessage(PlayerManager.COSMETICS_TAG + ChatColor.RED + "Vous n'avez pas le grade nécessaire pour utiliser cette cosmétique."); } } else { player.sendMessage(PlayerManager.COSMETICS_TAG + ChatColor.RED + "Vous ne possédez pas ce cosmétique. Tentez de le débloquer auprès de Graou !"); } }
@Override public void enableCosmetic(Player player, ParticleCosmetic cosmetic, ClickType clickType, boolean login, NullType useless) { try { Effect particleEffectObject = cosmetic.getParticleEffect().getConstructor(EffectManager.class).newInstance(this.effectManager); particleEffectObject.setEntity(player); particleEffectObject.infinite(); particleEffectObject.start(); this.playersParticleEffect.put(player.getUniqueId(), particleEffectObject); if (!login) player.sendMessage(PlayerManager.COSMETICS_TAG + ChatColor.GREEN + "Vous voilà noyé sous les particules..."); } catch (ReflectiveOperationException e) { this.hub.getCosmeticManager().log(Level.SEVERE, "Can't create EntityEffect object to " + player.getName() + "'s particle effect!"); } }
@Override public void onClick(Player player, ItemStack stack, String action, ClickType clickType) { if (action.startsWith("cosmetic_")) { int cosmetic = Integer.parseInt(action.split("_")[1]); this.manager.enableCosmetic(player, this.manager.getRegistry().getElementByStorageId(cosmetic), clickType, false); } else if (action.equals("delete")) { this.manager.disableCosmetics(player, false, false); } else if (action.equals("back")) { this.hub.getGuiManager().openGui(player, new GuiCosmetics(this.hub)); } }
@Override public void onClick(Player player, ItemStack stack, String action, ClickType clickType) { if (action.startsWith("cosmetic_")) { int cosmetic = Integer.parseInt(action.split("_")[1]); this.hub.getCosmeticManager().getClothManager().enableCosmetic(player, this.hub.getCosmeticManager().getClothManager().getRegistry().getElementByStorageId(cosmetic), clickType, false); } else if (action.equals("delete")) { this.hub.getCosmeticManager().getClothManager().disableCosmetics(player, false, false); } else if (action.equals("back")) { this.hub.getGuiManager().openGui(player, new GuiClothingSets(this.hub)); } }
@Override public void onClick(Player player, ItemStack stack, String action, ClickType clickType) { if (action.startsWith("set_")) { int setStorageId = Integer.parseInt(action.split("_")[1]); this.hub.getGuiManager().openGui(player, new GuiClothingSet(this.hub, ((ClothRegistry) this.hub.getCosmeticManager().getClothManager().getRegistry()).getClothingSetByStorageId(setStorageId))); } else if (action.equals("delete")) { this.hub.getCosmeticManager().getClothManager().disableCosmetics(player, false, false); } else if (action.equals("back")) { this.hub.getGuiManager().openGui(player, new GuiCosmetics(this.hub)); } }
@Override public void onClick(Player player, ItemStack stack, String action, ClickType clickType) { if (action.equals("back")) { if (this.before != null) this.hub.getGuiManager().openGui(player, this.before); else this.hub.getGuiManager().closeGui(player); } else if (!action.equals("none")) { String iconAction = action.split("_")[1]; ShopIcon shopIcon = this.category.getIconByAction(iconAction); shopIcon.execute(player, clickType); } }
public GUICounter() { label = new GUILabel( "§a" + count, Material.REDSTONE ); label.setPosition( position ); label.setAmount( count ); addEvent( new GUIEvent() { @Override public void onClick( ComponentClickEvent event ) { if ( event.getClick() == ClickType.LEFT ) { count += steps; if ( count < 64 ) { label.setAmount( count ); label.setTitle( "§a" + GUICounter.this.count ); label.draw(); } } else if ( event.getClick() == ClickType.RIGHT ) { count -= steps; if ( count > 0 ) { label.setAmount( count ); label.setTitle( "§a" + GUICounter.this.count ); label.draw(); } } } } ); }
private void onIdeasClick(InventoryClickEvent event) { event.setCancelled(true); PageGUI.playSound(event); ItemStack button = event.getCurrentItem(); if (button == null) { return; } HumanEntity player = event.getWhoClicked(); if (button.equals(BACK)) { openGroups(player); return; } else if (!faction.isPrivileged(player)) { return; } Idea idea = IdeaGroup.getIdeaByIcon(button); if (faction.getIdeaGroups().contains(idea.getGroup()) && !faction.getIdeas().contains(idea) && event.getClick() == ClickType.SHIFT_LEFT) { boolean purchased = idea.purchase(faction); MessageUtil.sendMessage(player, (purchased ? FMessage.MISC_PURCHASE_SUCCESS : FMessage.MISC_PURCHASE_FAIL).getMessage(idea.getName())); } openIdeas(player, idea.getGroup()); }
/** * Clears all bindings on this slot for a given click type. * * @return this slot */ @Nonnull @Override public Slot clearBindings(ClickType type) { handlers.remove(type); return this; }
@Nonnull @Override public Slot bind(@Nonnull ClickType type, @Nonnull Consumer<InventoryClickEvent> handler) { Preconditions.checkNotNull(type, "type"); Preconditions.checkNotNull(handler, "handler"); handlers.computeIfAbsent(type, t -> ConcurrentHashMap.newKeySet()).add(handler); return this; }
@Nonnull @Override public Slot bind(@Nonnull ClickType type, @Nonnull Runnable handler) { Preconditions.checkNotNull(type, "type"); Preconditions.checkNotNull(handler, "handler"); handlers.computeIfAbsent(type, t -> ConcurrentHashMap.newKeySet()).add(Item.transformRunnable(handler)); return this; }
@Nonnull @Override public Slot bind(@Nonnull Consumer<InventoryClickEvent> handler, @Nonnull ClickType... types) { for (ClickType type : types) { bind(type, handler); } return this; }
@Nonnull @Override public Slot bind(@Nonnull Runnable handler, @Nonnull ClickType... types) { for (ClickType type : types) { bind(type, handler); } return this; }
@Nonnull public Builder bind(@Nonnull ClickType type, @Nullable Consumer<InventoryClickEvent> handler) { Preconditions.checkNotNull(type, "type"); if (handler != null) { handlers.put(type, handler); } else { handlers.remove(type); } return this; }
@Nonnull public Builder bind(@Nonnull ClickType type, @Nullable Runnable handler) { Preconditions.checkNotNull(type, "type"); if (handler != null) { handlers.put(type, transformRunnable(handler)); } else { handlers.remove(type); } return this; }
@Nonnull public Builder bind(@Nullable Consumer<InventoryClickEvent> handler, @Nonnull ClickType... types) { for (ClickType type : types) { bind(type, handler); } return this; }
@Nonnull public Builder bind(@Nullable Runnable handler, @Nonnull ClickType... types) { for (ClickType type : types) { bind(type, handler); } return this; }
@Nonnull public <T extends Runnable> Builder bindAllRunnables(@Nonnull Iterable<Map.Entry<ClickType, T>> handlers) { Preconditions.checkNotNull(handlers, "handlers"); for (Map.Entry<ClickType, T> handler : handlers) { bind(handler.getKey(), handler.getValue()); } return this; }
/** * Add a {@link InventoryMenuListener} for the specified {@link ClickType}s * * @param listener the {@link InventoryMenuListener} to add * @param actions the {@link ClickType}s the listener should listen for (you can also use {@link #ALL_CLICK_TYPES} or {@link ClickType#values()} * @return the InventoryMenuBuilder */ public InventoryMenuBuilder onInteract(InventoryMenuListener listener, ClickType... actions) { if (actions == null || (actions != null && actions.length == 0)) { throw new IllegalArgumentException("must specify at least one action"); } try { MenuBuilderPlugin.instance.inventoryListener.registerListener(this, listener, actions); } catch (IllegalArgumentException e) { throw e; } return this; }
@EventHandler public void onClick(InventoryClickEvent e) { if (ChatColor.stripColor(e.getInventory().getTitle()).equals("장신구 장착")) { if (e.getSlotType() != InventoryType.SlotType.OUTSIDE) { if ((e.getClick() == ClickType.RIGHT) || (e.getClick() == ClickType.LEFT)) { if ((e.getRawSlot() == 20) || (e.getRawSlot() == 21) || (e.getRawSlot() == 22) || (e.getRawSlot() == 23) || (e.getRawSlot() == 24)) { } else if (e.getRawSlot() <= e.getInventory().getSize()) { e.setCancelled(true); } } else e.setCancelled(true); } } }
public ExampleMenu() { super("Test Menu", 4); setItem(0, 0, new MenuItem() { public ItemStack getItem() { return new ItemBuilder(Material.PAPER).colorName("&a0,0").enchantEffect().build(); } public boolean shouldUpdateItem() { return false; } public boolean onClick(Player player, ClickType clickType, InventoryAction action) { Bukkit.broadcastMessage(player.getName()+" clicked"); return false; } }); setItem(1,1, new BasicItem( new ItemBuilder(Material.PAPER).colorName("&a1,1").enchantEffect().build(), (player, clickType, action) -> { Bukkit.broadcastMessage(player.getName() + " clicked BasicItem"); return false; }) ); }
public void registerListener(InventoryMenuBuilder builder, InventoryMenuListener listener, ClickType[] actions) { Map<ClickType, List<InventoryMenuListener>> map = listenerMap.get(builder.getInventory()); if (map == null) { map = new HashMap<>(); } for (ClickType action : actions) { List<InventoryMenuListener> list = map.get(action); if (list == null) { list = new ArrayList<>(); } if (list.contains(listener)) { throw new IllegalArgumentException("listener already registered"); } list.add(listener); map.put(action, list); } listenerMap.put(builder.getInventory(), map); }
@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; } }
void callObserverInteractEvent(PlayerInteractEntityEvent event) { MatchPlayer player = getMatch().getPlayer(event.getPlayer()); if(player == null || player.isSpawned()) return; getMatch().callEvent(new ObserverInteractEvent(player, convertClick(ClickType.RIGHT, event.getPlayer()), null, event.getRightClicked(), event.getPlayer().getInventory().getItem(event.getHand()))); }
@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())); } }
public ObserverInteractEvent(MatchPlayer player, ClickType clickType, @Nullable Block clickedBlock, @Nullable Entity clickedEntity, @Nullable ItemStack clickedItem) { super(player); this.clickType = checkNotNull(clickType); this.clickedBlock = clickedBlock; this.clickedEntity = clickedEntity; this.clickedItem = clickedItem; }
private boolean onButtonClick(ItemStack button, Player clicker, ClickType click, Event event) { if(!TAG.has(button)) return false; final String id = TAG.get(button); final ButtonListener listener = listeners.get(id); if(listener == null) return false; return listener.buttonClicked(button, clicker, click, event); }
/** * Called when an open window is clicked. */ default boolean windowClicked(InventoryView window, Inventory inventory, ClickType clickType, InventoryType.SlotType slotType, int slotIndex, @Nullable ItemStack item) { return false; }
@Override public boolean buttonClicked(ItemStack stack, Player clicker, ClickType clickType, Event event) { if(connector.isConnectable()) { windowManager.closeWindow(clicker); connector.teleport(clicker); } return true; }
@Override public void onClick(Player player, ItemStack stack, String action, ClickType clickType) { if (action.startsWith("pearl_")) { Pearl pearl = this.pearls.get(UUID.fromString(action.split("_")[1])); if (pearl.getStars() == 4 && !SamaGamesAPI.get().getPermissionsManager().hasPermission(player, "network.vip")) { player.sendMessage(Graou.TAG + ChatColor.GREEN + "Vous n'avez pas le grade nécéssaire pour échanger cette perle ! (" + ChatColor.GREEN + "VIP" + ChatColor.RED + ")"); return; } else if (pearl.getStars() == 5 && !SamaGamesAPI.get().getPermissionsManager().hasPermission(player, "network.vipplus")) { player.sendMessage(Graou.TAG + ChatColor.GREEN + "Vous n'avez pas le grade nécéssaire pour échanger cette perle ! (" + ChatColor.AQUA + "VIP" + ChatColor.LIGHT_PURPLE + "+" + ChatColor.RED + ")"); return; } this.parent.openBox(player, this.pearls.get(UUID.fromString(action.split("_")[1]))); this.hub.getGuiManager().closeGui(player); } else if (action.equals("back")) { this.hub.getGuiManager().closeGui(player); this.parent.stop(player); } }
@Override public void onClick(Player player, ItemStack stack, String action, ClickType clickType) { if (action.startsWith("slot_")) { int slot = Integer.parseInt(action.split("_")[1]); if (clickType == ClickType.LEFT && this.getRemainingPowders() > 0) { this.numbers[slot]++; } else if (clickType == ClickType.RIGHT && this.numbers[slot] > 0) { this.numbers[slot]--; } this.update(player); } else if (action.equals("confirm")) { if (this.getRemainingPowders() == 0) { this.hub.getInteractionManager().getWellManager().startPearlCrafting(player, this.numbers); this.hub.getGuiManager().openGui(player, new GuiWell(this.hub, this.parent)); } else { player.sendMessage(Well.TAG + ChatColor.RED + "Vous devez placer l'intégralité des poussières d'\u272F !"); } } else if (action.equals("reset")) { System.arraycopy(new int[] {0, 0, 0, 0}, 0, this.numbers, 0, 4); this.update(player); } else if (action.equals("back")) { this.hub.getGuiManager().openGui(player, new GuiWell(this.hub, this.parent)); } }