use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemPatterns method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("patterns")) {
List<Pattern> patterns = new ArrayList<>();
ListTag list = mechanism.valueAsType(ListTag.class);
List<String> split;
for (String string : list) {
try {
split = CoreUtilities.split(string, '/', 2);
patterns.add(new Pattern(DyeColor.valueOf(split.get(0).toUpperCase()), PatternType.valueOf(split.get(1).toUpperCase())));
} catch (Exception e) {
Debug.echoError("Could not apply pattern to banner: " + string);
}
}
setPatterns(patterns);
}
}
use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemNBT method getObjectAttribute.
@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
if (attribute.startsWith("has_nbt")) {
Deprecations.itemNbt.warn(attribute.context);
return new ElementTag(CustomNBT.hasCustomNBT(item.getItemStack(), attribute.getParam(), CustomNBT.KEY_DENIZEN)).getObjectAttribute(attribute.fulfill(1));
}
if (attribute.startsWith("nbt_keys")) {
Deprecations.itemNbt.warn(attribute.context);
return new ListTag(CustomNBT.listNBT(item.getItemStack(), CustomNBT.KEY_DENIZEN)).getObjectAttribute(attribute.fulfill(1));
}
if (attribute.matches("nbt")) {
Deprecations.itemNbt.warn(attribute.context);
if (!attribute.hasParam()) {
ListTag list = getNBTDataList();
if (list == null) {
return null;
}
return list.getObjectAttribute(attribute.fulfill(1));
}
String res = CustomNBT.getCustomNBT(item.getItemStack(), attribute.getParam(), CustomNBT.KEY_DENIZEN);
if (res == null) {
return null;
}
return new ElementTag(res).getObjectAttribute(attribute.fulfill(1));
}
return null;
}
use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemNBT method adjust.
@Override
public void adjust(Mechanism mechanism) {
if (mechanism.matches("remove_nbt")) {
Deprecations.itemNbt.warn(mechanism.context);
if (item.getMaterial().getMaterial() == Material.AIR) {
mechanism.echoError("Cannot apply NBT to AIR!");
return;
}
ItemStack itemStack = item.getItemStack();
List<String> list;
if (mechanism.hasValue()) {
list = mechanism.valueAsType(ListTag.class);
} else {
list = CustomNBT.listNBT(itemStack, CustomNBT.KEY_DENIZEN);
}
for (String string : list) {
itemStack = CustomNBT.removeCustomNBT(itemStack, string, CustomNBT.KEY_DENIZEN);
}
item.setItemStack(itemStack);
}
if (mechanism.matches("nbt")) {
Deprecations.itemNbt.warn(mechanism.context);
if (item.getMaterial().getMaterial() == Material.AIR) {
mechanism.echoError("Cannot apply NBT to AIR!");
return;
}
ListTag list = mechanism.valueAsType(ListTag.class);
ItemStack itemStack = item.getItemStack();
for (String string : list) {
String[] split = string.split("/", 2);
itemStack = CustomNBT.addCustomNBT(itemStack, EscapeTagBase.unEscape(split[0]), EscapeTagBase.unEscape(split[1]), CustomNBT.KEY_DENIZEN);
}
item.setItemStack(itemStack);
}
}
use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemNBT method getNBTDataList.
public ListTag getNBTDataList() {
ItemStack itemStack = item.getItemStack();
List<String> nbtKeys = CustomNBT.listNBT(itemStack, CustomNBT.KEY_DENIZEN);
if (nbtKeys != null && !nbtKeys.isEmpty()) {
ListTag list = new ListTag();
for (String key : nbtKeys) {
list.add(EscapeTagBase.escape(key) + "/" + EscapeTagBase.escape(CustomNBT.getCustomNBT(itemStack, key, CustomNBT.KEY_DENIZEN)));
}
return list;
}
return null;
}
use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class EntityPotionEffects method registerTags.
public static void registerTags() {
// <--[tag]
// @attribute <EntityTag.list_effects>
// @returns ListTag
// @group attribute
// @mechanism EntityTag.potion_effects
// @deprecated use 'effects_data' instead
// @description
// Deprecated in favor of <@link tag EntityTag.effects_data>
// -->
PropertyParser.<EntityPotionEffects, ListTag>registerTag(ListTag.class, "list_effects", (attribute, object) -> {
Deprecations.oldPotionEffects.warn(attribute.context);
return object.getEffectsListTag();
});
// <--[tag]
// @attribute <EntityTag.effects_data>
// @returns ListTag(MapTag)
// @group attribute
// @mechanism EntityTag.potion_effects
// @description
// Returns the active potion effects on the entity, in the MapTag format of the mechanism.
// -->
PropertyParser.<EntityPotionEffects, ListTag>registerTag(ListTag.class, "effects_data", (attribute, object) -> {
return object.getEffectsMapTag();
});
// <--[tag]
// @attribute <EntityTag.has_effect[<effect>]>
// @returns ElementTag(Boolean)
// @group attributes
// @mechanism EntityTag.potion_effects
// @description
// Returns whether the entity has a specified effect.
// If no effect is specified, returns whether the entity has any effect.
// The effect type must be from <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/potion/PotionEffectType.html>.
// -->
PropertyParser.<EntityPotionEffects, ElementTag>registerTag(ElementTag.class, "has_effect", (attribute, object) -> {
boolean returnElement = false;
if (attribute.hasParam()) {
PotionEffectType effectType = PotionEffectType.getByName(attribute.getParam());
if (effectType == null) {
attribute.echoError("Invalid effect type specified: " + attribute.getParam());
return null;
}
if (object.entity.isLivingEntity()) {
returnElement = object.entity.getLivingEntity().hasPotionEffect(effectType);
} else if (object.isArrow()) {
returnElement = object.getArrow().hasCustomEffect(effectType);
}
} else if (!object.getEffectsList().isEmpty()) {
returnElement = true;
}
return new ElementTag(returnElement);
});
}
Aggregations