Search in sources :

Example 1 with Material

use of org.bukkit.Material in project TotalFreedomMod by TotalFreedom.

the class Command_dispfill method run.

@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
    if (args.length == 2) {
        int radius;
        try {
            radius = Math.max(5, Math.min(25, Integer.parseInt(args[0])));
        } catch (NumberFormatException ex) {
            sender.sendMessage("Invalid radius.");
            return true;
        }
        final List<ItemStack> items = new ArrayList<>();
        final String[] itemsRaw = StringUtils.split(args[1], ",");
        for (final String searchItem : itemsRaw) {
            Material material = Material.matchMaterial(searchItem);
            if (material == null) {
                try {
                    material = DepreciationAggregator.getMaterial(Integer.parseInt(searchItem));
                } catch (NumberFormatException ex) {
                }
            }
            if (material != null) {
                items.add(new ItemStack(material, 64));
            } else {
                sender.sendMessage("Skipping invalid item: " + searchItem);
            }
        }
        final ItemStack[] itemsArray = items.toArray(new ItemStack[items.size()]);
        int affected = 0;
        final Location centerLocation = playerSender.getLocation();
        final Block centerBlock = centerLocation.getBlock();
        for (int xOffset = -radius; xOffset <= radius; xOffset++) {
            for (int yOffset = -radius; yOffset <= radius; yOffset++) {
                for (int zOffset = -radius; zOffset <= radius; zOffset++) {
                    final Block targetBlock = centerBlock.getRelative(xOffset, yOffset, zOffset);
                    if (targetBlock.getLocation().distanceSquared(centerLocation) < (radius * radius)) {
                        if (targetBlock.getType().equals(Material.DISPENSER)) {
                            sender.sendMessage("Filling dispenser @ " + FUtil.formatLocation(targetBlock.getLocation()));
                            setDispenserContents(targetBlock, itemsArray);
                            affected++;
                        }
                    }
                }
            }
        }
        sender.sendMessage("Done. " + affected + " dispenser(s) filled.");
    } else {
        return false;
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location)

Example 2 with Material

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

the class dEntity method spawnAt.

public void spawnAt(Location location) {
    if (isCitizensNPC()) {
        if (getDenizenNPC().getCitizen().isSpawned()) {
            getDenizenNPC().getCitizen().teleport(location, TeleportCause.PLUGIN);
        } else {
            getDenizenNPC().getCitizen().spawn(location);
            entity = getDenizenNPC().getCitizen().getEntity();
            uuid = getDenizenNPC().getCitizen().getEntity().getUniqueId();
        }
    } else if (entity != null && isUnique()) {
        entity.teleport(location);
    } else {
        if (entity_type != null) {
            if (despawned_entity != null) {
                // If entity had a custom_script, use the script to rebuild the base entity.
                if (despawned_entity.custom_script != null) {
                // TODO: Build entity from custom script
                } else // Else, use the entity_type specified/remembered
                {
                    entity = entity_type.spawnNewEntity(location, mechanisms);
                }
                getLivingEntity().teleport(location);
                getLivingEntity().getEquipment().setArmorContents(despawned_entity.equipment);
                getLivingEntity().setHealth(despawned_entity.health);
                despawned_entity = null;
            } else {
                org.bukkit.entity.Entity ent = null;
                if (entity_type.getName().equals("PLAYER")) {
                    if (Depends.citizens == null) {
                        dB.echoError("Cannot spawn entity of type PLAYER!");
                        return;
                    } else {
                        dNPC npc = new dNPC(net.citizensnpcs.api.CitizensAPI.getNPCRegistry().createNPC(EntityType.PLAYER, data1));
                        npc.getCitizen().spawn(location);
                        entity = npc.getEntity();
                        uuid = entity.getUniqueId();
                    }
                } else if (entity_type.getName().equals("FALLING_BLOCK")) {
                    Material material = null;
                    if (data1 != null && dMaterial.matches(data1)) {
                        material = dMaterial.valueOf(data1).getMaterial();
                        // air or portals, keep trying
                        while (data1.equalsIgnoreCase("RANDOM") && ((!material.isBlock()) || material == Material.AIR || material == Material.PORTAL || material == Material.ENDER_PORTAL)) {
                            material = dMaterial.valueOf(data1).getMaterial();
                        }
                    }
                    // If material is null or not a block, default to SAND
                    if (material == null || (!material.isBlock())) {
                        material = Material.SAND;
                    }
                    byte materialData = 0;
                    // Get special data value from data2 if it is a valid integer
                    if (data2 != null && aH.matchesInteger(data2)) {
                        materialData = (byte) aH.getIntegerFrom(data2);
                    }
                    // This is currently the only way to spawn a falling block
                    ent = location.getWorld().spawnFallingBlock(location, material, materialData);
                    entity = ent;
                    uuid = entity.getUniqueId();
                } else {
                    ent = entity_type.spawnNewEntity(location, mechanisms);
                    entity = ent;
                    if (entity == null) {
                        if (dB.verbose) {
                            dB.echoError("Failed to spawn entity of type " + entity_type.getName());
                        }
                        return;
                    }
                    uuid = entity.getUniqueId();
                    if (entityScript != null) {
                        EntityScriptHelper.setEntityScript(entity, entityScript);
                    }
                    if (entity_type.getName().equals("PIG_ZOMBIE")) {
                        // a different weapon
                        if (!dItem.matches(data1)) {
                            data1 = "gold_sword";
                        }
                        ((PigZombie) entity).getEquipment().setItemInHand(dItem.valueOf(data1).getItemStack());
                    } else if (entity_type.getName().equals("SKELETON")) {
                        // a different weapon
                        if (!dItem.matches(data2)) {
                            data2 = "bow";
                        }
                        ((Skeleton) entity).getEquipment().setItemInHand(dItem.valueOf(data2).getItemStack());
                    }
                    // Otherwise, just use entity-specific methods manually
                    if (data1 != null) {
                        // TODO: Remove in 1.0
                        try {
                            // Allow creepers to be powered - replaced by EntityPowered
                            if (ent instanceof Creeper && data1.equalsIgnoreCase("POWERED")) {
                                ((Creeper) entity).setPowered(true);
                            } else // Allow setting of blocks held by endermen - replaced by EntityItem
                            if (ent instanceof Enderman && dMaterial.matches(data1)) {
                                ((Enderman) entity).setCarriedMaterial(dMaterial.valueOf(data1).getMaterialData());
                            } else // Allow setting of horse variants and colors - replaced by EntityColor
                            if (ent instanceof Horse) {
                                setSubtype("org.bukkit.entity.Horse", "org.bukkit.entity.Horse$Variant", "setVariant", data1);
                                if (data2 != null) {
                                    setSubtype("org.bukkit.entity.Horse", "org.bukkit.entity.Horse$Color", "setColor", data2);
                                }
                            } else // Allow setting of ocelot types - replaced by EntityColor
                            if (ent instanceof Ocelot) {
                                setSubtype("org.bukkit.entity.Ocelot", "org.bukkit.entity.Ocelot$Type", "setCatType", data1);
                            } else // Allow setting of sheep colors - replaced by EntityColor
                            if (ent instanceof Sheep) {
                                setSubtype("org.bukkit.entity.Sheep", "org.bukkit.DyeColor", "setColor", data1);
                            } else // Allow setting of skeleton types - replaced by EntitySkeleton
                            if (ent instanceof Skeleton) {
                                setSubtype("org.bukkit.entity.Skeleton", "org.bukkit.entity.Skeleton$SkeletonType", "setSkeletonType", data1);
                            } else // Allow setting of slime sizes - replaced by EntitySize
                            if (ent instanceof Slime && aH.matchesInteger(data1)) {
                                ((Slime) entity).setSize(aH.getIntegerFrom(data1));
                            } else // Allow setting of villager professions - replaced by EntityProfession
                            if (ent instanceof Villager) {
                                setSubtype("org.bukkit.entity.Villager", "org.bukkit.entity.Villager$Profession", "setProfession", data1);
                            }
                        } catch (Exception e) {
                            dB.echoError("Error setting custom entity data.");
                            dB.echoError(e);
                        }
                    }
                }
            }
        } else {
            dB.echoError("Cannot spawn a null dEntity!");
        }
        if (!isUnique()) {
            dB.echoError("Error spawning entity - bad entity type, blocked by another plugin, or tried to spawn in an unloaded chunk?");
            return;
        }
        for (Mechanism mechanism : mechanisms) {
            adjust(mechanism);
        }
        mechanisms.clear();
    }
}
Also used : Material(org.bukkit.Material)

Example 3 with Material

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

the class dEntity method getAttribute.

@Override
public String getAttribute(Attribute attribute) {
    if (attribute == null) {
        return null;
    }
    if (entity == null && entity_type == null) {
        if (npc != null) {
            return new Element(identify()).getAttribute(attribute);
        }
        dB.echoError("dEntity has returned null.");
        return null;
    }
    // -->
    if (attribute.startsWith("debug.log")) {
        dB.log(debug());
        return new Element(Boolean.TRUE.toString()).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("debug.no_color")) {
        return new Element(ChatColor.stripColor(debug())).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("debug")) {
        return new Element(debug()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("prefix")) {
        return new Element(prefix).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("type")) {
        return new Element("Entity").getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("entity_type")) {
        return new Element(entity_type.getName()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("is_spawned")) {
        return new Element(isSpawned()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("eid")) {
        return new Element(entity.getEntityId()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("uuid")) {
        return new Element(getUUID().toString()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("script")) {
        // TODO: Maybe return legit null?
        return new Element(entityScript == null ? "null" : entityScript).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("has_flag")) {
        String flag_name;
        if (attribute.hasContext(1)) {
            flag_name = attribute.getContext(1);
        } else {
            return null;
        }
        if (isPlayer() || isCitizensNPC()) {
            dB.echoError("Reading flag for PLAYER or NPC as if it were an ENTITY!");
            return null;
        }
        return new Element(FlagManager.entityHasFlag(this, flag_name)).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("flag")) {
        String flag_name;
        if (attribute.hasContext(1)) {
            flag_name = attribute.getContext(1);
        } else {
            return null;
        }
        if (isPlayer() || isCitizensNPC()) {
            dB.echoError("Reading flag for PLAYER or NPC as if it were an ENTITY!");
            return null;
        }
        if (attribute.getAttribute(2).equalsIgnoreCase("is_expired") || attribute.startsWith("isexpired")) {
            return new Element(!FlagManager.entityHasFlag(this, flag_name)).getAttribute(attribute.fulfill(2));
        }
        if (attribute.getAttribute(2).equalsIgnoreCase("size") && !FlagManager.entityHasFlag(this, flag_name)) {
            return new Element(0).getAttribute(attribute.fulfill(2));
        }
        if (FlagManager.entityHasFlag(this, flag_name)) {
            FlagManager.Flag flag = DenizenAPI.getCurrentInstance().flagManager().getEntityFlag(this, flag_name);
            return new dList(flag.toString(), true, flag.values()).getAttribute(attribute.fulfill(1));
        }
        return new Element(identify()).getAttribute(attribute);
    }
    // -->
    if (attribute.startsWith("list_flags")) {
        dList allFlags = new dList(DenizenAPI.getCurrentInstance().flagManager().listEntityFlags(this));
        dList searchFlags = null;
        if (!allFlags.isEmpty() && attribute.hasContext(1)) {
            searchFlags = new dList();
            String search = attribute.getContext(1);
            if (search.startsWith("regex:")) {
                try {
                    Pattern pattern = Pattern.compile(search.substring(6), Pattern.CASE_INSENSITIVE);
                    for (String flag : allFlags) {
                        if (pattern.matcher(flag).matches()) {
                            searchFlags.add(flag);
                        }
                    }
                } catch (Exception e) {
                    dB.echoError(e);
                }
            } else {
                search = CoreUtilities.toLowerCase(search);
                for (String flag : allFlags) {
                    if (CoreUtilities.toLowerCase(flag).contains(search)) {
                        searchFlags.add(flag);
                    }
                }
            }
        }
        return searchFlags == null ? allFlags.getAttribute(attribute.fulfill(1)) : searchFlags.getAttribute(attribute.fulfill(1));
    }
    if (entity == null) {
        return new Element(identify()).getAttribute(attribute);
    }
    // -->
    if (attribute.startsWith("custom_id")) {
        if (CustomNBT.hasCustomNBT(getLivingEntity(), "denizen-script-id")) {
            return new dScript(CustomNBT.getCustomNBT(getLivingEntity(), "denizen-script-id")).getAttribute(attribute.fulfill(1));
        } else {
            return new Element(entity.getType().name()).getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("name")) {
        return new Element(getName()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("saddle")) {
        if (getLivingEntity().getType() == EntityType.HORSE) {
            return new dItem(((Horse) getLivingEntity()).getInventory().getSaddle()).getAttribute(attribute.fulfill(1));
        } else if (getLivingEntity().getType() == EntityType.PIG) {
            return new dItem(((Pig) getLivingEntity()).hasSaddle() ? Material.SADDLE : Material.AIR).getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("horse_armor") || attribute.startsWith("horse_armour")) {
        if (getLivingEntity().getType() == EntityType.HORSE) {
            return new dItem(((Horse) getLivingEntity()).getInventory().getArmor()).getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("has_saddle")) {
        if (getLivingEntity().getType() == EntityType.HORSE) {
            return new Element(((Horse) getLivingEntity()).getInventory().getSaddle().getType() == Material.SADDLE).getAttribute(attribute.fulfill(1));
        } else if (getLivingEntity().getType() == EntityType.PIG) {
            return new Element(((Pig) getLivingEntity()).hasSaddle()).getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("item_in_hand") || attribute.startsWith("iteminhand")) {
        return new dItem(NMSHandler.getInstance().getEntityHelper().getItemInHand(getLivingEntity())).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("item_in_offhand") || attribute.startsWith("iteminoffhand")) {
        return new dItem(NMSHandler.getInstance().getEntityHelper().getItemInOffHand(getLivingEntity())).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("map_trace")) {
        EntityHelper.MapTraceResult mtr = NMSHandler.getInstance().getEntityHelper().mapTrace(getLivingEntity(), 200);
        if (mtr != null) {
            double x = 0;
            double y = 0;
            double basex = mtr.hitLocation.getX() - Math.floor(mtr.hitLocation.getX());
            double basey = mtr.hitLocation.getY() - Math.floor(mtr.hitLocation.getY());
            double basez = mtr.hitLocation.getZ() - Math.floor(mtr.hitLocation.getZ());
            if (mtr.angle == BlockFace.NORTH) {
                x = 128f - (basex * 128f);
            } else if (mtr.angle == BlockFace.SOUTH) {
                x = basex * 128f;
            } else if (mtr.angle == BlockFace.WEST) {
                x = basez * 128f;
            } else if (mtr.angle == BlockFace.EAST) {
                x = 128f - (basez * 128f);
            }
            y = 128f - (basey * 128f);
            return new dLocation(null, Math.round(x), Math.round(y)).getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("can_see")) {
        if (isLivingEntity() && attribute.hasContext(1) && dEntity.matches(attribute.getContext(1))) {
            dEntity toEntity = dEntity.valueOf(attribute.getContext(1));
            if (toEntity != null && toEntity.isSpawned()) {
                return new Element(getLivingEntity().hasLineOfSight(toEntity.getBukkitEntity())).getAttribute(attribute.fulfill(1));
            }
        }
    }
    // -->
    if (attribute.startsWith("eye_location")) {
        return new dLocation(getEyeLocation()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("eye_height")) {
        if (isLivingEntity()) {
            return new Element(getLivingEntity().getEyeHeight()).getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("location.cursor_on")) {
        int range = attribute.getIntContext(2);
        if (range < 1) {
            range = 50;
        }
        Set<Material> set = new HashSet<Material>();
        set.add(Material.AIR);
        attribute = attribute.fulfill(2);
        if (attribute.startsWith("ignore") && attribute.hasContext(1)) {
            List<dMaterial> ignoreList = dList.valueOf(attribute.getContext(1)).filter(dMaterial.class);
            for (dMaterial material : ignoreList) {
                set.add(material.getMaterial());
            }
            attribute = attribute.fulfill(1);
        }
        return new dLocation(getLivingEntity().getTargetBlock(set, range).getLocation()).getAttribute(attribute);
    }
    // -->
    if (attribute.startsWith("location.standing_on")) {
        return new dLocation(entity.getLocation().clone().add(0, -0.5f, 0)).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("location")) {
        return new dLocation(entity.getLocation()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("velocity")) {
        return new dLocation(entity.getVelocity().toLocation(entity.getWorld())).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("world")) {
        return new dWorld(entity.getWorld()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("can_pickup_items")) {
        if (isLivingEntity()) {
            return new Element(getLivingEntity().getCanPickupItems()).getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("fallingblock_material")) {
        return dMaterial.getMaterialFrom(((FallingBlock) entity).getMaterial()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("fall_distance")) {
        return new Element(entity.getFallDistance()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("fire_time")) {
        return new Duration(entity.getFireTicks() / 20).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("on_fire")) {
        return new Element(entity.getFireTicks() > 0).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("leash_holder") || attribute.startsWith("get_leash_holder")) {
        if (isLivingEntity() && getLivingEntity().isLeashed()) {
            return new dEntity(getLivingEntity().getLeashHolder()).getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("passenger") || attribute.startsWith("get_passenger")) {
        if (!entity.isEmpty()) {
            return new dEntity(entity.getPassenger()).getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("shooter") || attribute.startsWith("get_shooter")) {
        if (isProjectile() && hasShooter()) {
            return getShooter().getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("vehicle") || attribute.startsWith("get_vehicle")) {
        if (entity.isInsideVehicle()) {
            return new dEntity(entity.getVehicle()).getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("has_effect")) {
        boolean returnElement = false;
        if (attribute.hasContext(1)) {
            PotionEffectType effectType = PotionEffectType.getByName(attribute.getContext(1));
            for (org.bukkit.potion.PotionEffect effect : getLivingEntity().getActivePotionEffects()) {
                if (effect.getType().equals(effectType)) {
                    returnElement = true;
                }
            }
        } else if (!getLivingEntity().getActivePotionEffects().isEmpty()) {
            returnElement = true;
        }
        return new Element(returnElement).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("can_breed")) {
        return new Element(((Ageable) getLivingEntity()).canBreed()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("breeding") || attribute.startsWith("is_breeding")) {
        return new Element(NMSHandler.getInstance().getEntityHelper().isBreeding((Animals) getLivingEntity())).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("has_passenger")) {
        return new Element(!entity.isEmpty()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("empty") || attribute.startsWith("is_empty")) {
        return new Element(entity.isEmpty()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("inside_vehicle") || attribute.startsWith("is_inside_vehicle")) {
        return new Element(entity.isInsideVehicle()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("leashed") || attribute.startsWith("is_leashed")) {
        if (isLivingEntity()) {
            return new Element(getLivingEntity().isLeashed()).getAttribute(attribute.fulfill(1));
        } else {
            return Element.FALSE.getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("on_ground") || attribute.startsWith("is_on_ground")) {
        return new Element(entity.isOnGround()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("persistent") || attribute.startsWith("is_persistent")) {
        if (isLivingEntity()) {
            return new Element(!getLivingEntity().getRemoveWhenFarAway()).getAttribute(attribute.fulfill(1));
        } else {
            return Element.FALSE.getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("killer")) {
        return getPlayerFrom(getLivingEntity().getKiller()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("last_damage.amount")) {
        return new Element(getLivingEntity().getLastDamage()).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("last_damage.cause") && entity.getLastDamageCause() != null) {
        return new Element(entity.getLastDamageCause().getCause().name()).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("last_damage.duration")) {
        return new Duration((long) getLivingEntity().getNoDamageTicks()).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("oxygen.max")) {
        return new Duration((long) getLivingEntity().getMaximumAir()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("oxygen")) {
        return new Duration((long) getLivingEntity().getRemainingAir()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("remove_when_far")) {
        return new Element(getLivingEntity().getRemoveWhenFarAway()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("target")) {
        if (getBukkitEntity() instanceof Creature) {
            Entity target = ((Creature) getLivingEntity()).getTarget();
            if (target != null) {
                return new dEntity(target).getAttribute(attribute.fulfill(1));
            }
        }
        return null;
    }
    // -->
    if (attribute.startsWith("time_lived")) {
        return new Duration(entity.getTicksLived() / 20).getAttribute(attribute.fulfill(1));
    }
    // -->
    if ((attribute.startsWith("pickup_delay") || attribute.startsWith("pickupdelay")) && getBukkitEntity() instanceof Item) {
        return new Duration(((Item) getBukkitEntity()).getPickupDelay() * 20).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_9_R2) && attribute.startsWith("gliding")) {
        return new Element(getLivingEntity().isGliding()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_9_R2) && attribute.startsWith("glowing")) {
        return new Element(getLivingEntity().isGlowing()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("is_living")) {
        return new Element(isLivingEntity()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("is_mob")) {
        if (!isPlayer() && !isNPC()) {
            return Element.TRUE.getAttribute(attribute.fulfill(1));
        } else {
            return Element.FALSE.getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("is_npc")) {
        return new Element(isCitizensNPC()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("is_player")) {
        return new Element(isPlayer()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("is_projectile")) {
        return new Element(isProjectile()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("tameable") || attribute.startsWith("is_tameable")) {
        return new Element(EntityTame.describes(this)).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("ageable") || attribute.startsWith("is_ageable")) {
        return new Element(EntityAge.describes(this)).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("colorable") || attribute.startsWith("is_colorable")) {
        return new Element(EntityColor.describes(this)).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("experience") && getBukkitEntity() instanceof ExperienceOrb) {
        return new Element(((ExperienceOrb) getBukkitEntity()).getExperience()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("dragon_phase") && getBukkitEntity() instanceof EnderDragon) {
        return new Element(((EnderDragon) getLivingEntity()).getPhase().name()).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("describe")) {
        String escript = getEntityScript();
        return new Element("e@" + (escript != null && escript.length() > 0 ? escript : getEntityType().getLowercaseName()) + PropertyParser.getPropertiesString(this)).getAttribute(attribute.fulfill(1));
    }
    // Iterate through this object's properties' attributes
    for (Property property : PropertyParser.getProperties(this)) {
        String returned = property.getAttribute(attribute);
        if (returned != null) {
            return returned;
        }
    }
    return new Element(identify()).getAttribute(attribute);
}
Also used : FlagManager(net.aufdemrand.denizen.flags.FlagManager) Property(net.aufdemrand.denizencore.objects.properties.Property) Pattern(java.util.regex.Pattern) PotionEffectType(org.bukkit.potion.PotionEffectType) EntityHelper(net.aufdemrand.denizen.nms.interfaces.EntityHelper) Material(org.bukkit.Material) PotionEffect(org.bukkit.potion.PotionEffect)

Example 4 with Material

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

the class dLocation method adjust.

@Override
public void adjust(Mechanism mechanism) {
    Element value = mechanism.getValue();
    // -->
    if (mechanism.matches("block_type") && mechanism.requireObject(dMaterial.class)) {
        dMaterial mat = value.asType(dMaterial.class);
        byte data = mat.hasData() ? mat.getData() : 0;
        getBlock().setTypeIdAndData(mat.getMaterial().getId(), data, false);
    }
    // -->
    if (mechanism.matches("biome") && mechanism.requireObject(dBiome.class)) {
        value.asType(dBiome.class).getBiome().changeBlockBiome(this);
    }
    // -->
    if (mechanism.matches("spawner_type") && mechanism.requireObject(dEntity.class) && getBlock().getState() instanceof CreatureSpawner) {
        ((CreatureSpawner) getBlock().getState()).setSpawnedType(value.asType(dEntity.class).getBukkitEntityType());
    }
    // -->
    if (mechanism.matches("sign_contents") && getBlock().getState() instanceof Sign) {
        Sign state = (Sign) getBlock().getState();
        for (int i = 0; i < 4; i++) {
            state.setLine(i, "");
        }
        dList list = value.asType(dList.class);
        if (list.size() > 4) {
            dB.echoError("Sign can only hold four lines!");
        } else {
            for (int i = 0; i < list.size(); i++) {
                state.setLine(i, EscapeTags.unEscape(list.get(i)));
            }
        }
        state.update();
    }
    // -->
    if (mechanism.matches("skull_skin")) {
        final BlockState blockState = getBlock().getState();
        if (blockState instanceof Skull) {
            dList list = mechanism.getValue().asType(dList.class);
            String idString = list.get(0);
            PlayerProfile profile;
            if (idString.contains("-")) {
                UUID uuid = UUID.fromString(idString);
                profile = new PlayerProfile(null, uuid, null);
            } else {
                profile = new PlayerProfile(idString, null, null);
            }
            profile = NMSHandler.getInstance().fillPlayerProfile(profile);
            NMSHandler.getInstance().getBlockHelper().setPlayerProfile((Skull) blockState, profile);
        }
    }
    // -->
    if (mechanism.matches("command_block_name")) {
        if (getBlock().getType() == Material.COMMAND) {
            CommandBlock block = ((CommandBlock) getBlock().getState());
            block.setName(value.asString());
            block.update();
        }
    }
    // -->
    if (mechanism.matches("command_block")) {
        if (getBlock().getType() == Material.COMMAND) {
            CommandBlock block = ((CommandBlock) getBlock().getState());
            block.setCommand(value.asString());
            block.update();
        }
    }
    // -->
    if (mechanism.matches("furnace_burn_time")) {
        Material material = getBlock().getType();
        if (material == Material.FURNACE || material == Material.BURNING_FURNACE) {
            Furnace furnace = (Furnace) getBlock().getState();
            furnace.setBurnTime((short) value.asInt());
        }
    }
    // -->
    if (mechanism.matches("furnace_cook_time")) {
        Material material = getBlock().getType();
        if (material == Material.FURNACE || material == Material.BURNING_FURNACE) {
            Furnace furnace = (Furnace) getBlock().getState();
            furnace.setCookTime((short) value.asInt());
        }
    }
    // -->
    if (mechanism.matches("base_color")) {
        Banner banner = (Banner) getBlock().getState();
        banner.setBaseColor(DyeColor.valueOf(mechanism.getValue().asString().toUpperCase()));
        banner.update();
    }
    // -->
    if (mechanism.matches("patterns")) {
        List<org.bukkit.block.banner.Pattern> patterns = new ArrayList<org.bukkit.block.banner.Pattern>();
        dList list = mechanism.getValue().asType(dList.class);
        List<String> split;
        for (String string : list) {
            try {
                split = CoreUtilities.split(string, '/', 2);
                patterns.add(new org.bukkit.block.banner.Pattern(DyeColor.valueOf(split.get(0).toUpperCase()), PatternType.valueOf(split.get(1).toUpperCase())));
            } catch (Exception e) {
                dB.echoError("Could not apply pattern to banner: " + string);
            }
        }
        Banner banner = (Banner) getBlock().getState();
        banner.setPatterns(patterns);
        banner.update();
    }
    // -->
    if (mechanism.matches("head_rotation") && mechanism.requireInteger()) {
        ((Skull) getBlock().getState()).setRotation(getSkullBlockFace(value.asInt() - 1));
    }
    // -->
    if (mechanism.matches("data") && mechanism.hasValue()) {
        getBlock().setData((byte) value.asInt());
    }
    if (!mechanism.fulfilled()) {
        mechanism.reportInvalid();
    }
}
Also used : org.bukkit.block(org.bukkit.block) Pattern(java.util.regex.Pattern) PlayerProfile(net.aufdemrand.denizen.nms.util.PlayerProfile) Material(org.bukkit.Material)

Example 5 with Material

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

the class PathBlockExaminer method isPassable.

@Override
public PassableState isPassable(BlockSource source, PathPoint point) {
    Vector pos = point.getVector();
    Material above = source.getMaterialAt(pos.clone().add(UP));
    Material below = source.getMaterialAt(pos.clone().add(DOWN));
    Material in = source.getMaterialAt(pos);
    if (!below.isBlock() || !canStandOn(below)) {
        return PassableState.UNPASSABLE;
    }
    if (!canStandIn(above) || !canStandIn(in)) {
        return PassableState.UNPASSABLE;
    }
    return PassableState.PASSABLE;
}
Also used : net.aufdemrand.denizen.objects.dMaterial(net.aufdemrand.denizen.objects.dMaterial) Material(org.bukkit.Material) Vector(org.bukkit.util.Vector)

Aggregations

Material (org.bukkit.Material)427 ItemStack (org.bukkit.inventory.ItemStack)99 Block (org.bukkit.block.Block)87 EventHandler (org.bukkit.event.EventHandler)51 ArrayList (java.util.ArrayList)46 Player (org.bukkit.entity.Player)44 Location (org.bukkit.Location)42 Vector (org.bukkit.util.Vector)27 EntityType (org.bukkit.entity.EntityType)26 GlowBlock (net.glowstone.block.GlowBlock)24 Test (org.junit.Test)24 BlockFace (org.bukkit.block.BlockFace)23 Entity (org.bukkit.entity.Entity)22 MaterialData (org.bukkit.material.MaterialData)22 World (org.bukkit.World)20 HashMap (java.util.HashMap)19 IOException (java.io.IOException)17 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)16 File (java.io.File)15 HashSet (java.util.HashSet)13