use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemPotion method effectToMap.
public static MapTag effectToMap(PotionEffect effect) {
MapTag map = new MapTag();
map.putObject("type", new ElementTag(effect.getType().getName()));
map.putObject("amplifier", new ElementTag(effect.getAmplifier()));
map.putObject("duration", new DurationTag((long) effect.getDuration()));
map.putObject("ambient", new ElementTag(effect.isAmbient()));
map.putObject("particles", new ElementTag(effect.hasParticles()));
map.putObject("icon", new ElementTag(effect.hasIcon()));
return map;
}
use of com.denizenscript.denizencore.objects.core.ElementTag 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;
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemPotion method parseEffect.
public static PotionEffect parseEffect(String str, TagContext context) {
String[] d2 = str.split(",");
PotionEffectType type;
try {
type = PotionEffectType.getByName(d2[0].toUpperCase());
} catch (IllegalArgumentException ex) {
if (context.showErrors()) {
Debug.echoError("Invalid potion effect type '" + d2[0] + "'");
}
return null;
}
if (d2.length < 3) {
return null;
}
// NOTE: amplifier and duration are swapped around in the input format
// as compared to the PotionEffect constructor!
int duration = new ElementTag(d2[2]).asInt();
int amplifier = new ElementTag(d2[1]).asInt();
boolean ambient = true;
boolean particles = true;
if (d2.length > 3) {
ambient = new ElementTag(d2[3]).asBoolean();
particles = new ElementTag(d2[4]).asBoolean();
}
boolean icon = false;
if (d2.length > 5) {
ElementTag check = new ElementTag(d2[5]);
if (check.isBoolean()) {
icon = check.asBoolean();
}
}
return new PotionEffect(type, duration, amplifier, ambient, particles, icon);
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemSpawnerMaxNearbyEntities method getObjectAttribute.
@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
// -->
if (attribute.startsWith("spawner_max_nearby_entities")) {
BlockStateMeta meta = (BlockStateMeta) item.getItemMeta();
CreatureSpawner state = (CreatureSpawner) meta.getBlockState();
return new ElementTag(state.getMaxNearbyEntities()).getObjectAttribute(attribute.fulfill(1));
}
return null;
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemAttributeModifiers method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("attribute_modifiers") && mechanism.requireObject(MapTag.class)) {
Multimap<org.bukkit.attribute.Attribute, AttributeModifier> metaMap = LinkedHashMultimap.create();
MapTag map = mechanism.valueAsType(MapTag.class);
for (Map.Entry<StringHolder, ObjectTag> mapEntry : map.map.entrySet()) {
org.bukkit.attribute.Attribute attr = org.bukkit.attribute.Attribute.valueOf(mapEntry.getKey().str.toUpperCase());
for (ObjectTag listValue : CoreUtilities.objectToList(mapEntry.getValue(), mechanism.context)) {
metaMap.put(attr, EntityAttributeModifiers.modiferForMap(attr, (MapTag) listValue));
}
}
ItemMeta meta = item.getItemMeta();
meta.setAttributeModifiers(metaMap);
item.setItemMeta(meta);
}
// -->
if (mechanism.matches("add_attribute_modifiers") && mechanism.requireObject(MapTag.class)) {
ItemMeta meta = item.getItemMeta();
MapTag input = mechanism.valueAsType(MapTag.class);
for (Map.Entry<StringHolder, ObjectTag> subValue : input.map.entrySet()) {
org.bukkit.attribute.Attribute attr = org.bukkit.attribute.Attribute.valueOf(subValue.getKey().str.toUpperCase());
for (ObjectTag listValue : CoreUtilities.objectToList(subValue.getValue(), mechanism.context)) {
meta.addAttributeModifier(attr, EntityAttributeModifiers.modiferForMap(attr, (MapTag) listValue));
}
}
item.setItemMeta(meta);
}
// -->
if (mechanism.matches("remove_attribute_modifiers") && mechanism.requireObject(ListTag.class)) {
ItemMeta meta = item.getItemMeta();
ArrayList<String> inputList = new ArrayList<>(mechanism.valueAsType(ListTag.class));
for (String toRemove : new ArrayList<>(inputList)) {
if (new ElementTag(toRemove).matchesEnum(org.bukkit.attribute.Attribute.class)) {
inputList.remove(toRemove);
org.bukkit.attribute.Attribute attr = org.bukkit.attribute.Attribute.valueOf(toRemove.toUpperCase());
meta.removeAttributeModifier(attr);
}
}
for (String toRemove : inputList) {
UUID id = UUID.fromString(toRemove);
Multimap<org.bukkit.attribute.Attribute, AttributeModifier> metaMap = meta.getAttributeModifiers();
for (org.bukkit.attribute.Attribute attribute : metaMap.keys()) {
for (AttributeModifier modifer : metaMap.get(attribute)) {
if (modifer.getUniqueId().equals(id)) {
meta.removeAttributeModifier(attribute, modifer);
break;
}
}
}
}
item.setItemMeta(meta);
}
}
Aggregations