use of com.denizenscript.denizencore.objects.core.MapTag 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.MapTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityArmorPose method getPoseMap.
public MapTag getPoseMap() {
ArmorStand armorStand = (ArmorStand) entity.getBukkitEntity();
MapTag map = new MapTag();
for (PosePart posePart : PosePart.values()) {
map.putObject(CoreUtilities.toLowerCase(posePart.name()), fromEulerAngle(posePart.getAngle(armorStand)));
}
return map;
}
use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityAttributeBaseValues method attributeBaseValues.
public MapTag attributeBaseValues() {
MapTag result = new MapTag();
Attributable ent = getAttributable();
for (Attribute attr : Attribute.values()) {
AttributeInstance instance = ent.getAttribute(attr);
if (instance != null) {
result.putObject(attr.name(), new ElementTag(instance.getBaseValue()));
}
}
return result;
}
use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityAttributeBaseValues method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("attribute_base_values") && mechanism.requireObject(MapTag.class)) {
MapTag input = mechanism.valueAsType(MapTag.class);
Attributable ent = getAttributable();
for (Map.Entry<StringHolder, ObjectTag> subValue : input.map.entrySet()) {
Attribute attr = Attribute.valueOf(subValue.getKey().str.toUpperCase());
AttributeInstance instance = ent.getAttribute(attr);
if (instance == null) {
mechanism.echoError("Attribute " + attr.name() + " is not applicable to entity of type " + entity.getBukkitEntityType().name());
continue;
}
ElementTag value = subValue.getValue().asElement();
if (!value.isDouble()) {
mechanism.echoError("Invalid input '" + value + "': must be a decimal number.");
continue;
}
instance.setBaseValue(value.asDouble());
}
}
}
use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemPotion method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("potion_effects")) {
List<ObjectTag> data = new ArrayList<>(CoreUtilities.objectToList(mechanism.value, mechanism.context));
ObjectTag firstObj = data.remove(0);
PotionMeta meta = getMeta();
PotionType type;
boolean upgraded = false;
boolean extended = false;
ColorTag color = null;
if (firstObj.canBeType(MapTag.class)) {
MapTag baseEffect = firstObj.asType(MapTag.class, mechanism.context);
if (baseEffect.getObject("type") != null) {
ElementTag typeElement = baseEffect.getObject("type").asElement();
if (!typeElement.matchesEnum(PotionType.class)) {
mechanism.echoError("Invalid base potion type '" + typeElement + "': type is required");
return;
}
type = PotionType.valueOf(typeElement.asString().toUpperCase());
} else {
mechanism.echoError("No base potion type specified: type is required");
return;
}
if (baseEffect.getObject("upgraded") != null) {
ElementTag upgradedElement = baseEffect.getObject("upgraded").asElement();
if (upgradedElement.isBoolean()) {
upgraded = upgradedElement.asBoolean();
} else {
mechanism.echoError("Invalid upgraded state '" + upgradedElement + "': must be a boolean");
}
}
if (baseEffect.getObject("extended") != null) {
ElementTag extendedElement = baseEffect.getObject("extended").asElement();
if (extendedElement.isBoolean()) {
extended = extendedElement.asBoolean();
} else {
mechanism.echoError("Invalid extended state '" + extendedElement + "': must be a boolean");
}
}
if (baseEffect.getObject("color") != null) {
ObjectTag colorObj = baseEffect.getObject("color");
if (colorObj.canBeType(ColorTag.class)) {
color = colorObj.asType(ColorTag.class, mechanism.context);
} else {
mechanism.echoError("Invalid color '" + colorObj + "': must be a valid ColorTag");
}
}
} else {
String[] d1 = firstObj.toString().split(",");
try {
type = PotionType.valueOf(d1[0].toUpperCase());
} catch (IllegalArgumentException ex) {
mechanism.echoError("Invalid base potion type '" + d1[0] + "': type is required");
return;
}
upgraded = CoreUtilities.equalsIgnoreCase(d1[1], "true");
extended = CoreUtilities.equalsIgnoreCase(d1[2], "true");
if (d1.length > 3) {
ColorTag temp = ColorTag.valueOf(d1[3].replace("&comma", ","), mechanism.context);
if (temp == null) {
mechanism.echoError("Invalid color '" + d1[3] + "': must be a valid ColorTag");
} else {
color = temp;
}
}
}
if (upgraded && !type.isUpgradeable()) {
mechanism.echoError("Cannot upgrade potion of type '" + type.name() + "'");
upgraded = false;
}
if (extended && !type.isExtendable()) {
mechanism.echoError("Cannot extend potion of type '" + type.name() + "'");
extended = false;
}
if (upgraded && extended) {
mechanism.echoError("Cannot both upgrade and extend a potion");
extended = false;
}
if (color != null) {
meta.setColor(color.getColor());
}
meta.setBasePotionData(new PotionData(type, extended, upgraded));
meta.clearCustomEffects();
for (ObjectTag effectObj : data) {
PotionEffect effect;
if (effectObj.canBeType(MapTag.class)) {
effect = parseEffect(effectObj.asType(MapTag.class, mechanism.context), mechanism.context);
} else {
effect = parseEffect(effectObj.toString(), mechanism.context);
}
if (effect != null) {
meta.addCustomEffect(effect, false);
} else {
mechanism.echoError("Invalid potion effect '" + effectObj + "'");
}
}
item.setItemMeta(meta);
}
}
Aggregations