本文整理汇总了Java中org.bukkit.inventory.Inventory.first方法的典型用法代码示例。如果您正苦于以下问题:Java Inventory.first方法的具体用法?Java Inventory.first怎么用?Java Inventory.first使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.inventory.Inventory
的用法示例。
在下文中一共展示了Inventory.first方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: notify
import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
@Override
public void notify(Player player, Object extra) {
Location eye = player.getEyeLocation();
Vector direction = eye.getDirection().multiply(2);
Block source = (Block) extra;
Projectile projectile = player.getWorld().spawn(source.getRelative(BlockFace.UP).getLocation().setDirection(direction), LargeFireball.class);
projectile.setShooter(player);
projectile.setVelocity(direction);
Inventory inv = player.getInventory();
if (inv.contains(Material.TNT)) {
int slot = inv.first(Material.TNT);
ItemStack ammo = inv.getItem(slot);
int amount = ammo.getAmount();
if (amount > 1) {
ammo.setAmount(amount - 1);
inv.setItem(slot, ammo);
} else {
inv.setItem(slot, null);
}
projectile.setCustomName("recreator.structure.turret.tnt");
}
AzureAPI.playSound(player, Sound.ITEM_FIRECHARGE_USE, true);
}
示例2: run
import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
@Override
public void run(PlayerInteractEvent evt) {
Player player = evt.getPlayer();
Inventory inv = player.getInventory();
if (!inv.contains(Material.FIREWORK_CHARGE)) {
AzureAPI.log(player, "你没有弹药! 需要 " + ChatColor.RED + "迷你核弹" + ChatColor.GOLD + " 作为弹药");
AzureAPI.playSound(player, Sound.ENTITY_ITEM_BREAK);
return;
}
int slot = inv.first(Material.FIREWORK_CHARGE);
ItemStack ammo = inv.getItem(slot);
if (ammo.hasItemMeta()) {
if (!ammo.getItemMeta().hasLore()) return;
if (!ammo.getItemMeta().getLore().contains("弹药")) return;
} else {
return;
}
int amount = ammo.getAmount();
if (amount > 1) {
ammo.setAmount(amount - 1);
inv.setItem(slot, ammo);
} else {
inv.setItem(slot, null);
}
Location eye = player.getEyeLocation();
Vector direction = eye.getDirection().multiply(2);
Projectile projectile = player.getWorld().spawn(eye.add(direction), DragonFireball.class);
projectile.setBounce(true);
projectile.setGravity(true);
projectile.setShooter(player);
projectile.setVelocity(direction);
projectile.setCustomName("recreator.item.fatman");
AzureAPI.playSound(player, Sound.ITEM_FIRECHARGE_USE, true);
}
示例3: run
import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
@Override
@SuppressWarnings("all")
public void run(PlayerInteractEvent evt) {
Player player = evt.getPlayer();
if (ControlTicker.isTracking(player)) {
AzureAPI.playSound(player, Sound.UI_BUTTON_CLICK);
AzureAPI.log(player, "上一次攻击任务尚未结束!");
return;
}
Inventory inv = player.getInventory();
Block block = evt.getClickedBlock();
Comparator data = (Comparator) block.getState().getData();
if (!inv.contains(Material.SULPHUR)) {
AzureAPI.playSound(player, Sound.ENTITY_ITEM_BREAK);
AzureAPI.log(player, "你没有弹药! 需要 " + ChatColor.RED + "火药" + ChatColor.GOLD + " 作为弹药");
return;
}
int slot = inv.first(Material.SULPHUR);
ItemStack ammo = inv.getItem(slot);
int amount = ammo.getAmount();
if (amount > 1) {
ammo.setAmount(amount - 1);
inv.setItem(slot, ammo);
} else {
inv.setItem(slot, null);
}
int timeout = 6;
ControlTicker.request(this, player, block, TimeUnit.SECONDS, timeout);
AzureAPI.playSound(player, Sound.UI_BUTTON_CLICK, true);
AzureAPI.log(player, "攻击任务预定成功, 你有 " + ChatColor.GREEN + timeout + ChatColor.GOLD + " 秒时间设定弹道");
}
示例4: run
import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
@Override
public void run(PlayerInteractEvent evt) {
Player player = evt.getPlayer();
if (CooldownTicker.can(this, player) || evt.getItem().getItemMeta().getLore().contains("§6高速射击")) {
Inventory inv = player.getInventory();
if (!inv.contains(Material.SULPHUR)) {
AzureAPI.log(player, "你没有弹药! 需要 " + ChatColor.RED + "火药" + ChatColor.GOLD + " 作为弹药");
AzureAPI.playSound(player, Sound.ENTITY_ITEM_BREAK);
return;
}
int slot = inv.first(Material.SULPHUR);
ItemStack ammo = inv.getItem(slot);
int amount = ammo.getAmount();
if (amount > 1) {
ammo.setAmount(amount - 1);
inv.setItem(slot, ammo);
} else {
inv.setItem(slot, null);
}
Location eye = player.getEyeLocation();
Vector direction = eye.getDirection().multiply(2);
Projectile projectile = player.getWorld().spawn(eye.add(direction), Fireball.class);
projectile.setShooter(player);
projectile.setVelocity(direction);
AzureAPI.playSound(player, Sound.ITEM_FIRECHARGE_USE, true);
CooldownTicker.cooldown(this, player, TimeUnit.SECONDS, 3);
} else {
AzureAPI.playSound(player, Sound.UI_BUTTON_CLICK);
AzureAPI.log(player, "冷却时间还没有结束呢!");
}
}