Search in sources :

Example 6 with LivingEntity

use of org.bukkit.entity.LivingEntity in project Denizen-For-Bukkit by DenizenScript.

the class dChunk method registerTags.

public static void registerTags() {
    // <--[tag]
    // @attribute <ch@chunk.add[<#>,<#>]>
    // @returns dChunk
    // @description
    // Returns the chunk with the specified coordinates added to it.
    // -->
    registerTag("add", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            if (!attribute.hasContext(1)) {
                dB.echoError("The tag ch@chunk.add[<#>,<#>] must have a value.");
                return null;
            }
            List<String> coords = CoreUtilities.split(attribute.getContext(1), ',');
            if (coords.size() < 2) {
                dB.echoError("The tag ch@chunk.add[<#>,<#>] requires two values!");
                return null;
            }
            double x = aH.getDoubleFrom(coords.get(0)) * 16;
            double z = aH.getDoubleFrom(coords.get(1)) * 16;
            return new dChunk(((dChunk) object).getCenter().clone().add(x, 0, z).getChunk()).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.sub[<#>,<#>]>
    // @returns dChunk
    // @description
    // Returns the chunk with the specified coordinates subtracted from it.
    // -->
    registerTag("sub", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            if (!attribute.hasContext(1)) {
                dB.echoError("The tag ch@chunk.add[<#>,<#>] must have a value.");
                return null;
            }
            List<String> coords = CoreUtilities.split(attribute.getContext(1), ',');
            if (coords.size() < 2) {
                dB.echoError("The tag ch@chunk.sub[<#>,<#>] requires two values!");
                return null;
            }
            double x = aH.getDoubleFrom(coords.get(0)) * 16;
            double z = aH.getDoubleFrom(coords.get(1)) * 16;
            return new dChunk(((dChunk) object).getCenter().clone().subtract(x, 0, z).getChunk()).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.is_loaded>
    // @returns Element(Boolean)
    // @description
    // Returns true if the chunk is currently loaded into memory.
    // -->
    registerTag("is_loaded", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return new Element(((dChunk) object).chunk.isLoaded()).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.x>
    // @returns Element(Number)
    // @description
    // Returns the x coordinate of the chunk.
    // -->
    registerTag("x", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return new Element(((dChunk) object).chunk.getX()).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.z>
    // @returns Element(Number)
    // @description
    // Returns the z coordinate of the chunk.
    // -->
    registerTag("z", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return new Element(((dChunk) object).chunk.getZ()).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.world>
    // @returns dWorld
    // @description
    // Returns the world associated with the chunk.
    // -->
    registerTag("world", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return dWorld.mirrorBukkitWorld(((dChunk) object).chunk.getWorld()).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.cuboid>
    // @returns dCuboid
    // @description
    // Returns a cuboid of this chunk.
    // -->
    registerTag("cuboid", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            dChunk chunk = (dChunk) object;
            return new dCuboid(new Location(chunk.getWorld(), chunk.getX() * 16, 0, chunk.getZ() * 16), new Location(chunk.getWorld(), chunk.getX() * 16 + 15, 255, chunk.getZ() * 16 + 15)).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.entities>
    // @returns dList(dEntity)
    // @description
    // Returns a list of entities in the chunk.
    // -->
    registerTag("entities", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            dList entities = new dList();
            for (Entity ent : ((dChunk) object).chunk.getEntities()) {
                entities.add(new dEntity(ent).identify());
            }
            return entities.getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.living_entities>
    // @returns dList(dEntity)
    // @description
    // Returns a list of living entities in the chunk. This includes Players, mobs, NPCs, etc., but excludes
    // dropped items, experience orbs, etc.
    // -->
    registerTag("living_entities", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            dList entities = new dList();
            for (Entity ent : ((dChunk) object).chunk.getEntities()) {
                if (ent instanceof LivingEntity) {
                    entities.add(new dEntity(ent).identify());
                }
            }
            return entities.getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.players>
    // @returns dList(dPlayer)
    // @description
    // Returns a list of players in the chunk.
    // -->
    registerTag("players", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            dList entities = new dList();
            for (Entity ent : ((dChunk) object).chunk.getEntities()) {
                if (dEntity.isPlayer(ent)) {
                    entities.add(new dEntity(ent).identify());
                }
            }
            return entities.getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.height_map>
    // @returns dList(Element)
    // @description
    // Returns a list of the height of each block in the chunk.
    // -->
    registerTag("height_map", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            int[] heightMap = ((dChunk) object).getHeightMap();
            List<String> height_map = new ArrayList<String>(heightMap.length);
            for (int i : heightMap) {
                height_map.add(String.valueOf(i));
            }
            return new dList(height_map).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.average_height>
    // @returns Element(Decimal)
    // @description
    // Returns the average height of the blocks in the chunk.
    // -->
    registerTag("average_height", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            int sum = 0;
            int[] heightMap = ((dChunk) object).getHeightMap();
            for (int i : heightMap) {
                sum += i;
            }
            return new Element(((double) sum) / heightMap.length).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.is_flat[#]>
    // @returns Element(Boolean)
    // @description
    // scans the heights of the blocks to check variance between them. If no number is supplied, is_flat will return
    // true if all the blocks are less than 2 blocks apart in height. Specifying a number will modify the number
    // criteria for determining if it is flat.
    // -->
    registerTag("is_flat", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            int tolerance = attribute.hasContext(1) && aH.matchesInteger(attribute.getContext(1)) ? Integer.valueOf(attribute.getContext(1)) : 2;
            int[] heightMap = ((dChunk) object).getHeightMap();
            int x = heightMap[0];
            for (int i : heightMap) {
                if (Math.abs(x - i) > tolerance) {
                    return Element.FALSE.getAttribute(attribute.fulfill(1));
                }
            }
            return Element.TRUE.getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.surface_blocks>
    // @returns dList(dLocation)
    // @description
    // Returns a list of the highest non-air surface blocks in the chunk.
    // -->
    registerTag("surface_blocks", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            dList surface_blocks = new dList();
            for (int x = 0; x < 16; x++) {
                for (int z = 0; z < 16; z++) {
                    surface_blocks.add(new dLocation(((dChunk) object).chunk.getBlock(x, ((dChunk) object).getSnapshot().getHighestBlockYAt(x, z) - 1, z).getLocation()).identify());
                }
            }
            return surface_blocks.getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.spawn_slimes>
    // @returns dList(dLocation)
    // @description
    // Returns whether the chunk is a specially located 'slime spawner' chunk.
    // -->
    registerTag("spawn_slimes", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            dChunk chunk = (dChunk) object;
            Random random = new Random(chunk.getWorld().getSeed() + chunk.getX() * chunk.getX() * 4987142 + chunk.getX() * 5947611 + chunk.getZ() * chunk.getZ() * 4392871L + chunk.getZ() * 389711 ^ 0x3AD8025F);
            return new Element(random.nextInt(10) == 0).getAttribute(attribute.fulfill(1));
        }
    });
    // <--[tag]
    // @attribute <ch@chunk.type>
    // @returns Element
    // @description
    // Always returns 'Chunk' for dChunk objects. All objects fetchable by the Object Fetcher will return the
    // type of object that is fulfilling this attribute.
    // -->
    registerTag("type", new TagRunnable() {

        @Override
        public String run(Attribute attribute, dObject object) {
            return new Element("Chunk").getAttribute(attribute.fulfill(1));
        }
    });
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Attribute(net.aufdemrand.denizencore.tags.Attribute) LivingEntity(org.bukkit.entity.LivingEntity) Location(org.bukkit.Location)

Example 7 with LivingEntity

use of org.bukkit.entity.LivingEntity in project Denizen-For-Bukkit by DenizenScript.

the class EntityInfected method setInfected.

public void setInfected(boolean bool) {
    if (bool) {
        if (infected.isCitizensNPC()) {
            NPC infected_npc = infected.getDenizenNPC().getCitizen();
            infected_npc.setBukkitEntityType(EntityType.ZOMBIE_VILLAGER);
        } else // TODO: Improve upon.
        if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_11_R1)) {
            LivingEntity entity = infected.getLivingEntity();
            // Make a new entity
            ZombieVillager infect = (ZombieVillager) entity.getLocation().getWorld().spawnEntity(infected.getLocation(), EntityType.ZOMBIE_VILLAGER);
            // Set health
            infect.setHealth(entity.getHealth());
            // Set equipment
            infect.getEquipment().setArmorContents(entity.getEquipment().getArmorContents());
            // Remove the Villager
            entity.remove();
            // Set the dEntity to the new entity
            infected.setEntity(infect);
        } else // TODO: Improve upon.
        if (infected.getBukkitEntity() instanceof Villager) {
            Villager villager = (Villager) infected.getBukkitEntity();
            // Make a new entity
            Zombie infect = (Zombie) villager.getLocation().getWorld().spawnEntity(infected.getLocation(), EntityType.ZOMBIE);
            infect.setVillager(true);
            // Set health
            infect.setHealth(villager.getHealth());
            // Set equipment
            infect.getEquipment().setArmorContents(villager.getEquipment().getArmorContents());
            // Remove the Villager
            villager.remove();
            // Set the dEntity to the new entity
            infected.setEntity(infect);
        } else // Much much easier
        if (infected.getBukkitEntity() instanceof Zombie) {
            ((Zombie) infected).setVillager(true);
        }
    }
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) LivingEntity(org.bukkit.entity.LivingEntity) Zombie(org.bukkit.entity.Zombie) ZombieVillager(org.bukkit.entity.ZombieVillager) Villager(org.bukkit.entity.Villager) ZombieVillager(org.bukkit.entity.ZombieVillager)

Example 8 with LivingEntity

use of org.bukkit.entity.LivingEntity in project EliteMobs by MagmaGuy.

the class StatsCommandHandler method statsHandler.

public void statsHandler(CommandSender commandSender) {
    int mobLevelSavingsCount = 0;
    int totalMobCount = 0;
    int aggressiveCount = 0;
    int passiveCount = 0;
    int blazeCount = 0;
    int caveSpiderCount = 0;
    int creeperCount = 0;
    int endermanCount = 0;
    int endermiteCount = 0;
    int huskCount = 0;
    int ironGolemCount = 0;
    int pigZombieCount = 0;
    int polarBearCount = 0;
    int silverfishCount = 0;
    int skeletonCount = 0;
    int spiderCount = 0;
    int strayCount = 0;
    int witchCount = 0;
    int witherSkeletonCount = 0;
    int zombieCount = 0;
    int zombieVillagerCount = 0;
    int chickenCount = 0;
    int cowCount = 0;
    int mushroomCowCount = 0;
    int pigCount = 0;
    int sheepCount = 0;
    for (World world : worldList) {
        for (LivingEntity livingEntity : world.getLivingEntities()) {
            if (livingEntity.hasMetadata(MetadataHandler.ELITE_MOB_MD) || livingEntity.hasMetadata(MetadataHandler.PASSIVE_ELITE_MOB_MD)) {
                totalMobCount++;
                if (livingEntity.hasMetadata(MetadataHandler.ELITE_MOB_MD)) {
                    mobLevelSavingsCount += livingEntity.getMetadata(MetadataHandler.ELITE_MOB_MD).get(0).asInt();
                    aggressiveCount++;
                    switch(livingEntity.getType()) {
                        case ZOMBIE:
                            zombieCount++;
                            break;
                        case HUSK:
                            huskCount++;
                            break;
                        case ZOMBIE_VILLAGER:
                            zombieVillagerCount++;
                            break;
                        case SKELETON:
                            skeletonCount++;
                            break;
                        case WITHER_SKELETON:
                            witherSkeletonCount++;
                            break;
                        case STRAY:
                            strayCount++;
                            break;
                        case PIG_ZOMBIE:
                            pigZombieCount++;
                            break;
                        case CREEPER:
                            creeperCount++;
                            break;
                        case SPIDER:
                            spiderCount++;
                            break;
                        case ENDERMAN:
                            endermanCount++;
                            break;
                        case CAVE_SPIDER:
                            caveSpiderCount++;
                            break;
                        case SILVERFISH:
                            silverfishCount++;
                            break;
                        case BLAZE:
                            blazeCount++;
                            break;
                        case WITCH:
                            witchCount++;
                            break;
                        case ENDERMITE:
                            endermiteCount++;
                            break;
                        case POLAR_BEAR:
                            polarBearCount++;
                            break;
                        case IRON_GOLEM:
                            ironGolemCount++;
                            break;
                        default:
                            getLogger().info("Error: Couldn't assign custom mob name due to unexpected aggressive boss mob (talk to the dev!)");
                            getLogger().info("Missing mob type: " + livingEntity.getType());
                            break;
                    }
                } else if (livingEntity.hasMetadata(MetadataHandler.PASSIVE_ELITE_MOB_MD)) {
                    //passive EliteMobs only stack at 50 right now
                    //TODO: redo this count at some other stage of this plugin's development
                    mobLevelSavingsCount += ConfigValues.defaultConfig.getInt("Passive EliteMob stack amount");
                    passiveCount++;
                    switch(livingEntity.getType()) {
                        case CHICKEN:
                            chickenCount++;
                            break;
                        case COW:
                            cowCount++;
                            break;
                        case MUSHROOM_COW:
                            mushroomCowCount++;
                            break;
                        case PIG:
                            pigCount++;
                            break;
                        case SHEEP:
                            sheepCount++;
                            break;
                        default:
                            getLogger().info("Error: Couldn't assign custom mob name due to unexpected passive boss mob (talk to the dev!)");
                            getLogger().info("Missing mob type: " + livingEntity.getType());
                            break;
                    }
                }
            }
        }
    }
    if (commandSender instanceof Player) {
        Player player = (Player) commandSender;
        player.sendMessage("§5§m-----------------------------------------------------");
        player.sendMessage("§a§lEliteMobs stats:");
        player.sendMessage("There are currently §l§6" + totalMobCount + " §f§rEliteMobs replacing §l§e" + mobLevelSavingsCount + " §f§rregular mobs.");
        if (aggressiveCount > 0) {
            String aggressiveCountMessage = "§c" + aggressiveCount + " §4Aggressive EliteMobs: §f";
            HashMap unsortedMobCount = new HashMap();
            unsortedMobCountFilter(unsortedMobCount, blazeCount, "blazes");
            unsortedMobCountFilter(unsortedMobCount, caveSpiderCount, "cave spiders");
            unsortedMobCountFilter(unsortedMobCount, creeperCount, "creepers");
            unsortedMobCountFilter(unsortedMobCount, endermanCount, "endermen");
            unsortedMobCountFilter(unsortedMobCount, endermiteCount, "endermites");
            unsortedMobCountFilter(unsortedMobCount, huskCount, "husks");
            unsortedMobCountFilter(unsortedMobCount, pigZombieCount, "zombiepigmen");
            unsortedMobCountFilter(unsortedMobCount, polarBearCount, "polar bears");
            unsortedMobCountFilter(unsortedMobCount, silverfishCount, "silverfish");
            unsortedMobCountFilter(unsortedMobCount, skeletonCount, "skeletons");
            unsortedMobCountFilter(unsortedMobCount, spiderCount, "spiders");
            unsortedMobCountFilter(unsortedMobCount, strayCount, "strays");
            unsortedMobCountFilter(unsortedMobCount, witchCount, "witches");
            unsortedMobCountFilter(unsortedMobCount, witherSkeletonCount, "wither skeletons");
            unsortedMobCountFilter(unsortedMobCount, zombieCount, "zombie");
            unsortedMobCountFilter(unsortedMobCount, zombieVillagerCount, "zombie villagers");
            player.sendMessage(messageStringAppender(aggressiveCountMessage, unsortedMobCount));
        }
        if (passiveCount > 0) {
            String passiveCountMessage = "§b" + passiveCount + " §3Passive EliteMobs: §f";
            HashMap unsortedMobCount = new HashMap();
            unsortedMobCountFilter(unsortedMobCount, chickenCount, "chickens");
            unsortedMobCountFilter(unsortedMobCount, cowCount, "cows");
            unsortedMobCountFilter(unsortedMobCount, ironGolemCount, "iron golems");
            unsortedMobCountFilter(unsortedMobCount, mushroomCowCount, "mushroom cows");
            unsortedMobCountFilter(unsortedMobCount, pigCount, "pigs");
            unsortedMobCountFilter(unsortedMobCount, sheepCount, "sheep");
            player.sendMessage(messageStringAppender(passiveCountMessage, unsortedMobCount));
        }
        player.sendMessage("§5§m-----------------------------------------------------");
    } else if (commandSender instanceof ConsoleCommandSender) {
        getServer().getConsoleSender().sendMessage("§5§m-------------------------------------------------------------");
        getServer().getConsoleSender().sendMessage("§a§lEliteMobs stats:");
        getServer().getConsoleSender().sendMessage("There are currently §l§6" + totalMobCount + " §f§rEliteMobs replacing §l§e" + mobLevelSavingsCount + " §f§rregular mobs.");
        if (aggressiveCount > 0) {
            String aggressiveCountMessage = "§c" + aggressiveCount + " §4Aggressive EliteMobs: §f";
            HashMap unsortedMobCount = new HashMap();
            unsortedMobCountFilter(unsortedMobCount, blazeCount, "blazes");
            unsortedMobCountFilter(unsortedMobCount, caveSpiderCount, "cave spiders");
            unsortedMobCountFilter(unsortedMobCount, creeperCount, "creepers");
            unsortedMobCountFilter(unsortedMobCount, endermanCount, "endermen");
            unsortedMobCountFilter(unsortedMobCount, endermiteCount, "endermites");
            unsortedMobCountFilter(unsortedMobCount, huskCount, "husks");
            unsortedMobCountFilter(unsortedMobCount, ironGolemCount, "iron golems");
            unsortedMobCountFilter(unsortedMobCount, pigZombieCount, "zombiepigmen");
            unsortedMobCountFilter(unsortedMobCount, polarBearCount, "polar bears");
            unsortedMobCountFilter(unsortedMobCount, silverfishCount, "silverfish");
            unsortedMobCountFilter(unsortedMobCount, skeletonCount, "skeletons");
            unsortedMobCountFilter(unsortedMobCount, spiderCount, "spiders");
            unsortedMobCountFilter(unsortedMobCount, strayCount, "strays");
            unsortedMobCountFilter(unsortedMobCount, witchCount, "witches");
            unsortedMobCountFilter(unsortedMobCount, witherSkeletonCount, "wither skeletons");
            unsortedMobCountFilter(unsortedMobCount, zombieCount, "zombie");
            unsortedMobCountFilter(unsortedMobCount, zombieVillagerCount, "zombie villagers");
            getServer().getConsoleSender().sendMessage(messageStringAppender(aggressiveCountMessage, unsortedMobCount));
        }
        if (passiveCount > 0) {
            String passiveCountMessage = "§b" + passiveCount + " §3Passive EliteMobs: §f";
            HashMap unsortedMobCount = new HashMap();
            unsortedMobCountFilter(unsortedMobCount, chickenCount, "chickens");
            unsortedMobCountFilter(unsortedMobCount, cowCount, "cows");
            unsortedMobCountFilter(unsortedMobCount, mushroomCowCount, "mushroom cows");
            unsortedMobCountFilter(unsortedMobCount, pigCount, "pigs");
            unsortedMobCountFilter(unsortedMobCount, sheepCount, "sheep");
            getServer().getConsoleSender().sendMessage(messageStringAppender(passiveCountMessage, unsortedMobCount));
        }
        getServer().getConsoleSender().sendMessage("§5§m-------------------------------------------------------------");
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) HashMap(java.util.HashMap) World(org.bukkit.World) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Example 9 with LivingEntity

use of org.bukkit.entity.LivingEntity in project EliteMobs by MagmaGuy.

the class AttackGravity method attackGravity.

@EventHandler
public void attackGravity(EntityDamageByEntityEvent event) {
    Entity damager = event.getDamager();
    Entity damagee = event.getEntity();
    if (damager.hasMetadata(powerMetadata) && damagee instanceof LivingEntity) {
        ((LivingEntity) damagee).addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, 2 * 20, 1));
    }
    if (damager instanceof Projectile) {
        if (ProjectileMetadataDetector.projectileMetadataDetector(((Projectile) damager), powerMetadata)) {
            ((LivingEntity) damagee).addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, 2 * 20, 1));
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) PotionEffect(org.bukkit.potion.PotionEffect) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 10 with LivingEntity

use of org.bukkit.entity.LivingEntity in project Glowstone by GlowstoneMC.

the class BlockType method rightClickBlock.

@Override
public final void rightClickBlock(GlowPlayer player, GlowBlock against, BlockFace face, ItemStack holding, Vector clickedLoc) {
    GlowBlock target = against.getRelative(face);
    // prevent building above the height limit
    if (target.getLocation().getY() >= target.getWorld().getMaxHeight()) {
        player.sendMessage(ChatColor.RED + "The height limit for this world is " + target.getWorld().getMaxHeight() + " blocks");
        return;
    }
    // check whether the block clicked against should absorb the placement
    BlockType againstType = ItemTable.instance().getBlock(against.getTypeId());
    if (againstType != null) {
        if (againstType.canAbsorb(against, face, holding)) {
            target = against;
        } else if (!target.isEmpty()) {
            // air can always be overridden
            BlockType targetType = ItemTable.instance().getBlock(target.getTypeId());
            if (targetType != null && !targetType.canOverride(target, face, holding)) {
                return;
            }
        }
    }
    if (getMaterial().isSolid()) {
        BlockBoundingBox box = new BlockBoundingBox(target);
        List<Entity> entities = target.getWorld().getEntityManager().getEntitiesInside(box, null);
        for (Entity e : entities) {
            if (e instanceof LivingEntity) {
                return;
            }
        }
    }
    // call canBuild event
    boolean canBuild = canPlaceAt(target, face);
    BlockCanBuildEvent canBuildEvent = new BlockCanBuildEvent(target, getId(), canBuild);
    if (!EventFactory.callEvent(canBuildEvent).isBuildable()) {
        //revert(player, target);
        return;
    }
    // grab states and update block
    GlowBlockState oldState = target.getState(), newState = target.getState();
    ItemType itemType = ItemTable.instance().getItem(holding.getType());
    if (itemType.getPlaceAs() == null) {
        placeBlock(player, newState, face, holding, clickedLoc);
    } else {
        placeBlock(player, newState, face, new ItemStack(itemType.getPlaceAs().getMaterial(), holding.getAmount(), holding.getDurability()), clickedLoc);
    }
    newState.update(true);
    // call blockPlace event
    BlockPlaceEvent event = new BlockPlaceEvent(target, oldState, against, holding, player, canBuild);
    EventFactory.callEvent(event);
    if (event.isCancelled() || !event.canBuild()) {
        oldState.update(true);
        return;
    }
    // play the placement sound, except for the current player (handled by the client)
    SoundUtil.playSoundAtLocationExcept(target.getLocation(), getPlaceSound().getSound(), (getPlaceSound().getVolume() + 1F) / 2F, getPlaceSound().getPitch() * 0.8F, player);
    // do any after-place actions
    afterPlace(player, target, holding, oldState);
    // deduct from stack if not in creative mode
    if (player.getGameMode() != GameMode.CREATIVE) {
        holding.setAmount(holding.getAmount() - 1);
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) BlockEntity(net.glowstone.block.entity.BlockEntity) GlowBlock(net.glowstone.block.GlowBlock) BlockCanBuildEvent(org.bukkit.event.block.BlockCanBuildEvent) GlowBlockState(net.glowstone.block.GlowBlockState) BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent) ItemType(net.glowstone.block.itemtype.ItemType) BlockBoundingBox(net.glowstone.entity.physics.BlockBoundingBox) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

LivingEntity (org.bukkit.entity.LivingEntity)324 Entity (org.bukkit.entity.Entity)170 Player (org.bukkit.entity.Player)123 Location (org.bukkit.Location)72 EventHandler (org.bukkit.event.EventHandler)64 Vector (org.bukkit.util.Vector)60 ItemStack (org.bukkit.inventory.ItemStack)47 ArrayList (java.util.ArrayList)41 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)37 PotionEffect (org.bukkit.potion.PotionEffect)34 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)30 Block (org.bukkit.block.Block)24 Mage (com.elmakers.mine.bukkit.api.magic.Mage)22 Projectile (org.bukkit.entity.Projectile)20 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)18 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)17 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)16 Target (com.elmakers.mine.bukkit.utility.Target)15 World (org.bukkit.World)14 Creature (org.bukkit.entity.Creature)14