Search in sources :

Example 16 with DurationTag

use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.

the class ChunkLoadCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ElementTag action = scriptEntry.getElement("action");
    ListTag chunklocs = scriptEntry.getObjectTag("location");
    DurationTag length = scriptEntry.getObjectTag("duration");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), action, chunklocs, length);
    }
    for (String chunkText : chunklocs) {
        Chunk chunk;
        if (ChunkTag.matches(chunkText)) {
            chunk = ChunkTag.valueOf(chunkText, scriptEntry.context).getChunk();
        } else if (LocationTag.matches(chunkText)) {
            chunk = LocationTag.valueOf(chunkText, scriptEntry.context).getChunk();
        } else {
            Debug.echoError("Chunk input '" + chunkText + "' is invalid.");
            return;
        }
        ChunkCoordinate coord = new ChunkCoordinate(chunk);
        switch(Action.valueOf(action.asString())) {
            case ADD:
                if (length.getSeconds() != 0) {
                    chunkDelays.put(coord, System.currentTimeMillis() + length.getMillis());
                } else {
                    chunkDelays.put(coord, (long) 0);
                }
                Debug.echoDebug(scriptEntry, "...added chunk " + chunk.getX() + ", " + chunk.getZ() + " with a delay of " + length.getSeconds() + " seconds.");
                if (!chunk.isLoaded()) {
                    chunk.load();
                }
                chunk.addPluginChunkTicket(Denizen.getInstance());
                if (length.getSeconds() > 0) {
                    Bukkit.getScheduler().scheduleSyncDelayedTask(Denizen.getInstance(), () -> {
                        if (chunkDelays.containsKey(coord) && chunkDelays.get(coord) <= System.currentTimeMillis()) {
                            chunk.removePluginChunkTicket(Denizen.getInstance());
                            chunkDelays.remove(coord);
                        }
                    }, length.getTicks() + 20);
                }
                break;
            case REMOVE:
                if (chunkDelays.containsKey(coord)) {
                    chunkDelays.remove(coord);
                    chunk.removePluginChunkTicket(Denizen.getInstance());
                    Debug.echoDebug(scriptEntry, "...allowing unloading of chunk " + chunk.getX() + ", " + chunk.getZ());
                } else {
                    Debug.echoDebug(scriptEntry, "Chunk '" + coord + "' was not on the load list, ignoring.");
                }
                break;
            case REMOVEALL:
                Debug.echoDebug(scriptEntry, "...allowing unloading of all stored chunks");
                for (ChunkCoordinate loopCoord : chunkDelays.keySet()) {
                    loopCoord.getChunk().getChunk().removePluginChunkTicket(Denizen.getInstance());
                }
                chunkDelays.clear();
                break;
        }
    }
}
Also used : ChunkCoordinate(com.denizenscript.denizen.utilities.blocks.ChunkCoordinate) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) Chunk(org.bukkit.Chunk) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 17 with DurationTag

use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.

the class TitleCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    String title = scriptEntry.getElement("title").asString();
    String subtitle = scriptEntry.getElement("subtitle").asString();
    DurationTag fade_in = scriptEntry.getObjectTag("fade_in");
    DurationTag stay = scriptEntry.getObjectTag("stay");
    DurationTag fade_out = scriptEntry.getObjectTag("fade_out");
    List<PlayerTag> targets = (List<PlayerTag>) scriptEntry.getObject("targets");
    ElementTag perPlayerObj = scriptEntry.getElement("per_player");
    boolean perPlayer = perPlayerObj != null && perPlayerObj.asBoolean();
    BukkitTagContext context = (BukkitTagContext) scriptEntry.getContext();
    if (!perPlayer) {
        title = TagManager.tag(title, context);
        subtitle = TagManager.tag(subtitle, context);
    }
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("title", title), db("subtitle", subtitle), fade_in, stay, fade_out, db("targets", targets), perPlayerObj);
    }
    for (PlayerTag player : targets) {
        if (player != null) {
            if (!player.isOnline()) {
                Debug.echoDebug(scriptEntry, "Player is offline, can't send title to them. Skipping.");
                continue;
            }
            String personalTitle = title;
            String personalSubtitle = subtitle;
            if (perPlayer) {
                context.player = player;
                personalTitle = TagManager.tag(personalTitle, context);
                personalSubtitle = TagManager.tag(personalSubtitle, context);
            }
            NMSHandler.getPacketHelper().showTitle(player.getPlayerEntity(), personalTitle, personalSubtitle, fade_in.getTicksAsInt(), stay.getTicksAsInt(), fade_out.getTicksAsInt());
        } else {
            Debug.echoError("Sent title to non-existent player!?");
        }
    }
}
Also used : BukkitTagContext(com.denizenscript.denizen.tags.BukkitTagContext) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 18 with DurationTag

use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.

the class DebugBlockCommand method parseArgs.

// <--[command]
// @Name DebugBlock
// @Syntax debugblock [<location>|.../clear] (color:<color>) (alpha:<#.#>) (name:<name>) (players:<player>|...) (d:<duration>{10s})
// @Required 1
// @Maximum 6
// @Short Shows or clears minecraft debug blocks.
// @Synonyms GameTestMarker
// @Group player
// 
// @Description
// Shows or clears minecraft debug blocks, AKA "Game Test Markers".
// These are block-grid-aligned markers that are a perfect cube of a single (specifiable) transparent color, and stay for a specified duration of time or until cleared.
// Markers can optionally also have simple text names.
// 
// If arguments are unspecified, the default color is white (in practice: green), the default alpha is 1.0 (most opaque, but not completely opaque),
// the default player is the linked player, the default name is none, and the default duration is 10 seconds.
// 
// The underlying color input is a full color value, however the current minecraft client can only render shades between green and gray (ie the red and blue color channels are ignored).
// 
// @Tags
// None
// 
// @Usage
// Use to show a debug block where the player is looking.
// - debugblock <player.cursor_on>
// 
// @Usage
// Use to show a transparent green debug block in front of the player for five seconds.
// - debugblock <player.eye_location.forward[2]> color:green alpha:0.5 d:5s
// 
// @Usage
// Use to remove all debug blocks,
// - debugblock clear
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("players") && arg.matchesPrefix("to", "players")) {
            scriptEntry.addObject("players", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry));
        } else if (arg.matchesPrefix("d", "duration") && arg.matchesArgumentType(DurationTag.class)) {
            scriptEntry.addObject("duration", arg.asType(DurationTag.class));
        } else if (arg.matchesPrefix("color") && arg.matchesArgumentType(ColorTag.class)) {
            scriptEntry.addObject("color", arg.asType(ColorTag.class));
        } else if (arg.matchesPrefix("alpha") && arg.matchesFloat()) {
            scriptEntry.addObject("alpha", arg.asElement());
        } else if (arg.matchesPrefix("name")) {
            scriptEntry.addObject("name", arg.asElement());
        } else if (arg.matches("clear")) {
            scriptEntry.addObject("clear", new ElementTag(true));
        } else if (!scriptEntry.hasObject("locations") && arg.matchesArgumentList(LocationTag.class)) {
            scriptEntry.addObject("locations", arg.asType(ListTag.class).filter(LocationTag.class, scriptEntry));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("players") && Utilities.entryHasPlayer(scriptEntry)) {
        scriptEntry.defaultObject("players", Collections.singletonList(Utilities.getEntryPlayer(scriptEntry)));
    }
    if (!scriptEntry.hasObject("locations") && !scriptEntry.hasObject("clear")) {
        throw new InvalidArgumentsException("Must specify at least one valid location!");
    }
    if (!scriptEntry.hasObject("players")) {
        throw new InvalidArgumentsException("Must have a valid, online player attached!");
    }
    scriptEntry.defaultObject("duration", new DurationTag(10));
    scriptEntry.defaultObject("color", new ColorTag(255, 255, 255));
    scriptEntry.defaultObject("alpha", new ElementTag("1"));
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) Argument(com.denizenscript.denizencore.objects.Argument) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ColorTag(com.denizenscript.denizen.objects.ColorTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 19 with DurationTag

use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.

the class DebugBlockCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    DurationTag duration = scriptEntry.getObjectTag("duration");
    ElementTag clear = scriptEntry.getElement("clear");
    List<LocationTag> locations = (List<LocationTag>) scriptEntry.getObject("locations");
    List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
    ColorTag color = scriptEntry.getObjectTag("color");
    ElementTag alpha = scriptEntry.getElement("alpha");
    ElementTag name = scriptEntry.getElement("name");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), clear == null ? db("locations", locations) : clear, duration, db("players", players), color, alpha, name);
    }
    if (clear != null && clear.asBoolean()) {
        for (PlayerTag player : players) {
            NMSHandler.getPacketHelper().clearDebugTestMarker(player.getPlayerEntity());
        }
    } else {
        int alphaInt = (int) (alpha.asFloat() * 255);
        for (LocationTag location : locations) {
            for (PlayerTag player : players) {
                NMSHandler.getPacketHelper().showDebugTestMarker(player.getPlayerEntity(), location, color, alphaInt, name == null ? "" : name.asString(), (int) duration.getMillis());
            }
        }
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ColorTag(com.denizenscript.denizen.objects.ColorTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 20 with DurationTag

use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.

the class EngageCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    if (!Utilities.entryHasNPC(scriptEntry)) {
        throw new InvalidArgumentsRuntimeException("This command requires a linked NPC!");
    }
    DurationTag duration = scriptEntry.getObjectTag("duration");
    boolean linkedPlayer = scriptEntry.argAsBoolean("player");
    NPCTag npc = Utilities.getEntryNPC(scriptEntry);
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), npc, duration, db("player", linkedPlayer));
    }
    if (duration.getSecondsAsInt() > 0) {
        setEngaged(npc.getCitizen(), linkedPlayer ? Utilities.getEntryPlayer(scriptEntry) : null, duration.getSecondsAsInt());
    } else {
        setEngaged(npc.getCitizen(), linkedPlayer ? Utilities.getEntryPlayer(scriptEntry) : null, true);
    }
}
Also used : InvalidArgumentsRuntimeException(com.denizenscript.denizencore.exceptions.InvalidArgumentsRuntimeException) NPCTag(com.denizenscript.denizen.objects.NPCTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Aggregations

DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)54 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)39 LocationTag (com.denizenscript.denizen.objects.LocationTag)19 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)16 ListTag (com.denizenscript.denizencore.objects.core.ListTag)16 EntityTag (com.denizenscript.denizen.objects.EntityTag)15 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)13 List (java.util.List)11 Player (org.bukkit.entity.Player)7 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)6 ColorTag (com.denizenscript.denizen.objects.ColorTag)5 PotionEffect (org.bukkit.potion.PotionEffect)5 PotionEffectType (org.bukkit.potion.PotionEffectType)5 ItemTag (com.denizenscript.denizen.objects.ItemTag)4 NPCTag (com.denizenscript.denizen.objects.NPCTag)4 WorldTag (com.denizenscript.denizen.objects.WorldTag)4 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)4 LivingEntity (org.bukkit.entity.LivingEntity)4 NMSHandler (com.denizenscript.denizen.nms.NMSHandler)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3