Don't depend directly on Vault in MoneyThingParser.

It turns out that the method reference on MobArena#getEconomy() in ThingManager is a tight enough dependency on Vault's Economy interface that it results in a NoClassDefFoundError if Vault isn't present.

By resorting to a more "naive" approach of resolving the Economy instance from the main plugin class on every parse call in MoneyThingParser, the NoClassDefFoundError is avoided along with the load/enable ordering issue that was fixed with the lazy-fetching in commit 2fcb20b2ae.

This reverts 2fcb20b2ae and partly 4c34a183c7.

Fixes #463
This commit is contained in:
Andreas Troelsen
2018-05-12 13:06:15 +02:00
parent 8dbee5d4b5
commit ce392bddc3
3 changed files with 12 additions and 9 deletions
@@ -1,17 +1,15 @@
package com.garbagemule.MobArena.things;
import net.milkbowl.vault.economy.Economy;
import java.util.function.Supplier;
import com.garbagemule.MobArena.MobArena;
class MoneyThingParser implements ThingParser {
private static final String PREFIX_LONG = "money:";
private static final String PREFIX_SHORT = "$";
private Supplier<Economy> economy;
private MobArena plugin;
MoneyThingParser(Supplier<Economy> economy) {
this.economy = economy;
MoneyThingParser(MobArena plugin) {
this.plugin = plugin;
}
@Override
@@ -20,7 +18,7 @@ class MoneyThingParser implements ThingParser {
if (money == null) {
return null;
}
return new MoneyThing(economy.get(), Double.parseDouble(money));
return new MoneyThing(plugin.getEconomy(), Double.parseDouble(money));
}
private String trimPrefix(String s) {
@@ -12,7 +12,7 @@ public class ThingManager implements ThingParser {
public ThingManager(MobArena plugin, ItemStackThingParser parser) {
parsers = new ArrayList<>();
parsers.add(new CommandThingParser());
parsers.add(new MoneyThingParser(plugin::getEconomy));
parsers.add(new MoneyThingParser(plugin));
items = parser;
}