use of com.denizenscript.denizencore.objects.core.ListTag 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.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityArmorPose method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("armor_pose")) {
ArmorStand armorStand = (ArmorStand) entity.getBukkitEntity();
if (mechanism.value.canBeType(MapTag.class)) {
MapTag map = mechanism.valueAsType(MapTag.class);
for (Map.Entry<StringHolder, ObjectTag> entry : map.map.entrySet()) {
PosePart posePart = PosePart.fromName(entry.getKey().str);
if (posePart == null) {
mechanism.echoError("Invalid pose part specified: " + entry.getKey().str);
} else {
posePart.setAngle(armorStand, toEulerAngle(entry.getValue().asType(LocationTag.class, mechanism.context)));
}
}
} else {
ListTag list = mechanism.valueAsType(ListTag.class);
Iterator<String> iterator = list.iterator();
while (iterator.hasNext()) {
String name = iterator.next();
String angle = iterator.next();
PosePart posePart = PosePart.fromName(name);
if (posePart == null) {
mechanism.echoError("Invalid pose part specified: " + name + "; ignoring next: " + angle);
} else {
posePart.setAngle(armorStand, toEulerAngle(LocationTag.valueOf(angle, mechanism.context)));
}
}
}
}
}
use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityArmorPose method getPoseList.
private ListTag getPoseList() {
ArmorStand armorStand = (ArmorStand) entity.getBukkitEntity();
ListTag list = new ListTag();
for (PosePart posePart : PosePart.values()) {
list.add(CoreUtilities.toLowerCase(posePart.name()));
list.addObject(fromEulerAngle(posePart.getAngle(armorStand)));
}
return list;
}
use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityAttributeModifiers method getAttributes.
@Deprecated
public ListTag getAttributes() {
ListTag list = new ListTag();
for (Attribute attribute : Attribute.values()) {
AttributeInstance instance = getAttributable().getAttribute(attribute);
if (instance == null) {
continue;
}
StringBuilder modifiers = new StringBuilder();
for (AttributeModifier modifier : instance.getModifiers()) {
modifiers.append("/").append(stringify(modifier));
}
list.add(EscapeTagBase.escape(attribute.name()) + "/" + instance.getBaseValue() + modifiers.toString());
}
return list;
}
use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class TriggerTrait method trigger.
public TriggerContext trigger(AbstractTrigger triggerClass, PlayerTag player, Map<String, ObjectTag> context) {
String trigger_type = triggerClass.getName();
if (!Denizen.getInstance().triggerRegistry.checkCooldown(npc, player, triggerClass)) {
return new TriggerContext(false);
}
if (context == null) {
context = new HashMap<>();
}
if (EngageCommand.getEngaged(npc, player)) {
context.put("trigger_type", new ElementTag(trigger_type));
// TODO: Should this be refactored?
if (new NPCTag(npc).action("unavailable", player, context).containsCaseInsensitive("available")) {
// If determined available, continue on...
// else, return a 'non-triggered' state.
} else {
return new TriggerContext(false);
}
}
Denizen.getInstance().triggerRegistry.setCooldown(npc, player, triggerClass, getCooldownDuration(trigger_type));
ListTag determination = new NPCTag(npc).action(trigger_type, player, context);
return new TriggerContext(determination, true);
}
Aggregations