Search in sources :

Example 21 with Duration

use of net.aufdemrand.denizencore.objects.Duration in project Denizen-For-Bukkit by DenizenScript.

the class LightCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    dLocation location = scriptEntry.getdObject("location");
    Element light = scriptEntry.getElement("light");
    Element reset = scriptEntry.getElement("reset");
    Duration duration = scriptEntry.getdObject("duration");
    dB.report(scriptEntry, getName(), location.debug() + reset.debug() + (light != null ? light.debug() : "") + (duration != null ? duration.debug() : ""));
    if (location.getY() < 0 || location.getY() > 255) {
        dB.echoError(scriptEntry.getResidingQueue(), "Invalid light location!");
        return;
    }
    for (int x = -1; x <= 1; x++) {
        for (int z = -1; z <= 1; z++) {
            location.clone().add(x * 16, 0, z * 16).getChunk().load();
        }
    }
    if (!reset.asBoolean()) {
        int brightness = light.asInt();
        if (brightness < 0 || brightness > 15) {
            throw new CommandExecutionException("Light brightness must be between 0 and 15, inclusive!");
        }
        NMSHandler.getInstance().createBlockLight(location, brightness, duration == null ? 0 : duration.getTicks());
    } else {
        BlockLight.removeLight(location);
    }
}
Also used : Element(net.aufdemrand.denizencore.objects.Element) Duration(net.aufdemrand.denizencore.objects.Duration) CommandExecutionException(net.aufdemrand.denizencore.exceptions.CommandExecutionException) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Example 22 with Duration

use of net.aufdemrand.denizencore.objects.Duration in project Denizen-For-Bukkit by DenizenScript.

the class ShowFakeCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    dList locations = new dList();
    dList entities = new dList();
    boolean added_entities = false;
    // Iterate through arguments
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (arg.matchesPrefix("to", "players")) {
            for (String entity : dList.valueOf(arg.getValue())) {
                if (dPlayer.matches(entity)) {
                    entities.add(entity);
                }
            }
            // TODO: handle lists properly
            added_entities = true;
        } else if (arg.matchesArgumentList(dMaterial.class)) {
            scriptEntry.addObject("materials", arg.asType(dList.class));
        } else if (locations.isEmpty() && arg.matchesArgumentType(dList.class)) {
            for (String item : dList.valueOf(arg.getValue())) {
                if (dLocation.matches(item)) {
                    locations.add(item);
                }
            }
        } else if (locations.isEmpty() && arg.matchesArgumentType(dLocation.class)) {
            locations.add(arg.getValue());
        } else if (arg.matchesPrefix("d", "duration") && arg.matchesArgumentType(Duration.class)) {
            scriptEntry.addObject("duration", arg.asType(Duration.class));
        } else if (arg.matches("cancel")) {
            scriptEntry.addObject("cancel", new Element(true));
        } else {
            arg.reportUnhandled();
        }
    }
    if (entities.isEmpty() && ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer()) {
        entities.add(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().identify());
    }
    if (locations.isEmpty()) {
        throw new InvalidArgumentsException("Must specify at least one valid location!");
    }
    if (!added_entities && (!((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() || !((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().isOnline())) {
        throw new InvalidArgumentsException("Must have a valid, online player attached!");
    }
    if (entities.isEmpty() && added_entities) {
        throw new InvalidArgumentsException("Must specify valid targets!");
    }
    if (!scriptEntry.hasObject("materials") && !scriptEntry.hasObject("cancel")) {
        throw new InvalidArgumentsException("Must specify valid material(s)!");
    }
    scriptEntry.addObject("entities", entities);
    scriptEntry.addObject("locations", locations);
    scriptEntry.defaultObject("duration", new Duration(10)).defaultObject("cancel", new Element(false));
}
Also used : net.aufdemrand.denizen.objects.dMaterial(net.aufdemrand.denizen.objects.dMaterial) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) net.aufdemrand.denizencore.objects.aH(net.aufdemrand.denizencore.objects.aH) Element(net.aufdemrand.denizencore.objects.Element) Duration(net.aufdemrand.denizencore.objects.Duration) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Example 23 with Duration

use of net.aufdemrand.denizencore.objects.Duration in project Denizen-For-Bukkit by DenizenScript.

the class ShowFakeCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Duration duration = scriptEntry.getdObject("duration");
    dList material_list = scriptEntry.getdObject("materials");
    dList list = scriptEntry.getdObject("locations");
    dList players = scriptEntry.getdObject("entities");
    Element cancel = scriptEntry.getElement("cancel");
    dB.report(scriptEntry, getName(), (material_list != null ? material_list.debug() : "") + list.debug() + players.debug() + duration.debug() + cancel.debug());
    boolean shouldCancel = cancel.asBoolean();
    List<dMaterial> mats = null;
    if (!shouldCancel) {
        mats = material_list.filter(dMaterial.class);
    }
    int i = 0;
    for (dLocation loc : list.filter(dLocation.class)) {
        if (!shouldCancel) {
            FakeBlock.showFakeBlockTo(players.filter(dPlayer.class), loc, mats.get(i % mats.size()), duration);
        } else {
            FakeBlock.stopShowingTo(players.filter(dPlayer.class), loc);
        }
        i++;
    }
}
Also used : net.aufdemrand.denizen.objects.dMaterial(net.aufdemrand.denizen.objects.dMaterial) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Duration(net.aufdemrand.denizencore.objects.Duration) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Example 24 with Duration

use of net.aufdemrand.denizencore.objects.Duration in project Denizen-For-Bukkit by DenizenScript.

the class TitleCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Element title = scriptEntry.getElement("title");
    Element subtitle = scriptEntry.getElement("subtitle");
    Duration fade_in = scriptEntry.getdObject("fade_in");
    Duration stay = scriptEntry.getdObject("stay");
    Duration fade_out = scriptEntry.getdObject("fade_out");
    List<dPlayer> targets = (List<dPlayer>) scriptEntry.getObject("targets");
    dB.report(scriptEntry, getName(), (title != null ? title.debug() : "") + (subtitle != null ? subtitle.debug() : "") + fade_in.debug() + stay.debug() + fade_out.debug() + aH.debugObj("targets", targets));
    for (dPlayer player : targets) {
        if (player.isValid() && player.isOnline()) {
            NMSHandler.getInstance().getPacketHelper().showTitle(player.getPlayerEntity(), title != null ? title.asString() : "", subtitle != null ? subtitle.asString() : "", fade_in.getTicksAsInt(), stay.getTicksAsInt(), fade_out.getTicksAsInt());
        }
    }
}
Also used : Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Duration(net.aufdemrand.denizencore.objects.Duration) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList)

Example 25 with Duration

use of net.aufdemrand.denizencore.objects.Duration in project Denizen-For-Bukkit by DenizenScript.

the class BurnCommand method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
    // Get objects
    List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
    Duration duration = (Duration) scriptEntry.getObject("duration");
    // Report to dB
    dB.report(scriptEntry, getName(), duration.debug() + aH.debugObj("entities", entities.toString()));
    // Go through all the entities and set them on fire
    for (dEntity entity : entities) {
        if (entity.isSpawned()) {
            entity.getBukkitEntity().setFireTicks(duration.getTicksAsInt());
        }
    }
}
Also used : net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Duration(net.aufdemrand.denizencore.objects.Duration)

Aggregations

Duration (net.aufdemrand.denizencore.objects.Duration)31 Element (net.aufdemrand.denizencore.objects.Element)20 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)12 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)11 InvalidArgumentsException (net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)10 BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)9 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)9 List (java.util.List)7 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)6 CommandExecutionException (net.aufdemrand.denizencore.exceptions.CommandExecutionException)6 net.aufdemrand.denizencore.objects.aH (net.aufdemrand.denizencore.objects.aH)6 net.aufdemrand.denizen.objects.dNPC (net.aufdemrand.denizen.objects.dNPC)5 net.aufdemrand.denizencore.objects.dScript (net.aufdemrand.denizencore.objects.dScript)4 ScriptQueue (net.aufdemrand.denizencore.scripts.queues.ScriptQueue)4 Player (org.bukkit.entity.Player)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3 net.aufdemrand.denizen.objects.dItem (net.aufdemrand.denizen.objects.dItem)2 net.aufdemrand.denizen.objects.dMaterial (net.aufdemrand.denizen.objects.dMaterial)2 Delayable (net.aufdemrand.denizencore.scripts.queues.core.Delayable)2 BufferedReader (java.io.BufferedReader)1