Lazy load Economy reference in MoneyThingParser.
The eager loading results in nothing but nulls because ThingManager (and, by proxy, MoneyThingParser) is instantiated on load, while the Economy provider from Vault is fetched on enable.
The bug was introduced with 4c34a183c7.
This fixes #451
This commit is contained in:
@@ -2,13 +2,15 @@ package com.garbagemule.MobArena.things;
|
|||||||
|
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
|
||||||
|
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 Economy economy;
|
private Supplier<Economy> economy;
|
||||||
|
|
||||||
MoneyThingParser(Economy economy) {
|
MoneyThingParser(Supplier<Economy> economy) {
|
||||||
this.economy = economy;
|
this.economy = economy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,7 +20,7 @@ class MoneyThingParser implements ThingParser {
|
|||||||
if (money == null) {
|
if (money == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new MoneyThing(economy, Double.parseDouble(money));
|
return new MoneyThing(economy.get(), 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::getEconomy));
|
||||||
items = parser;
|
items = parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public class MoneyThingParserTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
Economy economy = mock(Economy.class);
|
Economy economy = mock(Economy.class);
|
||||||
subject = new MoneyThingParser(economy);
|
subject = new MoneyThingParser(() -> economy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user