use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemRawNBT method setFullNBT.
public void setFullNBT(ItemTag item, MapTag input, TagContext context, boolean retainOld) {
CompoundTag compoundTag = retainOld ? NMSHandler.getItemHelper().getNbtData(item.getItemStack()) : null;
Map<String, Tag> result = compoundTag == null ? new LinkedHashMap<>() : new LinkedHashMap<>(compoundTag.getValue());
for (Map.Entry<StringHolder, ObjectTag> entry : input.map.entrySet()) {
try {
Tag tag = convertObjectToNbt(entry.getValue().toString(), context, "(item).");
if (tag != null) {
result.put(entry.getKey().str, tag);
}
} catch (Exception ex) {
Debug.echoError("Raw_Nbt input failed for root key '" + entry.getKey().str + "'.");
Debug.echoError(ex);
return;
}
}
compoundTag = NMSHandler.getInstance().createCompoundTag(result);
item.setItemStack(NMSHandler.getItemHelper().setNbtData(item.getItemStack(), compoundTag));
}
use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemRawNBT method jnbtTagToObject.
public static ObjectTag jnbtTagToObject(Tag tag) {
if (tag instanceof CompoundTag) {
MapTag result = new MapTag();
for (Map.Entry<String, Tag> entry : ((CompoundTag) tag).getValue().entrySet()) {
result.putObject(entry.getKey(), jnbtTagToObject(entry.getValue()));
}
return result;
} else if (tag instanceof JNBTListTag) {
ListTag result = new ListTag();
for (Tag entry : ((JNBTListTag) tag).getValue()) {
result.addObject(jnbtTagToObject(entry));
}
return new ElementTag("list:" + NBTUtils.getTypeCode(((JNBTListTag) tag).getType()) + ":" + result.identify());
} else if (tag instanceof ByteArrayTag) {
byte[] data = ((ByteArrayTag) tag).getValue();
StringBuilder output = new StringBuilder(data.length * 4);
for (int i = 0; i < data.length; i++) {
output.append(data[i]).append("|");
}
return new ElementTag("byte_array:" + output.toString());
} else if (tag instanceof IntArrayTag) {
int[] data = ((IntArrayTag) tag).getValue();
StringBuilder output = new StringBuilder(data.length * 4);
for (int i = 0; i < data.length; i++) {
output.append(data[i]).append("|");
}
return new ElementTag("int_array:" + output.toString());
} else if (tag instanceof ByteTag) {
return new ElementTag("byte:" + ((ByteTag) tag).getValue());
} else if (tag instanceof ShortTag) {
return new ElementTag("short:" + ((ShortTag) tag).getValue());
} else if (tag instanceof IntTag) {
return new ElementTag("int:" + ((IntTag) tag).getValue());
} else if (tag instanceof LongTag) {
return new ElementTag("long:" + ((LongTag) tag).getValue());
} else if (tag instanceof FloatTag) {
return new ElementTag("float:" + ((FloatTag) tag).getValue());
} else if (tag instanceof DoubleTag) {
return new ElementTag("double:" + ((DoubleTag) tag).getValue());
} else if (tag instanceof StringTag) {
return new ElementTag("string:" + ((StringTag) tag).getValue());
} else if (tag instanceof EndTag) {
return new ElementTag("end");
} else {
return new ElementTag("unknown:" + tag.getValue());
}
}
use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemRawNBT method getNonDefaultNBTMap.
public MapTag getNonDefaultNBTMap() {
MapTag result = getFullNBTMap();
for (StringHolder key : defaultNbtKeys) {
result.map.remove(key);
}
if (item.getBukkitMaterial() == Material.ITEM_FRAME) {
MapTag entityMap = (MapTag) result.getObject("EntityTag");
if (entityMap != null) {
entityMap.putObject("Invisible", null);
if (entityMap.map.isEmpty()) {
result.putObject("EntityTag", null);
}
}
}
if (item.getBukkitMaterial() == Material.ARMOR_STAND) {
MapTag entityMap = (MapTag) result.getObject("EntityTag");
if (entityMap != null) {
entityMap.putObject("Pose", null);
entityMap.putObject("Small", null);
entityMap.putObject("NoBasePlate", null);
entityMap.putObject("Marker", null);
entityMap.putObject("Invisible", null);
entityMap.putObject("ShowArms", null);
if (entityMap.map.isEmpty()) {
result.putObject("EntityTag", null);
}
}
}
return result;
}
use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.
the class EnchantmentTag method registerTags.
public static void registerTags() {
AbstractFlagTracker.registerFlagHandlers(tagProcessor);
// <--[tag]
// @attribute <EnchantmentTag.name>
// @returns ElementTag
// @description
// Gets the name of this enchantment. For vanilla enchantments, uses the vanilla name like 'sharpness'.
// For Denizen custom enchantments, returns the 'id' specified in the script.
// For any other enchantments, returns the full key.
// -->
tagProcessor.registerTag(ElementTag.class, "name", (attribute, object) -> {
return new ElementTag(object.getCleanName());
});
// <--[tag]
// @attribute <EnchantmentTag.key>
// @returns ElementTag
// @description
// Returns the full key for this enchantment, like "minecraft:sharpness".
// -->
tagProcessor.registerTag(ElementTag.class, "key", (attribute, object) -> {
return new ElementTag(object.enchantment.getKey().toString());
});
// <--[tag]
// @attribute <EnchantmentTag.full_name[<level>]>
// @returns ElementTag
// @description
// Returns the full name for this enchantment for a given level, like "Sharpness V".
// For vanilla enchantments, uses language translation keys.
// -->
tagProcessor.registerTag(ElementTag.class, "full_name", (attribute, object) -> {
if (!attribute.hasParam()) {
return null;
}
return new ElementTag(NMSHandler.enchantmentHelper.getFullName(object.enchantment, attribute.getIntParam()));
});
// <--[tag]
// @attribute <EnchantmentTag.script>
// @returns ScriptTag
// @description
// Returns the script that created this enchantment type, if any.
// -->
tagProcessor.registerTag(ScriptTag.class, "script", (attribute, object) -> {
if (!object.enchantment.getKey().getNamespace().equals("denizen")) {
return null;
}
EnchantmentScriptContainer.EnchantmentReference ref = EnchantmentScriptContainer.registeredEnchantmentContainers.get(object.enchantment.getKey().getKey());
if (ref == null) {
return null;
}
return new ScriptTag(ref.script);
});
// <--[tag]
// @attribute <EnchantmentTag.min_level>
// @returns ElementTag(Number)
// @description
// Returns the minimum level of this enchantment. Usually '1'.
// -->
tagProcessor.registerTag(ElementTag.class, "min_level", (attribute, object) -> {
return new ElementTag(object.enchantment.getStartLevel());
});
// <--[tag]
// @attribute <EnchantmentTag.max_level>
// @returns ElementTag(Number)
// @description
// Returns the minimum level of this enchantment. Usually between 1 and 5.
// -->
tagProcessor.registerTag(ElementTag.class, "max_level", (attribute, object) -> {
return new ElementTag(object.enchantment.getMaxLevel());
});
// <--[tag]
// @attribute <EnchantmentTag.treasure_only>
// @returns ElementTag(Boolean)
// @description
// Returns whether this enchantment is only for spawning as treasure.
// -->
tagProcessor.registerTag(ElementTag.class, "treasure_only", (attribute, object) -> {
return new ElementTag(object.enchantment.isTreasure());
});
// <--[tag]
// @attribute <EnchantmentTag.is_tradable>
// @returns ElementTag(Boolean)
// @description
// Returns whether this enchantment is only considered to be tradable. Villagers won't trade this enchantment if set to false.
// -->
tagProcessor.registerTag(ElementTag.class, "is_tradable", (attribute, object) -> {
return new ElementTag(NMSHandler.enchantmentHelper.isTradable(object.enchantment));
});
// <--[tag]
// @attribute <EnchantmentTag.is_discoverable>
// @returns ElementTag(Boolean)
// @description
// Returns whether this enchantment is only considered to be discoverable.
// If true, this will spawn from vanilla sources like the enchanting table. If false, it can only be given directly by script.
// -->
tagProcessor.registerTag(ElementTag.class, "is_discoverable", (attribute, object) -> {
return new ElementTag(NMSHandler.enchantmentHelper.isDiscoverable(object.enchantment));
});
// <--[tag]
// @attribute <EnchantmentTag.is_curse>
// @returns ElementTag(Boolean)
// @description
// Returns whether this enchantment is only considered to be a curse. Curses are removed at grindstones, and spread from crafting table repairs.
// -->
tagProcessor.registerTag(ElementTag.class, "is_curse", (attribute, object) -> {
return new ElementTag(NMSHandler.enchantmentHelper.isCurse(object.enchantment));
});
// <--[tag]
// @attribute <EnchantmentTag.category>
// @returns ElementTag
// @description
// Returns the category of this enchantment. Can be any of: ARMOR, ARMOR_FEET, ARMOR_LEGS, ARMOR_CHEST, ARMOR_HEAD,
// WEAPON, DIGGER, FISHING_ROD, TRIDENT, BREAKABLE, BOW, WEARABLE, CROSSBOW, VANISHABLE
// -->
tagProcessor.registerTag(ElementTag.class, "category", (attribute, object) -> {
return new ElementTag(object.enchantment.getItemTarget().name());
});
// <--[tag]
// @attribute <EnchantmentTag.rarity>
// @returns ElementTag
// @description
// Returns the rarity of this enchantment. Can be any of: COMMON, UNCOMMON, RARE, VERY_RARE
// -->
tagProcessor.registerTag(ElementTag.class, "rarity", (attribute, object) -> {
return new ElementTag(NMSHandler.enchantmentHelper.getRarity(object.enchantment));
});
// <--[tag]
// @attribute <EnchantmentTag.can_enchant[<item>]>
// @returns ElementTag(Boolean)
// @description
// Returns whether this enchantment can enchant the given ItemTag (based on material mainly).
// -->
tagProcessor.registerTag(ElementTag.class, "can_enchant", (attribute, object) -> {
if (!attribute.hasParam()) {
return null;
}
return new ElementTag(object.enchantment.canEnchantItem(attribute.paramAsType(ItemTag.class).getItemStack()));
});
// <--[tag]
// @attribute <EnchantmentTag.is_compatible[<enchantment>]>
// @returns ElementTag(Boolean)
// @description
// Returns whether this enchantment is compatible with another given enchantment.
// -->
tagProcessor.registerTag(ElementTag.class, "is_compatible", (attribute, object) -> {
if (!attribute.hasParam()) {
return null;
}
return new ElementTag(!object.enchantment.conflictsWith(attribute.paramAsType(EnchantmentTag.class).enchantment));
});
// <--[tag]
// @attribute <EnchantmentTag.min_cost[<level>]>
// @returns ElementTag(Decimal)
// @description
// Returns the minimum cost for this enchantment for the given level.
// -->
tagProcessor.registerTag(ElementTag.class, "min_cost", (attribute, object) -> {
if (!attribute.hasParam()) {
return null;
}
return new ElementTag(NMSHandler.enchantmentHelper.getMinCost(object.enchantment, attribute.getIntParam()));
});
// <--[tag]
// @attribute <EnchantmentTag.max_cost[<level>]>
// @returns ElementTag(Decimal)
// @description
// Returns the maximum cost for this enchantment for the given level.
// -->
tagProcessor.registerTag(ElementTag.class, "max_cost", (attribute, object) -> {
if (!attribute.hasParam()) {
return null;
}
return new ElementTag(NMSHandler.enchantmentHelper.getMaxCost(object.enchantment, attribute.getIntParam()));
});
// <--[tag]
// @attribute <EnchantmentTag.damage_bonus[level=<level>;type=<type>]>
// @returns ElementTag(Decimal)
// @description
// Returns the damage bonus this enchantment applies against the given monster type.
// The input is a MapTag with a level value and a monster type specified, where the type can be any of: ARTHROPOD, ILLAGER, WATER, UNDEAD, or UNDEFINED
// For example, <[my_enchantment].damage_bonus[level=3;type=undead]>
// -->
tagProcessor.registerTag(ElementTag.class, "damage_bonus", (attribute, object) -> {
if (!attribute.hasParam()) {
return null;
}
MapTag map = attribute.paramAsType(MapTag.class);
if (map == null) {
attribute.echoError("Invalid MapTag input to damage_bonus - not a valid map.");
return null;
}
ObjectTag level = map.getObject("level");
ObjectTag type = map.getObject("type");
if (level == null || type == null) {
attribute.echoError("Invalid MapTag input to damage_bonus - missing 'level' or 'type'");
return null;
}
return new ElementTag(NMSHandler.enchantmentHelper.getDamageBonus(object.enchantment, new ElementTag(level.toString()).asInt(), CoreUtilities.toLowerCase(type.toString())));
});
// <--[tag]
// @attribute <EnchantmentTag.damage_protection[level=<level>;type=<cause>;attacker=<entity>]>
// @returns ElementTag(Number)
// @description
// Returns the damage protection this enchantment applies against the given damage cause and optional attacker.
// The input is a MapTag with a level value and a damage type specified, where the damage type must be from <@link language Damage Cause>.
// For entity damage causes, optionally specify the entity attacker.
// For example, <[my_enchantment].damage_protection[level=3;type=undead]>
// -->
tagProcessor.registerTag(ElementTag.class, "damage_protection", (attribute, object) -> {
if (!attribute.hasParam()) {
return null;
}
MapTag map = attribute.paramAsType(MapTag.class);
if (map == null) {
attribute.echoError("Invalid MapTag input to damage_protection - not a valid map.");
return null;
}
ObjectTag level = map.getObject("level");
ObjectTag type = map.getObject("type");
if (level == null || type == null) {
attribute.echoError("Invalid MapTag input to damage_protection - missing 'level' or 'type'");
return null;
}
EntityDamageEvent.DamageCause cause;
try {
cause = EntityDamageEvent.DamageCause.valueOf(type.toString().toUpperCase());
} catch (IllegalArgumentException ex) {
attribute.echoError("Invalid MapTag input to damage_protection - cause '" + type.toString() + "' is not a valid DamageCause.");
return null;
}
ObjectTag attacker = map.getObject("attacker");
return new ElementTag(NMSHandler.enchantmentHelper.getDamageProtection(object.enchantment, new ElementTag(level.toString()).asInt(), cause, attacker == null ? null : attacker.asType(EntityTag.class, attribute.context).getBukkitEntity()));
});
}
use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemFirework method getFireworkDataMap.
public ListTag getFireworkDataMap() {
List<FireworkEffect> effects;
ListTag list = new ListTag();
if (item.getItemMeta() instanceof FireworkMeta) {
effects = ((FireworkMeta) item.getItemMeta()).getEffects();
} else {
effects = Collections.singletonList(((FireworkEffectMeta) item.getItemMeta()).getEffect());
}
if (effects != null) {
for (FireworkEffect effect : effects) {
if (effect == null) {
continue;
}
Color ColOne = effect.getColors() != null && effect.getColors().size() > 0 ? effect.getColors().get(0) : Color.BLUE;
Color ColTwo = effect.getFadeColors() != null && effect.getFadeColors().size() > 0 ? effect.getFadeColors().get(0) : ColOne;
MapTag effectMap = new MapTag();
effectMap.putObject("trail", new ElementTag(effect.hasTrail()));
effectMap.putObject("flicker", new ElementTag(effect.hasFlicker()));
effectMap.putObject("type", new ElementTag(effect.getType().name()));
effectMap.putObject("color", new ColorTag(ColOne));
effectMap.putObject("fade_color", new ColorTag(ColTwo));
list.addObject(effectMap);
}
}
return list;
}
Aggregations