use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityColor method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("color")) {
EntityType type = colored.getBukkitEntityType();
if (type == EntityType.HORSE && mechanism.requireObject(ListTag.class)) {
ListTag list = mechanism.valueAsType(ListTag.class);
Horse horse = (Horse) colored.getBukkitEntity();
String color = list.get(0);
if (new ElementTag(color).matchesEnum(Horse.Color.class)) {
horse.setColor(Horse.Color.valueOf(color.toUpperCase()));
} else {
mechanism.echoError("Invalid horse color specified: " + color);
}
if (list.size() > 1) {
String style = list.get(1);
if (new ElementTag(style).matchesEnum(Horse.Style.class)) {
horse.setStyle(Horse.Style.valueOf(style.toUpperCase()));
} else {
mechanism.echoError("Invalid horse style specified: " + style);
}
}
} else if (type == EntityType.SHEEP && mechanism.requireEnum(DyeColor.class)) {
((Sheep) colored.getBukkitEntity()).setColor(DyeColor.valueOf(mechanism.getValue().asString().toUpperCase()));
} else if (type == EntityType.WOLF && mechanism.requireEnum(DyeColor.class)) {
((Wolf) colored.getBukkitEntity()).setCollarColor(DyeColor.valueOf(mechanism.getValue().asString().toUpperCase()));
} else if (type == EntityType.OCELOT && mechanism.requireEnum(Ocelot.Type.class)) {
// TODO: Deprecate?
((Ocelot) colored.getBukkitEntity()).setCatType(Ocelot.Type.valueOf(mechanism.getValue().asString().toUpperCase()));
} else if (type == EntityType.RABBIT && mechanism.requireEnum(Rabbit.Type.class)) {
((Rabbit) colored.getBukkitEntity()).setRabbitType(Rabbit.Type.valueOf(mechanism.getValue().asString().toUpperCase()));
} else if ((type == EntityType.LLAMA || type == EntityType.TRADER_LLAMA) && mechanism.requireEnum(Llama.Color.class)) {
((Llama) colored.getBukkitEntity()).setColor(Llama.Color.valueOf(mechanism.getValue().asString().toUpperCase()));
} else if (type == EntityType.PARROT && mechanism.requireEnum(Parrot.Variant.class)) {
((Parrot) colored.getBukkitEntity()).setVariant(Parrot.Variant.valueOf(mechanism.getValue().asString().toUpperCase()));
} else if (type == EntityType.SHULKER && mechanism.requireEnum(DyeColor.class)) {
((Shulker) colored.getBukkitEntity()).setColor(DyeColor.valueOf(mechanism.getValue().asString().toUpperCase()));
} else if (type == EntityType.MUSHROOM_COW && mechanism.requireEnum(MushroomCow.Variant.class)) {
((MushroomCow) colored.getBukkitEntity()).setVariant(MushroomCow.Variant.valueOf(mechanism.getValue().asString().toUpperCase()));
} else if (type == EntityType.TROPICAL_FISH && mechanism.requireObject(ListTag.class)) {
ListTag list = mechanism.valueAsType(ListTag.class);
TropicalFish fish = ((TropicalFish) colored.getBukkitEntity());
String pattern = list.get(0);
if (new ElementTag(pattern).matchesEnum(TropicalFish.Pattern.class)) {
fish.setPattern(TropicalFish.Pattern.valueOf(pattern.toUpperCase()));
} else {
mechanism.echoError("Invalid tropical fish pattern specified: " + pattern);
}
if (list.size() > 1) {
String color = list.get(1);
if (new ElementTag(color).matchesEnum(DyeColor.class)) {
fish.setBodyColor(DyeColor.valueOf(color.toUpperCase()));
} else {
mechanism.echoError("Invalid color specified: " + color);
}
}
if (list.size() > 2) {
String patternColor = list.get(2);
if (new ElementTag(patternColor).matchesEnum(DyeColor.class)) {
fish.setPatternColor(DyeColor.valueOf(patternColor.toUpperCase()));
} else {
mechanism.echoError("Invalid pattern color specified: " + patternColor);
}
}
} else if (type == EntityType.FOX && mechanism.requireEnum(Fox.Type.class)) {
((Fox) colored.getBukkitEntity()).setFoxType(Fox.Type.valueOf(mechanism.getValue().asString().toUpperCase()));
} else if (type == EntityType.CAT && mechanism.requireObject(ListTag.class)) {
Cat cat = (Cat) colored.getBukkitEntity();
ListTag list = mechanism.valueAsType(ListTag.class);
String catType = list.get(0);
if (new ElementTag(catType).matchesEnum(Cat.Type.class)) {
cat.setCatType(Cat.Type.valueOf(catType.toUpperCase()));
} else {
mechanism.echoError("Invalid cat type specified: " + catType);
}
if (list.size() > 1) {
String color = list.get(1);
if (new ElementTag(color).matchesEnum(DyeColor.class)) {
cat.setCollarColor(DyeColor.valueOf(list.get(1).toUpperCase()));
} else {
mechanism.echoError("Invalid color specified: " + color);
}
}
} else if (type == EntityType.PANDA && mechanism.requireObject(ListTag.class)) {
Panda panda = (Panda) colored.getBukkitEntity();
ListTag list = mechanism.valueAsType(ListTag.class);
String mainGene = list.get(0);
if (new ElementTag(mainGene).matchesEnum(Panda.Gene.class)) {
panda.setMainGene(Panda.Gene.valueOf(mainGene.toUpperCase()));
} else {
mechanism.echoError("Invalid panda gene specified: " + mainGene);
}
if (list.size() > 1) {
String hiddenGene = list.get(1);
if (new ElementTag(hiddenGene).matchesEnum(Panda.Gene.class)) {
panda.setHiddenGene(Panda.Gene.valueOf(hiddenGene.toUpperCase()));
} else {
mechanism.echoError("Invalid panda hidden gene specified: " + hiddenGene);
}
}
} else if (type == EntityType.VILLAGER && mechanism.requireEnum(Villager.Type.class)) {
((Villager) colored.getBukkitEntity()).setVillagerType(Villager.Type.valueOf(mechanism.getValue().asString().toUpperCase()));
} else if (type == EntityType.ARROW && mechanism.requireObject(ColorTag.class)) {
((Arrow) colored.getBukkitEntity()).setColor(mechanism.valueAsType(ColorTag.class).getColor());
} else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17) && MultiVersionHelper1_17.colorIsApplicable(type)) {
MultiVersionHelper1_17.setColor(colored.getBukkitEntity(), mechanism);
}
}
}
use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityEquipment method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("equipment") && mechanism.hasValue()) {
org.bukkit.inventory.EntityEquipment equip = entity.getLivingEntity().getEquipment();
if (mechanism.value.canBeType(MapTag.class)) {
MapTag map = mechanism.valueAsType(MapTag.class);
ObjectTag boots = map.getObject("boots");
if (boots != null) {
ItemStack bootsItem = boots.asType(ItemTag.class, mechanism.context).getItemStack();
if (entity.isCitizensNPC()) {
entity.getDenizenNPC().getEquipmentTrait().set(Equipment.EquipmentSlot.BOOTS, bootsItem);
} else {
equip.setBoots(bootsItem);
}
}
ObjectTag leggings = map.getObject("leggings");
if (leggings != null) {
ItemStack leggingsItem = leggings.asType(ItemTag.class, mechanism.context).getItemStack();
if (entity.isCitizensNPC()) {
entity.getDenizenNPC().getEquipmentTrait().set(Equipment.EquipmentSlot.LEGGINGS, leggingsItem);
} else {
equip.setLeggings(leggingsItem);
}
}
ObjectTag chestplate = map.getObject("chestplate");
if (chestplate != null) {
ItemStack chestplateItem = chestplate.asType(ItemTag.class, mechanism.context).getItemStack();
if (entity.isCitizensNPC()) {
entity.getDenizenNPC().getEquipmentTrait().set(Equipment.EquipmentSlot.CHESTPLATE, chestplateItem);
} else {
equip.setChestplate(chestplateItem);
}
}
ObjectTag helmet = map.getObject("helmet");
if (helmet != null) {
ItemStack helmetItem = helmet.asType(ItemTag.class, mechanism.context).getItemStack();
if (entity.isCitizensNPC()) {
entity.getDenizenNPC().getEquipmentTrait().set(Equipment.EquipmentSlot.HELMET, helmetItem);
} else {
equip.setHelmet(helmetItem);
}
}
} else {
// Soft-deprecate: no warn, but long term back-support
ListTag list = mechanism.valueAsType(ListTag.class);
ItemStack[] stacks = new ItemStack[list.size()];
for (int i = 0; i < list.size(); i++) {
stacks[i] = ItemTag.valueOf(list.get(i), mechanism.context).getItemStack();
}
equip.setArmorContents(stacks);
}
}
}
use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityDisabledSlots method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("disabled_slots_raw") && mechanism.requireInteger()) {
CustomNBT.addCustomNBT(dentity.getBukkitEntity(), CustomNBT.KEY_DISABLED_SLOTS, mechanism.getValue().asInt());
}
// -->
if (mechanism.matches("disabled_slots")) {
if (!mechanism.hasValue()) {
CustomNBT.removeCustomNBT(dentity.getBukkitEntity(), CustomNBT.KEY_DISABLED_SLOTS);
return;
}
ListTag list = mechanism.valueAsType(ListTag.class);
Map<EquipmentSlot, Set<Action>> map = new HashMap<>();
for (String string : list) {
String[] split = string.toUpperCase().split("/", 2);
EquipmentSlot slot;
Action action = null;
try {
slot = EquipmentSlot.valueOf(split[0]);
} catch (IllegalArgumentException e) {
mechanism.echoError("Invalid equipment slot specified: " + split[0]);
continue;
}
if (split.length == 2) {
try {
action = Action.valueOf(split[1]);
} catch (IllegalArgumentException e) {
mechanism.echoError("Invalid action specified: " + split[1]);
continue;
}
}
Set<Action> set = map.computeIfAbsent(slot, k -> new HashSet<>());
set.add(action == null ? Action.ALL : action);
}
CustomNBT.setDisabledSlots(dentity.getBukkitEntity(), map);
}
}
use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemPotion method registerTags.
public static void registerTags() {
// <--[tag]
// @attribute <ItemTag.potion_base_type>
// @returns ElementTag
// @mechanism ItemTag.potion_effects
// @group properties
// @description
// Returns the base potion type name for this potion item.
// The type will be from <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/potion/PotionType.html>.
// -->
PropertyParser.<ItemPotion, ElementTag>registerTag(ElementTag.class, "potion_base_type", (attribute, object) -> {
return new ElementTag(object.getMeta().getBasePotionData().getType().name());
});
// <--[tag]
// @attribute <ItemTag.potion_base>
// @returns ElementTag
// @group attribute
// @mechanism ItemTag.potion_effects
// @deprecated use 'effects_data' instead
// @description
// Deprecated in favor of <@link tag ItemTag.effects_data>
// -->
PropertyParser.<ItemPotion, ElementTag>registerTag(ElementTag.class, "potion_base", (attribute, object) -> {
Deprecations.oldPotionEffects.warn(attribute.context);
PotionMeta meta = object.getMeta();
return new ElementTag(meta.getBasePotionData().getType().name() + "," + (meta.getBasePotionData().isUpgraded() ? 2 : 1) + "," + meta.getBasePotionData().isExtended() + "," + (object.item.getBukkitMaterial() == Material.SPLASH_POTION) + (meta.hasColor() ? "," + new ColorTag(meta.getColor()).identify() : ""));
});
// <--[tag]
// @attribute <ItemTag.potion_effects>
// @returns ListTag
// @group attribute
// @mechanism ItemTag.potion_effects
// @deprecated use 'effects_data' instead
// @description
// Deprecated in favor of <@link tag ItemTag.effects_data>
// -->
PropertyParser.<ItemPotion, ListTag>registerTag(ListTag.class, "potion_effects", (attribute, object) -> {
Deprecations.oldPotionEffects.warn(attribute.context);
ListTag result = new ListTag();
for (PotionEffect pot : object.getMeta().getCustomEffects()) {
result.add(stringifyEffect(pot));
}
return result;
});
// <--[tag]
// @attribute <ItemTag.has_potion_effect>
// @returns ElementTag(Boolean)
// @mechanism ItemTag.potion_effects
// @description
// Returns whether the potion has a potion effect.
// -->
PropertyParser.<ItemPotion, ElementTag>registerTag(ElementTag.class, "has_potion_effect", (attribute, object) -> {
return new ElementTag(object.getMeta().hasCustomEffects());
});
// <--[tag]
// @attribute <ItemTag.potion_effect[<#>]>
// @returns ElementTag
// @group attribute
// @mechanism ItemTag.potion_effects
// @deprecated use 'effects_data' instead
// @description
// Deprecated in favor of <@link tag ItemTag.effects_data>
// -->
PropertyParser.<ItemPotion, ElementTag>registerTag(ElementTag.class, "potion_effect", (attribute, object) -> {
Deprecations.oldPotionEffects.warn(attribute.context);
PotionMeta meta = object.getMeta();
int potN = attribute.hasParam() ? attribute.getIntParam() - 1 : 0;
if (potN < 0 || potN > meta.getCustomEffects().size()) {
return null;
}
if (attribute.startsWith("is_splash", 2)) {
attribute.fulfill(1);
return new ElementTag(object.item.getBukkitMaterial() == Material.SPLASH_POTION);
}
if (attribute.startsWith("is_extended", 2)) {
attribute.fulfill(1);
return new ElementTag(meta.getBasePotionData().isExtended());
}
if (attribute.startsWith("level", 2)) {
attribute.fulfill(1);
return new ElementTag(meta.getBasePotionData().isUpgraded() ? 2 : 1);
}
if (attribute.startsWith("is_ambient", 2)) {
attribute.fulfill(1);
return new ElementTag(meta.getCustomEffects().get(potN).isAmbient());
}
if (attribute.startsWith("icon", 2)) {
attribute.fulfill(1);
return new ElementTag(meta.getCustomEffects().get(potN).hasIcon());
}
if (attribute.startsWith("has_particles", 2)) {
attribute.fulfill(1);
return new ElementTag(meta.getCustomEffects().get(potN).hasParticles());
}
if (attribute.startsWith("duration", 2)) {
attribute.fulfill(1);
return new ElementTag(meta.getCustomEffects().get(potN).getDuration());
}
if (attribute.startsWith("amplifier", 2)) {
attribute.fulfill(1);
return new ElementTag(meta.getCustomEffects().get(potN).getAmplifier());
}
if (attribute.startsWith("type", 2)) {
attribute.fulfill(1);
return new ElementTag(meta.getCustomEffects().get(potN).getType().getName());
}
if (attribute.startsWith("data", 2)) {
attribute.fulfill(1);
return new ElementTag(0);
}
PotionData data = meta.getBasePotionData();
return new ElementTag(data.getType().name() + "," + (data.isUpgraded() ? 2 : 1) + "," + data.isExtended() + "," + (object.item.getBukkitMaterial() == Material.SPLASH_POTION));
});
// <--[tag]
// @attribute <ItemTag.effects_data>
// @returns ListTag(MapTag)
// @mechanism ItemTag.potion_effects
// @group properties
// @description
// Returns a list of all potion effects on this item, in the same format as the MapTag input to the mechanism.
// Note that the first value in the list is the potion's base type, and all subsequent entries are effect data.
// -->
PropertyParser.<ItemPotion, ListTag>registerTag(ListTag.class, "effects_data", (attribute, object) -> {
return object.getMapTagData();
});
}
use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemPotion method getMapTagData.
public ListTag getMapTagData() {
ListTag result = new ListTag();
MapTag base = new MapTag();
PotionMeta meta = getMeta();
base.putObject("type", new ElementTag(meta.getBasePotionData().getType().name()));
base.putObject("upgraded", new ElementTag(meta.getBasePotionData().isUpgraded()));
base.putObject("extended", new ElementTag(meta.getBasePotionData().isExtended()));
if (meta.hasColor()) {
base.putObject("color", new ColorTag(meta.getColor()));
}
result.addObject(base);
for (PotionEffect effect : meta.getCustomEffects()) {
result.addObject(effectToMap(effect));
}
return result;
}
Aggregations