Package net.aufdemrand.denizen.objects

Examples of net.aufdemrand.denizen.objects.Element


            if (!scriptEntry.hasObject("qty")
                    && arg.matchesPrefix("q", "qty", "quantity")
                    && arg.matchesPrimitive(aH.PrimitiveType.Double)) {
                scriptEntry.addObject("qty", arg.asElement());
                scriptEntry.addObject("set_quantity"new Element(true));
            }

            else if (!scriptEntry.hasObject("type")
                        && arg.matches("money", "coins"))
                scriptEntry.addObject("type", Type.MONEY);

            else if (!scriptEntry.hasObject("type")
                        && arg.matches("xp", "exp", "experience"))
                scriptEntry.addObject("type", Type.EXP);

            else if (!scriptEntry.hasObject("engrave")
                        && arg.matches("engrave"))
                scriptEntry.addObject("engrave"new Element(true));

            else if (!scriptEntry.hasObject("unlimit_stack_size")
                    && arg.matches("unlimit_stack_size"))
                scriptEntry.addObject("unlimit_stack_size", new Element(true));

            else if (!scriptEntry.hasObject("items")
                        && !scriptEntry.hasObject("type")
                        && arg.matchesArgumentList(dItem.class)) {
                scriptEntry.addObject("items", dList.valueOf(arg.raw_value.replace("item:", "")).filter(dItem.class, scriptEntry));
            }

            else if (!scriptEntry.hasObject("inventory")
                        && arg.matchesPrefix("t", "to")
                        && arg.matchesArgumentType(dInventory.class))
                scriptEntry.addObject("inventory", arg.asType(dInventory.class));

            else if (!scriptEntry.hasObject("slot")
                    && arg.matchesPrefix("slot")
                    && arg.matchesPrimitive(aH.PrimitiveType.Integer))
                scriptEntry.addObject("slot", arg.asElement());

            else
                arg.reportUnhandled();

        }

        scriptEntry.defaultObject("type", Type.ITEM)
                .defaultObject("engrave"new Element(false))
                .defaultObject("unlimit_stack_size", new Element(false))
                .defaultObject("qty", new Element(1))
                .defaultObject("slot", new Element(1));

        Type type = (Type) scriptEntry.getObject("type");

        if (type != Type.MONEY && scriptEntry.getObject("inventory") == null)
            scriptEntry.addObject("inventory", ((BukkitScriptEntryData)scriptEntry.entryData).hasPlayer() ? ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getInventory(): null);
View Full Code Here


    }

    @Override
    public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

        Element engrave = scriptEntry.getElement("engrave");
        Element unlimit_stack_size = scriptEntry.getElement("unlimit_stack_size");
        dInventory inventory = (dInventory) scriptEntry.getObject("inventory");
        Element qty = scriptEntry.getElement("qty");
        Type type = (Type) scriptEntry.getObject("type");
        Element slot = scriptEntry.getElement("slot");

        Object items_object = scriptEntry.getObject("items");
        List<dItem> items = null;

        if (items_object != null)
            items = (List<dItem>) items_object;

        dB.report(scriptEntry, getName(),
                aH.debugObj("Type", type.name())
                        + (inventory != null ? inventory.debug(): "")
                        + aH.debugObj("Quantity", qty.asDouble())
                        + engrave.debug()
                        + unlimit_stack_size.debug()
                        + (items != null ? aH.debugObj("Items", items) : "")
                        + slot.debug());

        switch (type) {

            case MONEY:
                if(Depends.economy != null)
                    Depends.economy.depositPlayer(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getName(), qty.asDouble());
                else
                    dB.echoError("No economy loaded! Have you installed Vault and a compatible economy plugin?");
                break;

            case EXP:
                ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getPlayerEntity().giveExp(qty.asInt());
                break;

            case ITEM:
                boolean set_quantity = scriptEntry.hasObject("set_quantity");
                boolean limited = !unlimit_stack_size.asBoolean();
                for (dItem item : items) {
                    ItemStack is = item.getItemStack();
                    if (is.getType() == Material.AIR) {
                        dB.echoError("Cannot give air!");
                        continue;
                    }
                    if (set_quantity)
                        is.setAmount(qty.asInt());
                    if (engrave.asBoolean()) is = CustomNBT.addCustomNBT(item.getItemStack(), "owner", ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getName());

                    List<ItemStack> leftovers = inventory.addWithLeftovers(slot.asInt()-1, limited, is);

                    if (!leftovers.isEmpty()) {
                        dB.echoDebug (scriptEntry, "The inventory didn't have enough space, the rest of the items have been placed on the floor.");
                        for (ItemStack leftoverItem : leftovers)
                            inventory.getLocation().getWorld().dropItem(inventory.getLocation(), leftoverItem);
View Full Code Here

            else arg.reportUnhandled();
        }

        if (!scriptEntry.hasObject("amount"))
            scriptEntry.addObject("amount", new Element(-1));

        if (!specified_targets) {
            List<dEntity> entities = new ArrayList<dEntity>();
            if (((BukkitScriptEntryData)scriptEntry.entryData).getPlayer() != null)
                entities.add(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getDenizenEntity());
View Full Code Here

    public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

        List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
        if (entities == null)
            return;
        Element amountelement = scriptEntry.getElement("amount");

        dB.report(scriptEntry, getName(), amountelement.debug() + aH.debugObj("entities", entities));
        if (amountelement.asDouble() == -1)
            for (dEntity entity : entities)
                entity.getLivingEntity().setHealth(entity.getLivingEntity().getMaxHealth());
        else {
            double amount = amountelement.asDouble();
            for (dEntity entity : entities)
                if (entity.getLivingEntity().getHealth() + amount < entity.getLivingEntity().getMaxHealth())
                    entity.getLivingEntity().setHealth(entity.getLivingEntity().getHealth() + amount);
                else
                    entity.getLivingEntity().setHealth(entity.getLivingEntity().getMaxHealth());
View Full Code Here

    }

    @Override
    public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

        Element action = scriptEntry.getElement("action");
        dWorld world = (dWorld) scriptEntry.getObject("world");
        Element group = scriptEntry.getElement("group");

        // Report to dB
        dB.report(scriptEntry, getName(), action.debug() + (world != null ? world.debug(): "") + group.debug());

        World bukkitWorld = null;
        if (world != null)
            bukkitWorld = world.getWorld();

        OfflinePlayer player = ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getOfflinePlayer();
        boolean inGroup = Depends.permissions.playerInGroup((bukkitWorld == null ? null: bukkitWorld.getName()), player, group.asString());

        switch (Action.valueOf(action.asString().toUpperCase())) {
            case ADD:
                if (inGroup)
                    dB.echoDebug(scriptEntry, "Player " + player.getName() + " is already in group " + group);
                else
                    Depends.permissions.playerAddGroup((bukkitWorld == null ? null: bukkitWorld.getName()), player, group.asString());
                return;
            case REMOVE:
                if (!inGroup)
                    dB.echoDebug(scriptEntry, "Player " + player.getName() + " is not in group " + group);
                else
                    Depends.permissions.playerRemoveGroup((bukkitWorld == null ? null: bukkitWorld.getName()), player, group.asString());
                return;
        }

    }
View Full Code Here

                scriptEntry.addObject("spread", arg.asElement());
            }

            else if (!scriptEntry.hasObject("no_rotate")
                && arg.matches("no_rotate")) {
                scriptEntry.addObject("no_rotate", new Element(true));
            }

            else arg.reportUnhandled();
        }

        // Use the NPC or player's locations as the origin if one is not specified

        if (!scriptEntry.hasObject("originLocation")) {

            scriptEntry.defaultObject("originEntity",
                    ((BukkitScriptEntryData)scriptEntry.entryData).hasNPC() ? ((BukkitScriptEntryData)scriptEntry.entryData).getNPC().getDenizenEntity() : null,
                    ((BukkitScriptEntryData)scriptEntry.entryData).hasPlayer() ? ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getDenizenEntity() : null);
        }

        scriptEntry.defaultObject("height", new Element(3));

        // Check to make sure required arguments have been filled

        if (!scriptEntry.hasObject("entities"))
            throw new InvalidArgumentsException("Must specify entity/entities!");
View Full Code Here

        final List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
        final dScript script = (dScript) scriptEntry.getObject("script");
        dEntity shooter = (dEntity) scriptEntry.getObject("shooter");

        Element height = scriptEntry.getElement("height");
        Element gravity = scriptEntry.getElement("gravity");
        Element speed = scriptEntry.getElement("speed");
        Element spread = scriptEntry.getElement("spread");

        dLocation lead = (dLocation) scriptEntry.getObject("lead");

        // Report to dB
        dB.report(scriptEntry, getName(), aH.debugObj("origin", originEntity != null ? originEntity : originLocation) +
                             aH.debugObj("entities", entities.toString()) +
                             destination.debug() +
                             height.debug() +
                             (gravity != null ? gravity.debug(): "") +
                             (speed != null ? speed.debug(): "") +
                             (script != null ? script.debug() : "") +
                             (shooter != null ? shooter.debug() : "") +
                             (spread != null ? spread.debug() : "") +
                             (lead != null ? lead.debug(): "") +
                             (no_rotate ? aH.debugObj("no_rotate", "true"): ""));

        // Keep a dList of entities that can be called using <entry[name].shot_entities>
        // later in the script queue

        final dList entityList = new dList();

        // Go through all the entities, spawning/teleporting and rotating them
        for (dEntity entity : entities) {
            entity.spawnAt(originLocation);

            // Only add to entityList after the entities have been
            // spawned, otherwise you'll get something like "e@skeleton"
            // instead of "e@57" on it
            entityList.add(entity.toString());

            if (!no_rotate)
                Rotation.faceLocation(entity.getBukkitEntity(), destination);

            // If the current entity is a projectile, set its shooter
            // when applicable
            if (entity.isProjectile() && (shooter != null || originEntity != null)) {
                entity.setShooter(shooter != null ? shooter : originEntity);
                // Also, watch for it hitting a target
                arrows.put(entity.getUUID(), null);
            }
        }

        // Add entities to context so that the specific entities created/spawned
        // can be fetched.
        scriptEntry.addObject("shot_entities", entityList);

        if (spread == null)
            Position.mount(Conversion.convertEntities(entities));

        // Get the entity at the bottom of the entity list, because
        // only its gravity should be affected and tracked considering
        // that the other entities will be mounted on it
        final dEntity lastEntity = entities.get(entities.size() - 1);

        if (gravity == null) {

            String entityType = lastEntity.getEntityType().name();

            for (Gravity defaultGravity : Gravity.values()) {

                if (defaultGravity.name().equals(entityType)) {

                    gravity = new Element(defaultGravity.getGravity());
                }
            }

            // If the gravity is still null, use a default value
            if (gravity == null) {
                gravity = new Element(0.115);
            }
        }

        if (speed == null) {
            Vector v1 = lastEntity.getLocation().toVector();
            Vector v2 = destination.toVector();
            Vector v3 = Velocity.calculate(v1, v2, gravity.asDouble(), height.asDouble());
            lastEntity.setVelocity(v3);
        }
        else if (lead == null) {
            Vector relative = destination.clone().subtract(originLocation).toVector();
            lastEntity.setVelocity(relative.normalize().multiply(speed.asDouble()));
        }
        else {
            double g = 20;
            double v = speed.asDouble();
            Vector relative = destination.clone().subtract(originLocation).toVector();
            double testAng = Velocity.launchAngle(originLocation, destination.toVector(), v, relative.getY(), g);
            double hangTime = Velocity.hangtime(testAng, v, relative.getY(), g);
            Vector to = destination.clone().add(lead.clone().multiply(hangTime)).toVector();
            relative = to.clone().subtract(originLocation.toVector());
            Double dist = Math.sqrt(relative.getX() * relative.getX() + relative.getZ() * relative.getZ());
            if (dist == 0) dist = 0.1d;
            testAng = Velocity.launchAngle(originLocation, to, v, relative.getY(), g);
            relative.setY(Math.tan(testAng) * dist);
            relative = relative.normalize();
            v = v + (1.188 * Math.pow(hangTime, 2));
            relative = relative.multiply(v / 20.0d);
            lastEntity.setVelocity(relative);
        }

        if (spread != null) {
            Vector base = lastEntity.getVelocity().clone();
            float sf = spread.asFloat();
            for (dEntity entity: entities) {
                Vector newvel = Velocity.spread(base, (CoreUtilities.getRandom().nextDouble() > 0.5f ? 1: -1) * Math.toRadians(CoreUtilities.getRandom().nextDouble() * sf),
                        (CoreUtilities.getRandom().nextDouble() > 0.5f ? 1: -1) * Math.toRadians(CoreUtilities.getRandom().nextDouble() * sf));
                entity.setVelocity(newvel);
            }
View Full Code Here

    }

    @Override
    public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

        Element action = scriptEntry.getElement("action");
        Element permission = scriptEntry.getElement("permission");
        Element group = scriptEntry.getElement("group");
        dWorld world = (dWorld) scriptEntry.getObject("world");

        // Report to dB
        dB.report(scriptEntry, getName(), action.debug() + permission.debug()
                + (group != null ? group.debug() : "") + (world != null ? world.debug(): ""));

        World bukkitWorld = null;
        if (world != null)
            bukkitWorld = world.getWorld();

        OfflinePlayer player = ((BukkitScriptEntryData)scriptEntry.entryData).hasPlayer() ? ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getOfflinePlayer() : null;

        switch (Action.valueOf(action.asString().toUpperCase())) {
            case ADD:
                if (group != null) {
                    if (Depends.permissions.groupHas(bukkitWorld, group.asString(), permission.asString()))
                        dB.echoDebug(scriptEntry, "Group " + group + " already has permission " + permission);
                    else
                        Depends.permissions.groupAdd(bukkitWorld, group.asString(), permission.asString());
                } else {
                    if(Depends.permissions.playerHas(bukkitWorld == null ? null: bukkitWorld.getName(), player, permission.asString()))
                        dB.echoDebug(scriptEntry, "Player " + player.getName() + " already has permission " + permission);
                    else
                        Depends.permissions.playerAdd(bukkitWorld == null ? null: bukkitWorld.getName(), player, permission.asString());
                }
                return;
            case REMOVE:
                if (group != null) {
                    if(!Depends.permissions.groupHas(bukkitWorld, group.asString(), permission.asString()))
                        dB.echoDebug(scriptEntry, "Group " + group + " does not have access to permission " + permission);
                    else
                        Depends.permissions.groupRemove(bukkitWorld, group.asString(), permission.asString());
                } else {
                    if(!Depends.permissions.playerHas(bukkitWorld == null ? null: bukkitWorld.getName(), player, permission.asString()))
                        dB.echoDebug(scriptEntry, "Player " + player.getName() + " does not have access to permission " + permission);
                    else
                        Depends.permissions.playerRemove(bukkitWorld == null ? null: bukkitWorld.getName(), player, permission.asString());
View Full Code Here

    // -->
    @EventHandler
    public void onBlockRedstone(BlockRedstoneEvent event) {
        Map<String, dObject> context = new HashMap<String, dObject>();
        context.put("location", new dLocation(event.getBlock().getLocation()));
        context.put("old_current", new Element(event.getOldCurrent()));
        context.put("new_current", new Element(event.getNewCurrent()));
        String determination = EventManager.doEvents(Arrays.asList("redstone recalculated"), null, null, context, true);
        Element det = new Element(determination);
        if (det.isInt())
            event.setNewCurrent(det.asInt());
    }
View Full Code Here

        // @description
        // If the entity is a wolf or ocelot, returns whether the animal is sitting.
        // -->
        if (attribute.startsWith("sitting")) {
            if (entity.getEntityType() == EntityType.WOLF)
                return new Element(((Wolf)entity.getBukkitEntity()).isSitting())
                        .getAttribute(attribute.fulfill(1));
            else
                return new Element(((Ocelot)entity.getBukkitEntity()).isSitting())
                        .getAttribute(attribute.fulfill(1));
        }

        return null;
    }
View Full Code Here

TOP

Related Classes of net.aufdemrand.denizen.objects.Element

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.