use of org.bukkit.util.BlockIterator in project Denizen-For-Bukkit by DenizenScript.
the class ProjectileHitsScriptEvent method onProjectileHits.
@EventHandler
public void onProjectileHits(ProjectileHitEvent event) {
projectile = new dEntity(event.getEntity());
if (projectile.getLocation() == null) {
// No, I can't explain how or why this would ever happen... nonetheless, it appears it does happen sometimes.
return;
}
if (Double.isNaN(projectile.getLocation().getDirection().normalize().getX())) {
// I can't explain this one either. It also chooses to happen whenever it pleases.
return;
}
Block block = null;
try {
BlockIterator bi = new BlockIterator(projectile.getLocation().getWorld(), projectile.getLocation().toVector(), projectile.getLocation().getDirection().normalize(), 0, 4);
while (bi.hasNext()) {
block = bi.next();
if (block.getTypeId() != 0) {
break;
}
}
} catch (IllegalStateException ex) {
// As this error happens on no fault of the user, display no error message... just cancel the event.
return;
}
if (block == null) {
return;
}
material = dMaterial.getMaterialFrom(block.getType(), block.getData());
shooter = projectile.getShooter();
location = new dLocation(block.getLocation());
this.event = event;
fire();
}
use of org.bukkit.util.BlockIterator in project AreaShop by NLthijs48.
the class AddsignCommand method execute.
@Override
public void execute(CommandSender sender, String[] args) {
if (!sender.hasPermission("areashop.addsign")) {
plugin.message(sender, "addsign-noPermission");
return;
}
if (!(sender instanceof Player)) {
plugin.message(sender, "cmd-onlyByPlayer");
return;
}
Player player = (Player) sender;
// Get the sign
Block block = null;
BlockIterator blockIterator = new BlockIterator(player, 100);
while (blockIterator.hasNext() && block == null) {
Block next = blockIterator.next();
if (next.getType() != Material.AIR) {
block = next;
}
}
if (block == null || !(block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)) {
plugin.message(sender, "addsign-noSign");
return;
}
GeneralRegion region;
if (args.length > 1) {
// Get region by argument
region = plugin.getFileManager().getRegion(args[1]);
if (region == null) {
plugin.message(sender, "cmd-notRegistered", args[1]);
return;
}
} else {
// Get region by sign position
List<GeneralRegion> regions = Utils.getRegionsInSelection(new CuboidSelection(block.getWorld(), block.getLocation(), block.getLocation()));
if (regions.isEmpty()) {
plugin.message(sender, "addsign-noRegions");
return;
} else if (regions.size() > 1) {
plugin.message(sender, "addsign-couldNotDetect", regions.get(0).getName(), regions.get(1).getName());
return;
}
region = regions.get(0);
}
Sign sign = (Sign) block.getState().getData();
String profile = null;
if (args.length > 2) {
profile = args[2];
Set<String> profiles = plugin.getConfig().getConfigurationSection("signProfiles").getKeys(false);
if (!profiles.contains(profile)) {
plugin.message(sender, "addsign-wrongProfile", Utils.createCommaSeparatedList(profiles), region);
return;
}
}
RegionSign regionSign = SignsFeature.getSignByLocation(block.getLocation());
if (regionSign != null) {
plugin.message(sender, "addsign-alreadyRegistered", regionSign.getRegion());
return;
}
region.getSignsFeature().addSign(block.getLocation(), block.getType(), sign.getFacing(), profile);
if (profile == null) {
plugin.message(sender, "addsign-success", region);
} else {
plugin.message(sender, "addsign-successProfile", profile, region);
}
region.update();
}
use of org.bukkit.util.BlockIterator in project AreaShop by NLthijs48.
the class DelsignCommand method execute.
@Override
public void execute(CommandSender sender, String[] args) {
if (!sender.hasPermission("areashop.delsign")) {
plugin.message(sender, "delsign-noPermission");
return;
}
if (!(sender instanceof Player)) {
plugin.message(sender, "cmd-onlyByPlayer");
return;
}
Player player = (Player) sender;
// Get the sign
Block block = null;
BlockIterator blockIterator = new BlockIterator(player, 100);
while (blockIterator.hasNext() && block == null) {
Block next = blockIterator.next();
if (next.getType() != Material.AIR) {
block = next;
}
}
if (block == null || !(block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)) {
plugin.message(sender, "delsign-noSign");
return;
}
RegionSign regionSign = SignsFeature.getSignByLocation(block.getLocation());
if (regionSign == null) {
plugin.message(sender, "delsign-noRegion");
return;
}
plugin.message(sender, "delsign-success", regionSign.getRegion());
regionSign.remove();
}
use of org.bukkit.util.BlockIterator in project CommandHelper by EngineHub.
the class BukkitMCLivingEntity method getLineOfSight.
private List<Block> getLineOfSight(HashSet<Short> transparent, int maxDistance, int maxLength) {
if (maxDistance > 512) {
maxDistance = 512;
}
ArrayList<Block> blocks = new ArrayList<>();
Iterator<Block> itr = new BlockIterator(le, maxDistance);
while (itr.hasNext()) {
Block block = itr.next();
blocks.add(block);
if (maxLength != 0 && blocks.size() > maxLength) {
blocks.remove(0);
}
int id = block.getTypeId();
if (transparent == null) {
if (id != 0) {
break;
}
} else {
if (!transparent.contains((short) id)) {
break;
}
}
}
return blocks;
}
use of org.bukkit.util.BlockIterator in project MagicPlugin by elBukkit.
the class Targeting method initializeBlockIterator.
protected boolean initializeBlockIterator(Location location, double range) {
if (blockIterator != null) {
return true;
}
if (location.getBlockY() < 0) {
location = location.clone();
location.setY(0);
}
int maxHeight = location.getWorld().getMaxHeight();
if (location.getBlockY() > maxHeight) {
location = location.clone();
location.setY(maxHeight);
}
try {
blockIterator = new BlockIterator(location, yOffset, (int) Math.ceil(range));
} catch (Exception ex) {
if (Target.DEBUG_TARGETING) {
org.bukkit.Bukkit.getLogger().warning("Exception creating BlockIterator");
ex.printStackTrace();
}
// cross our fingers!
return false;
}
return true;
}
Aggregations