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;
}
}
}
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!?");
}
}
}
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"));
}
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());
}
}
}
}
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);
}
}
Aggregations