本文整理汇总了Java中org.bukkit.block.Dispenser类的典型用法代码示例。如果您正苦于以下问题:Java Dispenser类的具体用法?Java Dispenser怎么用?Java Dispenser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Dispenser类属于org.bukkit.block包,在下文中一共展示了Dispenser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onEntityExplode
import org.bukkit.block.Dispenser; //导入依赖的package包/类
@EventHandler
public void onEntityExplode(EntityExplodeEvent event) {
if (event.getEntity() != null) {
if (event.getEntity().getType() == EntityType.PRIMED_TNT) {
for (Block block : event.blockList()) {
if (block.getType() == Material.TNT && getWhoPlaced(event.getEntity()) != null) {
Location location = block.getLocation();
tntPlaced.put(location.getBlockX() + "," + location.getBlockY() + "," + location.getBlockZ(), getWhoPlaced(event.getEntity()));
}
}
for (Entity entity : event.getEntity().getNearbyEntities(8, 8, 8)) {
// F.debug("Found tnt");
if (entity instanceof TNTPrimed) {
UUID playerUUID = getWhoPlaced(event.getEntity());
if(playerUUID != null) {
Dispenser dispenser;
// F.debug("found placer: " + Bukkit.getServer().getPlayer(playerUUID));
entity.setMetadata("source", new FixedMetadataValue(GamePlate.getInstance(), playerUUID));
}
}
}
}
}
}
示例2: updatePearlHolder
import org.bukkit.block.Dispenser; //导入依赖的package包/类
/**
* 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);
}
}
示例3: getDispenserLocationFromRange
import org.bukkit.block.Dispenser; //导入依赖的package包/类
private List<Location> getDispenserLocationFromRange(int radius, Location location) {
List<Location> locations = new ArrayList<Location>();
for (int x = (radius * -1); x <= radius; x++) {
for (int y = (radius * -1); y <= radius; y++) {
for (int z = (radius * -1); z <= radius; z++) {
Block block = location.getWorld().getBlockAt(location.getBlockX() + x, location.getBlockY() + y, location.getBlockZ() + z);
if (block.getType() == Material.DISPENSER) {
if (block.getState() instanceof Dispenser) {
locations.add(block.getLocation());
}
}
}
}
}
return locations;
}
示例4: 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;
}
示例5: 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;
}
示例6: onBlockDispense
import org.bukkit.block.Dispenser; //导入依赖的package包/类
@EventHandler
public void onBlockDispense(BlockDispenseEvent event) {
if (event.getBlock().getType() == Material.DISPENSER) {
Dispenser diq = (Dispenser) event.getBlock().getState();
Block maybeSign = event
.getBlock()
.getWorld()
.getBlockAt(event.getBlock().getX(),
event.getBlock().getY() - 1,
event.getBlock().getZ()); // TODO
if (maybeSign.getState() instanceof Sign) {
if (plugin.isUnlimitedSign(((Sign) maybeSign.getState())
.getLine(0))) {
diq.getInventory().addItem(new ItemStack(event.getItem()));
}
}
}
}
示例7: onPower
import org.bukkit.block.Dispenser; //导入依赖的package包/类
@EventHandler
public void onPower(BlockDispenseEvent e) {
if(e.getBlock().getType() == Material.DISPENSER) {
if(hasNearbySign(e.getBlock())) {
org.bukkit.block.Sign sign = getSign(e.getBlock());
if(sign.getLine(0).equalsIgnoreCase(ChatColor.BLUE + "[Dispense]")) {
Dispenser disp = (Dispenser) e.getBlock().getState();
for(ItemStack stack : disp.getInventory().getContents()) {
if(stack != null) {
ItemStack clone = stack.clone();
clone.setAmount(64);
disp.getInventory().addItem(clone);
}
}
}
}
}
}
示例8: 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;
}
}
示例9: 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;
}
}
示例10: 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;
}
}
示例11: 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;
}
}
示例12: dispenserNukes
import org.bukkit.block.Dispenser; //导入依赖的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);
}
}
}
示例13: WorldInfo
import org.bukkit.block.Dispenser; //导入依赖的package包/类
public WorldInfo(World world) {
this.worldName = world.getName();
this.totalOnline = world.getPlayers().size();
for (Entity entity : world.getEntities()) {
this.totalEntity++;
if (entity instanceof Animals) {
this.totalAnimals++;
} else if (entity instanceof Monster) {
this.totalMonsters++;
} else if (entity instanceof Item) {
this.totalDropItem++;
}
}
for (Chunk loadedChunk : world.getLoadedChunks()) {
this.totalChunk++;
for (BlockState tiles : loadedChunk.getTileEntities()) {
this.totalTiles++;
if (tiles instanceof Hopper) {
this.totalHopper++;
} else if (tiles instanceof Chest) {
this.totalChest++;
} else if (tiles instanceof Dispenser) {
this.totalDispenser++;
} else if (tiles instanceof Dropper) {
this.totalDropper++;
} else if (tiles instanceof BrewingStand) {
this.totalBrewingStand++;
}
}
}
}
示例14: destroyThisBlock
import org.bukkit.block.Dispenser; //导入依赖的package包/类
public static void destroyThisBlock(Block blk, Town town) {
WarRegen.saveBlock(blk, town.getName(), false);
switch (blk.getType()) {
case TRAPPED_CHEST:
((Chest)blk.getState()).getBlockInventory().clear();
break;
case CHEST:
((Chest)blk.getState()).getBlockInventory().clear();
break;
case DISPENSER:
((Dispenser)blk.getState()).getInventory().clear();
break;
case BURNING_FURNACE:
case FURNACE:
((Furnace)blk.getState()).getInventory().clear();
break;
case DROPPER:
((Dropper)blk.getState()).getInventory().clear();
break;
case HOPPER:
((Hopper)blk.getState()).getInventory().clear();
break;
default:
break;
}
ItemManager.setTypeId(blk, CivData.AIR);
ItemManager.setData(blk, 0x0, true);
}
示例15: getInventory
import org.bukkit.block.Dispenser; //导入依赖的package包/类
public Inventory getInventory(Location loc) {
if (loc.getBlock().getState() instanceof MainChest) {
return ((MainChest) loc.getBlock().getState()).getInventory();
}
if (loc.getBlock().getState() instanceof RelatedChest) {
return ((RelatedChest) loc.getBlock().getState()).getInventory();
}
if (loc.getBlock().getState() instanceof Chest) {
return ((Chest) loc.getBlock().getState()).getInventory();
}
if (loc.getBlock().getState() instanceof DoubleChest) {
return ((DoubleChest) loc.getBlock().getState()).getInventory();
}
if (loc.getBlock().getState() instanceof BrewingStand) {
return ((BrewingStand) loc.getBlock().getState()).getInventory();
}
if (loc.getBlock().getState() instanceof Dispenser) {
return ((Dispenser) loc.getBlock().getState()).getInventory();
}
if (loc.getBlock().getState() instanceof Dropper) {
return ((Dropper) loc.getBlock().getState()).getInventory();
}
return null;
}