本文整理匯總了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, "冷卻時間還沒有結束呢!");
}
}