/**
* 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;
}
java类org.bukkit.inventory.InventoryHolder的实例源码
StandardGun.java 文件源码
项目:AddGun
阅读 27
收藏 0
点赞 0
评论 0
StandardGun.java 文件源码
项目:AddGun
阅读 23
收藏 0
点赞 0
评论 0
/**
* 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;
}
RailGun.java 文件源码
项目:AddGun
阅读 18
收藏 0
点赞 0
评论 0
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;
}
RailGun.java 文件源码
项目:AddGun
阅读 31
收藏 0
点赞 0
评论 0
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;
}
RailGun.java 文件源码
项目:AddGun
阅读 19
收藏 0
点赞 0
评论 0
/**
* 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;
}
Utilities.java 文件源码
项目:AddGun
阅读 26
收藏 0
点赞 0
评论 0
/**
* 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;
}
MenuManager.java 文件源码
项目:SparseBukkitAPI
阅读 19
收藏 0
点赞 0
评论 0
@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);
}
}
WoolMatchModule.java 文件源码
项目:ProjectAres
阅读 29
收藏 0
点赞 0
评论 0
@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);
}
}
}
}
}
}
FillListener.java 文件源码
项目:ProjectAres
阅读 19
收藏 0
点赞 0
评论 0
/**
* 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;
}
}
ViewInventoryMatchModule.java 文件源码
项目:ProjectAres
阅读 22
收藏 0
点赞 0
评论 0
@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());
}
}
AntiNegativeItemDupe.java 文件源码
项目:NeverLag
阅读 18
收藏 0
点赞 0
评论 0
@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);
}
}
}
}
PearlGlitchListener.java 文件源码
项目:HCFCore
阅读 25
收藏 0
点赞 0
评论 0
@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
}
}
}
PearlGlitchListener.java 文件源码
项目:HCFCore
阅读 25
收藏 0
点赞 0
评论 0
@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
}
}
}
Furnace_V1_7_R4.java 文件源码
项目:AnnihilationPro
阅读 20
收藏 0
点赞 0
评论 0
@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;
}
Furnace_V1_8_R1.java 文件源码
项目:AnnihilationPro
阅读 18
收藏 0
点赞 0
评论 0
@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;
}
Furnace_V1_7_R3.java 文件源码
项目:AnnihilationPro
阅读 17
收藏 0
点赞 0
评论 0
@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;
}
Furnace_v1_8_R2.java 文件源码
项目:AnnihilationPro
阅读 17
收藏 0
点赞 0
评论 0
@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;
}
Utils.java 文件源码
项目:TradeShop
阅读 24
收藏 0
点赞 0
评论 0
/**
* Reads the name of the inventory
*
* @param state blockState to change the name of
* @return Name of inventory
*/
public String readInvName(BlockState state) {
if (!plugin.getAllowedInventories().contains(state.getType())) {
return null;
}
Inventory inv = ((InventoryHolder) state).getInventory();
if (((Nameable) state).getCustomName() == null) {
return "";
}
String[] names = inv.getName().split(" <");
if (names[0] == null || names[0].equalsIgnoreCase("")) {
return "";
} else {
return names[0];
}
}
Utils.java 文件源码
项目:TradeShop
阅读 24
收藏 0
点赞 0
评论 0
/**
* Resets the name of the inventory
*
* @param state blockState to change the name of
* @return void
*/
public void resetInvName(BlockState state) {
Inventory inv = ((InventoryHolder) state).getInventory();
String name = inv.getName();
String[] temp = name.split(";");
if (name.startsWith("o:")) {
name = "";
}
String[] names = name.split(" <");
while (names[0].endsWith(" ")) {
names[0] = names[0].substring(0, name.length() - 2);
}
setName(((InventoryHolder) state), names[0]);
}
PlayerListener.java 文件源码
项目:ExilePearl
阅读 24
收藏 0
点赞 0
评论 0
/**
* Handle inventory dragging properly
* @param event
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryDrag(InventoryDragEvent event) {
Map<Integer, ItemStack> items = event.getNewItems();
for(Integer slot : items.keySet()) {
ItemStack item = items.get(slot);
ExilePearl pearl = pearlApi.getPearlFromItemStack(item);
if(pearl != null) {
boolean clickedTop = event.getView().convertSlot(slot) == slot;
InventoryHolder holder = clickedTop ? event.getView().getTopInventory().getHolder() : event.getView().getBottomInventory().getHolder();
updatePearlHolder(pearl, holder, event);
if(event.isCancelled()) {
return;
}
}
}
}
PlayerListener.java 文件源码
项目:ExilePearl
阅读 26
收藏 0
点赞 0
评论 0
/**
* Updates the pearl holder
* @param pearl The pearl to update
* @param holder The pearl holder
* @param event The event
*/
private void updatePearlHolder(ExilePearl pearl, InventoryHolder holder, Cancellable event) {
if (holder instanceof Chest) {
updatePearl(pearl, (Chest)holder);
} else if (holder instanceof DoubleChest) {
updatePearl(pearl, (Chest) ((DoubleChest) holder).getLeftSide());
} else if (holder instanceof Furnace) {
updatePearl(pearl, (Furnace) holder);
} else if (holder instanceof Dispenser) {
updatePearl(pearl, (Dispenser) holder);
} else if (holder instanceof Dropper) {
updatePearl(pearl, (Dropper) holder);
} else if (holder instanceof Hopper) {
updatePearl(pearl, (Hopper) holder);
} else if (holder instanceof BrewingStand) {
updatePearl(pearl, (BrewingStand) holder);
} else if (holder instanceof Player) {
updatePearl(pearl, (Player) holder);
}else {
event.setCancelled(true);
}
}
ShopUtils.java 文件源码
项目:ShopChest
阅读 21
收藏 0
点赞 0
评论 0
/**
* Get the amount of shops of a player
* @param p Player, whose shops should be counted
* @return The amount of a shops a player has (if {@link Config#exclude_admin_shops} is true, admin shops won't be counted)
*/
public int getShopAmount(OfflinePlayer p) {
float shopCount = 0;
for (Shop shop : getShops()) {
if (shop.getVendor().equals(p)) {
if (shop.getShopType() != Shop.ShopType.ADMIN || !plugin.getShopChestConfig().exclude_admin_shops) {
shopCount++;
InventoryHolder ih = shop.getInventoryHolder();
if (ih instanceof DoubleChest)
shopCount -= 0.5;
}
}
}
return Math.round(shopCount);
}
BusyMenu.java 文件源码
项目:BusyInv
阅读 19
收藏 0
点赞 0
评论 0
@Override
public boolean isOpenFor(Player p)
{
InventoryView iview = p.getOpenInventory();
if(null == iview)
return false;
Inventory inv = iview.getTopInventory();
if(null == inv)
return false;
InventoryHolder holder = inv.getHolder();
if(!(holder instanceof BusyHolder))
return false;
IBusyMenu menu = ((BusyHolder)holder).getMenu();
if(!menu.equals(this))
return false;
return true;
}
ShopUtils.java 文件源码
项目:ShopChest
阅读 22
收藏 0
点赞 0
评论 0
/** Remove a shop
* @param shop Shop to remove
* @param removeFromDatabase Whether the shop should also be removed from the database
* @param callback Callback that - if succeeded - returns null
*/
public void removeShop(Shop shop, boolean removeFromDatabase, Callback<Void> callback) {
plugin.debug("Removing shop (#" + shop.getID() + ")");
InventoryHolder ih = shop.getInventoryHolder();
if (ih instanceof DoubleChest) {
DoubleChest dc = (DoubleChest) ih;
Chest r = (Chest) dc.getRightSide();
Chest l = (Chest) dc.getLeftSide();
shopLocation.remove(r.getLocation());
shopLocation.remove(l.getLocation());
} else {
shopLocation.remove(shop.getLocation());
}
shop.removeItem();
shop.removeHologram();
if (removeFromDatabase) {
plugin.getShopDatabase().removeShop(shop, callback);
} else {
if (callback != null) callback.callSyncResult(null);
}
}
BusyMenu.java 文件源码
项目:BusyInv
阅读 19
收藏 0
点赞 0
评论 0
/**
* If a BusyMenu is opened for the target player, this method will reload
* the menu for the player.
*
* @see {@link IBusyMenu#reload}
*
* @param p
* Target player
* @return true if and only if the menu is reloaded. Otherwise false(for
* example the player didn't open an inventory or the inventory
* isn't a menu)
*/
public static boolean reloadFor(Player p)
{
InventoryView iview = p.getOpenInventory();
if(null == iview)
return false;
Inventory inv = iview.getTopInventory();
if(null == inv)
return false;
InventoryHolder holder = inv.getHolder();
if(!(holder instanceof BusyHolder))
return false;
((BusyHolder)holder).getMenu().updateFor(p);
p.updateInventory();
return true;
}
FactoryProperties.java 文件源码
项目:Contraptions
阅读 20
收藏 0
点赞 0
评论 0
/**
* Creates a Factory Contraptions
*
* @param location Location to attempt creation
* @return Created Contraption if successful
*/
@Override
public Response createContraption(BlockLocation location) {
Anchor anchor = structureGadget.exists(location);
if (anchor == null) {
return new Response(false, "Incorrect structure for factory");
}
Inventory inventory = ((InventoryHolder) location.getBlock().getState()).getInventory();
if (matchGadget.matches(inventory) && matchGadget.consume(inventory)) {
Factory newFactory = new Factory(this, anchor);
contraptionManager.registerContraption(newFactory);
SoundType.CREATION.play(newFactory.getLocation());
return new Response(true, "Created a " + newFactory.getName() + " factory!", newFactory);
}
return new Response(false, "Incorrect items for a Factory");
}
GeneratorProperties.java 文件源码
项目:Contraptions
阅读 18
收藏 0
点赞 0
评论 0
/**
* Creates a Factory Contraptions
*
* @param anchor Anchor to attempt creation
* @return Created Contraption if successful
*/
@Override
public Response createContraption(BlockLocation location) {
//Check if interaction block is correct
if (structureGadget.validBlock(location.getBlock())) {
return new Response(false, "Incorrect block for a Factory");
}
Anchor anchor = structureGadget.exists(location);
if (anchor == null) {
return new Response(false, "Incorrect structure for factory");
}
Inventory inventory = ((InventoryHolder) location.getBlock().getState()).getInventory();
if (matchGadget.matches(inventory) && matchGadget.consume(inventory)) {
Generator newGenerator = new Generator(this, anchor);
contraptionManager.registerContraption(newGenerator);
SoundType.CREATION.play(anchor.getLocation());
return new Response(true, "Created a " + newGenerator.getName() + " factory!", newGenerator);
}
return new Response(false, "Incorrect items for a Factory");
}
GriefContainer.java 文件源码
项目:vanillacraft
阅读 21
收藏 0
点赞 0
评论 0
public GriefContainer(BlockState block, UUID owner, boolean allowed)
{
this.block = block;
this.owner = owner;
this.allowed = allowed;
if (block instanceof Chest)
{
items = ((Chest) block).getBlockInventory().getContents();
}
else
{
items = ((InventoryHolder) block).getInventory().getContents();
}
timestamp = System.currentTimeMillis();
}
WoolChestModule.java 文件源码
项目:Warzone
阅读 27
收藏 0
点赞 0
评论 0
@Override
public void load(Match match) {
runnableId = Bukkit.getScheduler().scheduleSyncRepeatingTask(TGM.get(), new Runnable() {
@Override
public void run() {
for (InventoryHolder inventory : woolChests.keySet()) {
fillInventoryWithWool(inventory.getInventory(), woolChests.get(inventory));
}
}
}, 10 * 20L, 10 * 20L);
}
CraftInventoryCustom.java 文件源码
项目:Uranium
阅读 20
收藏 0
点赞 0
评论 0
public MinecraftInventory(InventoryHolder owner, int size, String title) {
Validate.notNull(title, "Title cannot be null");
Validate.isTrue(title.length() <= 32, "Title cannot be longer than 32 characters");
this.items = new net.minecraft.item.ItemStack[size];
this.title = title;
this.viewers = new ArrayList<HumanEntity>();
this.owner = owner;
this.type = InventoryType.CHEST;
}