Search in sources :

Example 1 with BlockIterator

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();
}
Also used : BlockIterator(org.bukkit.util.BlockIterator) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) Block(org.bukkit.block.Block) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) EventHandler(org.bukkit.event.EventHandler)

Example 2 with BlockIterator

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();
}
Also used : BlockIterator(org.bukkit.util.BlockIterator) Player(org.bukkit.entity.Player) CuboidSelection(com.sk89q.worldedit.bukkit.selections.CuboidSelection) GeneralRegion(me.wiefferink.areashop.regions.GeneralRegion) Block(org.bukkit.block.Block) Sign(org.bukkit.material.Sign) RegionSign(me.wiefferink.areashop.features.signs.RegionSign) RegionSign(me.wiefferink.areashop.features.signs.RegionSign)

Example 3 with BlockIterator

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();
}
Also used : BlockIterator(org.bukkit.util.BlockIterator) Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) RegionSign(me.wiefferink.areashop.features.signs.RegionSign)

Example 4 with BlockIterator

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;
}
Also used : BlockIterator(org.bukkit.util.BlockIterator) ArrayList(java.util.ArrayList) MCBlock(com.laytonsmith.abstraction.blocks.MCBlock) Block(org.bukkit.block.Block) BukkitMCBlock(com.laytonsmith.abstraction.bukkit.blocks.BukkitMCBlock)

Example 5 with BlockIterator

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;
}
Also used : BlockIterator(org.bukkit.util.BlockIterator)

Aggregations

BlockIterator (org.bukkit.util.BlockIterator)23 Block (org.bukkit.block.Block)20 Player (org.bukkit.entity.Player)10 Location (org.bukkit.Location)7 Material (org.bukkit.Material)6 EventHandler (org.bukkit.event.EventHandler)6 Entity (org.bukkit.entity.Entity)5 ItemStack (org.bukkit.inventory.ItemStack)5 ArrayList (java.util.ArrayList)4 ASkyBlock (com.wasteofplastic.acidisland.ASkyBlock)3 ASkyBlock (com.wasteofplastic.askyblock.ASkyBlock)3 RegionSign (me.wiefferink.areashop.features.signs.RegionSign)3 World (org.bukkit.World)3 HashMultiset (com.google.common.collect.HashMultiset)2 Multiset (com.google.common.collect.Multiset)2 Island (com.wasteofplastic.acidisland.Island)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 FileWriter (java.io.FileWriter)2 FilenameFilter (java.io.FilenameFilter)2