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 commit2fcb20b2ae. This reverts2fcb20b2aeand partly4c34a183c7. Fixes #463
This commit is contained in:
@@ -1,17 +1,15 @@
|
|||||||
package com.garbagemule.MobArena.things;
|
package com.garbagemule.MobArena.things;
|
||||||
|
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import com.garbagemule.MobArena.MobArena;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
class MoneyThingParser implements ThingParser {
|
class MoneyThingParser implements ThingParser {
|
||||||
private static final String PREFIX_LONG = "money:";
|
private static final String PREFIX_LONG = "money:";
|
||||||
private static final String PREFIX_SHORT = "$";
|
private static final String PREFIX_SHORT = "$";
|
||||||
|
|
||||||
private Supplier<Economy> economy;
|
private MobArena plugin;
|
||||||
|
|
||||||
MoneyThingParser(Supplier<Economy> economy) {
|
MoneyThingParser(MobArena plugin) {
|
||||||
this.economy = economy;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -20,7 +18,7 @@ class MoneyThingParser implements ThingParser {
|
|||||||
if (money == null) {
|
if (money == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new MoneyThing(economy.get(), Double.parseDouble(money));
|
return new MoneyThing(plugin.getEconomy(), Double.parseDouble(money));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String trimPrefix(String s) {
|
private String trimPrefix(String s) {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public class ThingManager implements ThingParser {
|
|||||||
public ThingManager(MobArena plugin, ItemStackThingParser parser) {
|
public ThingManager(MobArena plugin, ItemStackThingParser parser) {
|
||||||
parsers = new ArrayList<>();
|
parsers = new ArrayList<>();
|
||||||
parsers.add(new CommandThingParser());
|
parsers.add(new CommandThingParser());
|
||||||
parsers.add(new MoneyThingParser(plugin::getEconomy));
|
parsers.add(new MoneyThingParser(plugin));
|
||||||
items = parser;
|
items = parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ import static org.hamcrest.CoreMatchers.not;
|
|||||||
import static org.hamcrest.CoreMatchers.nullValue;
|
import static org.hamcrest.CoreMatchers.nullValue;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import com.garbagemule.MobArena.MobArena;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
@@ -21,8 +23,11 @@ public class MoneyThingParserTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
|
MobArena plugin = mock(MobArena.class);
|
||||||
Economy economy = mock(Economy.class);
|
Economy economy = mock(Economy.class);
|
||||||
subject = new MoneyThingParser(() -> economy);
|
when(plugin.getEconomy()).thenReturn(economy);
|
||||||
|
|
||||||
|
subject = new MoneyThingParser(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user