use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.
the class RotateCommand method execute.
@Override
public void execute(final ScriptEntry scriptEntry) {
final List<EntityTag> entities = new ArrayList<>((List<EntityTag>) scriptEntry.getObject("entities"));
final DurationTag duration = scriptEntry.getObjectTag("duration");
final DurationTag frequency = scriptEntry.getObjectTag("frequency");
final ElementTag yaw = scriptEntry.getElement("yaw");
final ElementTag pitch = scriptEntry.getElement("pitch");
boolean cancel = scriptEntry.hasObject("cancel");
final boolean infinite = scriptEntry.hasObject("infinite");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), (cancel ? db("cancel", true) : ""), db("entities", entities), (infinite ? db("duration", "infinite") : duration), frequency, yaw, pitch);
}
for (EntityTag entity : entities) {
if (cancel) {
rotatingEntities.remove(entity.getUUID());
} else {
rotatingEntities.add(entity.getUUID());
}
}
if (cancel) {
return;
}
BukkitRunnable task = new BukkitRunnable() {
int ticks = 0;
int maxTicks = duration.getTicksAsInt();
ArrayList<EntityTag> unusedEntities = new ArrayList<>();
@Override
public void run() {
if (entities.isEmpty()) {
scriptEntry.setFinished(true);
this.cancel();
} else if (infinite || ticks < maxTicks) {
for (EntityTag entity : entities) {
if (entity.isSpawned() && rotatingEntities.contains(entity.getUUID())) {
NMSHandler.getEntityHelper().rotate(entity.getBukkitEntity(), EntityHelper.normalizeYaw(entity.getLocation().getYaw() + yaw.asFloat()), entity.getLocation().getPitch() + pitch.asFloat());
} else {
rotatingEntities.remove(entity.getUUID());
unusedEntities.add(entity);
}
}
if (!unusedEntities.isEmpty()) {
for (EntityTag unusedEntity : unusedEntities) {
entities.remove(unusedEntity);
}
unusedEntities.clear();
}
ticks = (int) (ticks + frequency.getTicks());
} else {
scriptEntry.setFinished(true);
this.cancel();
}
}
};
task.runTaskTimer(Denizen.getInstance(), 0, frequency.getTicks());
}
use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.
the class CooldownCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ScriptTag script = scriptEntry.getObjectTag("script");
DurationTag duration = scriptEntry.getObjectTag("duration");
Type type = (scriptEntry.hasObject("type") ? (Type) scriptEntry.getObject("type") : Type.PLAYER);
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("Type", type.name()), script, (type.name().equalsIgnoreCase("player") ? Utilities.getEntryPlayer(scriptEntry) : null), duration);
}
switch(type) {
case PLAYER:
setCooldown(Utilities.getEntryPlayer(scriptEntry), duration, script.getName(), false);
break;
case GLOBAL:
setCooldown(null, duration, script.getName(), true);
break;
}
}
use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.
the class TriggerCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag toggle = scriptEntry.getElement("toggle");
ElementTag trigger = scriptEntry.getElement("trigger");
ElementTag radius = scriptEntry.getElement("radius");
DurationTag cooldown = scriptEntry.getObjectTag("cooldown");
NPCTag npc = scriptEntry.hasObject("npc") ? (NPCTag) scriptEntry.getObject("npc") : Utilities.getEntryNPC(scriptEntry);
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), trigger, toggle, radius, cooldown, npc);
}
// Add trigger trait
if (!npc.getCitizen().hasTrait(TriggerTrait.class)) {
npc.getCitizen().addTrait(TriggerTrait.class);
}
TriggerTrait trait = npc.getCitizen().getOrAddTrait(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 com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemCooldownCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ArrayList<MaterialTag> materials = (ArrayList<MaterialTag>) scriptEntry.getObject("materials");
DurationTag duration = scriptEntry.getObjectTag("duration");
PlayerTag player = Utilities.getEntryPlayer(scriptEntry);
if (player == null) {
Debug.echoError("Invalid linked player.");
return;
}
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("materials", materials), duration);
}
for (MaterialTag mat : materials) {
player.getPlayerEntity().setCooldown(mat.getMaterial(), duration.getTicksAsInt());
}
}
use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.
the class ShowFakeCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
NetworkInterceptHelper.enable();
DurationTag duration = scriptEntry.getObjectTag("duration");
ElementTag cancel = scriptEntry.getElement("cancel");
List<MaterialTag> materials = (List<MaterialTag>) scriptEntry.getObject("materials");
List<LocationTag> locations = (List<LocationTag>) scriptEntry.getObject("locations");
List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), duration, cancel, db("materials", materials), db("locations", locations), db("players", players));
}
boolean shouldCancel = cancel.asBoolean();
int i = 0;
for (LocationTag loc : locations) {
if (!shouldCancel) {
FakeBlock.showFakeBlockTo(players, loc.getBlockLocation(), materials.get(i % materials.size()), duration, locations.size() < 5);
} else {
FakeBlock.stopShowingTo(players, loc.getBlockLocation());
}
i++;
}
}
Aggregations