Skip to content

Commit

Permalink
use new core tag registration tools
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 21, 2022
1 parent bc0a87c commit 70bc926
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,7 @@ public static void registerTags() {
// 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) -> {
MapTag map = attribute.inputParameterMap();
tagProcessor.registerTag(ElementTag.class, MapTag.class, "damage_bonus", (attribute, object, map) -> {
ElementTag level = map.getElement("level");
ElementTag type = map.getElement("type");
if (level == null || type == null) {
Expand All @@ -381,8 +380,7 @@ public static void registerTags() {
// 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) -> {
MapTag map = attribute.inputParameterMap();
tagProcessor.registerTag(ElementTag.class, MapTag.class, "damage_protection", (attribute, object, map) -> {
ElementTag level = map.getRequiredObjectAs("level", ElementTag.class, attribute);
ElementTag type = map.getRequiredObjectAs("type", ElementTag.class, attribute);
if (level == null || type == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.tags.TagContext;
import com.denizenscript.denizencore.tags.TagManager;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import net.md_5.bungee.api.ChatColor;

import java.util.HashMap;
Expand All @@ -18,16 +17,15 @@ public class CustomColorTagBase {

public static String defaultColor = null;

public static String getColor(String name, TagContext context) {
String key = CoreUtilities.toLowerCase(name);
String result = customColors.get(key);
public static String getColor(String nameLow, TagContext context) {
String result = customColors.get(nameLow);
if (result != null) {
return result;
}
String unparsed = customColorsRaw.get(key);
String unparsed = customColorsRaw.get(nameLow);
if (unparsed != null) {
result = TagManager.tag(unparsed, context);
customColors.put(key, result);
customColors.put(nameLow, result);
return result;
}
if (defaultColor == null) {
Expand All @@ -46,11 +44,8 @@ public CustomColorTagBase() {
// If the color name is unrecognized, returns the value of color named 'default'.
// Default color names are 'base', 'emphasis', 'warning', 'error'.
// -->
TagManager.registerStaticTagBaseHandler(ElementTag.class, "&", attribute -> {
if (!attribute.hasParam()) {
return null;
}
return new ElementTag(getColor(attribute.getParam(), attribute.context));
TagManager.registerStaticTagBaseHandler(ElementTag.class, ElementTag.class, "&", (attribute, name) -> {
return new ElementTag(getColor(name.asLowerString(), attribute.context));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,7 @@ else if (colorName.startsWith("co@") || colorName.lastIndexOf(',') > colorName.i
// @example
// - narrate "<&gradient[from=black;to=white]>these are the shades of gray <white>that solidifies to pure white"
// -->
TagManager.registerStaticTagBaseHandler(ElementTag.class, "&gradient", (attribute) -> {
if (!attribute.hasParam()) {
return null;
}
MapTag inputMap = attribute.inputParameterMap();
TagManager.registerStaticTagBaseHandler(ElementTag.class, MapTag.class, "&gradient", (attribute, inputMap) -> {
ColorTag fromColor = inputMap.getRequiredObjectAs("from", ColorTag.class, attribute);
ColorTag toColor = inputMap.getRequiredObjectAs("to", ColorTag.class, attribute);
ElementTag style = inputMap.getElement("style", "RGB");
Expand Down

0 comments on commit 70bc926

Please sign in to comment.