use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.
the class DropCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
LocationTag location = scriptEntry.getObjectTag("location");
ElementTag quantity = scriptEntry.getElement("quantity");
ElementTag action = scriptEntry.getElement("action");
ElementTag speed = scriptEntry.getElement("speed");
List<ItemTag> items = (List<ItemTag>) scriptEntry.getObject("item");
EntityTag entity = scriptEntry.getObjectTag("entity");
DurationTag delay = scriptEntry.getObjectTag("delay");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), action, location, quantity, db("items", items), entity, speed, delay);
}
ListTag entityList = new ListTag();
switch(Action.valueOf(action.asString())) {
case DROP_EXP:
EntityTag orb = new EntityTag(location.getWorld().spawnEntity(location, EntityType.EXPERIENCE_ORB));
((ExperienceOrb) orb.getBukkitEntity()).setExperience(quantity.asInt());
entityList.addObject(orb);
break;
case DROP_ITEM:
for (ItemTag item : items) {
if (item.getMaterial().getMaterial() == Material.AIR) {
continue;
}
if (quantity.asInt() > 1 && item.isUnique()) {
Debug.echoDebug(scriptEntry, "Cannot drop multiples of this item because it is Unique!");
}
for (int x = 0; x < quantity.asInt(); x++) {
EntityTag e = new EntityTag(location.getWorld().dropItem(location, item.getItemStack()));
if (e.isValid()) {
e.setVelocity(e.getVelocity().multiply(speed != null ? speed.asDouble() : 1d));
if (delay != null) {
((Item) e.getBukkitEntity()).setPickupDelay(delay.getTicksAsInt());
}
}
entityList.addObject(e);
}
}
break;
case DROP_ENTITY:
if (quantity.asInt() > 1 && entity.isUnique()) {
Debug.echoDebug(scriptEntry, "Cannot drop multiples of this entity because it is Unique!");
entity.spawnAt(location);
entityList.addObject(entity);
break;
}
for (int x = 0; x < quantity.asInt(); x++) {
ArrayList<Mechanism> mechanisms = new ArrayList<>();
for (Mechanism mechanism : entity.getWaitingMechanisms()) {
mechanisms.add(new Mechanism(mechanism.getName(), mechanism.value, scriptEntry.context));
}
EntityTag ent = new EntityTag(entity.getEntityType(), mechanisms);
ent.spawnAt(location);
entityList.addObject(ent);
}
break;
}
scriptEntry.addObject("dropped_entities", entityList);
if (entityList.size() == 1) {
scriptEntry.addObject("dropped_entity", entityList.getObject(0));
}
}
use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.
the class FireworkCommand method execute.
@Override
public void execute(final ScriptEntry scriptEntry) {
final LocationTag location = (LocationTag) scriptEntry.getObject("location");
ElementTag type = scriptEntry.getElement("type");
List<ColorTag> primary = scriptEntry.argForPrefixList("primary", ColorTag.class, true);
if (primary == null) {
primary = Collections.singletonList(new ColorTag(Color.YELLOW));
}
List<ColorTag> fade = scriptEntry.argForPrefixList("fade", ColorTag.class, true);
boolean flicker = scriptEntry.argAsBoolean("flicker");
boolean trail = scriptEntry.argAsBoolean("trail");
ElementTag power = scriptEntry.argForPrefixAsElement("power", "1");
DurationTag life = scriptEntry.argForPrefix("life", DurationTag.class, true);
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), location, type, power, life, db("flicker", flicker), db("trail", trail), db("primary colors", primary), db("fade colors", fade));
}
Firework firework = location.getWorld().spawn(location, Firework.class);
FireworkMeta fireworkMeta = firework.getFireworkMeta();
fireworkMeta.setPower(power.asInt());
Builder fireworkBuilder = FireworkEffect.builder();
fireworkBuilder.with(FireworkEffect.Type.valueOf(type.asString().toUpperCase()));
fireworkBuilder.withColor(Conversion.convertColors(primary));
if (fade != null) {
fireworkBuilder.withFade(Conversion.convertColors(fade));
}
if (flicker) {
fireworkBuilder.withFlicker();
}
if (trail) {
fireworkBuilder.withTrail();
}
fireworkMeta.addEffects(fireworkBuilder.build());
firework.setFireworkMeta(fireworkMeta);
if (life != null) {
NMSHandler.getEntityHelper().setFireworkLifetime(firework, life.getTicksAsInt());
}
scriptEntry.addObject("launched_firework", new EntityTag(firework));
}
use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.
the class LightCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
LocationTag location = scriptEntry.getObjectTag("location");
ElementTag light = scriptEntry.getElement("light");
ElementTag reset = scriptEntry.getElement("reset");
DurationTag duration = scriptEntry.getObjectTag("duration");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), location, reset, light, duration);
}
if (!Utilities.isLocationYSafe(location)) {
Debug.echoError(scriptEntry, "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) {
Debug.echoError("Light brightness must be between 0 and 15, inclusive!");
return;
}
NMSHandler.getInstance().createBlockLight(location, brightness, duration == null ? 0 : duration.getTicks());
} else {
BlockLight.removeLight(location);
}
}
use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.
the class TitleCommand method parseArgs.
// <--[command]
// @Name Title
// @Syntax title (title:<text>) (subtitle:<text>) (fade_in:<duration>/{1s}) (stay:<duration>/{3s}) (fade_out:<duration>/{1s}) (targets:<player>|...) (per_player)
// @Required 1
// @Maximum 7
// @Short Displays a title to specified players.
// @Group player
//
// @Description
// Shows the players a large, noticeable wall of text in the center of the screen.
// You can also show a "subtitle" below that title.
// You may add timings for fading in, staying there, and fading out.
// The defaults for these are: 1 second, 3 seconds, and 1 second, respectively.
//
// Optionally use 'per_player' with a list of player targets, to have the tags in the text input be reparsed for each and every player.
// So, for example, "- title 'title:hello <player.name>' targets:<server.online_players>"
// would normally say "hello bob" to every player (every player sees the exact same name in the text, ie bob sees "hello bob", steve also sees "hello bob", etc)
// but if you use "per_player", each player online would see their own name (so bob sees "hello bob", steve sees "hello steve", etc).
//
// @Tags
// None
//
// @Usage
// Use to alert players of impending server restart.
// - title "title:<red>Server Restarting" "subtitle:<red>In 1 minute!" stay:1m targets:<server.online_players>
//
// @Usage
// Use to inform the player about the area they have just entered.
// - title "title:<green>Tatooine" "subtitle:<gold>What a desolate place this is."
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : ArgumentHelper.interpret(scriptEntry, scriptEntry.getOriginalArguments())) {
if (arg.matchesPrefix("title")) {
scriptEntry.addObject("title", arg.asElement());
} else if (arg.matchesPrefix("subtitle")) {
scriptEntry.addObject("subtitle", arg.asElement());
} else if (arg.matchesPrefix("fade_in")) {
String argStr = TagManager.tag(arg.getValue(), scriptEntry.getContext());
scriptEntry.addObject("fade_in", DurationTag.valueOf(argStr, scriptEntry.context));
} else if (arg.matchesPrefix("stay")) {
String argStr = TagManager.tag(arg.getValue(), scriptEntry.getContext());
scriptEntry.addObject("stay", DurationTag.valueOf(argStr, scriptEntry.context));
} else if (arg.matchesPrefix("fade_out")) {
String argStr = TagManager.tag(arg.getValue(), scriptEntry.getContext());
scriptEntry.addObject("fade_out", DurationTag.valueOf(argStr, scriptEntry.context));
} else if (arg.matchesPrefix("targets", "target")) {
scriptEntry.addObject("targets", ListTag.getListFor(TagManager.tagObject(arg.getValue(), scriptEntry.getContext()), scriptEntry.getContext()).filter(PlayerTag.class, scriptEntry));
} else if (!scriptEntry.hasObject("per_player") && arg.matches("per_player")) {
scriptEntry.addObject("per_player", new ElementTag(true));
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("title") && !scriptEntry.hasObject("subtitle")) {
throw new InvalidArgumentsException("Must have a title or subtitle!");
}
scriptEntry.defaultObject("fade_in", new DurationTag(1)).defaultObject("stay", new DurationTag(3)).defaultObject("fade_out", new DurationTag(1)).defaultObject("targets", Collections.singletonList(Utilities.getEntryPlayer(scriptEntry))).defaultObject("subtitle", new ElementTag("")).defaultObject("title", new ElementTag(""));
}
use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.
the class WorldBorderCommand method parseArgs.
// <--[command]
// @Name WorldBorder
// @Syntax worldborder [<world>/<player>|...] (center:<location>) (size:<#.#>) (current_size:<#.#>) (damage:<#.#>) (damagebuffer:<#.#>) (warningdistance:<#>) (warningtime:<duration>) (duration:<duration>) (reset)
// @Required 2
// @Maximum 10
// @Short Modifies a world border.
// @Group world
//
// @Description
// Modifies the world border of a specified world or a list of players.
// NOTE: Modifying player world borders is client-side and will reset on death, relog, or other actions.
// Options are:
// center: Sets the center of the world border.
// size: Sets the new size of the world border.
// current_size: Sets the initial size of the world border when resizing it over a duration.
// damage: Sets the amount of damage a player takes when outside the world border buffer radius.
// damagebuffer: Sets the radius a player may safely be outside the world border before taking damage.
// warningdistance: Causes the screen to be tinted red when the player is within the specified radius from the world border.
// warningtime: Causes the screen to be tinted red when a contracting world border will reach the player within the specified time.
// duration: Causes the world border to grow or shrink from its current size to its new size over the specified duration.
// reset: Resets the world border to its vanilla defaults for a world, or to the current world border for players.
//
// @Tags
// <LocationTag.is_within_border>
// <WorldTag.border_size>
// <WorldTag.border_center>
// <WorldTag.border_damage>
// <WorldTag.border_damage_buffer>
// <WorldTag.border_warning_distance>
// <WorldTag.border_warning_time>
//
// @Usage
// Use to set the size of a world border.
// - worldborder <player.location.world> size:4
//
// @Usage
// Use to update a world border's center, and then the size over the course of 10 seconds.
// - worldborder <[world]> center:<[world].spawn_location> size:100 duration:10s
//
// @Usage
// Use to show a client-side world border to the attached player.
// - worldborder <player> center:<player.location> size:10
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("center") && arg.matchesArgumentType(LocationTag.class) && arg.matchesPrefix("center")) {
scriptEntry.addObject("center", arg.asType(LocationTag.class));
} else if (!scriptEntry.hasObject("damage") && arg.matchesFloat() && arg.matchesPrefix("damage")) {
scriptEntry.addObject("damage", arg.asElement());
} else if (!scriptEntry.hasObject("damagebuffer") && arg.matchesFloat() && arg.matchesPrefix("damagebuffer")) {
scriptEntry.addObject("damagebuffer", arg.asElement());
} else if (!scriptEntry.hasObject("size") && arg.matchesFloat() && arg.matchesPrefix("size")) {
scriptEntry.addObject("size", arg.asElement());
} else if (!scriptEntry.hasObject("current_size") && arg.matchesFloat() && arg.matchesPrefix("current_size")) {
scriptEntry.addObject("current_size", arg.asElement());
} else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(DurationTag.class) && arg.matchesPrefix("duration")) {
scriptEntry.addObject("duration", arg.asType(DurationTag.class));
} else if (!scriptEntry.hasObject("warningdistance") && arg.matchesInteger() && arg.matchesPrefix("warningdistance")) {
scriptEntry.addObject("warningdistance", arg.asElement());
} else if (!scriptEntry.hasObject("warningtime") && arg.matchesArgumentType(DurationTag.class) && arg.matchesPrefix("warningtime")) {
scriptEntry.addObject("warningtime", arg.asType(DurationTag.class));
} else if (!scriptEntry.hasObject("world") && arg.matchesArgumentType(WorldTag.class)) {
scriptEntry.addObject("world", arg.asType(WorldTag.class));
} else if (!scriptEntry.hasObject("players") && arg.matchesArgumentList(PlayerTag.class)) {
scriptEntry.addObject("players", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry));
} else if (!scriptEntry.hasObject("reset") && arg.matches("reset")) {
scriptEntry.addObject("reset", new ElementTag("true"));
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("world") && !scriptEntry.hasObject("players")) {
throw new InvalidArgumentsException("Must specify a world or players!");
}
if (!scriptEntry.hasObject("center") && !scriptEntry.hasObject("size") && !scriptEntry.hasObject("damage") && !scriptEntry.hasObject("damagebuffer") && !scriptEntry.hasObject("warningdistance") && !scriptEntry.hasObject("warningtime") && !scriptEntry.hasObject("reset")) {
throw new InvalidArgumentsException("Must specify at least one option!");
}
scriptEntry.defaultObject("duration", new DurationTag(0));
scriptEntry.defaultObject("reset", new ElementTag("false"));
}
Aggregations