use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityAreaEffectCloud method getObjectAttribute.
@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
// -->
if (attribute.startsWith("base_potion")) {
attribute = attribute.fulfill(1);
// -->
if (attribute.startsWith("type")) {
return new ElementTag(getHelper().getBPName()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("is_upgraded")) {
return new ElementTag(getHelper().getBPUpgraded()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("is_extended")) {
return new ElementTag(getHelper().getBPExtended()).getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(getHelper().getBPName() + "," + getHelper().getBPUpgraded() + "," + getHelper().getBPExtended()).getObjectAttribute(attribute);
}
// -->
if (attribute.startsWith("particle")) {
attribute = attribute.fulfill(1);
// -->
if (attribute.startsWith("color")) {
return new ColorTag(getHelper().getColor()).getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(getHelper().getParticle()).getObjectAttribute(attribute);
}
// -->
if (attribute.startsWith("duration")) {
attribute = attribute.fulfill(1);
// -->
if (attribute.startsWith("on_use")) {
return new DurationTag(getHelper().getDurationOnUse()).getObjectAttribute(attribute.fulfill(1));
}
return new DurationTag(getHelper().getDuration()).getObjectAttribute(attribute);
}
// -->
if (attribute.startsWith("radius")) {
attribute = attribute.fulfill(1);
// -->
if (attribute.startsWith("on_use")) {
return new ElementTag(getHelper().getRadiusOnUse()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("per_tick")) {
return new ElementTag(getHelper().getRadiusPerTick()).getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(getHelper().getRadius()).getObjectAttribute(attribute);
}
// -->
if (attribute.startsWith("reapplication_delay")) {
return new DurationTag(getHelper().getReappDelay()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("wait_time")) {
return new DurationTag(getHelper().getWaitTime()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("has_custom_effect")) {
if (attribute.hasParam()) {
PotionEffectType effectType = PotionEffectType.getByName(attribute.getParam());
for (PotionEffect effect : getHelper().getCustomEffects()) {
if (effect.getType().equals(effectType)) {
return new ElementTag(true).getObjectAttribute(attribute.fulfill(1));
}
}
return new ElementTag(false).getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(getHelper().hasCustomEffects()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("source")) {
ProjectileSource shooter = getHelper().getSource();
if (shooter instanceof LivingEntity) {
return new EntityTag((LivingEntity) shooter).getObjectAttribute(attribute.fulfill(1));
}
}
// -->
if (attribute.startsWith("custom_effects")) {
List<PotionEffect> effects = getHelper().getCustomEffects();
if (!attribute.hasParam()) {
ListTag list = new ListTag();
for (PotionEffect effect : effects) {
list.add(effect.getType().getName() + "," + effect.getAmplifier() + "," + new DurationTag((long) effect.getDuration()).identify() + "," + effect.isAmbient() + "," + effect.hasParticles());
}
return list.getObjectAttribute(attribute.fulfill(1));
}
int val = attribute.getIntParam() - 1;
if (val < 0 || val >= effects.size()) {
return null;
}
attribute = attribute.fulfill(1);
PotionEffect effect = effects.get(val);
// -->
if (attribute.startsWith("type")) {
return new ElementTag(effect.getType().getName()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("amplifier")) {
return new ElementTag(effect.getAmplifier()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("duration")) {
return new DurationTag((long) effect.getDuration()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("has_particles")) {
return new ElementTag(effect.hasParticles()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("is_ambient")) {
return new ElementTag(effect.isAmbient()).getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(effect.getType().getName() + "," + effect.getAmplifier() + "," + new DurationTag((long) effect.getDuration()).identify() + "," + effect.isAmbient() + "," + effect.hasParticles()).getObjectAttribute(attribute);
}
return null;
}
use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityAreaEffectCloud method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("clear_custom_effects")) {
getHelper().clearEffects();
}
// -->
if (mechanism.matches("remove_custom_effect")) {
PotionEffectType type = PotionEffectType.getByName(mechanism.getValue().asString().toUpperCase());
if (type != null) {
getHelper().removeEffect(type);
}
}
// -->
if (mechanism.matches("custom_effects")) {
ListTag list = mechanism.valueAsType(ListTag.class);
getHelper().clearEffects();
for (String item : list) {
List<String> potionData = CoreUtilities.split(item, ',', 5);
if (potionData.size() >= 3) {
PotionEffectType type = PotionEffectType.getByName(potionData.get(0));
ElementTag amplifier = new ElementTag(potionData.get(1));
DurationTag duration = DurationTag.valueOf(potionData.get(2), mechanism.context);
ElementTag ambient = new ElementTag((potionData.size() > 3) ? potionData.get(3) : "false");
ElementTag particles = new ElementTag((potionData.size() > 4) ? potionData.get(4) : "true");
if (type == null || duration == null || !amplifier.isInt() || !ambient.isBoolean() || !particles.isBoolean()) {
mechanism.echoError(item + " is not a valid potion effect!");
} else {
getHelper().addEffect(new PotionEffect(type, duration.getTicksAsInt(), amplifier.asInt(), ambient.asBoolean(), particles.asBoolean()), true);
}
} else {
mechanism.echoError(item + " is not a valid potion effect!");
}
}
}
// -->
if (mechanism.matches("particle_color") && mechanism.requireObject(ColorTag.class)) {
getHelper().setColor(mechanism.valueAsType(ColorTag.class).getColor());
}
// -->
if (mechanism.matches("base_potion")) {
List<String> data = CoreUtilities.split(mechanism.getValue().asString().toUpperCase(), ',');
if (data.size() != 3) {
mechanism.echoError(mechanism.getValue().asString() + " is not a valid base potion!");
} else {
try {
PotionType type = PotionType.valueOf(data.get(0));
boolean extended = type.isExtendable() && CoreUtilities.equalsIgnoreCase(data.get(1), "true");
boolean upgraded = type.isUpgradeable() && CoreUtilities.equalsIgnoreCase(data.get(2), "true");
if (extended && upgraded) {
mechanism.echoError("Potion cannot be both upgraded and extended");
} else {
getHelper().setBP(type, extended, upgraded);
}
} catch (Exception e) {
mechanism.echoError(mechanism.getValue().asString() + " is not a valid base potion!");
}
}
}
// -->
if (mechanism.matches("duration") && mechanism.requireObject(DurationTag.class)) {
getHelper().setDuration(mechanism.valueAsType(DurationTag.class).getTicksAsInt());
}
// -->
if (mechanism.matches("duration_on_use") && mechanism.requireObject(DurationTag.class)) {
getHelper().setDurationOnUse(mechanism.valueAsType(DurationTag.class).getTicksAsInt());
}
// -->
if (mechanism.matches("particle") && mechanism.hasValue()) {
getHelper().setParticle(mechanism.getValue().asString().toUpperCase());
}
// -->
if (mechanism.matches("radius") && mechanism.requireFloat()) {
getHelper().setRadius(mechanism.getValue().asFloat());
}
// -->
if (mechanism.matches("radius_on_use") && mechanism.requireFloat()) {
getHelper().setRadiusOnUse(mechanism.getValue().asFloat());
}
// -->
if (mechanism.matches("radius_per_tick") && mechanism.requireFloat()) {
getHelper().setRadiusPerTick(mechanism.getValue().asFloat());
}
// -->
if (mechanism.matches("reapplication_delay") && mechanism.requireObject(DurationTag.class)) {
getHelper().setReappDelay(mechanism.valueAsType(DurationTag.class).getTicksAsInt());
}
// -->
if (mechanism.matches("source") && mechanism.requireObject(EntityTag.class)) {
getHelper().setSource((ProjectileSource) mechanism.valueAsType(EntityTag.class).getBukkitEntity());
}
// -->
if (mechanism.matches("wait_time") && mechanism.requireObject(DurationTag.class)) {
getHelper().setWaitTime(mechanism.valueAsType(DurationTag.class).getTicksAsInt());
}
}
use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.
the class PaperTagBase method paperTag.
public void paperTag(ReplaceableTagEvent event) {
if (!event.matches("paper") || event.replaced()) {
return;
}
Attribute attribute = event.getAttributes().fulfill(1);
// -->
if (attribute.startsWith("tick_times")) {
ListTag list = new ListTag();
for (long time : Bukkit.getServer().getTickTimes()) {
list.addObject(new DurationTag(time / 1000000000D));
}
event.setReplacedObject(list.getObjectAttribute(attribute.fulfill(1)));
return;
}
}
use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.
the class ZapCommand method execute.
@Override
public void execute(final ScriptEntry scriptEntry) {
final ScriptTag script = scriptEntry.getObjectTag("script");
DurationTag duration = scriptEntry.getObjectTag("duration");
ElementTag stepElement = scriptEntry.getElement("step");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), Utilities.getEntryPlayer(scriptEntry), script, stepElement != null ? stepElement : db("step", "++ (inc)"), duration);
}
String step = stepElement == null ? null : stepElement.asString();
String currentStep = InteractScriptHelper.getCurrentStep(Utilities.getEntryPlayer(scriptEntry), script.getName());
// Special-case for backwards compatibility: ability to use ZAP to count up steps.
if (step == null) {
// to '1' so it can be incremented next time.
if (ArgumentHelper.matchesInteger(currentStep)) {
step = String.valueOf(Integer.parseInt(currentStep) + 1);
} else {
step = "1";
}
} else if (step.equals("*")) {
step = ((InteractScriptContainer) script.getContainer()).getDefaultStepName();
}
if (step.equalsIgnoreCase(currentStep)) {
Debug.echoError(scriptEntry, "Zapping to own current step!");
return;
}
TimeTag expiration = null;
if (duration != null && duration.getSeconds() > 0) {
expiration = new TimeTag(TimeTag.now().millis() + duration.getMillis());
}
Utilities.getEntryPlayer(scriptEntry).getFlagTracker().setFlag("__interact_step." + script.getName(), new ElementTag(step), expiration);
}
use of com.denizenscript.denizencore.objects.core.DurationTag in project Denizen-For-Bukkit by DenizenScript.
the class BurnCommand method execute.
@Override
public void execute(final ScriptEntry scriptEntry) {
List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
DurationTag duration = scriptEntry.getObjectTag("duration");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), duration, db("entities", entities));
}
for (EntityTag entity : entities) {
if (entity.isSpawned()) {
entity.getBukkitEntity().setFireTicks(duration.getTicksAsInt());
}
}
}
Aggregations