本文整理汇总了Java中org.bukkit.inventory.ItemStack.getType方法的典型用法代码示例。如果您正苦于以下问题:Java ItemStack.getType方法的具体用法?Java ItemStack.getType怎么用?Java ItemStack.getType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.inventory.ItemStack
的用法示例。
在下文中一共展示了ItemStack.getType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onInteract
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST)
public void onInteract(PlayerInteractEvent event) {
Action action = event.getAction();
ItemStack item = event.getItem();
if (item == null) {
return;
}
if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) {
Player player = event.getPlayer();
InventoryData data = InventoryData.getData(player);
// check if we are consuming an item.
if (item.getType().isEdible() || item.getType() == Material.POTION) {
// update data.
data.setConsumeTime(System.currentTimeMillis());
}
}
}
示例2: isApplicableFor
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public boolean isApplicableFor(Player player)
{
PlayerInventory playerInventory = player.getInventory();
ItemStack helmet = playerInventory.getHelmet();
if ((helmet == null) || (helmet.getType() != Material.LEATHER_HELMET)) {
return false;
}
ItemStack chestplate = playerInventory.getChestplate();
if ((chestplate == null) || (chestplate.getType() != Material.LEATHER_CHESTPLATE)) {
return false;
}
ItemStack leggings = playerInventory.getLeggings();
if ((leggings == null) || (leggings.getType() != Material.LEATHER_LEGGINGS)) {
return false;
}
ItemStack boots = playerInventory.getBoots();
return (boots != null) && (boots.getType() == Material.LEATHER_BOOTS);
}
示例3: onEntityDeath
import org.bukkit.inventory.ItemStack; //导入方法依赖的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);
}
}
}
}
示例4: onClick
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
/**
* Handle the GUI stuff.
*/
@EventHandler
public void onClick(InventoryClickEvent event) {
Inventory inventory = event.getInventory();
if (inventory.getTitle().contains("Summary for ")) {
event.setCancelled(true);
ItemStack item = event.getCurrentItem();
Player viewer = (Player) event.getWhoClicked();
if (item.getType() == Material.IRON_SWORD) {
Player player = Bukkit.getPlayer(inventory.getTitle().split(" ")[2]);
if (player == null) {
viewer.sendMessage(ChatColor.RED + "This player has logged out.");
viewer.closeInventory();
return;
}
Arc.getArcPlayerManager().scheduleBan(player);
}
}
}
示例5: onCommand
import org.bukkit.inventory.ItemStack; //导入方法依赖的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;
}
示例6: contains
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@Override
public boolean contains( Material material, int i ) throws IllegalArgumentException {
int j = 0;
for ( ItemStack item : items ) {
if( item != null && item.getType() == material ) {
j += item.getAmount();
}
}
return j >= i;
}
示例7: onPlayerItemHeldEvent
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@EventHandler
public void onPlayerItemHeldEvent(PlayerItemHeldEvent event) {
ItemStack itemStack = event.getPlayer().getInventory().getItem(event.getPreviousSlot());
if (itemStack != null && itemStack.getType() == Material.ENDER_PEARL && itemStack.getItemMeta() != null) {
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setDisplayName(null);
itemStack.setItemMeta(itemMeta);
}
}
示例8: insertItem
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@Override
public ItemStack insertItem(WrappedDirection insertDirection, ItemStack insertion) {
if (!cachedChunk.isLoaded()) {
return insertion;
}
if (isInvLocked(cachedBrewingStand)) {
return insertion;
}
if (insertion.getType() == Material.POTION || insertion.getType() == Material.SPLASH_POTION || insertion.getType() == Material.LINGERING_POTION) {
if (cachedInv.getItem(0) == null) {
cachedInv.setItem(0, insertion);
return null;
} else if (cachedInv.getItem(1) == null) {
cachedInv.setItem(1, insertion);
return null;
} else if (cachedInv.getItem(2) == null) {
cachedInv.setItem(2, insertion);
return null;
}
} else if (insertDirection.isSide() && insertion.getType() == Material.BLAZE_POWDER) {
ItemStack oldFuel = cachedInv.getFuel();
cachedInv.setFuel(putItemInSlot(insertion, oldFuel));
if (insertion == null || insertion.getAmount() == 0) {
insertion = null;
}
} else if (isBrewingIngredient(insertion)) {
ItemStack oldIngredient = cachedInv.getIngredient();
cachedInv.setIngredient(putItemInSlot(insertion, oldIngredient));
if (insertion == null || insertion.getAmount() == 0) {
insertion = null;
}
}
return insertion;
}
示例9: isBoots
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public static boolean isBoots(ItemStack item) {
switch(item.getType()) {
case LEATHER_BOOTS:
case IRON_BOOTS:
case CHAINMAIL_BOOTS:
case GOLD_BOOTS:
case DIAMOND_BOOTS:
return true;
default:
return false;
}
}
示例10: dispenserNukes
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void dispenserNukes(BlockTransformEvent event) {
BlockState oldState = event.getOldState();
if(oldState instanceof Dispenser &&
this.properties.dispenserNukeLimit > 0 &&
this.properties.dispenserNukeMultiplier > 0 &&
event.getCause() instanceof EntityExplodeEvent) {
EntityExplodeEvent explodeEvent = (EntityExplodeEvent) event.getCause();
Dispenser dispenser = (Dispenser) oldState;
int tntLimit = Math.round(this.properties.dispenserNukeLimit / this.properties.dispenserNukeMultiplier);
int tntCount = 0;
for(ItemStack stack : dispenser.getInventory().contents()) {
if(stack != null && stack.getType() == Material.TNT) {
int transfer = Math.min(stack.getAmount(), tntLimit - tntCount);
if(transfer > 0) {
stack.setAmount(stack.getAmount() - transfer);
tntCount += transfer;
}
}
}
tntCount = (int) Math.ceil(tntCount * this.properties.dispenserNukeMultiplier);
for(int i = 0; i < tntCount; i++) {
TNTPrimed tnt = this.getMatch().getWorld().spawn(BlockUtils.base(dispenser), TNTPrimed.class);
tnt.setFuseTicks(10 + this.getMatch().getRandom().nextInt(10)); // between 0.5 and 1.0 seconds, same as vanilla TNT chaining
Random random = this.getMatch().getRandom();
Vector velocity = new Vector(random.nextGaussian(), random.nextGaussian(), random.nextGaussian()); // uniform random direction
velocity.normalize().multiply(0.5 + 0.5 * random.nextDouble());
tnt.setVelocity(velocity);
callPrimeEvent(tnt, explodeEvent.getEntity(), false);
}
}
}
示例11: testValidity
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
private boolean testValidity(ItemStack[] contents) {
for (ItemStack stack : contents) {
if (stack != null && stack.getType() == Material.POTION && stack.getDurability() != 0) {
Potion potion = Potion.fromItemStack(stack);
// Just to be safe, null check this.
if (potion == null)
continue;
PotionType type = potion.getType();
// Mundane potions etc, can return a null type
if (type == null)
continue;
// is 33s poison, allow
if (type == PotionType.POISON && !potion.hasExtendedDuration() && potion.getLevel() == 1) {
continue;
}
if (potion.getLevel() > getMaxLevel(type)) {
return false;
}
}
}
return true;
}
示例12: handleSlotClick
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@Override
protected void handleSlotClick( int slot ) {
if( slot == 0 ) {
for( int i = 1; i < getSize(); i++ ) {
ItemStack s = getItem( i );
if( s != null && s.getType() != Material.AIR ) {
s.setAmount( s.getAmount() - 1 );
setItem( slot, s.getAmount() <= 0 ? null : s );
}
}
}
}
示例13: onItemSpawn
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@EventHandler
public void onItemSpawn(ItemSpawnEvent event) {
Item item = event.getEntity();
ItemStack stack = item.getItemStack();
World world = item.getWorld();
if (world.getEnvironment() != Environment.THE_END || stack.getType() != Material.DRAGON_EGG
|| stack.hasItemMeta()) return;
DragonTemplate dragon = plugin.getDEDManager().getWorldWrapper(world).getActiveBattle();
DragonLoot loot = dragon.getLoot();
String eggName = loot.getEggName().replace("%dragon%", dragon.getName());
List<String> eggLore = loot.getEggLore().stream()
.map(s -> s.replace("%dragon%", dragon.getName()))
.collect(Collectors.toList());
ItemMeta eggMeta = stack.getItemMeta();
if (eggName != null && !eggName.isEmpty()) {
eggMeta.setDisplayName(eggName);
}
if (eggLore != null && !eggLore.isEmpty()) {
eggMeta.setLore(eggLore);
}
stack.setItemMeta(eggMeta);
}
示例14: onClick
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public boolean onClick(VPPlayer clicker, int slot, Long coolDownUntil, MenuLink ml,
InventoryClickEvent event) {
Icon icon = this.getIcon(clicker, slot);
if (icon != null) {
event.setCancelled(!icon.canMove(clicker));
long now = System.currentTimeMillis();
if (coolDownUntil == null || coolDownUntil < now) {
if(icon.closeOnClick())
clicker.getPlayer().closeInventory();
if(icon.onClick(clicker, event.getClick(), ml)){
return true;
}
}
}
if(!event.isCancelled()) {
if(event.getClick() == ClickType.DOUBLE_CLICK || event.getClick() == ClickType.SHIFT_LEFT || event.getClick() == ClickType.SHIFT_RIGHT || event.getClick() == ClickType.NUMBER_KEY) {
ItemStack item = event.getCurrentItem();
if(item != null && item.getType() != Material.AIR && MinecraftUtils.getExtra(item, Icon.FREEZE).equals("1"))
event.setCancelled(true);
else if(event.getClick() == ClickType.NUMBER_KEY){
item = event.getWhoClicked().getInventory().getItem(event.getHotbarButton());
if(item != null && item.getType() != Material.AIR && MinecraftUtils.getExtra(item, Icon.FREEZE).equals("1"))
event.setCancelled(true);
}
}
}
return false;
}
示例15: onInteract
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@EventHandler
public void onInteract(PlayerInteractEvent event) {
if (!event.getAction().name().contains("RIGHT")) {
return;
}
Game game = plugin.getGameManager().getGame();
if (game.hasStarted()) {
return;
}
Player player = event.getPlayer();
Profile profile = plugin.getProfileManager().getProfileByUuid(player.getUniqueId());
ItemStack item = player.getItemInHand();
if (item == null || item.getType() == Material.AIR) {
event.setCancelled(true);
return;
}
Material material = item.getType();
if (!teamMap.containsKey(material)) {
return;
}
Team team = teamMap.get(material);
if (team == null) {
plugin.getTeamManager().getRandomTeam().addMember(profile);
} else {
if (profile.getTeam() != null && profile.getTeam() == team) {
event.setCancelled(true);
return;
}
if (team.isFull()) {
player.sendMessage(ChatColor.RED + "That team is currently full. Please join another team.");
return;
}
team.addMember(profile);
}
if (profile.getTeam() != null) {
event.setCancelled(true);
profile.sendMessage(ChatColor.GRAY + "You have joined team " + profile.getTeam().getFormattedName() + ChatColor.GRAY + "." + ChatColor.RED + " (" + profile.getTeam().getSize() + "/5)");
}
}