use of net.aufdemrand.denizencore.objects.Duration in project Denizen-For-Bukkit by DenizenScript.
the class TriggerCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
Element toggle = scriptEntry.getElement("toggle");
Element trigger = scriptEntry.getElement("trigger");
Element radius = scriptEntry.getElement("radius");
Duration cooldown = (Duration) scriptEntry.getObject("cooldown");
dNPC npc = scriptEntry.hasObject("npc") ? (dNPC) scriptEntry.getObject("npc") : ((BukkitScriptEntryData) scriptEntry.entryData).getNPC();
dB.report(scriptEntry, getName(), trigger.debug() + toggle.debug() + (radius != null ? radius.debug() : "") + (cooldown != null ? cooldown.debug() : "") + npc.debug());
// Add trigger trait
if (!npc.getCitizen().hasTrait(TriggerTrait.class)) {
npc.getCitizen().addTrait(TriggerTrait.class);
}
TriggerTrait trait = npc.getCitizen().getTrait(TriggerTrait.class);
switch(Toggle.valueOf(toggle.asString().toUpperCase())) {
case TOGGLE:
trait.toggleTrigger(trigger.asString());
break;
case TRUE:
trait.toggleTrigger(trigger.asString(), true);
break;
case FALSE:
trait.toggleTrigger(trigger.asString(), false);
break;
}
if (radius != null) {
trait.setLocalRadius(trigger.asString(), radius.asInt());
}
if (cooldown != null) {
trait.setLocalCooldown(trigger.asString(), cooldown.getSeconds());
}
}
use of net.aufdemrand.denizencore.objects.Duration in project Denizen-For-Bukkit by DenizenScript.
the class DisplayItemCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
dItem item = (dItem) scriptEntry.getObject("item");
Duration duration = (Duration) scriptEntry.getObject("duration");
dLocation location = (dLocation) scriptEntry.getObject("location");
dB.report(scriptEntry, getName(), item.debug() + duration.debug() + location.debug());
// Drop the item
final Item dropped = location.getWorld().dropItem(location.getBlock().getLocation().clone().add(0.5, 1.5, 0.5), item.getItemStack());
dropped.setVelocity(dropped.getVelocity().multiply(0));
dropped.setPickupDelay(duration.getTicksAsInt() + 1000);
dropped.setTicksLived(duration.getTicksAsInt() + 1000);
// Remember the item entity
scriptEntry.addObject("dropped", new dEntity(dropped));
// Remove it later
Bukkit.getScheduler().scheduleSyncDelayedTask(DenizenAPI.getCurrentInstance(), new Runnable() {
@Override
public void run() {
if (dropped.isValid() && !dropped.isDead()) {
dropped.remove();
}
}
}, duration.getTicks());
}
use of net.aufdemrand.denizencore.objects.Duration in project Denizen-For-Bukkit by DenizenScript.
the class FakeItemCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
List<dItem> items = (List<dItem>) scriptEntry.getObject("item");
final Element elSlot = scriptEntry.getElement("slot");
Duration duration = scriptEntry.getdObject("duration");
final List<dPlayer> players = (List<dPlayer>) scriptEntry.getObject("players");
final Element player_only = scriptEntry.getElement("player_only");
dB.report(scriptEntry, getName(), aH.debugList("items", items) + elSlot.debug() + duration.debug() + aH.debugList("players", players) + player_only.debug());
int slot = elSlot.asInt() - 1;
final boolean playerOnly = player_only.asBoolean();
final PacketHelper packetHelper = NMSHandler.getInstance().getPacketHelper();
for (dItem item : items) {
if (item == null) {
slot++;
continue;
}
for (dPlayer player : players) {
Player ent = player.getPlayerEntity();
packetHelper.setSlot(ent, translateSlot(ent, slot, playerOnly), item.getItemStack(), playerOnly);
}
final int slotSnapshot = slot;
slot++;
if (duration.getSeconds() > 0) {
DenizenCore.schedule(new OneTimeSchedulable(new Runnable() {
@Override
public void run() {
for (dPlayer player : players) {
Player ent = player.getPlayerEntity();
ItemStack original = ent.getOpenInventory().getItem(translateSlot(ent, slotSnapshot, playerOnly));
packetHelper.setSlot(ent, slotSnapshot, original, playerOnly);
}
}
}, (float) duration.getSeconds()));
}
}
}
use of net.aufdemrand.denizencore.objects.Duration in project Denizen-For-Bukkit by DenizenScript.
the class PushCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("origin") && arg.matchesPrefix("origin", "o", "source", "shooter", "s")) {
if (arg.matchesArgumentType(dEntity.class)) {
scriptEntry.addObject("originEntity", arg.asType(dEntity.class));
} else if (arg.matchesArgumentType(dLocation.class)) {
scriptEntry.addObject("originLocation", arg.asType(dLocation.class));
} else {
dB.echoError("Ignoring unrecognized argument: " + arg.raw_value);
}
} else if (!scriptEntry.hasObject("destination") && arg.matchesArgumentType(dLocation.class) && arg.matchesPrefix("destination", "d")) {
scriptEntry.addObject("destination", arg.asType(dLocation.class));
} else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(Duration.class) && arg.matchesPrefix("duration", "d")) {
scriptEntry.addObject("duration", arg.asType(Duration.class));
} else if (!scriptEntry.hasObject("speed") && arg.matchesPrimitive(aH.PrimitiveType.Double) && arg.matchesPrefix("speed", "s")) {
scriptEntry.addObject("speed", arg.asElement());
} else if (!scriptEntry.hasObject("script") && (arg.matchesArgumentType(dScript.class) || arg.matchesPrefix("script"))) {
scriptEntry.addObject("script", arg.asType(dScript.class));
} else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(dEntity.class)) {
scriptEntry.addObject("entities", arg.asType(dList.class).filter(dEntity.class));
} else if (!scriptEntry.hasObject("force_along") && arg.matches("force_along")) {
scriptEntry.addObject("force_along", new Element(true));
} else if (!scriptEntry.hasObject("no_rotate") && arg.matches("no_rotate")) {
scriptEntry.addObject("no_rotate", new Element(true));
} else if (!scriptEntry.hasObject("precision") && arg.matchesPrefix("precision")) {
scriptEntry.addObject("precision", arg.asElement());
} else if (!scriptEntry.hasObject("no_damage") && arg.matches("no_damage")) {
scriptEntry.addObject("no_damage", new Element(true));
} else if (arg.matchesPrefix("def", "define", "context")) {
scriptEntry.addObject("definitions", arg.asType(dList.class));
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("originLocation")) {
scriptEntry.defaultObject("originEntity", ((BukkitScriptEntryData) scriptEntry.entryData).hasNPC() ? ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getDenizenEntity() : null, ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getDenizenEntity() : null);
}
scriptEntry.defaultObject("speed", new Element(1.5));
scriptEntry.defaultObject("duration", new Duration(20));
scriptEntry.defaultObject("force_along", new Element(false));
scriptEntry.defaultObject("precision", new Element(2));
if (!scriptEntry.hasObject("entities")) {
throw new InvalidArgumentsException("Must specify entity/entities!");
}
if (!scriptEntry.hasObject("originEntity") && !scriptEntry.hasObject("originLocation")) {
throw new InvalidArgumentsException("Must specify an origin location!");
}
}
use of net.aufdemrand.denizencore.objects.Duration in project Denizen-For-Bukkit by DenizenScript.
the class RotateCommand method execute.
@SuppressWarnings("unchecked")
@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
final List<dEntity> entities = new ArrayList<dEntity>((List<dEntity>) scriptEntry.getObject("entities"));
final Duration duration = (Duration) scriptEntry.getObject("duration");
final Duration frequency = (Duration) scriptEntry.getObject("frequency");
final Element yaw = (Element) scriptEntry.getObject("yaw");
final Element pitch = (Element) scriptEntry.getObject("pitch");
boolean cancel = scriptEntry.hasObject("cancel");
final boolean infinite = scriptEntry.hasObject("infinite");
// Report to dB
dB.report(scriptEntry, getName(), (cancel ? aH.debugObj("cancel", cancel) : "") + aH.debugObj("entities", entities.toString()) + (infinite ? aH.debugObj("duration", "infinite") : duration.debug()) + frequency.debug() + yaw.debug() + pitch.debug());
// them from it
for (dEntity entity : entities) {
if (cancel) {
rotatingEntities.remove(entity.getUUID());
} else {
rotatingEntities.add(entity.getUUID());
}
}
// Go no further if we are canceling a rotation
if (cancel) {
return;
}
// Run a task that will keep rotating the entities
BukkitRunnable task = new BukkitRunnable() {
int ticks = 0;
int maxTicks = duration.getTicksAsInt();
// Track entities that are no longer used, to remove them from
// the regular list
Collection<dEntity> unusedEntities = new LinkedList<dEntity>();
@Override
public void run() {
if (entities.isEmpty()) {
scriptEntry.setFinished(true);
this.cancel();
} else if (infinite || ticks < maxTicks) {
for (dEntity entity : entities) {
if (entity.isSpawned() && rotatingEntities.contains(entity.getUUID())) {
NMSHandler.getInstance().getEntityHelper().rotate(entity.getBukkitEntity(), NMSHandler.getInstance().getEntityHelper().normalizeYaw(entity.getLocation().getYaw() + yaw.asFloat()), entity.getLocation().getPitch() + pitch.asFloat());
} else {
rotatingEntities.remove(entity.getUUID());
unusedEntities.add(entity);
}
}
// Remove any entities that are no longer spawned
if (!unusedEntities.isEmpty()) {
for (dEntity unusedEntity : unusedEntities) {
entities.remove(unusedEntity);
}
unusedEntities.clear();
}
ticks = (int) (ticks + frequency.getTicks());
} else {
scriptEntry.setFinished(true);
this.cancel();
}
}
};
task.runTaskTimer(DenizenAPI.getCurrentInstance(), 0, frequency.getTicks());
}
Aggregations