Skip to content

Commit

Permalink
use new MapTag input utils
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 15, 2022
1 parent fc15cc7 commit c7fbb1e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 49 deletions.
Expand Up @@ -356,14 +356,7 @@ public static void registerTags() {
// 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;
}
MapTag map = attribute.inputParameterMap();
ElementTag level = map.getElement("level");
ElementTag type = map.getElement("type");
if (level == null || type == null) {
Expand All @@ -383,18 +376,10 @@ public static void registerTags() {
// 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;
}
ElementTag level = map.getElement("level");
ElementTag type = map.getElement("type");
MapTag map = attribute.inputParameterMap();
ElementTag level = map.getRequiredObjectAs("level", ElementTag.class, attribute);
ElementTag type = map.getRequiredObjectAs("type", ElementTag.class, attribute);
if (level == null || type == null) {
attribute.echoError("Invalid MapTag input to damage_protection - missing 'level' or 'type'");
return null;
}
EntityDamageEvent.DamageCause cause;
Expand Down
Expand Up @@ -780,15 +780,9 @@ public static double[] getRotatedAroundZ(double angle, double x, double y) {
}

public static double[] parsePointsAroundArgs(Attribute attribute) {
if (!attribute.hasParam()) {
return null;
}
MapTag inputMap = attribute.paramAsType(MapTag.class);
if (inputMap == null) {
return null;
}
ElementTag radiusElement = inputMap.getElement("radius");
ElementTag amountElement = inputMap.getElement("points");
MapTag inputMap = attribute.inputParameterMap();
ElementTag radiusElement = inputMap.getRequiredObjectAs("radius", ElementTag.class, attribute);
ElementTag amountElement = inputMap.getRequiredObjectAs("points", ElementTag.class, attribute);
if (radiusElement == null || amountElement == null) {
return null;
}
Expand Down
Expand Up @@ -788,20 +788,14 @@ else if (colorName.startsWith("co@")) {
// Or: <element[this looks kinda like fire doesn't it].color_gradient[from=#FF0000;to=#FFFF00]>
// -->
PropertyParser.<BukkitElementProperties, ElementTag>registerStaticTag(ElementTag.class, "color_gradient", (attribute, object) -> {
if (!attribute.hasParam()) {
return null;
}
String str = object.asString();
int length = ChatColor.stripColor(str).length();
if (length == 0) {
return new ElementTag("");
}
MapTag inputMap = attribute.paramAsType(MapTag.class);
if (inputMap == null) {
return null;
}
ColorTag fromColor = inputMap.getObjectAs("from", ColorTag.class, attribute.context);
ColorTag toColor = inputMap.getObjectAs("to", ColorTag.class, attribute.context);
MapTag inputMap = attribute.inputParameterMap();
ColorTag fromColor = inputMap.getRequiredObjectAs("from", ColorTag.class, attribute);
ColorTag toColor = inputMap.getRequiredObjectAs("to", ColorTag.class, attribute);
if (fromColor == null || toColor == null) {
return null;
}
Expand Down Expand Up @@ -864,20 +858,14 @@ else if (colorName.startsWith("co@")) {
// Specify the input as a map with keys 'from' and 'to' both set to hex colors (or any valid ColorTag).
// -->
PropertyParser.<BukkitElementProperties, ElementTag>registerStaticTag(ElementTag.class, "hsb_color_gradient", (attribute, object) -> {
if (!attribute.hasParam()) {
return null;
}
String str = object.asString();
int length = ChatColor.stripColor(str).length();
if (length == 0) {
return new ElementTag("");
}
MapTag inputMap = attribute.paramAsType(MapTag.class);
if (inputMap == null) {
return null;
}
ColorTag fromColor = inputMap.getObjectAs("from", ColorTag.class, attribute.context);
ColorTag toColor = inputMap.getObjectAs("to", ColorTag.class, attribute.context);
MapTag inputMap = attribute.inputParameterMap();
ColorTag fromColor = inputMap.getRequiredObjectAs("from", ColorTag.class, attribute);
ColorTag toColor = inputMap.getRequiredObjectAs("to", ColorTag.class, attribute);
if (fromColor == null || toColor == null) {
return null;
}
Expand Down
Expand Up @@ -2352,9 +2352,9 @@ else if ((attribute.matches("plugins_handling_event") || attribute.matches("list
// - give <server.generate_loot_table[id=chests/spawn_bonus_chest;killer=<player>;location=<player.location>]>
// -->
else if (attribute.startsWith("generate_loot_table") && attribute.hasParam()) {
MapTag map = attribute.paramAsType(MapTag.class);
ElementTag idObj = map.getElement("id");
LocationTag locationObj = map.getObjectAs("location", LocationTag.class, attribute.context);
MapTag map = attribute.inputParameterMap();
ElementTag idObj = map.getRequiredObjectAs("id", ElementTag.class, attribute);
LocationTag locationObj = map.getRequiredObjectAs("location", LocationTag.class, attribute);
if (idObj == null || locationObj == null) {
return;
}
Expand Down

0 comments on commit c7fbb1e

Please sign in to comment.