Java Code Examples for org.bukkit.inventory.EquipmentSlot#HAND
The following examples show how to use
org.bukkit.inventory.EquipmentSlot#HAND .
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: QuestItemHandler.java From BetonQuest with GNU General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) public void onItemFrameClick(final PlayerInteractEntityEvent event) { if (event.getPlayer().getGameMode() == GameMode.CREATIVE) { return; } // this prevents the journal from being placed inside of item frame if (event.getRightClicked() instanceof ItemFrame) { ItemStack item = null; item = (event.getHand() == EquipmentSlot.HAND) ? event.getPlayer().getInventory().getItemInMainHand() : event.getPlayer().getInventory().getItemInOffHand(); final String playerID = PlayerConverter.getID(event.getPlayer()); if (Journal.isJournal(playerID, item) || Utils.isQuestItem(item)) { event.setCancelled(true); } } }
Example 2
Source File: CraftEventFactory.java From Kettle with GNU General Public License v3.0 | 6 votes |
public static BlockPlaceEvent callBlockPlaceEvent(World world, EntityPlayer who, EnumHand hand, BlockState replacedBlockState, int clickedX, int clickedY, int clickedZ) { CraftWorld craftWorld = world.getWorld(); CraftServer craftServer = world.getServer(); Player player = (Player) who.getBukkitEntity(); Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ); Block placedBlock = replacedBlockState.getBlock(); boolean canBuild = canBuild(craftWorld, player, placedBlock.getX(), placedBlock.getZ()); org.bukkit.inventory.ItemStack item; EquipmentSlot equipmentSlot; if (hand == EnumHand.MAIN_HAND) { item = player.getInventory().getItemInMainHand(); equipmentSlot = EquipmentSlot.HAND; } else { item = player.getInventory().getItemInOffHand(); equipmentSlot = EquipmentSlot.OFF_HAND; } BlockPlaceEvent event = new BlockPlaceEvent(placedBlock, replacedBlockState, blockClicked, item, player, canBuild, equipmentSlot); craftServer.getPluginManager().callEvent(event); return event; }
Example 3
Source File: ItemListener.java From HubBasics with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) public void onLeftClick(PlayerInteractEvent event) { if (!(event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK)) { return; } ItemStack itemStack; if (event.getHand() == EquipmentSlot.HAND) { itemStack = event.getPlayer().getInventory().getItemInMainHand(); } else if (event.getHand() == EquipmentSlot.OFF_HAND) { itemStack = event.getPlayer().getInventory().getItemInOffHand(); } else { return; } if (itemStack.getType() != Material.AIR) { NBTItem nbtItem = new NBTItem(itemStack); if (!nbtItem.hasKey("HubBasics")) return; event.setCancelled(true); CustomItem item = HubBasics.getInstance().getItemManager().get(nbtItem.getString("HubBasics")); if (item == null) { itemStack.setType(Material.AIR); // Destroy old item return; } if (!item.getRunOnLeftClick()) return; if (event.getHand() == EquipmentSlot.OFF_HAND) { if (item.getRunOnOffhand()) { item.onCommand(event.getPlayer()); } } else { item.onCommand(event.getPlayer()); } } }
Example 4
Source File: PlantsListener.java From ExoticGarden with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onInteract(PlayerInteractEvent e) { if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return; if (e.getHand() != EquipmentSlot.HAND) return; if (e.getPlayer().isSneaking()) return; if (SlimefunPlugin.getProtectionManager().hasPermission(e.getPlayer(), e.getClickedBlock().getLocation(), ProtectableAction.BREAK_BLOCK)) { ItemStack item = ExoticGarden.harvestPlant(e.getClickedBlock()); if (item != null) { e.getClickedBlock().getWorld().playEffect(e.getClickedBlock().getLocation(), Effect.STEP_SOUND, Material.OAK_LEAVES); e.getClickedBlock().getWorld().dropItemNaturally(e.getClickedBlock().getLocation(), item); } } }
Example 5
Source File: CraftEventFactory.java From Kettle with GNU General Public License v3.0 | 5 votes |
public static PlayerInteractEvent callPlayerInteractEvent(EntityPlayer who, Action action, BlockPos position, EnumFacing direction, ItemStack itemstack, boolean cancelledBlock, EnumHand hand) { Player player = (who == null) ? null : (Player) who.getBukkitEntity(); CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack); CraftWorld craftWorld = (CraftWorld) player.getWorld(); CraftServer craftServer = (CraftServer) player.getServer(); Block blockClicked = null; if (position != null) { blockClicked = craftWorld.getBlockAt(position.getX(), position.getY(), position.getZ()); } else { switch (action) { case LEFT_CLICK_BLOCK: action = Action.LEFT_CLICK_AIR; break; case RIGHT_CLICK_BLOCK: action = Action.RIGHT_CLICK_AIR; break; } } BlockFace blockFace = CraftBlock.notchToBlockFace(direction); if (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0) { itemInHand = null; } PlayerInteractEvent event = new PlayerInteractEvent(player, action, itemInHand, blockClicked, blockFace, (hand == null) ? null : ((hand == EnumHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND)); if (cancelledBlock) { event.setUseInteractedBlock(Event.Result.DENY); } craftServer.getPluginManager().callEvent(event); return event; }
Example 6
Source File: IronGolemListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onIronGolemHeal(PlayerInteractEntityEvent e) { if (e.getRightClicked().getType() == EntityType.IRON_GOLEM) { PlayerInventory inv = e.getPlayer().getInventory(); ItemStack item = null; if (e.getHand() == EquipmentSlot.HAND) { item = inv.getItemInMainHand(); } else if (e.getHand() == EquipmentSlot.OFF_HAND) { item = inv.getItemInOffHand(); } if (item != null && item.getType() == Material.IRON_INGOT) { SlimefunItem sfItem = SlimefunItem.getByItem(item); if (sfItem != null && !(sfItem instanceof VanillaItem)) { e.setCancelled(true); SlimefunPlugin.getLocalization().sendMessage(e.getPlayer(), "messages.no-iron-golem-heal"); // This is just there to update the Inventory... // Somehow cancelling it isn't enough. if (e.getHand() == EquipmentSlot.HAND) { inv.setItemInMainHand(item); } else if (e.getHand() == EquipmentSlot.OFF_HAND) { inv.setItemInOffHand(item); } } } } }
Example 7
Source File: TestCargoNodeListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@ParameterizedTest @SlimefunItemsSource(items = { "CARGO_INPUT_NODE", "CARGO_OUTPUT_NODE", "CARGO_OUTPUT_NODE_2" }) public void testSidePlacement(ItemStack item) { Player player = server.addPlayer(); Location l = new Location(player.getWorld(), 190, 50, 400); Block b = l.getBlock(); Block against = b.getRelative(BlockFace.NORTH); BlockPlaceEvent event = new BlockPlaceEvent(b, new BlockStateMock(), against, item, player, true, EquipmentSlot.HAND); listener.onCargoNodePlace(event); Assertions.assertFalse(event.isCancelled()); }
Example 8
Source File: DebugFishListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onDebug(PlayerInteractEvent e) { if (e.getAction() == Action.PHYSICAL || e.getHand() != EquipmentSlot.HAND) { return; } Player p = e.getPlayer(); if (p.isOp() && SlimefunUtils.isItemSimilar(e.getItem(), SlimefunItems.DEBUG_FISH, true)) { e.setCancelled(true); if (e.getAction() == Action.LEFT_CLICK_BLOCK) { if (p.isSneaking()) { if (BlockStorage.hasBlockInfo(e.getClickedBlock())) { BlockStorage.clearBlockInfo(e.getClickedBlock()); } } else { e.setCancelled(false); } } else if (e.getAction() == Action.RIGHT_CLICK_BLOCK) { if (p.isSneaking()) { Block b = e.getClickedBlock().getRelative(e.getBlockFace()); b.setType(Material.PLAYER_HEAD); SkullBlock.setFromHash(b, HeadTexture.MISSING_TEXTURE.getTexture()); } else if (BlockStorage.hasBlockInfo(e.getClickedBlock())) { sendInfo(p, e.getClickedBlock()); } } } }
Example 9
Source File: NMSHandler.java From Shopkeepers with GNU General Public License v3.0 | 4 votes |
@Override public boolean isMainHandInteraction(PlayerInteractEvent event) { return event.getHand() == EquipmentSlot.HAND; }
Example 10
Source File: NMSHandler.java From Shopkeepers with GNU General Public License v3.0 | 4 votes |
@Override public boolean isMainHandInteraction(PlayerInteractEntityEvent event) { return event.getHand() == EquipmentSlot.HAND; }
Example 11
Source File: InteractListener.java From SaneEconomy with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onPlayerInteract(PlayerInteractEvent evt) { if (!evt.getPlayer().hasPermission("saneeconomy.signshop.use")) { return; } if (evt.getHand() != EquipmentSlot.HAND) { return; } if ((evt.getPlayer().getInventory().getItemInMainHand() != null) && (evt.getPlayer().getInventory().getItemInMainHand().getType() == Material.DIAMOND_AXE)) { return; } if ((evt.getAction() != Action.RIGHT_CLICK_BLOCK) && (evt.getAction() != Action.LEFT_CLICK_BLOCK)) { return; } Optional<SignShop> shopOptional = this.plugin.getSignShopManager().getSignShop(evt.getClickedBlock().getLocation()); if (!shopOptional.isPresent()) { return; } SignShop shop = shopOptional.get(); // Buy if (evt.getAction() == Action.RIGHT_CLICK_BLOCK) { evt.setCancelled(true); if (!shop.canBuy()) { this.plugin.getMessenger().sendMessage(evt.getPlayer(), "This shop does not permit buying."); return; } this.doBuy(shop, evt.getPlayer()); } // Sell if (evt.getAction() == Action.LEFT_CLICK_BLOCK) { evt.setCancelled(true); if (!shop.canSell()) { this.plugin.getMessenger().sendMessage(evt.getPlayer(), "This shop does not permit selling."); return; } this.doSell(shop, evt.getPlayer()); } }
Example 12
Source File: NMSHandler.java From Shopkeepers with GNU General Public License v3.0 | 4 votes |
@Override public boolean isMainHandInteraction(PlayerInteractEvent event) { return event.getHand() == EquipmentSlot.HAND; }
Example 13
Source File: NMSHandler.java From Shopkeepers with GNU General Public License v3.0 | 4 votes |
@Override public boolean isMainHandInteraction(PlayerInteractEvent event) { return event.getHand() == EquipmentSlot.HAND; }
Example 14
Source File: EasyHarvestListener.java From MineTinker with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onHarvestTry(PlayerInteractEvent event) { if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { return; } Player player = event.getPlayer(); if (Lists.WORLDS_EASYHARVEST.contains(player.getWorld().getName())) { return; } if (!(player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE || player.getGameMode() == GameMode.CREATIVE)) { return; } ItemStack tool = player.getInventory().getItemInMainHand(); if (!ToolType.HOE.contains(tool.getType())) { return; } if (!modManager.isToolViable(tool)) { return; } if (event.getClickedBlock() == null) { return; } if (event.getItem() == null) { return; } Block block = event.getClickedBlock(); if (!(block.getBlockData() instanceof Ageable)) { return; } //triggers a pseudoevent to find out if the Player can build BlockPlaceEvent placeEvent = new BlockPlaceEvent(block, block.getState(), block, event.getItem(), player, true, EquipmentSlot.HAND); Bukkit.getPluginManager().callEvent(placeEvent); //check the pseudoevent if (!placeEvent.canBuild() || placeEvent.isCancelled()) { return; } harvestCrops(player, tool, block); }
Example 15
Source File: Slot.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
@Override public EquipmentSlot toEquipmentSlot() { return EquipmentSlot.HAND; }
Example 16
Source File: PlayerInteractEvent.java From Kettle with GNU General Public License v3.0 | 4 votes |
public PlayerInteractEvent(final Player who, final Action action, final ItemStack item, final Block clickedBlock, final BlockFace clickedFace) { this(who, action, item, clickedBlock, clickedFace, EquipmentSlot.HAND); }
Example 17
Source File: PlayerInteractAtEntityEvent.java From Kettle with GNU General Public License v3.0 | 4 votes |
public PlayerInteractAtEntityEvent(Player who, Entity clickedEntity, Vector position) { this(who, clickedEntity, position, EquipmentSlot.HAND); }
Example 18
Source File: BlockPlaceEvent.java From Kettle with GNU General Public License v3.0 | 4 votes |
@Deprecated public BlockPlaceEvent(final Block placedBlock, final BlockState replacedBlockState, final Block placedAgainst, final ItemStack itemInHand, final Player thePlayer, final boolean canBuild) { this(placedBlock, replacedBlockState, placedAgainst, itemInHand, thePlayer, canBuild, EquipmentSlot.HAND); }
Example 19
Source File: NMSHandler.java From Shopkeepers with GNU General Public License v3.0 | 4 votes |
@Override public boolean isMainHandInteraction(PlayerInteractEntityEvent event) { return event.getHand() == EquipmentSlot.HAND; }
Example 20
Source File: BuildersWandListener.java From MineTinker with GNU General Public License v3.0 | 4 votes |
private boolean placeBlock(Block b, Player player, Location l, Location loc, ItemStack item, Vector vector) { if (!b.getWorld().getBlockAt(l).getType().equals(b.getType())) { return false; } Material type = b.getWorld().getBlockAt(loc).getType(); if (!(type == Material.AIR || type == Material.CAVE_AIR || type == Material.WATER || type == Material.BUBBLE_COLUMN || type == Material.LAVA || type == Material.GRASS)) { return false; } //triggers a pseudoevent to find out if the Player can build Block block = b.getWorld().getBlockAt(loc); BlockPlaceEvent placeEvent = new BlockPlaceEvent(block, block.getState(), b, item, player, true, EquipmentSlot.HAND); Bukkit.getPluginManager().callEvent(placeEvent); //check the pseudoevent if (!placeEvent.canBuild() || placeEvent.isCancelled()) { return false; } Block nb = b.getWorld().getBlockAt(loc); Block behind = nb.getWorld().getBlockAt(loc.clone().subtract(vector)); if (behind.getBlockData() instanceof Slab) { if (((Slab) behind.getBlockData()).getType().equals(Slab.Type.DOUBLE)) { if (item.getAmount() - 2 < 0) { return false; } } } nb.setType(item.getType()); BlockData bd = nb.getBlockData(); if (bd instanceof Directional) { ((Directional) bd).setFacing(((Directional) behind.getBlockData()).getFacing()); } if (bd instanceof Slab) { ((Slab) bd).setType(((Slab) behind.getBlockData()).getType()); } nb.setBlockData(bd); return true; }