Search in sources :

Example 1 with Duration

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

the class BanCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Element action = scriptEntry.getElement("action");
    List<dPlayer> targets = (List<dPlayer>) scriptEntry.getObject("targets");
    Element reason = scriptEntry.getElement("reason");
    Duration duration = scriptEntry.getdObject("duration");
    Date expiration = null;
    if (duration != null && duration.getTicks() != 0) {
        expiration = new Date(new Duration(System.currentTimeMillis() / 50 + duration.getTicks()).getTicks() * 50);
    }
    dB.report(scriptEntry, getName(), action.debug() + aH.debugObj("targets", targets) + reason.debug() + (duration != null ? duration.debug() : ""));
    Actions banAction = Actions.valueOf(action.toString().toUpperCase());
    switch(banAction) {
        case ADD:
            for (dPlayer player : targets) {
                if (player.isValid()) {
                    Bukkit.getBanList(BanList.Type.NAME).addBan(player.getName(), reason.toString(), expiration, null);
                    if (player.isOnline()) {
                        player.getPlayerEntity().kickPlayer(reason.toString());
                    }
                }
            }
            break;
        case REMOVE:
            for (dPlayer player : targets) {
                if (player.isValid()) {
                    if (player.getOfflinePlayer().isBanned()) {
                        Bukkit.getBanList(BanList.Type.NAME).pardon(player.getName());
                    }
                }
            }
            break;
    }
}
Also used : Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) BanList(org.bukkit.BanList) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Duration(net.aufdemrand.denizencore.objects.Duration) Date(java.util.Date)

Example 2 with Duration

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

the class ChunkLoadCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    // Get objects
    Element action = scriptEntry.getElement("action");
    dLocation chunkloc = (dLocation) scriptEntry.getObject("location");
    Duration length = (Duration) scriptEntry.getObject("duration");
    dB.report(scriptEntry, getName(), action.debug() + chunkloc.debug() + length.debug());
    Chunk chunk = chunkloc.getChunk();
    String chunkString = chunk.getX() + ", " + chunk.getZ();
    switch(Action.valueOf(action.asString())) {
        case ADD:
            if (length.getSeconds() != 0) {
                chunkDelays.put(chunkString, System.currentTimeMillis() + length.getMillis());
            } else {
                chunkDelays.put(chunkString, (long) 0);
            }
            dB.echoDebug(scriptEntry, "...added chunk " + chunk.getX() + ", " + chunk.getZ() + " with a delay of " + length.getSeconds() + " seconds.");
            if (!chunk.isLoaded()) {
                chunk.load();
            }
            break;
        case REMOVE:
            if (chunkDelays.containsKey(chunkString)) {
                chunkDelays.remove(chunkString);
                dB.echoDebug(scriptEntry, "...allowing unloading of chunk " + chunk.getX() + ", " + chunk.getZ());
            } else {
                dB.echoError("Chunk was not on the load list!");
            }
            break;
        case REMOVEALL:
            dB.echoDebug(scriptEntry, "...allowing unloading of all stored chunks");
            chunkDelays.clear();
            break;
    }
}
Also used : Element(net.aufdemrand.denizencore.objects.Element) Duration(net.aufdemrand.denizencore.objects.Duration) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) net.aufdemrand.denizen.objects.dChunk(net.aufdemrand.denizen.objects.dChunk) Chunk(org.bukkit.Chunk)

Example 3 with Duration

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

the class TimeCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    // Fetch objects
    Duration value = (Duration) scriptEntry.getObject("value");
    dWorld world = (dWorld) scriptEntry.getObject("world");
    Element type_element = scriptEntry.getElement("type");
    Type type = Type.valueOf(type_element.asString().toUpperCase());
    // Report to dB
    dB.report(scriptEntry, getName(), type_element.debug() + value.debug() + world.debug());
    if (type.equals(Type.GLOBAL)) {
        world.getWorld().setTime(value.getTicks());
    } else {
        if (!((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer()) {
            dB.echoError("Must have a valid player link!");
        } else {
            ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().setPlayerTime(value.getTicks(), true);
        }
    }
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) Element(net.aufdemrand.denizencore.objects.Element) Duration(net.aufdemrand.denizencore.objects.Duration) net.aufdemrand.denizen.objects.dWorld(net.aufdemrand.denizen.objects.dWorld)

Example 4 with Duration

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

the class SwitchCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (!scriptEntry.hasObject("locations") && arg.matchesArgumentList(dLocation.class)) {
            scriptEntry.addObject("locations", arg.asType(dList.class));
        } else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(Duration.class)) {
            scriptEntry.addObject("duration", arg.asType(Duration.class));
        } else if (!scriptEntry.hasObject("state") && arg.matchesEnum(SwitchState.values())) {
            scriptEntry.addObject("switchstate", new Element(arg.getValue().toUpperCase()));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("locations")) {
        throw new InvalidArgumentsException("Must specify a location!");
    }
    scriptEntry.defaultObject("duration", new Duration(0));
    scriptEntry.defaultObject("switchstate", new Element("TOGGLE"));
}
Also used : net.aufdemrand.denizencore.objects.aH(net.aufdemrand.denizencore.objects.aH) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Element(net.aufdemrand.denizencore.objects.Element) Duration(net.aufdemrand.denizencore.objects.Duration) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Example 5 with Duration

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

the class PushableCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    dNPC denizenNPC = ((BukkitScriptEntryData) scriptEntry.entryData).getNPC();
    if (denizenNPC == null) {
        throw new CommandExecutionException("No valid NPC attached to this queue!");
    }
    PushableTrait trait = denizenNPC.getPushableTrait();
    Element state = scriptEntry.getElement("state");
    Duration delay = scriptEntry.getdObject("delay");
    Element returnable = scriptEntry.getElement("return");
    if (state == null && delay == null && returnable == null) {
        state = new Element("TOGGLE");
    }
    dB.report(scriptEntry, getName(), (state != null ? state.debug() : "") + (delay != null ? delay.debug() : "") + (returnable != null ? returnable.debug() : ""));
    if (delay != null) {
        trait.setDelay(delay.getSecondsAsInt());
    }
    if (returnable != null) {
        trait.setReturnable(returnable.asBoolean());
    }
    if (state != null) {
        switch(Toggle.valueOf(state.asString().toUpperCase())) {
            case TRUE:
            case ON:
                trait.setPushable(true);
                break;
            case FALSE:
            case OFF:
                trait.setPushable(false);
                break;
            case TOGGLE:
                trait.setPushable(!trait.isPushable());
                break;
        }
    }
}
Also used : net.aufdemrand.denizen.objects.dNPC(net.aufdemrand.denizen.objects.dNPC) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) Element(net.aufdemrand.denizencore.objects.Element) CommandExecutionException(net.aufdemrand.denizencore.exceptions.CommandExecutionException) Duration(net.aufdemrand.denizencore.objects.Duration) PushableTrait(net.aufdemrand.denizen.npc.traits.PushableTrait)

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