本文整理汇总了Java中org.bukkit.entity.Player.getItemInHand方法的典型用法代码示例。如果您正苦于以下问题:Java Player.getItemInHand方法的具体用法?Java Player.getItemInHand怎么用?Java Player.getItemInHand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.entity.Player
的用法示例。
在下文中一共展示了Player.getItemInHand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: playerIsHolding
import org.bukkit.entity.Player; //导入方法依赖的package包/类
/**
* Checks if player has this type of item in either hand
* @param player
* @param type
* @return true if they are holding an item of type type
*/
@SuppressWarnings("deprecation")
public static boolean playerIsHolding(Player player, Material type) {
if (plugin.getServer().getVersion().contains("(MC: 1.7")
|| plugin.getServer().getVersion().contains("(MC: 1.8")) {
if (player.getItemInHand() != null && player.getItemInHand().getType().equals(type)) {
return true;
}
return false;
}
if (player.getInventory().getItemInMainHand() != null && player.getInventory().getItemInMainHand().getType().equals(type)) {
return true;
}
if (player.getInventory().getItemInMainHand() != null && player.getInventory().getItemInOffHand().getType().equals(type)) {
return true;
}
return false;
}
示例2: onCommand
import org.bukkit.entity.Player; //导入方法依赖的package包/类
public void onCommand(CommandSender sender, String[] args) throws CommandException {
if (args.length < 2) {
throw new CommandException(Collections.singletonList("You provided too few arguments."));
}
if (!ManagerHandler.getLadderManager().getLadders().containsKey(args[1])) {
throw new CommandException(Collections.singletonList("That ladder does not exist."));
}
Player player = (Player) sender;
if (player.getItemInHand() == null) {
throw new CommandException(Collections.singletonList("You must have an item in your hand."));
}
Ladder ladder = ManagerHandler.getLadderManager().getLadders().get(args[1]);
ladder.setDisplayIcon(player.getItemInHand());
ladder.save(player);
}
示例3: onGrenadeLaunch
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onGrenadeLaunch(final ProjectileLaunchEvent event) {
if (event.getEntity().getShooter() instanceof Player) {
Player player = (Player) event.getEntity().getShooter();
ItemStack stack = player.getItemInHand();
if(stack != null) {
// special case for grenade arrows
if (stack.getType() == Material.BOW) {
int arrows = player.getInventory().first(Material.ARROW);
if (arrows == -1) return;
stack = player.getInventory().getItem(arrows);
}
Grenade grenade = Grenade.ITEM_TAG.get(stack);
if(grenade != null) {
grenade.set(plugin, event.getEntity());
}
}
}
}
示例4: ignite
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public boolean ignite(Player igniter, Location loc, IgniteCause cause) {
Random rand = new Random();
loc.add(0.5, 0.5, 0.5);
BlockIgniteEvent igniteEvent = new BlockIgniteEvent(loc.getBlock(),
cause, (org.bukkit.entity.Entity) igniter);
Bukkit.getServer().getPluginManager().callEvent(igniteEvent);
if (igniteEvent.isCancelled()) {
return false;
}
BlockState blockState = loc.getBlock().getState();
BlockPlaceEvent placeEvent = new BlockPlaceEvent(loc.getBlock(),
blockState, loc.getBlock(), igniter.getItemInHand(), igniter, true);
Bukkit.getServer().getPluginManager().callEvent(placeEvent);
if (placeEvent.isCancelled() || !placeEvent.canBuild()) {
placeEvent.getBlockPlaced().setTypeIdAndData(0, (byte) 0, false);
return false;
}
loc.getWorld().playSound(loc, Sound.ITEM_FLINTANDSTEEL_USE, 1.0F, rand.nextFloat() * 0.4F + 0.8F);
loc.getBlock().setType(Material.FIRE);
return true;
}
示例5: onEntityDamageByEntity
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
Entity entity = event.getEntity();
Entity damager = event.getDamager();
if (entity instanceof Player && damager instanceof Player) {
Player attacker = (Player) damager;
if (plugin.getPvpClassManager().getEquippedClass(attacker) == this) {
ItemStack stack = attacker.getItemInHand();
if (stack != null && stack.getType() == Material.GOLD_SWORD && stack.getEnchantments().isEmpty()) {
Player player = (Player) entity;
player.sendMessage(SettingsYML.ENEMY_COLOUR + attacker.getName() + ChatColor.YELLOW + " has backstabbed you.");
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F);
attacker.sendMessage(ChatColor.YELLOW + "You have backstabbed " + SettingsYML.ENEMY_COLOUR + player.getName() + ChatColor.YELLOW + '.');
attacker.setItemInHand(new ItemStack(Material.AIR, 1));
player.setHealth(12);
attacker.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F);
event.setDamage(3.0);
}
}
}
}
示例6: onEntityDeath
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onEntityDeath(EntityDeathEvent event) {
double amount = event.getDroppedExp();
Player killer = event.getEntity().getKiller();
if (killer != null && amount > 0) {
ItemStack stack = killer.getItemInHand();
if (stack != null && stack.getType() != Material.AIR) {
int enchantmentLevel = stack.getEnchantmentLevel(Enchantment.LOOT_BONUS_MOBS);
if (enchantmentLevel > 0L) {
double multiplier = enchantmentLevel * SettingsYML.EXP_MULTIPLIER_LOOTING_PER_LEVEL;
int result = (int) Math.ceil(amount * multiplier);
event.setDroppedExp(result);
}
}
}
}
示例7: onArcherSpeedClick
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled=false, priority=EventPriority.HIGH)
public void onArcherSpeedClick(PlayerInteractEvent event)
{
Action action = event.getAction();
if (((action == Action.RIGHT_CLICK_AIR) || (action == Action.RIGHT_CLICK_BLOCK)) &&
(event.hasItem()) && (event.getItem().getType() == Material.SUGAR))
{
if (this.plugin.getPvpClassManager().getEquippedClass(event.getPlayer()) != this) {
return;
}
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
long timestamp = this.archerSpeedCooldowns.get(uuid);
long millis = System.currentTimeMillis();
long remaining = timestamp == this.archerSpeedCooldowns.getNoEntryValue() ? -1L : timestamp - millis;
if (remaining > 0L)
{
player.sendMessage(ChatColor.RED + "Cannot use Speed Boost for another " + DurationFormatUtils.formatDurationWords(remaining, true, true) + ".");
}
else
{
ItemStack stack = player.getItemInHand();
if (stack.getAmount() == 1) {
player.setItemInHand(new ItemStack(Material.AIR, 1));
} else {
stack.setAmount(stack.getAmount() - 1);
}
player.sendMessage(ChatColor.GREEN + "Speed 4 activated for 7 seconds.");
this.plugin.getEffectRestorer().setRestoreEffect(player, ARCHER_SPEED_EFFECT);
this.archerSpeedCooldowns.put(event.getPlayer().getUniqueId(), System.currentTimeMillis() + ARCHER_SPEED_COOLDOWN_DELAY);
}
}
}
示例8: onAttack
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST)
public void onAttack(EntityDamageByEntityEvent event)
{
if(event.isCancelled()) return;
if(event.getDamager() instanceof Player && event.getEntity() instanceof LivingEntity && event.getCause() == DamageCause.ENTITY_ATTACK)
{
Player player = (Player)event.getDamager();
ItemStack item = player.getItemInHand();
if(item.getType() == Material.WOOD_SPADE)
{
item.setDurability((short)(item.getDurability() - 2));
}
}
}
示例9: decrementHand
import org.bukkit.entity.Player; //导入方法依赖的package包/类
private void decrementHand(Player player) {
ItemStack stack = player.getItemInHand();
if (stack.getAmount() <= 1) {
player.setItemInHand(new ItemStack(Material.AIR, 1));
} else {
stack.setAmount(stack.getAmount() - 1);
}
}
示例10: onBlockBreak
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockBreak(final BlockBreakEvent event) {
Player player = event.getPlayer();
if (player.getGameMode() != GameMode.CREATIVE) {
if (player.hasPermission("hcf.listener.autosmeltore")) {
ItemStack stack = player.getItemInHand();
if (stack != null && stack.getType() != Material.AIR
&& !stack.containsEnchantment(Enchantment.SILK_TOUCH)) {
Block block = event.getBlock();
Material dropType = null;
switch (block.getType()) {
case IRON_ORE: {
dropType = Material.IRON_INGOT;
break;
}
case GOLD_ORE: {
dropType = Material.GOLD_INGOT;
break;
}
default: {
return;
}
}
Location location = block.getLocation();
World world = location.getWorld();
ItemStack drop = new ItemStack(dropType, 1);
world.dropItemNaturally(location, drop);
block.setType(Material.AIR);
block.getState().update();
}
}
}
}
示例11: onMinerSpeedClick
import org.bukkit.entity.Player; //导入方法依赖的package包/类
/**
* Applies the {@link MinerClass} invisibility {@link PotionEffect} depending on the {@link Player}s {@link Location}.
*
* @param player
* the {@link Player} to apply for
* @param from
* the from {@link Location}
* @param to
* the to {@link Location}
*/
@EventHandler(ignoreCancelled=false, priority=EventPriority.HIGH)
public void onMinerSpeedClick(PlayerInteractEvent event)
{
Action action = event.getAction();
if (((action == Action.RIGHT_CLICK_AIR) || (action == Action.RIGHT_CLICK_BLOCK)) &&
(event.hasItem()) && (event.getItem().getType() == Material.SUGAR))
{
if (this.plugin.getPvpClassManager().getEquippedClass(event.getPlayer()) != this) {
return;
}
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
long timestamp = this.minerSpeedCooldowns.get(uuid);
long millis = System.currentTimeMillis();
long remaining = timestamp == this.minerSpeedCooldowns.getNoEntryValue() ? -1L : timestamp - millis;
if (remaining > 0L)
{
player.sendMessage(ChatColor.RED + "Cannot use Speed Boost for another " + DurationFormatUtils.formatDurationWords(remaining, true, true) + ".");
}
else
{
ItemStack stack = player.getItemInHand();
if (stack.getAmount() == 1) {
player.setItemInHand(new ItemStack(Material.AIR, 1));
} else {
stack.setAmount(stack.getAmount() - 1);
}
player.sendMessage(ChatColor.GREEN + "Speed 3 activated for 10 seconds.");
this.plugin.getEffectRestorer().setRestoreEffect(player, MINER_SPEED_EFFECT);
this.minerSpeedCooldowns.put(event.getPlayer().getUniqueId(), System.currentTimeMillis() + MINER_SPEED_COOLDOWN_DELAY);
}
}
}
示例12: onCommand
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if(!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "This command is only executable by players.");
return true;
}
Player p = (Player) sender;
if(args.length < 1) {
p.sendMessage(ChatColor.RED + "Usage: " + this.getUsage(label));
p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c- &7You should use &e&&7's for colors!"));
} else {
ItemStack hand = p.getItemInHand();
if(hand.getType() != Material.AIR) {
String name = "";
for(int i = 0; i != args.length; i++)
name += args[i] + " ";
ItemMeta meta = hand.getItemMeta();
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&r" + name));
hand.setItemMeta(meta);
p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7You have successfully renamed your &c" + hand.getType().name().toLowerCase() + " &7to &r" + name));
} else {
p.sendMessage(ChatColor.RED + "You cannot rename Air!");
}
}
return true;
}
示例13: onArcherJumpClick
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled=false, priority=EventPriority.HIGH)
public void onArcherJumpClick(PlayerInteractEvent event)
{
Action action = event.getAction();
if (((action == Action.RIGHT_CLICK_AIR) || (action == Action.RIGHT_CLICK_BLOCK)) &&
(event.hasItem()) && (event.getItem().getType() == Material.FEATHER))
{
if (this.plugin.getPvpClassManager().getEquippedClass(event.getPlayer()) != this) {
return;
}
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
long timestamp = this.archerJumpCooldowns.get(uuid);
long millis = System.currentTimeMillis();
long remaining = timestamp == this.archerJumpCooldowns.getNoEntryValue() ? -1L : timestamp - millis;
if (remaining > 0L)
{
player.sendMessage(ChatColor.RED + "Cannot use Jump Boost for another " + DurationFormatUtils.formatDurationWords(remaining, true, true) + ".");
}
else
{
ItemStack stack = player.getItemInHand();
if (stack.getAmount() == 1) {
player.setItemInHand(new ItemStack(Material.AIR, 1));
} else {
stack.setAmount(stack.getAmount() - 1);
}
player.sendMessage(ChatColor.GREEN + "Jump Boost 4 activated for 7 seconds.");
this.plugin.getEffectRestorer().setRestoreEffect(player, ARCHER_JUMP_EFFECT);
this.archerJumpCooldowns.put(event.getPlayer().getUniqueId(), System.currentTimeMillis() + ARCHER_JUMP_COOLDOWN_DELAY);
}
}
}
示例14: onBlockBreak
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onBlockBreak(BlockBreakEvent event) {
double amount = event.getExpToDrop();
Player player = event.getPlayer();
ItemStack stack = player.getItemInHand();
if (stack != null && stack.getType() != Material.AIR && amount > 0) {
int enchantmentLevel = stack.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS);
if (enchantmentLevel > 0) {
double multiplier = enchantmentLevel * SettingsYML.EXP_MULTIPLIER_FORTUNE_PER_LEVEL;
int result = (int) Math.ceil(amount * multiplier);
event.setExpToDrop(result);
}
}
}
示例15: onBlockBreak
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.LOWEST)
public void onBlockBreak(BlockBreakEvent evt) {
Player player = evt.getPlayer();
if (player == null) {
return;
}
ItemStack itemStack = player.getItemInHand();
if (itemStack.getType() != Material.DIAMOND_PICKAXE) {
return;
}
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null) {
return;
}
String displayName = itemMeta.getDisplayName();
if (displayName == null) {
return;
}
if (!displayName.contains(ITEM_NAME)) {
return;
}
Block block = evt.getBlock();
if (block == null) {
return;
}
Location location = block.getLocation();
String playerName = player.getName();
Location[][] arrayOfLocation;
int j = (arrayOfLocation = LocationUtil.getExplosivePickaxeBreakLocations(location)).length;
for (int i = 0; i < j; i++) {
Location[] locations = arrayOfLocation[i];
Location[] arrayOfLocation1;
int m = (arrayOfLocation1 = locations).length;
for (int k = 0; k < m; k++) {
Location FOR_location = arrayOfLocation1[k];
ClaimedResidence claimedResidence = RESIDENCE_MAMAGER.getByLoc(FOR_location);
if (claimedResidence != null) {
ResidencePermissions perms = claimedResidence.getPermissions();
boolean hasdestroy = perms.playerHas(playerName, Flags.destroy, true);
if ((!hasdestroy) && (!player.hasPermission("residence.bypass.destroy"))) {
this.RESIDENCE.msg(player, lm.Flag_Deny, new Object[] { Flags.destroy });
evt.setCancelled(true);
return;
}
}
}
}
}