use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.
the class SwitchCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("no_physics") && arg.matches("no_physics")) {
scriptEntry.addObject("no_physics", new ElementTag(true));
} else if (!scriptEntry.hasObject("locations") && arg.matchesArgumentList(LocationTag.class)) {
scriptEntry.addObject("locations", arg.asType(ListTag.class));
} else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(DurationTag.class)) {
scriptEntry.addObject("duration", arg.asType(DurationTag.class));
} else if (!scriptEntry.hasObject("state") && arg.matchesEnum(SwitchState.class)) {
scriptEntry.addObject("switchstate", new ElementTag(arg.getValue().toUpperCase()));
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("locations")) {
throw new InvalidArgumentsException("Must specify a location!");
}
scriptEntry.defaultObject("duration", new DurationTag(0));
scriptEntry.defaultObject("switchstate", new ElementTag("TOGGLE"));
}
use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.
the class FakeItemCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
List<ItemTag> items = (List<ItemTag>) scriptEntry.getObject("item");
final ElementTag elSlot = scriptEntry.getElement("slot");
DurationTag duration = scriptEntry.getObjectTag("duration");
final List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
final ElementTag player_only = scriptEntry.getElement("player_only");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("items", items), elSlot, duration, db("players", players), player_only);
}
if (players.size() == 0) {
return;
}
int slot = SlotHelper.nameToIndex(elSlot.asString(), players.get(0).getPlayerEntity());
if (slot == -1) {
Debug.echoError(scriptEntry, "The input '" + elSlot.asString() + "' is not a valid slot!");
return;
}
final boolean playerOnly = player_only.asBoolean();
final PacketHelper packetHelper = NMSHandler.getPacketHelper();
for (ItemTag item : items) {
if (item == null) {
slot++;
continue;
}
for (PlayerTag 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(() -> {
for (PlayerTag player : players) {
Player ent = player.getPlayerEntity();
int translated = translateSlot(ent, slotSnapshot, playerOnly);
ItemStack original = ent.getOpenInventory().getItem(translated);
packetHelper.setSlot(ent, translated, original, playerOnly);
}
}, (float) duration.getSeconds()));
}
}
}
use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.
the class CastCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
PotionEffectType effect = (PotionEffectType) scriptEntry.getObject("effect");
int amplifier = scriptEntry.getElement("amplifier").asInt();
DurationTag duration = scriptEntry.getObjectTag("duration");
boolean remove = scriptEntry.getElement("remove").asBoolean();
ElementTag showParticles = scriptEntry.getElement("show_particles");
ElementTag ambient = scriptEntry.getElement("ambient");
ElementTag showIcon = scriptEntry.getElement("show_icon");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("Target(s)", entities.toString()), db("Effect", effect.getName()), db("Amplifier", amplifier), duration, ambient, showParticles, showIcon);
}
boolean amb = ambient.asBoolean();
boolean showP = showParticles.asBoolean();
boolean icon = showIcon.asBoolean();
for (EntityTag entity : entities) {
if (entity.getLivingEntity().hasPotionEffect(effect)) {
entity.getLivingEntity().removePotionEffect(effect);
}
if (remove) {
continue;
}
PotionEffect potion = new PotionEffect(effect, duration.getTicksAsInt(), amplifier, amb, showP, icon);
if (!potion.apply(entity.getLivingEntity())) {
Debug.echoError(scriptEntry, "Bukkit was unable to apply '" + potion.getType().getName() + "' to '" + entity.toString() + "'.");
}
}
}
use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.
the class PauseCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
DurationTag duration = scriptEntry.getObjectTag("duration");
ElementTag pauseTypeElement = scriptEntry.getElement("pause_type");
PauseType pauseType = PauseType.valueOf(pauseTypeElement.asString().toUpperCase());
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), duration, pauseTypeElement);
}
NPCTag npc = null;
if (Utilities.getEntryNPC(scriptEntry) != null) {
npc = Utilities.getEntryNPC(scriptEntry);
}
pause(npc, pauseType, !scriptEntry.getCommandName().equalsIgnoreCase("RESUME"));
if (duration != null) {
if (durations.containsKey(npc.getCitizen().getId() + pauseType.name())) {
try {
Denizen.getInstance().getServer().getScheduler().cancelTask(durations.get(npc.getCitizen().getId() + pauseType.name()));
} catch (Exception e) {
Debug.echoError(scriptEntry, "There was an error pausing that!");
Debug.echoError(scriptEntry, e);
}
}
Debug.echoDebug(scriptEntry, "Running delayed task: Unpause " + pauseType.toString());
final NPCTag theNpc = npc;
final ScriptEntry se = scriptEntry;
durations.put(npc.getId() + pauseType.name(), Denizen.getInstance().getServer().getScheduler().scheduleSyncDelayedTask(Denizen.getInstance(), () -> {
Debug.echoDebug(se, "Running delayed task: Pausing " + pauseType.toString());
pause(theNpc, pauseType, false);
}, duration.getTicks()));
}
}
use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.
the class DisplayItemCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ItemTag item = scriptEntry.getObjectTag("item");
DurationTag duration = scriptEntry.getObjectTag("duration");
LocationTag location = scriptEntry.getObjectTag("location");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), item, duration, location);
}
// Drop the item
final Item dropped = location.getWorld().dropItem(location.getBlockLocation().clone().add(0.5, 1.5, 0.5), item.getItemStack());
dropped.setVelocity(new Vector(0, 0, 0));
dropped.setGravity(false);
dropped.setPickupDelay(32767);
int ticks = duration.getTicksAsInt();
NMSHandler.getEntityHelper().setTicksLived(dropped, ticks <= 0 ? -32768 : -ticks);
if (!dropped.isValid()) {
Debug.echoDebug(scriptEntry, "Item failed to spawned (likely blocked by some plugin).");
return;
}
final UUID itemUUID = dropped.getUniqueId();
protectedEntities.add(itemUUID);
scriptEntry.addObject("dropped", new EntityTag(dropped));
if (ticks > 0) {
Bukkit.getScheduler().scheduleSyncDelayedTask(Denizen.getInstance(), () -> {
protectedEntities.remove(itemUUID);
if (dropped.isValid() && !dropped.isDead()) {
dropped.remove();
}
}, ticks);
}
}
Aggregations