本文整理汇总了Java中org.bukkit.inventory.InventoryHolder类的典型用法代码示例。如果您正苦于以下问题:Java InventoryHolder类的具体用法?Java InventoryHolder怎么用?Java InventoryHolder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InventoryHolder类属于org.bukkit.inventory包,在下文中一共展示了InventoryHolder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAmmo
import org.bukkit.inventory.InventoryHolder; //导入依赖的package包/类
/**
* This figures out if the gun's ammo is in the entity's inventory.
*
* @param entity the entity to check
* @return the Bullet type found that is valid for this gun, or null.
*/
public Bullet getAmmo(LivingEntity entity) {
if (entity == null || !enabled)
return null;
ItemStack[] inv;
if (entity instanceof InventoryHolder) {
// complex inventory
InventoryHolder holder = (InventoryHolder) entity;
inv = holder.getInventory().getContents();
} else {
// simple inventory
inv = entity.getEquipment().getArmorContents();
}
if (inv != null) {
for (ItemStack item : inv) {
Bullet bullet = AddGun.getPlugin().getAmmo().findBullet(item);
if (bullet != null && this.allBullets.contains(bullet.getName())) {
return bullet;
}
}
}
return null;
}
示例2: hasGun
import org.bukkit.inventory.InventoryHolder; //导入依赖的package包/类
/**
* Check if this living entity has a gun of this type already in possession
* @param entity the entity to check
* @return true if already in inventory, false otherwise.
*/
public boolean hasGun(LivingEntity entity) {
if (entity == null || !enabled)
return false;
ItemStack[] inv;
if (entity instanceof InventoryHolder) {
// complex inventory
InventoryHolder holder = (InventoryHolder) entity;
inv = holder.getInventory().getContents();
} else {
// simple inventory
inv = entity.getEquipment().getArmorContents();
}
if (inv != null) {
for (ItemStack item : inv) {
if (isGun(item)) {
return true;
}
}
}
return false;
}
示例3: hasBullet
import org.bukkit.inventory.InventoryHolder; //导入依赖的package包/类
public boolean hasBullet(LivingEntity entity) {
if (entity == null || !enabled)
return false;
ItemStack[] inv;
if (entity instanceof InventoryHolder) {
// complex inventory
InventoryHolder holder = (InventoryHolder) entity;
inv = holder.getInventory().getContents();
} else {
// simple inventory
inv = entity.getEquipment().getArmorContents();
}
if (inv != null) {
for (ItemStack item : inv) {
if (isBullet(item)) {
return true;
}
}
}
return false;
}
示例4: hasGun
import org.bukkit.inventory.InventoryHolder; //导入依赖的package包/类
public boolean hasGun(LivingEntity entity) {
if (entity == null || !enabled)
return false;
ItemStack[] inv;
if (entity instanceof InventoryHolder) {
// complex inventory
InventoryHolder holder = (InventoryHolder) entity;
inv = holder.getInventory().getContents();
} else {
// simple inventory
inv = entity.getEquipment().getArmorContents();
}
if (inv != null) {
for (ItemStack item : inv) {
if (isGun(item)) {
return true;
}
}
}
return false;
}
示例5: getInvXp
import org.bukkit.inventory.InventoryHolder; //导入依赖的package包/类
/**
* Estimates the XP this entity in inventory.
*
* @param entity
* @return
*/
private int getInvXp(LivingEntity entity) {
if (entity == null || !enabled)
return 0;
ItemStack[] inv;
if (entity instanceof InventoryHolder) {
// complex inventory
InventoryHolder holder = (InventoryHolder) entity;
inv = holder.getInventory().getContents();
} else {
// simple inventory
inv = entity.getEquipment().getArmorContents();
}
int total = 0;
if (inv != null) {
for (ItemStack item : inv) {
if (Material.EXP_BOTTLE.equals(item)) {
total += item.getAmount();
}
}
}
return total;
}
示例6: getInvXp
import org.bukkit.inventory.InventoryHolder; //导入依赖的package包/类
/**
* Estimates the XP this entity has in inventory.
*
* @param entity the entity to check
* @return how much XP is held
*/
public static int getInvXp(LivingEntity entity) {
if (entity == null)
return 0;
ItemStack[] inv;
if (entity instanceof InventoryHolder) {
// complex inventory
InventoryHolder holder = (InventoryHolder) entity;
inv = holder.getInventory().getContents();
} else {
// simple inventory
inv = entity.getEquipment().getArmorContents();
}
int total = 0;
if (inv != null) {
for (ItemStack item : inv) {
if (Material.EXP_BOTTLE.equals(item)) {
total += item.getAmount();
}
}
}
return total;
}
示例7: onInventoryClose
import org.bukkit.inventory.InventoryHolder; //导入依赖的package包/类
@EventHandler
public void onInventoryClose(InventoryCloseEvent e)
{
if(!(e.getPlayer() instanceof Player))
return;
Inventory inv = e.getInventory();
InventoryHolder holder = inv.getHolder();
if(holder != null && holder instanceof Menu)
{
Menu menu = (Menu) holder;
menu.viewers.remove(e.getPlayer());
if(menu.viewers.size() == 0)
openMenus.remove(menu);
}
}
示例8: handleWoolCrafting
import org.bukkit.inventory.InventoryHolder; //导入依赖的package包/类
@EventHandler
public void handleWoolCrafting(PrepareItemCraftEvent event) {
ItemStack result = event.getRecipe().getResult();
InventoryHolder holder = event.getInventory().getHolder();
if (holder instanceof Player) {
MatchPlayer playerHolder = this.match.getPlayer((Player) holder);
if (playerHolder != null && result != null && result.getType() == Material.WOOL) {
for(MonumentWool wool : this.wools) {
if(wool.getDefinition().isObjectiveWool(result)) {
if(!wool.getDefinition().isCraftable()) {
playerHolder.sendMessage(ChatColor.RED + PGMTranslations.t("match.wool.craftDisabled", playerHolder, BukkitUtils.woolMessage(wool.getDyeColor())));
event.getInventory().setResult(null);
}
}
}
}
}
}
示例9: passesFilter
import org.bukkit.inventory.InventoryHolder; //导入依赖的package包/类
/**
* Return a predicate that applies a Filter to the given InventoryHolder,
* or null if the InventoryHolder is not something that we should be filling.
*/
private static @Nullable Predicate<Filter> passesFilter(InventoryHolder holder) {
if(holder instanceof DoubleChest) {
final DoubleChest doubleChest = (DoubleChest) holder;
return filter -> !filter.denies((Chest) doubleChest.getLeftSide()) ||
!filter.denies((Chest) doubleChest.getRightSide());
} else if(holder instanceof BlockState) {
return filter -> !filter.denies((BlockState) holder);
} else if(holder instanceof Player) {
// This happens with crafting inventories, and possibly other transient inventory types
// Pretty sure we never want to fill an inventory held by the player
return null;
} else if(holder instanceof Entity) {
return filter -> !filter.denies(new EntityQuery((Entity) holder));
} else {
// If we're not sure what it is, don't fill it
return null;
}
}
示例10: showInventories
import org.bukkit.inventory.InventoryHolder; //导入依赖的package包/类
@EventHandler(ignoreCancelled = true)
public void showInventories(final ObserverInteractEvent event) {
if(event.getClickType() != ClickType.RIGHT) return;
if(event.getPlayer().isDead()) return;
if(event.getClickedParticipant() != null) {
event.setCancelled(true);
if(canPreviewInventory(event.getPlayer(), event.getClickedParticipant())) {
this.previewPlayerInventory(event.getPlayer().getBukkit(), event.getClickedParticipant().getInventory());
}
} else if(event.getClickedEntity() instanceof InventoryHolder && !(event.getClickedEntity() instanceof Player)) {
event.setCancelled(true);
this.previewInventory(event.getPlayer().getBukkit(), ((InventoryHolder) event.getClickedEntity()).getInventory());
} else if(event.getClickedBlockState() instanceof InventoryHolder) {
event.setCancelled(true);
this.previewInventory(event.getPlayer().getBukkit(), ((InventoryHolder) event.getClickedBlockState()).getInventory());
}
}
示例11: onBlockDispense
import org.bukkit.inventory.InventoryHolder; //导入依赖的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);
}
}
}
}
示例12: onPlayerInteract
import org.bukkit.inventory.InventoryHolder; //导入依赖的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
}
}
}
示例13: getOwner
import org.bukkit.inventory.InventoryHolder; //导入依赖的package包/类
@Override
public InventoryHolder getOwner()
{
// int x = 0;
// org.bukkit.block.Block b = this.world.getWorld().getBlockAt(x, 0, 0);
// while(b != null && b.getType() != Material.AIR)
// b = this.world.getWorld().getBlockAt(++x,0,0);
// Furnace furnace = new CraftFurnace(b);
Furnace furnace = new CraftFurnace(this.world.getWorld().getBlockAt(0, 0, 0));
try
{
ReflectionUtil.setValue(furnace, "furnace", this);
}
catch (Exception e)
{
e.printStackTrace();
}
return furnace;
}
示例14: getOwner
import org.bukkit.inventory.InventoryHolder; //导入依赖的package包/类
@Override
public InventoryHolder getOwner()
{
// int x = 0;
// org.bukkit.block.Block b = this.world.getWorld().getBlockAt(x, 0, 0);
// while(b != null && b.getType() != Material.AIR)
// b = this.world.getWorld().getBlockAt(++x,0,0);
// Furnace furnace = new CraftFurnace(b);
org.bukkit.block.Furnace furnace = new CraftFurnace(this.world.getWorld().getBlockAt(0, 0, 0));
try
{
ReflectionUtil.setValue(furnace, "furnace", this);
}
catch (Exception e)
{
e.printStackTrace();
}
return furnace;
}
示例15: getOwner
import org.bukkit.inventory.InventoryHolder; //导入依赖的package包/类
@Override
public InventoryHolder getOwner()
{
//Bukkit.getLogger().info("getOwner");
// int x = 0;
// org.bukkit.block.Block b = this.world.getWorld().getBlockAt(x, 0, 0);
// while(b != null && b.getType() != Material.AIR)
// b = this.world.getWorld().getBlockAt(++x,0,0);
// Furnace furnace = new CraftFurnace(b);
furnace = new CraftFurnace(this.world.getWorld().getBlockAt(0, 0, 0));
try
{
ReflectionUtil.setValue(furnace, "furnace", this);
}
catch (Exception e)
{
e.printStackTrace();
}
return furnace;
}