Skip to content

Commit

Permalink
cleanups and a few registered property mechs
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 30, 2022
1 parent 246cb1c commit d33aa65
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 32 deletions.
Expand Up @@ -52,7 +52,7 @@ public String getPropertyString() {
}
MapTag flags = new MapTag();
for (String name : flagNames) {
flags.putObject(name, ((DataPersistenceFlagTracker) tracker).getRootMap(name));
flags.putObject(name, tracker.getRootMap(name));
}
return flags.toString();
}
Expand All @@ -76,6 +76,7 @@ public void adjust(Mechanism mechanism) {
// @input MapTag
// @description
// Internal setter for the EntityTag flag map.
// Do not use this in scripts.
// -->
if (mechanism.matches("flag_map") && mechanism.requireObject(MapTag.class)) {
MapTagFlagTracker flags = new MapTagFlagTracker(mechanism.valueAsType(MapTag.class));
Expand Down
Expand Up @@ -2,7 +2,6 @@

import com.denizenscript.denizen.objects.ItemTag;
import com.denizenscript.denizen.objects.TradeTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.properties.Property;
Expand All @@ -25,10 +24,6 @@ public static TradeInputs getFrom(ObjectTag recipe) {
return new TradeInputs((TradeTag) recipe);
}

public static final String[] handledMechs = new String[] {
"inputs"
};

private TradeTag recipe;

public TradeInputs(TradeTag recipe) {
Expand Down Expand Up @@ -66,9 +61,6 @@ public static void registerTags() {
PropertyParser.registerTag(TradeInputs.class, ListTag.class, "inputs", (attribute, recipe) -> {
return recipe.getIngredientsList();
});
}

public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object TradeTag
Expand All @@ -80,25 +72,21 @@ public void adjust(Mechanism mechanism) {
// @tags
// <TradeTag.inputs>
// -->
if (mechanism.matches("inputs")) {
PropertyParser.registerMechanism(TradeInputs.class, ListTag.class, "inputs", (prop, mechanism, inList) -> {
List<ItemStack> ingredients = new ArrayList<>();
List<ItemTag> list = mechanism.valueAsType(ListTag.class).filter(ItemTag.class, mechanism.context);

List<ItemTag> list = inList.filter(ItemTag.class, mechanism.context);
if (!mechanism.hasValue() || list.isEmpty()) {
recipe.getRecipe().setIngredients(ingredients);
prop.recipe.getRecipe().setIngredients(ingredients);
return;
}

for (ItemTag item : list) {
ingredients.add(item.getItemStack());
}

if (ingredients.size() > 2) {
mechanism.echoError("Trade recipe input was given " + list.size() + " items. Only using the first two items!");
ingredients = ingredients.subList(0, 2);
}

recipe.getRecipe().setIngredients(ingredients);
}
prop.recipe.getRecipe().setIngredients(ingredients);
});
}
}
Expand Up @@ -2,7 +2,6 @@

import com.denizenscript.denizen.objects.ItemTag;
import com.denizenscript.denizen.objects.TradeTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
Expand All @@ -20,10 +19,6 @@ public static TradeResult getFrom(ObjectTag recipe) {
return new TradeResult((TradeTag) recipe);
}

public static final String[] handledMechs = new String[] {
"result"
};

private TradeTag recipe;

public TradeResult(TradeTag recipe) {
Expand Down Expand Up @@ -53,9 +48,6 @@ public static void registerTags() {
PropertyParser.registerTag(TradeResult.class, ItemTag.class, "result", (attribute, recipe) -> {
return new ItemTag(recipe.recipe.getRecipe().getResult());
});
}

public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object TradeTag
Expand All @@ -66,8 +58,8 @@ public void adjust(Mechanism mechanism) {
// @tags
// <TradeTag.result>
// -->
if (mechanism.matches("result") && mechanism.requireObject(ItemTag.class)) {
recipe.setRecipe(TradeTag.duplicateRecipe(mechanism.valueAsType(ItemTag.class).getItemStack(), recipe.getRecipe()));
}
PropertyParser.registerMechanism(TradeResult.class, ItemTag.class, "result", (prop, mechanism, item) -> {
prop.recipe.setRecipe(TradeTag.duplicateRecipe(item.getItemStack(), prop.recipe.getRecipe()));
});
}
}
@@ -1,7 +1,7 @@
package com.denizenscript.denizen.tags.core;

import com.denizenscript.denizen.objects.ColorTag;
import com.denizenscript.denizen.objects.properties.bukkit.BukkitElementProperties;
import com.denizenscript.denizen.objects.properties.bukkit.BukkitElementExtensions;
import com.denizenscript.denizen.utilities.FormattedTextHelper;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.core.ListTag;
Expand Down Expand Up @@ -516,7 +516,7 @@ else if (colorName.startsWith("co@") || colorName.lastIndexOf(',') > colorName.i
if (fromColor == null || toColor == null) {
return null;
}
if (!style.matchesEnum(BukkitElementProperties.GradientStyle.class)) {
if (!style.matchesEnum(BukkitElementExtensions.GradientStyle.class)) {
attribute.echoError("Invalid gradient style '" + style + "'");
return null;
}
Expand Down
Expand Up @@ -410,7 +410,7 @@ public void addExtraErrorHeaders(StringBuilder headerBuilder, ScriptEntry source

@Override
public String applyDebugColors(String uncolored) {
if (uncolored.indexOf('<') == -1) {
if (!CoreUtilities.contains(uncolored, '<')) {
return uncolored;
}
return uncolored
Expand Down

0 comments on commit d33aa65

Please sign in to comment.