本文整理汇总了Java中org.bukkit.entity.Player.setItemInHand方法的典型用法代码示例。如果您正苦于以下问题:Java Player.setItemInHand方法的具体用法?Java Player.setItemInHand怎么用?Java Player.setItemInHand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.entity.Player
的用法示例。
在下文中一共展示了Player.setItemInHand方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onVoucherRedeem
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true)
public void onVoucherRedeem(RVRedeemEvent e){
Player p = e.getPlayer();
Voucher v = e.getVoucher();
HashMap<String, String> vars = Maps.newHashMap();
vars.put("%tier%", v.getId());
FileManager.getInstance().getMessage(p, "redeem", vars);
UserManager um = UserManager.getConfig(p);
Integer lim = new Integer(VoucherAPI.getCount(p, v.getId()) + 1).intValue();
um.getConfig().set("voucher." + v.getId(), lim);
um.saveConfig();
if(p.getItemInHand().getAmount() == 1) p.setItemInHand(new ItemStack(Material.AIR));
else p.getItemInHand().setAmount(p.getItemInHand().getAmount()-1);
ActionAPI.dealAction(p, v);
}
示例2: onPlayerInteract
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.hasItem() && event.getItem().getType() == Material.ENDER_PEARL) {
Block block = event.getClickedBlock();
// Don't prevent opening chests, etc, as these won't throw the Enderpearls anyway
if (block.getType().isSolid() && !(block.getState() instanceof InventoryHolder)) {
Faction factionAt = HCF.getPlugin().getFactionManager().getFactionAt(block.getLocation());
if (!(factionAt instanceof ClaimableFaction)) {
return;
}
event.setCancelled(true);
Player player = event.getPlayer();
player.setItemInHand(event.getItem()); // required to update Enderpearl count
}
}
}
示例3: onPlayerInteract
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction() == Action.LEFT_CLICK_BLOCK && event.hasItem()) {
// The player didn't click an enchantment table, Creative players will instantly destroy.
Player player = event.getPlayer();
if (event.getClickedBlock().getType() == Material.ENCHANTMENT_TABLE && player.getGameMode() != GameMode.CREATIVE) {
// The player didn't click with an enchanted book.
ItemStack stack = event.getItem();
if (stack != null && stack.getType() == Material.ENCHANTED_BOOK) {
ItemMeta meta = stack.getItemMeta();
if (meta instanceof EnchantmentStorageMeta) {
EnchantmentStorageMeta enchantmentStorageMeta = (EnchantmentStorageMeta) meta;
for (Enchantment enchantment : enchantmentStorageMeta.getStoredEnchants().keySet()) {
enchantmentStorageMeta.removeStoredEnchant(enchantment);
}
event.setCancelled(true);
player.setItemInHand(EMPTY_BOOK);
player.sendMessage(ChatColor.GREEN + "You reverted this item to its original form.");
}
}
}
}
}
示例4: 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);
}
}
}
}
示例5: run
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public void run(PlayerInteractEvent evt) {
Block target = evt.getClickedBlock();
if (target == null) return;
Player player = evt.getPlayer();
if (fillFaceable(target) && !isFacedLog(target)) {
target.setData(fillData(target));
AzureAPI.playSound(player, Sound.BLOCK_WOOD_FALL, true);
ItemStack item = evt.getItem();
if (Item.isTool(item)) {
item.setDurability((short) (item.getDurability() + 4));
if (item.getType().getMaxDurability() <= item.getDurability()) {
player.setItemInHand(null);
AzureAPI.playSound(player, Sound.ENTITY_ITEM_BREAK, true);
}
}
} else {
AzureAPI.log(player, isFacedLog(target) ? "这块木头已削过皮了" : "这把刀只能削树皮用");
}
}
示例6: onInteract
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onInteract(PlayerInteractEvent event) {
if ((event.getAction() == Action.RIGHT_CLICK_BLOCK) && (event.hasItem()) && (event.getItem().getType() == Material.ENDER_PEARL)) {
Block block = event.getClickedBlock();
if ((block.getType().isSolid()) && (!(block.getState() instanceof InventoryHolder))) {
event.setCancelled(true);
Player player = event.getPlayer();
player.setItemInHand(event.getItem());
}
}
}
示例7: onEntityDamageByEntity
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = false, priority = EventPriority.NORMAL)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (event.getDamager() instanceof Player) {
Player player = (Player) event.getDamager();
if (isSubclaimWand(player.getItemInHand())) {
player.setItemInHand(new ItemStack(Material.AIR, 1));
plugin.getClaimHandler().clearClaimSelection(player);
}
}
}
示例8: onFoodEat
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@EventHandler
public void onFoodEat(PlayerInteractEvent event) {
if(!(event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK))) {
return;
}
if(!event.getPlayer().isSneaking() || event.getPlayer().getInventory().getItemInMainHand() == null) {
return;
}
Player player = event.getPlayer();
List<Integer> ids = GodFoodFile.getFoodId(player.getInventory().getItemInMainHand().getTypeId());
for(int id : ids) {
byte data = (byte)GodFoodFile.getData(id);
if(player.getInventory().getItemInMainHand().getData().getData() != data || id == 0)
continue;
if(player.getInventory().getItemInMainHand().getAmount() > GodFoodFile.getAmount(id)) {
ItemStack item = player.getInventory().getItemInMainHand();
item.setAmount(item.getAmount() - GodFoodFile.getAmount(id));
player.setItemInHand(item);
} else if(player.getInventory().getItemInMainHand().getAmount() == GodFoodFile.getAmount(id)) {
player.setItemInHand(new ItemStack(Material.AIR));
} else {
return;
}
event.setCancelled(true);
addPotionEffects(player, id);
player.sendMessage(Lang.HEADERS_FOG.toString() + "You used "
+ ChatColor.RED + GodFoodFile.getName(id) + ChatColor.GRAY + "!");
}
}
示例9: 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);
}
}
}
示例10: 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);
}
}
}
示例11: onEntityDamageByEntity
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = false, priority = EventPriority.NORMAL)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (event.getDamager() instanceof Player) {
Player player = (Player) event.getDamager();
if (isClaimingWand(player.getItemInHand())) {
player.setItemInHand(new ItemStack(Material.AIR, 1));
plugin.getClaimHandler().clearClaimSelection(player);
}
}
}
示例12: 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);
}
}
示例13: onPlayerInteract
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = false, priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Block block = event.getClickedBlock();
BlockState state = block.getState();
if (state instanceof Sign) {
Sign sign = (Sign) state;
String[] lines = sign.getLines();
Integer quantity = JavaUtils.tryParseInt(lines[2]);
if (quantity == null)
return;
Integer price = JavaUtils.tryParseInt(ALPHANUMERIC_REMOVER.matcher(lines[3]).replaceAll(""));
if (price == null)
return;
ItemStack stack;
if (lines[1].equalsIgnoreCase("Crowbar")) {
stack = new Crowbar().getItemIfPresent();
} else if ((stack = BasePlugin.getPlugin().getItemDb().getItem(ALPHANUMERIC_REMOVER.matcher(lines[1]).replaceAll(""), quantity)) == null) {
return;
}
// Final handling of shop.
Player player = event.getPlayer();
String[] fakeLines = Arrays.copyOf(sign.getLines(), 4);
if (lines[0].contains("Sell") && lines[0].contains(ChatColor.RED.toString())) {
int sellQuantity = Math.min(quantity, InventoryUtils.countAmount(player.getInventory(), stack.getType(), stack.getDurability()));
if (sellQuantity <= 0) {
fakeLines[0] = ChatColor.RED + "Not carrying any";
fakeLines[2] = ChatColor.RED + "on you.";
fakeLines[3] = "";
} else {
// Recalculate the price.
int newPrice = (int) (((double) price / (double) quantity) * (double) sellQuantity);
fakeLines[0] = ChatColor.GREEN + "Sold " + sellQuantity;
fakeLines[3] = ChatColor.GREEN + "for " + EconomyManager.ECONOMY_SYMBOL + newPrice;
plugin.getEconomyManager().addBalance(player.getUniqueId(), newPrice);
InventoryUtils.removeItem(player.getInventory(), stack.getType(), stack.getData().getData(), sellQuantity);
player.updateInventory();
}
} else if (lines[0].contains("Buy") && lines[0].contains(ChatColor.GREEN.toString())) {
if (price > plugin.getEconomyManager().getBalance(player.getUniqueId())) {
fakeLines[0] = ChatColor.RED + "Cannot afford";
} else {
fakeLines[0] = ChatColor.GREEN + "Item bought";
fakeLines[3] = ChatColor.GREEN + "for " + EconomyManager.ECONOMY_SYMBOL + price;
plugin.getEconomyManager().subtractBalance(player.getUniqueId(), price);
World world = player.getWorld();
Location location = player.getLocation();
Map<Integer, ItemStack> excess = player.getInventory().addItem(stack);
for (Map.Entry<Integer, ItemStack> excessItemStack : excess.entrySet()) {
world.dropItemNaturally(location, excessItemStack.getValue());
}
player.setItemInHand(player.getItemInHand()); // resend held item packet.
}
} else {
return;
}
event.setCancelled(true);
BasePlugin.getPlugin().getSignHandler().showLines(player, sign, fakeLines, SIGN_TEXT_REVERT_TICKS, true);
}
}
}