本文整理汇总了Java中org.bukkit.block.Dispenser.getInventory方法的典型用法代码示例。如果您正苦于以下问题:Java Dispenser.getInventory方法的具体用法?Java Dispenser.getInventory怎么用?Java Dispenser.getInventory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.block.Dispenser
的用法示例。
在下文中一共展示了Dispenser.getInventory方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hasAmmo
import org.bukkit.block.Dispenser; //导入方法依赖的package包/类
protected boolean hasAmmo(Player p) {
// This method is called after we already know that it is an advanced
// turret
Block b = p.getLocation().getBlock().getRelative(BlockFace.DOWN);
if (b.getType() != Material.DISPENSER)
return false;
Dispenser d = (Dispenser) b.getState();
Inventory i = d.getInventory();
for (Ammo ammo : ammos) {
if (i.contains(Material.SPLASH_POTION) && ammo.getName().equalsIgnoreCase("potion")){
i.removeItem(i.getItem(i.first(Material.SPLASH_POTION)));
return true;
} else if (i.contains(Material.LINGERING_POTION) && ammo.getName().equalsIgnoreCase("potion")){
i.removeItem(i.getItem(i.first(Material.LINGERING_POTION)));
return true;
} else if (i.contains(ammo.getItem().getType(), ammo.getItem().getAmount())) {
i.removeItem(ammo.getItem());
return true;
}
}
return false;
}
示例2: getLoadedAmmo
import org.bukkit.block.Dispenser; //导入方法依赖的package包/类
protected Ammo getLoadedAmmo(Player p) {
// This method returns the ammo type we are using
Block b = p.getLocation().getBlock().getRelative(BlockFace.DOWN);
Dispenser d = (Dispenser) b.getState();
Inventory i = d.getInventory();
for (Ammo ammo : this.getAmmos()) {
if (i.contains(Material.SPLASH_POTION) && ammo.getName().equalsIgnoreCase("potion")){
ammo.setItem(i.getItem(i.first(Material.SPLASH_POTION)));
return ammo;
} else if (i.contains(Material.LINGERING_POTION) && ammo.getName().equalsIgnoreCase("potion")){
ammo.setItem(i.getItem(i.first(Material.LINGERING_POTION)));
return ammo;
} else if (i.contains(ammo.getItem().getType())) {
ItemStack stack = new ItemStack(i.getItem(i.first(ammo.getItem().getType())));
stack.setAmount(ammo.getItem().getAmount());
ammo.setItem(stack);
return ammo;
}
}
return null;
}
示例3: isMaterialAvailable
import org.bukkit.block.Dispenser; //导入方法依赖的package包/类
/**
* Checks if a specific material of given amount is available in dispenser
*/
public static boolean isMaterialAvailable(int amount, Material material, Location machineLocation)
{
if (machineLocation.getBlock().getType() == Material.DISPENSER)
{
Dispenser dispenserBlock = (Dispenser)((BlockState)machineLocation.getBlock().getState());
Inventory dispenserInventory = dispenserBlock.getInventory();
HashMap<Integer,? extends ItemStack> upgradeMaterials = dispenserInventory.all(material);
int totalMaterial = 0;
for(Entry<Integer,? extends ItemStack> entry : upgradeMaterials.entrySet())
{
totalMaterial += entry.getValue().getAmount();
}
return (totalMaterial >= amount);
}
else
{
return false;
}
}
示例4: getMaterialAvailableAmount
import org.bukkit.block.Dispenser; //导入方法依赖的package包/类
/**
* Returns how much of a specified material is available in dispenser
*/
public static int getMaterialAvailableAmount(Material material, Location machineLocation)
{
if (machineLocation.getBlock().getType() == Material.DISPENSER)
{
Dispenser dispenserBlock = (Dispenser)((BlockState)machineLocation.getBlock().getState());
Inventory dispenserInventory = dispenserBlock.getInventory();
HashMap<Integer,? extends ItemStack> upgradeMaterials = dispenserInventory.all(material);
int totalMaterial = 0;
for(Entry<Integer,? extends ItemStack> entry : upgradeMaterials.entrySet())
{
totalMaterial += entry.getValue().getAmount();
}
return totalMaterial;
}
else
{
return 0;
}
}
示例5: initializeInventory
import org.bukkit.block.Dispenser; //导入方法依赖的package包/类
/**
* Initializes the inventory for this machine
*/
public void initializeInventory()
{
switch(machineType)
{
case OREGIN:
Dispenser dispenserBlock = (Dispenser)machineLocation.getBlock().getState();
machineInventory = dispenserBlock.getInventory();
break;
case CLOAKER:
machineInventory = Bukkit.getServer().createInventory(null, 27, "Cloaker Inventory");
break;
case SMELTER:
break;
}
}
示例6: getInventory
import org.bukkit.block.Dispenser; //导入方法依赖的package包/类
/**
* 'cloakerInventory' public accessor
*/
public Inventory getInventory()
{
switch (machineType)
{
case OREGIN:
Dispenser dispenserBlock = (Dispenser)machineLocation.getBlock().getState();
machineInventory = dispenserBlock.getInventory();
return machineInventory;
case CLOAKER:
return machineInventory;
case SMELTER:
return machineInventory;
default:
return machineInventory;
}
}
示例7: setDispenserContents
import org.bukkit.block.Dispenser; //导入方法依赖的package包/类
private static void setDispenserContents(Block targetBlock, ItemStack[] items)
{
Dispenser dispenser = (Dispenser) targetBlock.getState();
Inventory disp_inv = dispenser.getInventory();
disp_inv.clear();
disp_inv.addItem(items);
}
示例8: addMaterial
import org.bukkit.block.Dispenser; //导入方法依赖的package包/类
/**
* Adds a specific material to a given dispenser and returns left overs
*/
public static HashMap<Integer,ItemStack> addMaterial(int amount, Material material, Location machineLocation)
{
if (machineLocation.getBlock().getType() == Material.DISPENSER)
{
Dispenser dispenserBlock = (Dispenser)machineLocation.getBlock().getState();
Inventory dispenserInventory = dispenserBlock.getInventory();
HashMap<Integer,ItemStack> leftOvers = dispenserInventory.addItem(new ItemStack(material, amount));
return leftOvers;
}
return null;
}
示例9: onPlayerInteract
import org.bukkit.block.Dispenser; //导入方法依赖的package包/类
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
if (e.getAction() != Action.RIGHT_CLICK_BLOCK)
return;
if (e.getClickedBlock().getState() instanceof Sign) {
Sign s = (Sign) e.getClickedBlock().getState();
if (s.getLine(0).equalsIgnoreCase("[hsmissile]")) {
if (MissileDetection.detectLauncher(s.getBlock())) {
s.setLine(0, "");
s.setLine(1, ChatColor.LIGHT_PURPLE + "[" + ChatColor.GOLD + "Missile" + ChatColor.LIGHT_PURPLE + "]");
s.setLine(2, ChatColor.LIGHT_PURPLE + "[" + ChatColor.RED + "Heat Seeking" + ChatColor.LIGHT_PURPLE + "]");
s.setLine(3, "");
s.update();
return;
}
}
if (s.getLine(1).equals(ChatColor.LIGHT_PURPLE + "[" + ChatColor.GOLD + "Missile" + ChatColor.LIGHT_PURPLE + "]")
&& s.getLine(2).equals(ChatColor.LIGHT_PURPLE + "[" + ChatColor.RED + "Heat Seeking" + ChatColor.LIGHT_PURPLE + "]")) {
Block ammoDispenserBlock = MissileDetection.getAmmoDispenser(s.getBlock());
Dispenser ammoDispenser = (Dispenser) ammoDispenserBlock.getState();
Inventory dispenserInv = ammoDispenser.getInventory();
//Checks if the dispenser does not have missile ammo, if it does not, then it returns.
if (!dispenserInv.containsAtLeast(Missile.standardMissileAmmo(), 1) && !dispenserInv.containsAtLeast(Missile.EMPMissileAmmo(), 1)) return;
if (Missile.missileCoolDownList.contains(e.getPlayer())) {
e.getPlayer().sendMessage(ChatColor.RED + "You are still on cooldown...");
return;
}
// Fires the missile
if (dispenserInv.containsAtLeast(Missile.standardMissileAmmo(), 1)) {
if (MissileMovement.activateMissile(ammoDispenserBlock, s, e.getPlayer(), "standard")) {
dispenserInv.removeItem(Missile.standardMissileAmmo());
// Removes one ammo from the dispenser
}
return;
}
if (dispenserInv.containsAtLeast(Missile.EMPMissileAmmo(), 1)) {
if (MissileMovement.activateMissile(ammoDispenserBlock, s, e.getPlayer(), "emp")) {
dispenserInv.removeItem(Missile.EMPMissileAmmo());
// Removes one ammo from the dispenser
}
return;
}
}
}
}
示例10: removeMaterial
import org.bukkit.block.Dispenser; //导入方法依赖的package包/类
/**
* Attempts to remove a specific material of given amount from dispenser
*/
public static boolean removeMaterial(int amount, Material material, Location machineLocation)
{
if (machineLocation.getBlock().getType() == Material.DISPENSER)
{
Dispenser dispenserBlock = (Dispenser)machineLocation.getBlock().getState();
Inventory dispenserInventory = dispenserBlock.getInventory();
HashMap<Integer,? extends ItemStack> upgradeMaterials = dispenserInventory.all(material);
int materialsToRemove = amount;
for(Entry<Integer,? extends ItemStack> entry : upgradeMaterials.entrySet())
{
if (materialsToRemove <= 0)
break;
if(entry.getValue().getAmount() == materialsToRemove)
{
dispenserInventory.setItem(entry.getKey(), new ItemStack(Material.AIR, 0));
materialsToRemove = 0;
}
else if(entry.getValue().getAmount() > materialsToRemove)
{
dispenserInventory.setItem(entry.getKey(), new ItemStack(material, (entry.getValue().getAmount() - materialsToRemove)));
materialsToRemove = 0;
}
else
{
int inStack = entry.getValue().getAmount();
dispenserInventory.setItem(entry.getKey(), new ItemStack(Material.AIR, 0));
materialsToRemove -= inStack;
}
}
return materialsToRemove == 0;
}
else
{
return false;
}
}