Skip to content

Commit

Permalink
allow specifying mechanisms in item scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Apr 19, 2019
1 parent 2581b98 commit f7bc783
Showing 1 changed file with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.nbt.LeatherColorer;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.Mechanism;
import net.aufdemrand.denizencore.objects.dScript;
import net.aufdemrand.denizencore.scripts.ScriptRegistry;
import net.aufdemrand.denizencore.scripts.containers.ScriptContainer;
import net.aufdemrand.denizencore.tags.TagManager;
import net.aufdemrand.denizencore.utilities.YamlConfiguration;
import net.aufdemrand.denizencore.utilities.debugging.SlowWarning;
import net.aufdemrand.denizencore.utilities.text.StringHolder;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.meta.ItemMeta;

Expand Down Expand Up @@ -44,6 +47,11 @@ public class ItemScriptContainer extends ScriptContainer {
// # Must be a valid dItem (EG i@red_wool or i@potion,8226) See 'dItem' for more information.
// material: i@base_material
//
// # List any mechanisms you want to apply to the item within
// mechanisms:
// # An example of a mechanism to apply
// unbreakable: true
//
// # The 'custom name' can be anything you wish. Use color tags to make colored custom names.
// display name: custom name
//
Expand Down Expand Up @@ -160,9 +168,10 @@ public dItem getItemFrom(dPlayer player, dNPC npc) {
if (contains("DEBUG")) {
debug = Boolean.valueOf(getString("DEBUG"));
}
BukkitTagContext context = new BukkitTagContext(player, npc, false, null, debug, new dScript(this));
// Check validity of material
if (contains("MATERIAL")) {
String material = TagManager.tag(getString("MATERIAL"), new BukkitTagContext(player, npc, false, null, debug, new dScript(this)));
String material = TagManager.tag(getString("MATERIAL"), context);
if (material.startsWith("m@")) {
material = material.substring(2);
}
Expand All @@ -174,26 +183,35 @@ public dItem getItemFrom(dPlayer player, dNPC npc) {
return null;
}

// Handle listed mechanisms
if (contains("MECHANISMS")) {
YamlConfiguration mechs = getConfigurationSection("MECHANISMS");
for (StringHolder key : mechs.getKeys(false)) {
String val = TagManager.tag(mechs.getString(key.str), context);
stack.safeAdjust(new Mechanism(new Element(key.low), new Element(val), context));
}
}

ItemMeta meta = stack.getItemStack().getItemMeta();
List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<String>();
List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();

// Set Display Name
if (contains("DISPLAY NAME")) {
String displayName = TagManager.tag(getString("DISPLAY NAME"), new BukkitTagContext(player, npc, false, null, debug, new dScript(this)));
String displayName = TagManager.tag(getString("DISPLAY NAME"), context);
meta.setDisplayName(displayName);
}

// Set if the object is bound to the player
if (contains("BOUND")) {
boundWarning.warn();
bound = Boolean.valueOf(TagManager.tag(getString("BOUND"), new BukkitTagContext(player, npc, false, null, debug, new dScript(this))));
bound = Boolean.valueOf(TagManager.tag(getString("BOUND"), context));
}

// Set Lore
if (contains("LORE")) {

for (String l : getStringList("LORE")) {
l = TagManager.tag(l, new BukkitTagContext(player, npc, false, null, debug, new dScript(this)));
l = TagManager.tag(l, context);
lore.add(l);
}
}
Expand All @@ -211,7 +229,7 @@ public dItem getItemFrom(dPlayer player, dNPC npc) {
if (contains("ENCHANTMENTS")) {
for (String enchantment : getStringList("ENCHANTMENTS")) {

enchantment = TagManager.tag(enchantment, new BukkitTagContext(player, npc, false, null, debug, new dScript(this)));
enchantment = TagManager.tag(enchantment, context);
try {
// Build enchantment context
int level = 1;
Expand All @@ -233,16 +251,15 @@ public dItem getItemFrom(dPlayer player, dNPC npc) {

// Set Color
if (contains("COLOR")) {
String color = TagManager.tag(getString("COLOR"), new BukkitTagContext(player, npc, false, null, debug, new dScript(this)));
String color = TagManager.tag(getString("COLOR"), context);
LeatherColorer.colorArmor(stack, color);
}

// Set Book
if (contains("BOOK")) {
BookScriptContainer book = ScriptRegistry
.getScriptContainer(TagManager.tag(getString("BOOK"),
new BukkitTagContext(player, npc, false, null, debug,
new dScript(this))).replace("s@", ""));
context).replace("s@", ""));

stack = book.writeBookTo(stack, player, npc);
}
Expand Down

0 comments on commit f7bc783

Please sign in to comment.