Skip to content

Commit

Permalink
add 'flags' key to item script containers
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Dec 5, 2020
1 parent 7539054 commit 4398013
Showing 1 changed file with 15 additions and 0 deletions.
Expand Up @@ -2,6 +2,7 @@

import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.utilities.Utilities;
import com.denizenscript.denizencore.flags.AbstractFlagTracker;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.tags.TagContext;
import com.denizenscript.denizencore.utilities.CoreUtilities;
Expand Down Expand Up @@ -77,6 +78,12 @@ public class ItemScriptContainer extends ScriptContainer {
// - enchantment_name:level
// - ...
//
// # You can specify flags to be added to the item.
// flags:
// # Each line within the flags section should be a flag name as a key, and the flag value as the value.
// # You can use lists or maps here the way you would expect them to work.
// my_flag: my_value
//
// # You can optionally add crafting recipes for your item script.
// # Note that recipes won't show in the recipe book when you add a new item script, until you either reconnect or use the "resend_recipes" mechanism.
// # | Most item scripts should exclude this key, unless you're specifically building craftable items.
Expand Down Expand Up @@ -295,6 +302,14 @@ public ItemTag getItemFrom(TagContext context) {
BookScriptContainer book = ScriptRegistry.getScriptContainer(TagManager.tag(getString("book"), context).replace("s@", ""));
stack = book.writeBookTo(stack, context);
}
if (contains("flags")) {
YamlConfiguration flagSection = getConfigurationSection("flags");
AbstractFlagTracker tracker = stack.getFlagTracker();
for (StringHolder key : flagSection.getKeys(false)) {
tracker.setFlag(key.str, CoreUtilities.objectToTagForm(flagSection.get(key.str), context, true, true), null);
}
stack.reapplyTracker(tracker);
}
stack.setItemScript(this);
}
catch (Exception e) {
Expand Down

0 comments on commit 4398013

Please sign in to comment.