Skip to content

Commit

Permalink
(experimental) allow screwing with enchantments in the relevant events
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed May 14, 2017
1 parent 477fad5 commit 13015cd
Showing 1 changed file with 19 additions and 2 deletions.
Expand Up @@ -20,7 +20,8 @@

public class ItemEnchantedScriptEvent extends BukkitScriptEvent implements Listener {

// TODO: Find more appropriate package than 'entity' for this
// TODO: Find more appropriate package than 'entity' for this. Probably 'player'.

// <--[event]
// @Events
// item enchanted (in <area>)
Expand All @@ -42,6 +43,7 @@ public class ItemEnchantedScriptEvent extends BukkitScriptEvent implements Liste
//
// @Determine
// Element(Number) to set the experience level cost of the enchantment.
// "RESULT:" + dItem to change the item result (only affects metadata (like enchantments), not material/quantity/etc!).
// -->

public ItemEnchantedScriptEvent() {
Expand All @@ -56,6 +58,7 @@ public ItemEnchantedScriptEvent() {
public Element button;
public int cost;
public EnchantItemEvent event;
public boolean itemEdited;

@Override
public boolean couldMatch(ScriptContainer scriptContainer, String s) {
Expand Down Expand Up @@ -99,9 +102,19 @@ public void destroy() {
public boolean applyDetermination(ScriptContainer container, String determination) {
if (aH.matchesInteger(determination)) {
cost = aH.getIntegerFrom(determination);
return true;
}

else if (CoreUtilities.toLowerCase(determination).startsWith("result:")) {
String ditem = determination.substring("result:".length());
item = dItem.valueOf(ditem);
itemEdited = true;
return true;
}

return super.applyDetermination(container, determination);
else {
return super.applyDetermination(container, determination);
}
}

@Override
Expand Down Expand Up @@ -142,9 +155,13 @@ public void onItemEnchanted(EnchantItemEvent event) {
button = new Element(event.whichButton());
cost = event.getExpLevelCost();
cancelled = event.isCancelled();
itemEdited = false;
this.event = event;
fire();
event.setCancelled(cancelled);
event.setExpLevelCost(cost);
if (itemEdited) {
event.getItem().setItemMeta(item.getItemStack().getItemMeta());
}
}
}

0 comments on commit 13015cd

Please sign in to comment.