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);
}
}
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));
}
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++;
}
}
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());
}
}
}
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());
}
}
}
Aggregations