Java Code Examples for org.bukkit.entity.Player#setItemInHand()
The following examples show how to use
org.bukkit.entity.Player#setItemInHand() .
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: HealingShovel.java From ce with GNU Lesser General Public License v3.0 | 6 votes |
@Override public boolean effect(Event event, Player player) { EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event; if (e.getDamager() == player && e.getEntity() instanceof Player) { Player damaged = (Player) e.getEntity(); e.setDamage(0); EffectManager.playSound(damaged.getLocation(), "ENTITY_GENERIC_DRINK", 0.5f, 1f); EffectManager.playSound(damaged.getLocation(), "BLOCK_ANVIL_LAND", 0.5f, 2f); short currentDur = player.getItemInHand().getDurability(); if (((Damageable) damaged).getHealth() + Heal <= ((Damageable) damaged).getMaxHealth()) { damaged.setHealth(((Damageable) damaged).getHealth() + Heal); } else { damaged.setHealth(((Damageable) damaged).getMaxHealth()); } if (currentDur + Heal < player.getItemInHand().getType().getMaxDurability()) { player.getItemInHand().setDurability((short) (currentDur + Heal)); } else { player.setItemInHand(new ItemStack(Material.AIR, 1)); EffectManager.playSound(player.getLocation(), "ENTITY_ITEM_BREAK", 0.1f, 0.3f); } return true; } return false; }
Example 2
Source File: DebugCommand.java From civcraft with GNU General Public License v2.0 | 6 votes |
public void setcivnbt_cmd() throws CivException { Player player = getPlayer(); String key = getNamedString(1, "key"); String value = getNamedString(2, "value"); ItemStack inHand = player.getItemInHand(); if (inHand == null) { throw new CivException("You must have an item in hand."); } AttributeUtil attrs = new AttributeUtil(inHand); attrs.setCivCraftProperty(key, value); player.setItemInHand(attrs.getStack()); CivMessage.sendSuccess(player, "Set property."); }
Example 3
Source File: MarkerPlacementManager.java From civcraft with GNU General Public License v2.0 | 6 votes |
public static void addToPlacementMode(Player player, Structure structure, String markerName) throws CivException { if (player.getItemInHand() != null && ItemManager.getId(player.getItemInHand()) != CivData.AIR) { throw new CivException("You must not be holding anything to enter placement mode."); } playersInPlacementMode.put(player.getName(), structure); markers.put(player.getName(), new ArrayList<Location>()); ItemStack stack = ItemManager.createItemStack(CivData.REDSTONE_TORCH_OFF, 2); ItemMeta meta = stack.getItemMeta(); if (markerName != null) { meta.setDisplayName(markerName); } else { meta.setDisplayName("Marker"); } stack.setItemMeta(meta); player.setItemInHand(stack); CivMessage.send(player, "You're now in placement mode for a "+structure.getDisplayName()); }
Example 4
Source File: DebugCommand.java From civcraft with GNU General Public License v2.0 | 5 votes |
public void setspecial_cmd() throws CivException { Player player = getPlayer(); ItemStack inHand = player.getItemInHand(); if (inHand == null) { throw new CivException("You need an item in your hand."); } // AttributeUtil attrs = new AttributeUtil(inHand); // attrs.setCivCraftProperty("customId", "testMyCustomId"); ItemStack stack = LoreMaterial.addEnhancement(inHand, new LoreEnhancementSoulBound()); player.setItemInHand(stack); CivMessage.send(player, "Set it."); }
Example 5
Source File: DebugCommand.java From civcraft with GNU General Public License v2.0 | 5 votes |
public void colorme_cmd() throws CivException { Player player = getPlayer(); String hex = getNamedString(1, "color code"); long value = Long.decode(hex); ItemStack inHand = player.getItemInHand(); if (inHand == null || ItemManager.getId(inHand) == CivData.AIR) { throw new CivException("please have an item in your hand."); } AttributeUtil attrs = new AttributeUtil(inHand); attrs.setColor(value); player.setItemInHand(attrs.getStack()); CivMessage.sendSuccess(player, "Set color."); }
Example 6
Source File: MarkerPlacementManager.java From civcraft with GNU General Public License v2.0 | 5 votes |
public static void setMarker(Player player, Location location) throws CivException { ArrayList<Location> locs = markers.get(player.getName()); Structure struct = playersInPlacementMode.get(player.getName()); int amount = player.getItemInHand().getAmount(); if (amount == 1) { player.setItemInHand(null); } else { player.getItemInHand().setAmount((amount -1)); } locs.add(location); struct.onMarkerPlacement(player, location, locs); }
Example 7
Source File: MarkerPlacementManager.java From civcraft with GNU General Public License v2.0 | 5 votes |
public static void removeFromPlacementMode(Player player, boolean canceled) { if (canceled) { Structure struct = playersInPlacementMode.get(player.getName()); struct.getTown().removeStructure(struct); CivGlobal.removeStructure(struct); } playersInPlacementMode.remove(player.getName()); markers.remove(player.getName()); player.setItemInHand(ItemManager.createItemStack(CivData.AIR, 1)); CivMessage.send(player, "You're no longer in placement mode."); }
Example 8
Source File: EffRemoveCape.java From skRayFall with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") @Override protected void execute(Event evt) { if (player != null) { Player targetPlayer = player.getSingle(evt); ItemStack item = targetPlayer.getItemInHand(); targetPlayer.setItemInHand(null); Capes.capeInHand(targetPlayer); targetPlayer.setItemInHand(item); } }
Example 9
Source File: PlayerInventory.java From CS-CoreLib with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") public static void damageItemInHand(Player p) { if (p.getGameMode() != GameMode.CREATIVE) { ItemStack item = p.getItemInHand().clone(); item.setDurability((short) (item.getDurability() + 1)); p.setItemInHand(item.getDurability() < item.getType().getMaxDurability() ? item: null); } }
Example 10
Source File: PlayerInventory.java From CS-CoreLib with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") public static void consumeItemInHand(Player p) { if (p.getGameMode() != GameMode.CREATIVE) { ItemStack item = p.getItemInHand().clone(); item.setAmount(item.getAmount() - 1); p.setItemInHand(item.getAmount() > 0 ? item: null); } }
Example 11
Source File: Methods.java From Crazy-Auctions with MIT License | 5 votes |
@SuppressWarnings("deprecation") public static void setItemInHand(Player player, ItemStack item) { if (getVersion() >= 191) { player.getInventory().setItemInMainHand(item); } else { player.setItemInHand(item); } }
Example 12
Source File: BlockListener.java From Carbon with GNU Lesser General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") private void setDoubleSlab(Player player, Block block) { block.setType(Carbon.injector().redSandstoneDoubleSlabMat); block.setData((byte) 0); block.getWorld().playSound(block.getLocation(), Sound.DIG_STONE, 1, 1); if (player.getGameMode() != GameMode.CREATIVE) { if (player.getItemInHand().getAmount() > 1) player.getItemInHand().setAmount(player.getItemInHand().getAmount() - 1); else player.setItemInHand(null); } }
Example 13
Source File: IronsightsHandler.java From QualityArmory with GNU General Public License v3.0 | 5 votes |
public static void aim(Player player){ if(!QualityArmory.isIronSights(player.getItemInHand())){ //offHandStorage.put(player, player.getInventory().getItemInOffHand()); if(player.getInventory().getItemInOffHand()!=null){ player.getInventory().addItem(player.getInventory().getItemInOffHand()); } if (player.getItemInHand() != null && QualityArmory.isGun(player.getItemInHand())) { Gun gun = QualityArmory.getGun(player.getItemInHand()); QAMain.toggleNightvision(player, gun, true); } player.getInventory().setItemInOffHand(player.getItemInHand()); player.setItemInHand(QualityArmory.getIronSightsItemStack()); } }
Example 14
Source File: ArmorObject.java From QualityArmory with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") @Override public boolean onRMB(Player e, ItemStack usedItem) { QAMain.DEBUG("A Player is about to put on armor!"); ItemStack helm = e.getInventory().getHelmet(); e.setItemInHand(helm); e.getInventory().setHelmet(usedItem); try { e.getPlayer().playSound(e.getLocation(), Sound.ITEM_ARMOR_EQUIP_IRON, 2, 1); } catch (Error | Exception e3) { } return true; }
Example 15
Source File: Gun.java From QualityArmory with GNU General Public License v3.0 | 5 votes |
public void damageDurability(Player player){ if (QAMain.enableDurability) { if (QualityArmory.isIronSights(player.getItemInHand())) { Update19OffhandChecker.setOffhand(player, durabilityDamage(this, Update19OffhandChecker.getItemStackOFfhand(player))); } else { player.setItemInHand(durabilityDamage(this, player.getItemInHand())); } } }
Example 16
Source File: Grenade.java From QualityArmory with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") @Override public boolean onRMB(Player thrower, ItemStack usedItem) { if (throwItems.containsKey(thrower)) { ThrowableHolder holder = throwItems.get(thrower); ItemStack grenadeStack = thrower.getItemInHand(); ItemStack temp = grenadeStack.clone(); temp.setAmount(1); if (thrower.getGameMode() != GameMode.CREATIVE) { if (grenadeStack.getAmount() > 1) { grenadeStack.setAmount(grenadeStack.getAmount() - 1); } else { grenadeStack = null; } thrower.setItemInHand(grenadeStack); } Item grenade = holder.getHolder().getWorld().dropItem(holder.getHolder().getLocation().add(0, 1.5, 0), temp); grenade.setPickupDelay(Integer.MAX_VALUE); grenade.setVelocity(thrower.getLocation().getDirection().normalize().multiply(1.2)); holder.setHolder(grenade); thrower.getWorld().playSound(thrower.getLocation(), Sound.ENTITY_ARROW_SHOOT, 1, 1.5f); throwItems.put(grenade, holder); throwItems.remove(thrower); QAMain.DEBUG("Throw grenade"); } else { thrower.sendMessage(QAMain.prefix + QAMain.S_GRENADE_PULLPIN); } return true; }
Example 17
Source File: Library.java From civcraft with GNU General Public License v2.0 | 4 votes |
public void add_enchantment_to_tool(Player player, StructureSign sign, PlayerInteractEvent event) throws CivException { int special_id = Integer.valueOf(sign.getAction()); if (!event.hasItem()) { CivMessage.send(player, CivColor.Rose+"You must have the item you wish to enchant in hand."); return; } ItemStack item = event.getItem(); if (special_id >= this.enchantments.size()) { throw new CivException("Library enchantment not ready."); } LibraryEnchantment ench = this.enchantments.get(special_id); this.validateEnchantment(item, ench); int payToTown = (int) Math.round(ench.price*getNonResidentFee()); Resident resident; resident = CivGlobal.getResident(player.getName()); Town t = resident.getTown(); if (t == this.getTown()) { // Pay no taxes! You're a member. payToTown = 0; } // Determine if resident can pay. if (!resident.getTreasury().hasEnough(ench.price+payToTown)) { CivMessage.send(player, CivColor.Rose+"You do not have enough money, you need "+ench.price+payToTown+ " coins."); return; } // Take money, give to server, TEH SERVER HUNGERS ohmnom nom resident.getTreasury().withdraw(ench.price); // Send money to town for non-resident fee if (payToTown != 0) { getTown().depositDirect(payToTown); CivMessage.send(player, CivColor.Yellow + "Paid "+ payToTown+" coins in non-resident taxes."); } // Successful payment, process enchantment. ItemStack newStack = this.addEnchantment(item, ench); player.setItemInHand(newStack); CivMessage.send(player, CivColor.LightGreen+"Enchanted with "+ench.displayName+"!"); }
Example 18
Source File: PlayerInteractListener.java From IridiumSkyblock with GNU General Public License v2.0 | 4 votes |
@EventHandler public void onPlayerInteract(PlayerInteractEvent event) { try { final Player player = event.getPlayer(); final Location playerLocation = player.getLocation(); final IslandManager islandManager = IridiumSkyblock.getIslandManager(); if (!islandManager.isIslandWorld(playerLocation)) return; final User user = User.getUser(player); final Block block = event.getClickedBlock(); if (event.getAction().toString().startsWith("RIGHT_CLICK")) { if (player.getItemInHand() != null) { int crystals = Utils.getCrystals(player.getItemInHand()) * player.getItemInHand().getAmount(); if (crystals != 0) { player.setItemInHand(null); user.getIsland().setCrystals(user.getIsland().getCrystals() + crystals); player.sendMessage(Utils.color(IridiumSkyblock.getMessages().depositedCrystals.replace("%amount%", crystals + "").replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); } } } if (block != null) { final Location location = block.getLocation(); final Island island = islandManager.getIslandViaLocation(location); if (island != null) { if (!island.getPermissions(user).interact) { event.setCancelled(true); return; } final ItemStack itemInHand = player.getItemInHand(); if (itemInHand.getType().equals(Material.BUCKET) && island.failedGenerators.remove(location)) { if (itemInHand.getAmount() == 1) itemInHand.setType(Material.LAVA_BUCKET); else { player.getInventory().addItem(new ItemStack(Material.LAVA_BUCKET)); player.getItemInHand().setAmount(itemInHand.getAmount() - 1); } block.setType(Material.AIR); } } else if (!user.bypassing) { event.setCancelled(true); return; } } final ItemStack item = event.getItem(); if (IridiumSkyblock.getConfiguration().allowWaterInNether && event.getAction().equals(Action.RIGHT_CLICK_BLOCK) && item != null && block != null) { final World world = block.getWorld(); if (!world.getEnvironment().equals(World.Environment.NETHER)) return; if (!item.getType().equals(Material.WATER_BUCKET)) return; event.setCancelled(true); final BlockFace face = event.getBlockFace(); block.getRelative(face).setType(Material.WATER); final Block relative = block.getRelative(face); final BlockPlaceEvent blockPlaceEvent = new BlockPlaceEvent(relative, relative.getState(), block, item, player, false); if (blockPlaceEvent.isCancelled()) { block.getRelative(face).setType(Material.AIR); } else if (player.getGameMode().equals(GameMode.SURVIVAL)) { if (item.getAmount() == 1) { item.setType(Material.BUCKET); } else { item.setAmount(item.getAmount() - 1); player.getInventory().addItem(new ItemStack(Material.BUCKET)); } } } } catch (Exception e) { IridiumSkyblock.getInstance().sendErrorMessage(e); } }
Example 19
Source File: VeinMinerListener.java From UhcCore with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onBlockBreak(BlockBreakEvent e){ Player player = e.getPlayer(); if (!player.isSneaking()){ return; } Block block = e.getBlock(); ItemStack tool = player.getItemInHand(); if (block.getType() == UniversalMaterial.GLOWING_REDSTONE_ORE.getType()){ block.setType(Material.REDSTONE_ORE); } if (!UniversalMaterial.isCorrectTool(block.getType(), player.getItemInHand().getType())){ return; } // find all surrounding blocks Vein vein = new Vein(block); vein.process(); player.getWorld().dropItem(player.getLocation().getBlock().getLocation().add(.5,.5,.5), vein.getDrops(getVeinMultiplier(vein.getDropType()))); if (vein.getTotalXp() != 0){ UhcItems.spawnExtraXp(player.getLocation(), vein.getTotalXp()); } // Process blood diamonds. if (isActivated(Scenario.BLOODDIAMONDS) && vein.getDropType() == Material.DIAMOND){ player.getWorld().playSound(player.getLocation(), UniversalSound.PLAYER_HURT.getSound(), 1, 1); if (player.getHealth() < vein.getOres()){ player.setHealth(0); }else { player.setHealth(player.getHealth() - vein.getOres()); } } int newDurability = tool.getDurability()-vein.getOres(); if (newDurability<1) newDurability = 1; tool.setDurability((short) newDurability); player.setItemInHand(tool); }
Example 20
Source File: BlockPlace.java From FunnyGuilds with Apache License 2.0 | 4 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onPlace(BlockPlaceEvent event) { Player player = event.getPlayer(); Block block = event.getBlock(); Material type = block.getType(); Location blockLocation = block.getLocation(); if (!ProtectionSystem.build(player, blockLocation, true)) { return; } // always cancel to prevent breaking other protection // plugins or plugins using BlockPlaceEvent (eg. special ability blocks) event.setCancelled(true); // disabled bugged-blocks or blacklisted item if (!this.config.buggedBlocks || this.config.buggedBlocksExclude.contains(type)) { return; } // remove one item from the player ItemStack itemInHand = event.getItemInHand(); if ((itemInHand.getAmount() - 1) == 0) { // wondering why? because bukkit and you probably don't want dupe glitches if (Reflections.USE_PRE_9_METHODS) { player.setItemInHand(null); } else { itemInHand.setAmount(0); } } else { itemInHand.setAmount(itemInHand.getAmount() - 1); } // if the player is standing on the placed block add some velocity to prevent glitching // side effect: velocity with +y0.4 is like equivalent to jumping while building, just hold right click, that's real fun! Location playerLocation = player.getLocation(); boolean sameColumn = (playerLocation.getBlockX() == blockLocation.getBlockX()) && (playerLocation.getBlockZ() == blockLocation.getBlockZ()); double distanceUp = (playerLocation.getY() - blockLocation.getBlockY()); boolean upToTwoBlocks = (distanceUp > 0) && (distanceUp <= 2); if (sameColumn && upToTwoBlocks) { player.setVelocity(ANTI_GLITCH_VELOCITY); } // delay, because we cannot do {@link Block#setType(Material)} immediately Bukkit.getScheduler().runTask(FunnyGuilds.getInstance(), () -> { // fake place for bugged block block.setType(type); // start timer and return the item to the player if specified to do so ItemStack returnItem = event.getItemInHand().clone(); returnItem.setAmount(1); Bukkit.getScheduler().runTaskLater(FunnyGuilds.getInstance(), () -> { event.getBlockReplacedState().update(true); if (!player.isOnline()) { return; } if (this.config.buggedBlockReturn) { player.getInventory().addItem(returnItem); } }, this.config.buggedBlocksTimer); }); }