Package net.aufdemrand.denizen.objects

Examples of net.aufdemrand.denizen.objects.Element


    }


    @Override
    public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
        Element action = scriptEntry.getElement("action");
        Element type = scriptEntry.getElement("type");
        Element id = scriptEntry.getElement("id");
        dScript finish_script = (dScript) scriptEntry.getObject("finish_script");

        dB.report(scriptEntry, getName(), action.debug() + (type != null ? type.debug() : "")
                + id.debug() + (finish_script != null ? finish_script.debug() : ""));

        List<aH.Argument> arguments = (ArrayList<aH.Argument>) scriptEntry.getObject("args");

        switch (Action.valueOf(action.asString().toUpperCase())) {

            case NEW:
                // First make sure there isn't already a 'player listener' for this player with the specified ID.
                if (DenizenAPI.getCurrentInstance().getListenerRegistry()
                        .getListenersFor(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer()) != null
                        && DenizenAPI.getCurrentInstance().getListenerRegistry().getListenersFor(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer())
                        .containsKey(id.asString().toLowerCase())) {
                    dB.echoError(scriptEntry.getResidingQueue(), "Cancelled creation of NEW listener! Listener ID '" + id.asString() + "' already exists!");
                    break;
                }

                // Also make sure there is a valid script input
                if (finish_script == null) {
                    dB.echoError("Must specify a valid script!");
                    break;
                }

                try {
                    DenizenAPI.getCurrentInstance().getListenerRegistry().get(type.asString())
                            .createInstance(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(), id.asString())
                            .build(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(),
                                    id.asString(),
                                    type.asString(),
                                    arguments,
                                    finish_script,
                                    ((BukkitScriptEntryData)scriptEntry.entryData).getNPC());

                } catch (Exception e) {
                    dB.echoDebug(scriptEntry, "Cancelled creation of NEW listener!");

                    // Why? Maybe a wrong listener type...
                    if (DenizenAPI.getCurrentInstance().getListenerRegistry().get(type.asString()) == null)
                        dB.echoError(scriptEntry.getResidingQueue(), "Invalid listener type!");

                    // Just print the stacktrace if anything else, so we can debug other possible
                    // problems.
                    else
                        dB.echoError(scriptEntry.getResidingQueue(), e);

                    // Deconstruct the listener in case it was partially created while erroring out.
                    try { DenizenAPI.getCurrentInstance().getListenerRegistry().getListenerFor(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(), id.asString()).cancel(); }
                    catch (Exception ex) { }
                }
                break;

            case FINISH:
                if (DenizenAPI.getCurrentInstance().getListenerRegistry()
                        .getListenerFor(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(), id.asString()) != null)
                    DenizenAPI.getCurrentInstance().getListenerRegistry()
                            .getListenerFor(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(), id.asString()).finish();
                break;

            case CANCEL:
                if (((BukkitScriptEntryData)scriptEntry.entryData).getPlayer() != null) {
                    if (id != null)
                        if (DenizenAPI.getCurrentInstance().getListenerRegistry()
                                .getListenerFor(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(), id.asString()) != null)
                            DenizenAPI.getCurrentInstance().getListenerRegistry()
                                    .getListenerFor(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(), id.asString()).cancel();
                    else
                        for (AbstractListener listener :
                                DenizenAPI.getCurrentInstance().getListenerRegistry().getListenersFor(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer()).values())
                            listener.cancel();
                }
View Full Code Here


                scriptEntry.addObject("entities", arg.asType(dList.class).filter(dEntity.class));
            }

            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("speed", new Element(1.5));
        scriptEntry.defaultObject("duration", new Duration(20));

        // Check to make sure required arguments have been filled

        if (!scriptEntry.hasObject("entities"))
View Full Code Here

            throw new InvalidArgumentsException("Must have player context!");

        if (!scriptEntry.hasObject("amount"))
            throw new InvalidArgumentsException("Must specify a valid amount!");

        scriptEntry.defaultObject("type", new Element("REMAINING")).defaultObject("mode", new Element("SET"));

    }
View Full Code Here

    }

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

        Element type = scriptEntry.getElement("type");
        Element mode = scriptEntry.getElement("mode");
        Element amount = scriptEntry.getElement("amount");

        dB.report(scriptEntry, getName(), type.debug() + mode.debug() + amount.debug());

        dPlayer player = ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer();

        switch (Type.valueOf(type.asString().toUpperCase())) {
            case MAXIMUM:
                switch(Mode.valueOf(type.asString().toUpperCase())) {
                    case SET:
                        player.setMaximumAir(amount.asInt());
                        break;
                    case ADD:
                        player.setMaximumAir(player.getMaximumAir() + amount.asInt());
                        break;
                    case REMOVE:
                        player.setMaximumAir(player.getMaximumAir() - amount.asInt());
                        break;
                }
                return;
            case REMAINING:
                switch(Mode.valueOf(type.asString().toUpperCase())) {
                    case SET:
                        player.setRemainingAir(amount.asInt());
                        break;

                    case ADD:
                        player.setRemainingAir(player.getRemainingAir() + amount.asInt());
                        break;

                    case REMOVE:
                        player.setRemainingAir(player.getRemainingAir() - amount.asInt());
                        break;
                }
                return;
        }
    }
View Full Code Here

        if (!scriptEntry.hasObject("reset")
                && !scriptEntry.hasObject("image")
                && !scriptEntry.hasObject("text"))
            throw new InvalidArgumentsException("Must specify value to modify!");

        scriptEntry.defaultObject("x-value", new Element(0)).defaultObject("y-value", new Element(0))
                .defaultObject("resize", Element.FALSE);

    }
View Full Code Here

    }

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

        Element id = scriptEntry.getElement("map-id");
        dWorld create = scriptEntry.getdObject("new");
        dLocation reset = scriptEntry.getdObject("reset");
        Element image = scriptEntry.getElement("image");
        Element resize = scriptEntry.getElement("resize");
        Element text = scriptEntry.getElement("text");
        Element x = scriptEntry.getElement("x-value");
        Element y = scriptEntry.getElement("y-value");

        dB.report(scriptEntry, getName(), (id != null ? id.debug() : "") + (create != null ? create.debug() : "")
                + (reset != null ? reset.debug() : "") + (image != null ? image.debug() : "") + resize.debug()
                + (text != null ? text.debug() : "") + x.debug() + y.debug());

        MapView map = null;
        if (create != null) {
            map = Bukkit.getServer().createMap(create.getWorld());
            scriptEntry.addObject("created_map", new Element(map.getId()));
        }
        else if (id != null) {
            map = Bukkit.getServer().getMap((short) id.asInt());
            if (map == null)
                throw new CommandExecutionException("No map found for ID '" + id.asInt() + "'!");
        }
        else {
            throw new CommandExecutionException("The map command failed somehow! Report this to a developer!");
        }

        if (reset != null) {
            for (MapRenderer renderer : map.getRenderers()) {
                if (renderer instanceof DenizenMapRenderer) {
                    map.removeRenderer(renderer);
                    for (MapRenderer oldRenderer : ((DenizenMapRenderer) renderer).getOldRenderers())
                        map.addRenderer(oldRenderer);
                    map.setCenterX(reset.getBlockX());
                    map.setCenterZ(reset.getBlockZ());
                    map.setWorld(reset.getWorld());
                }
            }
        }
        else {
            DenizenMapRenderer dmr = null;
            List<MapRenderer> oldRendererList = map.getRenderers();
            for (MapRenderer renderer : oldRendererList) {
                if (!(renderer instanceof DenizenMapRenderer) || dmr != null)
                    map.removeRenderer(renderer);
                else
                    dmr = (DenizenMapRenderer) renderer;
            }
            if (dmr == null) {
                dmr = new DenizenMapRenderer(oldRendererList);
                map.addRenderer(dmr);
            }
            if (image != null)
                dmr.addImage(x.asInt(), y.asInt(), new File(DenizenAPI.getCurrentInstance().getDataFolder(),
                        image.asString()).getPath(), resize.asBoolean());
            else if (text != null)
                dmr.addText(x.asInt(), y.asInt(), text.asString());
        }

    }
View Full Code Here

        // @returns Element
        // @description
        // Returns the type of queue.
        // -->
        if (attribute.startsWith("type")) {
            return new Element("Timed").getAttribute(attribute.fulfill(1));
        }

        return super.getAttribute(attribute);

    }
View Full Code Here

        }

        // Meta defined in TimedQueue
        if (attribute.startsWith("type")) {

           return new Element("Instant").getAttribute(attribute.fulfill(1));
        }

        return super.getAttribute(attribute);

    }
View Full Code Here

        // Use the NPC or the Player as the default entity
        scriptEntry.defaultObject("entities",
                (((BukkitScriptEntryData)scriptEntry.entryData).hasPlayer() ? Arrays.asList(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getDenizenEntity()) : null),
                (((BukkitScriptEntryData)scriptEntry.entryData).hasNPC() ? Arrays.asList(((BukkitScriptEntryData)scriptEntry.entryData).getNPC().getDenizenEntity()) : null));

        scriptEntry.defaultObject("yaw", new Element(10));
        scriptEntry.defaultObject("pitch", new Element(0));
        scriptEntry.defaultObject("duration", new Duration(20));
        scriptEntry.defaultObject("frequency", Duration.valueOf("1t"));

        // Check to make sure required arguments have been filled
        if (!scriptEntry.hasObject("entities"))
View Full Code Here

    public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {

        final List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
        final Duration duration = (Duration) scriptEntry.getObject("duration");
        final Duration frequency = (Duration) scriptEntry.getObject("frequency");
        final Element yaw = (Element) scriptEntry.getObject("yaw");
        final Element pitch = (Element) scriptEntry.getObject("pitch");
        boolean cancel = scriptEntry.hasObject("cancel");
        final boolean infinite = scriptEntry.hasObject("infinite");

        // Report to dB
        dB.report(scriptEntry, getName(), (cancel ? aH.debugObj("cancel", cancel) : "") +
                             aH.debugObj("entities", entities.toString()) +
                             (infinite ? aH.debugObj("duration", "infinite") : duration.debug()) +
                             frequency.debug() +
                             yaw.debug() +
                             pitch.debug());

        // Add entities to the rotatingEntities list or remove
        // them from it
        for (dEntity entity : entities)
            if (cancel) rotatingEntities.remove(entity.getUUID());
            else        rotatingEntities.add(entity.getUUID());

        // Go no further if we are canceling a rotation
        if (cancel) return;

        // Run a task that will keep rotating the entities
        BukkitRunnable task = new BukkitRunnable() {
            int ticks = 0;
            int maxTicks = duration.getTicksAsInt();

            // Track entities that are no longer used, to remove them from
            // the regular list
            Collection<dEntity> unusedEntities = new LinkedList<dEntity>();

            @Override
            public void run() {

                if (entities.isEmpty()) {
                    scriptEntry.setFinished(true);
                    this.cancel();
                }

                else if (infinite || ticks < maxTicks) {
                    for (dEntity entity : entities) {
                        if (entity.isSpawned() && rotatingEntities.contains(entity.getUUID())) {
                            Rotation.rotate(entity.getBukkitEntity(),
                                    Rotation.normalizeYaw(entity.getLocation().getYaw() + yaw.asFloat()),
                                    entity.getLocation().getPitch() + pitch.asFloat());
                        }
                        else {
                            rotatingEntities.remove(entity.getUUID());
                            unusedEntities.add(entity);
                        }
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.