本文整理汇总了Java中org.bukkit.util.BlockIterator.next方法的典型用法代码示例。如果您正苦于以下问题:Java BlockIterator.next方法的具体用法?Java BlockIterator.next怎么用?Java BlockIterator.next使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.util.BlockIterator
的用法示例。
在下文中一共展示了BlockIterator.next方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTarget
import org.bukkit.util.BlockIterator; //导入方法依赖的package包/类
public static <T extends Entity> T getTarget(Player player, int range, Collection<T> entities) {
BlockIterator iterator = new BlockIterator(player, range);
while (iterator.hasNext()) {
Block block = iterator.next();
for (T entity : entities) {
int accuracy = 2;
for (int offX = -accuracy; offX < accuracy; offX++) {
for (int offY = -accuracy; offY < accuracy; offY++) {
for (int offZ = -accuracy; offZ < accuracy; offZ++) {
if (entity.getLocation().getBlock().getRelative(offX, offY, offZ).equals(block)) {
return entity;
}
}
}
}
}
}
return null;
}
示例2: getTarget
import org.bukkit.util.BlockIterator; //导入方法依赖的package包/类
private static Entity getTarget(final Player player) {
try {
BlockIterator iterator = new BlockIterator(player.getWorld(), player
.getLocation().toVector(), player.getEyeLocation()
.getDirection(), 0, 10);
while (iterator.hasNext()) {
Block item = iterator.next();
for (Entity entity : player.getNearbyEntities(10, 10, 10)) {
int acc = 2;
for (int y = -acc; y < acc; y++){
if (entity.getLocation().getBlock()
.getRelative(0, y, 0).equals(item)) {
return entity;
}
}
}
}
} catch(IllegalStateException ignored){}
return null;
}
示例3: getTargetBlock
import org.bukkit.util.BlockIterator; //导入方法依赖的package包/类
public static Block getTargetBlock(@Nullable Set<Material> transparent,
@Nonnull Location location, int maxDistance) {
Preconditions.checkNotNull(location, "location cannot be null.");
if (maxDistance > 120) {
maxDistance = 120;
}
Block result = null;
BlockIterator itr = new BlockIterator(location, 0, maxDistance);
while (itr.hasNext()) {
result = itr.next();
Material material = result.getType();
if (transparent == null) {
if (!material.equals(Material.AIR)) {
break;
}
} else if (!transparent.contains(material)) {
break;
}
}
return result;
}
示例4: getTargetEntity
import org.bukkit.util.BlockIterator; //导入方法依赖的package包/类
private LivingEntity getTargetEntity(int range) {
BlockIterator iterator = new BlockIterator(player, range);
while (iterator.hasNext()) {
Block block = iterator.next();
for (Entity entity : player.getNearbyEntities(range, range, range)) {
if (entity instanceof LivingEntity) {
int accuracy = 2;
for (int offX = -accuracy; offX < accuracy; offX++) {
for (int offY = -accuracy; offY < accuracy; offY++) {
for (int offZ = -accuracy; offZ < accuracy; offZ++) {
if (entity.getLocation().getBlock().getRelative(offX, offY, offZ).equals(block)) {
return (LivingEntity) entity;
}
}
}
}
}
}
}
return null;
}
示例5: getTargetBlock
import org.bukkit.util.BlockIterator; //导入方法依赖的package包/类
private Block getTargetBlock(Player player) {
BlockIterator iterator = new BlockIterator(player.getEyeLocation(), 0D, 10);
Block block = null;
while (iterator.hasNext()) {
Block b = iterator.next();
if (b != null && b.getType() != Material.AIR) {
block = b;
break;
}
}
if (block == null) {
plugin.getMessageManager().getMessage("errors.must_look_at_sign").sendTo(player);
return null;
}
if (!(block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN)) {
plugin.getMessageManager().getMessage("errors.block_not_sign").sendTo(player);
return null;
}
return block;
}
示例6: getTargetBlock
import org.bukkit.util.BlockIterator; //导入方法依赖的package包/类
/**
* Iterates over blocks in the direction the player is looking until the
* max distance is reached or a block that isn't {@link org.bukkit.Material#AIR}
* is found.
*
* @param player The {@link Player}.
* @param maxDistance The max distance to search.
*
* @return The {@link Block} that was found or null if the max distance was reached.
*/
@Nullable
public static Block getTargetBlock(Player player, int maxDistance) {
PreCon.notNull(player);
PreCon.positiveNumber(maxDistance);
BlockIterator bit = new BlockIterator(player, maxDistance);
Block next;
while(bit.hasNext())
{
next = bit.next();
if (next != null && next.getType() != Material.AIR)
return next;
}
return null;
}
示例7: getTarget
import org.bukkit.util.BlockIterator; //导入方法依赖的package包/类
private Entity getTarget(Player player) {
BlockIterator iterator = new BlockIterator(player.getWorld(), player
.getLocation().toVector(), player.getEyeLocation()
.getDirection(), 0, 100);
Entity target = null;
while (iterator.hasNext()) {
Block item = iterator.next();
for (Entity entity : player.getNearbyEntities(100, 100, 100)) {
int acc = 2;
for (int x = -acc; x < acc; x++)
for (int z = -acc; z < acc; z++)
for (int y = -acc; y < acc; y++)
if (entity.getLocation().getBlock()
.getRelative(x, y, z).equals(item))
return target = entity;
}
}
return target;
}
示例8: getTarget
import org.bukkit.util.BlockIterator; //导入方法依赖的package包/类
private Entity getTarget(Player player) {
BlockIterator iterator = new BlockIterator(player.getWorld(), player
.getLocation().toVector(), player.getEyeLocation()
.getDirection(), 0, 100);
Entity target = null;
while (iterator.hasNext()) {
Block item = iterator.next();
for (Entity entity : player.getNearbyEntities(100, 100, 100)) {
int acc = 2;
for (int x = -acc; x < acc; x++)
for (int z = -acc; z < acc; z++)
for (int y = -acc; y < acc; y++)
if (entity.getLocation().getBlock()
.getRelative(x, y, z).equals(item))
return target = entity;
}
}
return target;
}
示例9: getTarget
import org.bukkit.util.BlockIterator; //导入方法依赖的package包/类
/**
* Gets the player's target entity
*
* @param player
* The player to get the target of
* @return Null if there is no target
*/
public Entity getTarget(Player player) {
BlockIterator iterator = new BlockIterator(player.getWorld(), player.getLocation().toVector(), player
.getEyeLocation().getDirection(), 0, 100);
while (iterator.hasNext()) {
Block item = iterator.next();
for (Entity entity : player.getNearbyEntities(10, 10, 10)) {
int acc = 2;
for (int x = -acc; x < acc; x++) {
for (int z = -acc; z < acc; z++) {
for (int y = -acc; y < acc; y++) {
if (entity.getLocation().getBlock().getRelative(x, y, z).equals(item)) {
return entity;
}
}
}
}
}
}
return null;
}
示例10: onProjectileHitEvent
import org.bukkit.util.BlockIterator; //导入方法依赖的package包/类
@EventHandler
public void onProjectileHitEvent(ProjectileHitEvent event) {
final Projectile projectile = event.getEntity();
final ProjectileDefinition projectileDefinition = Projectiles.getProjectileDefinition(projectile);
if(projectileDefinition == null) return;
final Filter filter = projectileDefinition.destroyFilter();
if(filter == null) return;
final BlockIterator blockIterator = new BlockIterator(projectile.getWorld(), projectile.getLocation().toVector(), projectile.getVelocity().normalize(), 0d, 2);
Block hitBlock = null;
while(blockIterator.hasNext()) {
hitBlock = blockIterator.next();
if(hitBlock.getType() != Material.AIR) break;
}
if(hitBlock != null) {
final MatchPlayer shooter = projectile.getShooter() instanceof Player ? getMatch().getPlayer((Player) projectile.getShooter()) : null;
final IQuery query = shooter != null ? new PlayerBlockEventQuery(shooter, event, hitBlock.getState())
: new BlockEventQuery(event, hitBlock);
if(filter.query(query).isAllowed()) {
final BlockTransformEvent bte = new BlockTransformEvent(event, hitBlock, Material.AIR);
match.callEvent(bte);
if(!bte.isCancelled()) {
hitBlock.setType(Material.AIR);
projectile.remove();
}
}
}
}
示例11: getTargetLiving
import org.bukkit.util.BlockIterator; //导入方法依赖的package包/类
@Override
public LivingEntity getTargetLiving() {
if (livingEntityTarget != null)
return livingEntityTarget;
int range = 100;
Player player = getPlayer();
BlockIterator iterator = new BlockIterator(player, range);
List<Entity> entities = player.getNearbyEntities(range, range, range);
while (iterator.hasNext()) {
Block block = iterator.next();
for (Entity entity : entities) {
if (entity instanceof LivingEntity) {
int accuracy = 2;
for (int offX = -accuracy; offX < accuracy; offX++) {
for (int offY = -accuracy; offY < accuracy; offY++) {
for (int offZ = -accuracy; offZ < accuracy; offZ++) {
if (entity.getLocation().getBlock().getRelative(offX, offY, offZ).equals(block)) {
return livingEntityTarget = (LivingEntity) entity;
}
}
}
}
}
}
}
return livingEntityTarget = null;
}
示例12: getTargetPlayer
import org.bukkit.util.BlockIterator; //导入方法依赖的package包/类
public Player getTargetPlayer(int range) {
ConfigManager.load("blacklist.yml", "");
List<String> blacklist = ConfigManager.get("blacklist.yml").getStringList("list");
List<Material> materials = new ArrayList<Material>();
for(String s : blacklist){
materials.add(Material.valueOf(s));
}
BlockIterator bItr = new BlockIterator(player, range);
Block block;
Location loc;
int bx, by, bz;
double ex, ey, ez;
// loop through player's line of sight
while (bItr.hasNext()) {
block = bItr.next();
if(materials.contains(block.getType()))
bItr.next();
bx = block.getX();
by = block.getY();
bz = block.getZ();
// check for entities near this block in the line of sight
for (Entity e : player.getNearbyEntities(range, range, range)) {
loc = e.getLocation();
ex = loc.getX();
ey = loc.getY();
ez = loc.getZ();
if ((bx - .75 <= ex && ex <= bx + 1.75) && (bz - .75 <= ez && ez <= bz + 1.75)
&& (by - 1 <= ey && ey <= by + 2.5)) {
// entity is close enough, set target and stop
if(e instanceof Player){
return (Player)e;
}
}
}
}
return null;
}
示例13: getTargetEntity
import org.bukkit.util.BlockIterator; //导入方法依赖的package包/类
public Entity getTargetEntity(int range) {
ConfigManager.load("blacklist.yml", "");
List<String> blacklist = ConfigManager.get("blacklist.yml").getStringList("list");
List<Material> materials = new ArrayList<Material>();
for(String s : blacklist){
materials.add(Material.valueOf(s));
}
BlockIterator bItr = new BlockIterator(player, range);
Block block;
Location loc;
int bx, by, bz;
double ex, ey, ez;
// loop through player's line of sight
while (bItr.hasNext()) {
block = bItr.next();
if(materials.contains(block.getType()))
bItr.next();
bx = block.getX();
by = block.getY();
bz = block.getZ();
// check for entities near this block in the line of sight
for (Entity e : player.getNearbyEntities(range, range, range)) {
loc = e.getLocation();
ex = loc.getX();
ey = loc.getY();
ez = loc.getZ();
if ((bx - .75 <= ex && ex <= bx + 1.75) && (bz - .75 <= ez && ez <= bz + 1.75)
&& (by - 1 <= ey && ey <= by + 2.5)) {
// entity is close enough, set target and stop
return e;
}
}
}
return null;
}
示例14: sell
import org.bukkit.util.BlockIterator; //导入方法依赖的package包/类
@SubCommand(value = "sell", permission = "heh.signshop.sell")
public void sell(CommandSender sender, CommandHandler.Arguments args) {
if (args.length() != 3) {
msg(sender, "manual.shop.sell.usage");
return;
}
Player player = asPlayer(sender);
BlockIterator blockIterator = new BlockIterator(player, 5);
while (blockIterator.hasNext()) {
Block block = blockIterator.next();
if (SignShopManager.isSign(block)) {
Sign sign = plugin.signShopManager.getSign(block);
if (sign != null && player.getUniqueId().equals(sign.getOwner())) {
if (plugin.signShopManager.getItemCount(player) >= plugin.signShopManager.getSlotLimit(player)) {
player.sendMessage(I18n.format("user.signshop.not_enough_slot"));
return;
}
ItemStack itemStack = getItemInHand(sender).clone();
double unitPrice = args.nextDouble("#.##");
if (!(unitPrice >= 0.01)) {
msg(sender, "user.error.not_double");
return;
}
if(MarketManager.containsBook(itemStack)){
msg(sender,"user.error.shulker_box_contains_book");
return;
}
if (itemStack.getAmount() > 0) {
plugin.signShopManager.addItemToShop(player.getUniqueId(), itemStack.clone(),
itemStack.getAmount(), unitPrice, ShopMode.SELL);
player.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
player.sendMessage(I18n.format("user.signshop.buy.add"));
plugin.signShopManager.updateGUI(player.getUniqueId(), ShopMode.SELL);
}
return;
}
}
}
player.sendMessage(I18n.format("user.signshop.not_sign"));
}
示例15: getTargetBlock
import org.bukkit.util.BlockIterator; //导入方法依赖的package包/类
public static Block getTargetBlock(Player player, int maxDistance, Set<Material> transparentMaterials) {
final BlockIterator iterator = new BlockIterator(player.getLocation(), player.getEyeHeight(), maxDistance);
Block result = player.getLocation().getBlock().getRelative(BlockFace.UP);
while (iterator.hasNext()) {
result = iterator.next();
if (result.getType() != Material.AIR && !transparentMaterials.contains(result.getType())) {
return result;
}
}
return result;
}