本文整理汇总了Java中org.bukkit.inventory.ItemStack.setType方法的典型用法代码示例。如果您正苦于以下问题:Java ItemStack.setType方法的具体用法?Java ItemStack.setType怎么用?Java ItemStack.setType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.inventory.ItemStack
的用法示例。
在下文中一共展示了ItemStack.setType方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: takeOneItem
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public static boolean takeOneItem(Player p, ItemStack item) {
for (int k = 0; k < p.getInventory().getSize(); k++) {
ItemStack i = p.getInventory().getItem(k);
if (i != null && i.isSimilar(item)) {
if (i.getAmount() > 1) {
i.setAmount(i.getAmount() - 1);
p.getInventory().setItem(k, i);
p.updateInventory();
} else {
i.setType(Material.AIR);
i.setAmount(0);
p.getInventory().setItem(k, null);
}
return true;
}
}
return false;
}
示例2: take
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public static boolean take(Player p, ItemStack item, int amount) {
if (count(p, item) < amount)
return false;
int remaining = amount;
for (int k = 0; k < p.getInventory().getSize(); k++) {
ItemStack i = p.getInventory().getItem(k);
if (i != null && i.isSimilar(item)) {
if (i.getAmount() > remaining) {
i.setAmount(i.getAmount() - remaining);
remaining = 0;
p.getInventory().setItem(k, i);
p.updateInventory();
} else {
remaining -= i.getAmount();
System.out.println("subtracting " + i.getAmount() + ", " + remaining + " remaining");
i.setType(Material.AIR);
i.setAmount(0);
p.getInventory().setItem(k, null);
}
}
}
return true;
}
示例3: onItemConsume
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@EventHandler
public void onItemConsume(PlayerItemConsumeEvent e){
Player p = e.getPlayer();
ItemStack item = e.getItem();
Material type = item != null ? item.getType() : Material.AIR;
int thirst = p.getLevel();
if (type == Material.POTION && item.getDurability() == 0 && p.getInventory().getItemInMainHand().isSimilar(item)){
p.getInventory().getItemInMainHand().setType(Material.AIR);
for (ItemStack i : p.getInventory().getContents()){
if (i.getType() == Material.GLASS_BOTTLE){
i.setType(Material.AIR);
}
}
p.setLevel(0);
if (thirst + 256 >= 1000){
p.setLevel(1000);
return;
}
p.setLevel(thirst + 256);
p.sendMessage(p.getLevel() + " // " + thirst + 256);
}
}
示例4: onFurnaceSmelt
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
/**
* Handles the action of smelting all items at once, exploding the furnace, and dropping the smelted items on the
* ground.
*
* @param event The event
*/
@EventHandler(ignoreCancelled = true)
public void onFurnaceSmelt(FurnaceSmeltEvent event) {
ItemStack resultItem = event.getResult();
final Material result = resultItem.getType();
//TODO: Verify that the "smelting amount" contains any extra ingredients
final int amount = ((Furnace) event.getBlock().getState()).getInventory().getSmelting().getAmount();
event.getSource().setType(Material.AIR);
resultItem.setType(Material.AIR);
Block block = event.getBlock();
block.setType(Material.AIR);
Location location = block.getLocation().add(0.5, 0.5, 0.5);
World world = location.getWorld();
world.createExplosion(location, 7);
world.dropItem(location, new ItemStack(result, amount));
}
示例5: onBlockDispense
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onBlockDispense(BlockDispenseEvent e) {
if (!cm.isAntiNegativeItemDupe) {
return;
}
Inventory content = null;
if (e.getBlock().getState() instanceof InventoryHolder) {
content = ((InventoryHolder) e.getBlock().getState()).getInventory();
}
if (content == null || content.getSize() == 0) {
return;
}
for (ItemStack item : content.getContents()) {
if (item != null && item.getType() != Material.AIR) {
if (item.getAmount() <= 0) {
item.setType(Material.AIR);
}
}
}
}
示例6: onUseNetherStar
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@EventHandler
public void onUseNetherStar(PlayerInteractEvent event) {
if(event.getPlayer().getInventory().getItemInMainHand() == null)
return;
if(!(event.getAction().equals(Action.RIGHT_CLICK_BLOCK) || event.getAction().equals(Action.RIGHT_CLICK_AIR)))
return;
if(!(event.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.NETHER_STAR)))
return;
if(!event.getPlayer().getInventory().getItemInMainHand().hasItemMeta())
return;
if(!event.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals(ChatColor.LIGHT_PURPLE + "God Token"))
return;
Player player = event.getPlayer();
int amount = player.getInventory().getItemInMainHand().getAmount();
ItemStack item = player.getInventory().getItemInMainHand();
if(amount > 1) {
item.setAmount(amount - 1);
}
else {
item.setType(Material.AIR);
}
player.getInventory().setItemInMainHand(item);
plugin.getPlayerManager().addTokens(player, 1);
player.sendMessage(Lang.HEADERS_TOKENS.toString() + "You've successfully deposited 1 GT!");
}
示例7: onDeath
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@EventHandler
public void onDeath(PlayerDeathEvent event) {
Player player = event.getEntity();
PracticeProfile profile = ManagerHandler.getPlayerManager().getPlayerProfile(player);
if (profile.getStatus() != PlayerStatus.PLAYING) {
return;
}
player.spigot().respawn();
IMatch match = profile.getCurrentMatch();
match.handleDeath(player, player.getLocation(), ChatColor.RED + player.getName() + ChatColor.GRAY + " has been slain.");
event.setDeathMessage(null);
player.setHealth(20.0);
for (ItemStack i : event.getDrops()) {
i.setType(Material.AIR);
}
}
示例8: removeItem
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
private void removeItem(Player p){
ItemStack i = p.getInventory().getItemInMainHand();
int amount = i.getAmount();
if (amount == 1){
i.setType(Material.AIR);
} else {
i.setAmount(amount - 1);
}
}
示例9: onPlayerFish
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
/**
* Drops cooked fish whenever a player is fishing and receives raw fish.
*
* @param event The event
*/
@EventHandler(ignoreCancelled = true)
public void onPlayerFish(PlayerFishEvent event) {
Entity caught = event.getCaught();
if (caught instanceof ItemStack) {
ItemStack fish = (ItemStack) caught;
if (fish.getType().equals(Material.RAW_FISH)) {
fish.setType(Material.COOKED_FISH);
}
}
}
示例10: onClick
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onClick(InventoryClickEvent e) {
if (!cm.isAntiNegativeItemDupe) {
return;
}
ItemStack item = null;
if (e.getCurrentItem() != null && e.getCurrentItem().getType() != Material.AIR) {
item = e.getCurrentItem();
} else if (e.getCursor() != null && e.getCursor().getType() != Material.AIR) {
item = e.getCursor();
}
if (item != null && item.getAmount() <= 0) {
item.setType(Material.AIR);
}
}
示例11: onDeath
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@EventHandler
public void onDeath(PlayerDeathEvent event) {
event.setDeathMessage(null);
for (ItemStack i : event.getDrops()) {
i.setType(Material.AIR);
}
}