org.bukkit.event.player.PlayerItemHeldEvent Java Examples
The following examples show how to use
org.bukkit.event.player.PlayerItemHeldEvent.
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: CreateListener.java From Shopkeepers with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) void onItemHeld(PlayerItemHeldEvent event) { Player player = event.getPlayer(); if (player.getGameMode() == GameMode.CREATIVE) return; ItemStack newItemInHand = player.getInventory().getItem(event.getNewSlot()); if (!Settings.isShopCreationItem(newItemInHand)) { return; } if (!ShopkeepersPlugin.getInstance().hasCreatePermission(player)) { // player cannot create any shopkeeper at all return; } // print info message about usage: Utils.sendMessage(player, Settings.msgCreationItemSelected); }
Example #2
Source File: CustomItemManager.java From civcraft with GNU General Public License v2.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onItemHeld(PlayerItemHeldEvent event) { if (event.isCancelled()) { return; } ItemStack stack = event.getPlayer().getItemInHand(); if (stack == null) { return; } LoreMaterial material = LoreMaterial.getMaterial(stack); if (material != null) { material.onHold(event); } }
Example #3
Source File: CustomItemManager.java From civcraft with GNU General Public License v2.0 | 5 votes |
@EventHandler(priority = EventPriority.NORMAL) public void OnInventoryHold(PlayerItemHeldEvent event) { ItemStack stack = event.getPlayer().getInventory().getItem(event.getNewSlot()); if (stack == null) { return; } LoreCraftableMaterial craftMat = LoreCraftableMaterial.getCraftMaterial(stack); if (craftMat == null) { return; } craftMat.onHold(event); }
Example #4
Source File: PlayerListenerTest.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
@Test public void shouldHandleSimpleCancelableEvents() { withServiceMock(listenerService) .check(listener::onPlayerShear, PlayerShearEntityEvent.class) .check(listener::onPlayerFish, PlayerFishEvent.class) .check(listener::onPlayerBedEnter, PlayerBedEnterEvent.class) .check(listener::onPlayerDropItem, PlayerDropItemEvent.class) .check(listener::onPlayerHitPlayerEvent, EntityDamageByEntityEvent.class) .check(listener::onPlayerConsumeItem, PlayerItemConsumeEvent.class) .check(listener::onPlayerInteract, PlayerInteractEvent.class) .check(listener::onPlayerPickupItem, PlayerPickupItemEvent.class) .check(listener::onPlayerInteractEntity, PlayerInteractEntityEvent.class) .check(listener::onPlayerHeldItem, PlayerItemHeldEvent.class); }
Example #5
Source File: Defense.java From civcraft with GNU General Public License v2.0 | 5 votes |
@Override public void onHold(PlayerItemHeldEvent event) { Resident resident = CivGlobal.getResident(event.getPlayer()); if (!resident.hasTechForItem(event.getPlayer().getInventory().getItem(event.getNewSlot()))) { CivMessage.send(resident, CivColor.Rose+"Warning - "+CivColor.LightGray+ "You do not have the required technology to use this item. It's defense output will be reduced in half."); } }
Example #6
Source File: Attack.java From civcraft with GNU General Public License v2.0 | 5 votes |
@Override public void onHold(PlayerItemHeldEvent event) { Resident resident = CivGlobal.getResident(event.getPlayer()); if (!resident.hasTechForItem(event.getPlayer().getInventory().getItem(event.getNewSlot()))) { CivMessage.send(resident, CivColor.Rose+"Warning - "+CivColor.LightGray+ "You do not have the required technology to use this item. It's attack output will be reduced in half."); } }
Example #7
Source File: RangedAttack.java From civcraft with GNU General Public License v2.0 | 5 votes |
@Override public void onHold(PlayerItemHeldEvent event) { Resident resident = CivGlobal.getResident(event.getPlayer()); if (!resident.hasTechForItem(event.getPlayer().getInventory().getItem(event.getNewSlot()))) { CivMessage.send(resident, CivColor.Rose+"Warning - "+CivColor.LightGray+ "You do not have the required technology to use this item. It's attack output will be reduced in half."); } }
Example #8
Source File: BonusGoodieManager.java From civcraft with GNU General Public License v2.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR) public void OnItemHeldChange(PlayerItemHeldEvent event) { Inventory inv = event.getPlayer().getInventory(); ItemStack stack = inv.getItem(event.getNewSlot()); BonusGoodie goodie = CivGlobal.getBonusGoodie(stack); if (goodie == null) { return; } CivMessage.send(event.getPlayer(), CivColor.Purple+"Bonus Goodie: "+CivColor.Yellow+goodie.getDisplayName()); }
Example #9
Source File: DisplayProtectionListener.java From QuickShop-Reremake with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void item(PlayerItemHeldEvent e) { if (!useEnhanceProtection) { return; } if (DisplayItem.getNowUsing() != DisplayType.REALITEM) { return; } final ItemStack stack = e.getPlayer().getInventory().getItemInMainHand(); final ItemStack stackOffHand = e.getPlayer().getInventory().getItemInOffHand(); if (DisplayItem.checkIsGuardItemStack(stack)) { e.getPlayer().getInventory().setItemInMainHand(new ItemStack(Material.AIR, 0)); // You shouldn't be able to pick up that... sendAlert( "[DisplayGuard] Player " + e.getPlayer().getName() + " helded the displayItem, QuickShop already cancelled and removed it."); e.setCancelled(true); Util.inventoryCheck(e.getPlayer().getInventory()); } if (DisplayItem.checkIsGuardItemStack(stackOffHand)) { e.getPlayer().getInventory().setItemInOffHand(new ItemStack(Material.AIR, 0)); // You shouldn't be able to pick up that... sendAlert( "[DisplayGuard] Player " + e.getPlayer().getName() + " helded the displayItem, QuickShop already cancelled and removed it."); e.setCancelled(true); Util.inventoryCheck(e.getPlayer().getInventory()); } }
Example #10
Source File: MenuConvIO.java From BetonQuest with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void playerItemHeldEvent(PlayerItemHeldEvent event) { if (event.getPlayer() != player) { return; } if (!controls.containsKey(CONTROL.SCROLL)) { return; } event.setCancelled(true); if (debounce) { return; } // Cheat and assume the closest distance between previous and new slots is the direction scrolled int slotDistance = event.getPreviousSlot() - event.getNewSlot(); if (slotDistance > 5 || (slotDistance < 0 && slotDistance >= -5)) { // Scrolled down if (selectedOption < options.size() - 1) { oldSelectedOption = selectedOption; selectedOption++; updateDisplay(); debounce = true; } } else if (slotDistance != 0) { // Scrolled up if (selectedOption > 0) { oldSelectedOption = selectedOption; selectedOption--; updateDisplay(); debounce = true; } } }
Example #11
Source File: BrushListener.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerItemHoldEvent(final PlayerItemHeldEvent event) { final Player bukkitPlayer = event.getPlayer(); if (bukkitPlayer.isSneaking()) { return; } FawePlayer<Object> fp = FawePlayer.wrap(bukkitPlayer); com.sk89q.worldedit.entity.Player player = fp.getPlayer(); LocalSession session = fp.getSession(); Tool tool = session.getTool(player); if (tool instanceof ScrollTool) { final int slot = event.getNewSlot(); final int oldSlot = event.getPreviousSlot(); final int ri; if ((((slot - oldSlot) <= 4) && ((slot - oldSlot) > 0)) || (((slot - oldSlot) < -4))) { ri = 1; } else { ri = -1; } ScrollTool scrollable = (ScrollTool) tool; if (scrollable.increment(player, ri)) { if (Settings.IMP.EXPERIMENTAL.PERSISTENT_BRUSHES) { bukkitPlayer.getInventory().setHeldItemSlot(oldSlot); } else { final PlayerInventory inv = bukkitPlayer.getInventory(); final ItemStack item = inv.getItem(slot); final ItemStack newItem = inv.getItem(oldSlot); inv.setItem(slot, newItem); inv.setItem(oldSlot, item); bukkitPlayer.updateInventory(); } } } }
Example #12
Source File: PlayerListener.java From WorldEditSelectionVisualizer with MIT License | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerHeldItem(PlayerItemHeldEvent e) { Player player = e.getPlayer(); ItemStack oldItem = player.getInventory().getItem(e.getPreviousSlot()); ItemStack newItem = player.getInventory().getItem(e.getNewSlot()); if ((oldItem == null && newItem == null) || (oldItem != null && newItem != null && oldItem.getType() == newItem.getType())) { return; } Bukkit.getScheduler().runTask(plugin, () -> plugin.updateHoldingSelectionItem(plugin.getPlayerInfos(player))); }
Example #13
Source File: DurabilityBar.java From AdditionsAPI with MIT License | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onItemSwitch(PlayerItemHeldEvent event) { if (event.isCancelled()) return; Player player = event.getPlayer(); Bukkit.getScheduler().scheduleSyncDelayedTask(AdditionsAPI.getInstance(), () -> { sendDurabilityBossBar(player, player.getInventory().getItemInMainHand(), EquipmentSlot.HAND); sendDurabilityBossBar(player, player.getInventory().getItemInOffHand(), EquipmentSlot.OFF_HAND); }); }
Example #14
Source File: ActionListener.java From ActionHealth with MIT License | 5 votes |
@EventHandler(ignoreCancelled = true) public void onSwap(PlayerItemHeldEvent event) { if (!main.configStore.actionStore.enabled) return; ActionStore.ActionType actionType = ActionStore.ActionType.SWAP; Player player = event.getPlayer(); ItemStack itemStack = player.getInventory().getItem(event.getNewSlot()); actionHelper.executeTriggers(actionType, player, itemStack); }
Example #15
Source File: MarkerPlacementManager.java From civcraft with GNU General Public License v2.0 | 4 votes |
@EventHandler(priority = EventPriority.MONITOR) public void OnItemHeldChange(PlayerItemHeldEvent event) { if (isPlayerInPlacementMode(event.getPlayer())) { removeFromPlacementMode(event.getPlayer(), true); } }
Example #16
Source File: ThreadSafetyListener.java From LagMonitor with MIT License | 4 votes |
@EventHandler public void onItemHeldChange(PlayerItemHeldEvent itemHeldEvent) { checkSafety(itemHeldEvent); }
Example #17
Source File: ThreadSafetyListener.java From LagMonitor with MIT License | 4 votes |
@EventHandler public void onItemHeldChange(PlayerItemHeldEvent itemHeldEvent) { checkSafety(itemHeldEvent); }
Example #18
Source File: LoreCraftableMaterial.java From civcraft with GNU General Public License v2.0 | 4 votes |
@Override public void onHold(PlayerItemHeldEvent event) { for (ItemComponent comp : this.components.values()) { comp.onHold(event); } }
Example #19
Source File: UnitItemMaterial.java From civcraft with GNU General Public License v2.0 | 4 votes |
@Override public void onHold(PlayerItemHeldEvent event) { }
Example #20
Source File: UnitMaterial.java From civcraft with GNU General Public License v2.0 | 4 votes |
@Override public void onHold(PlayerItemHeldEvent event) { }
Example #21
Source File: InventoryEvent.java From MCAuthenticator with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onPlayerMoveItemHand(PlayerItemHeldEvent e){ if(!auth(e)) e.setCancelled(true); }
Example #22
Source File: ExprTool.java From Skript with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("unchecked") @Override public boolean setTime(final int time) { return super.setTime(time, getExpr(), PlayerItemHeldEvent.class, PlayerBucketFillEvent.class, PlayerBucketEmptyEvent.class); }
Example #23
Source File: PlayerListener.java From AuthMeReloaded with GNU General Public License v3.0 | 4 votes |
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onPlayerHeldItem(PlayerItemHeldEvent event) { if (listenerService.shouldCancelEvent(event)) { event.setCancelled(true); } }
Example #24
Source File: LoreMaterial.java From civcraft with GNU General Public License v2.0 | votes |
public abstract void onHold(PlayerItemHeldEvent event);
Example #25
Source File: ItemComponent.java From civcraft with GNU General Public License v2.0 | votes |
public void onHold(PlayerItemHeldEvent event) { }