Log missing Vault/economy plugin during parsing of money things.

Changes the "Vault was not found" message in Vault setup to INFO instead of WARNING, because this configuration isn't actually necessarily a warning sign. Parsing a money thing with no economy is, however. MoneyThingParser logs at ERROR level if Vault or an economy plugin isn't found, but a money thing is parsed.
This commit is contained in:
Andreas Troelsen 2018-05-13 17:43:13 +02:00
parent 3d7a9ff9d2
commit cc015f4e9a
3 changed files with 24 additions and 3 deletions

View File

@ -202,7 +202,7 @@ public class MobArena extends JavaPlugin
private void setupVault() { private void setupVault() {
Plugin vaultPlugin = this.getServer().getPluginManager().getPlugin("Vault"); Plugin vaultPlugin = this.getServer().getPluginManager().getPlugin("Vault");
if (vaultPlugin == null) { if (vaultPlugin == null) {
getLogger().warning("Vault was not found. Economy rewards will not work!"); getLogger().info("Vault was not found. Economy rewards will not work.");
return; return;
} }

View File

@ -1,6 +1,7 @@
package com.garbagemule.MobArena.things; package com.garbagemule.MobArena.things;
import com.garbagemule.MobArena.MobArena; import com.garbagemule.MobArena.MobArena;
import net.milkbowl.vault.economy.Economy;
class MoneyThingParser implements ThingParser { class MoneyThingParser implements ThingParser {
private static final String PREFIX_LONG = "money:"; private static final String PREFIX_LONG = "money:";
@ -18,7 +19,11 @@ class MoneyThingParser implements ThingParser {
if (money == null) { if (money == null) {
return null; return null;
} }
return new MoneyThing(plugin.getEconomy(), Double.parseDouble(money)); Economy economy = plugin.getEconomy();
if (economy == null) {
plugin.getLogger().severe("Vault or economy plugin missing while parsing: " + s);
}
return new MoneyThing(economy, Double.parseDouble(money));
} }
private String trimPrefix(String s) { private String trimPrefix(String s) {

View File

@ -4,7 +4,9 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not; 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.Matchers.anyString;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import com.garbagemule.MobArena.MobArena; import com.garbagemule.MobArena.MobArena;
@ -14,16 +16,19 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import java.util.logging.Logger;
public class MoneyThingParserTest { public class MoneyThingParserTest {
private MoneyThingParser subject; private MoneyThingParser subject;
private MobArena plugin;
@Rule @Rule
public ExpectedException exception = ExpectedException.none(); public ExpectedException exception = ExpectedException.none();
@Before @Before
public void setup() { public void setup() {
MobArena plugin = mock(MobArena.class); plugin = mock(MobArena.class);
Economy economy = mock(Economy.class); Economy economy = mock(Economy.class);
when(plugin.getEconomy()).thenReturn(economy); when(plugin.getEconomy()).thenReturn(economy);
@ -51,6 +56,17 @@ public class MoneyThingParserTest {
assertThat(result, not(nullValue())); assertThat(result, not(nullValue()));
} }
@Test
public void nullEconomyNullMoney() {
Logger logger = mock(Logger.class);
when(plugin.getEconomy()).thenReturn(null);
when(plugin.getLogger()).thenReturn(logger);
subject.parse("$500");
verify(logger).severe(anyString());
}
@Test @Test
public void numberFormatForNaughtyValues() { public void numberFormatForNaughtyValues() {
exception.expect(NumberFormatException.class); exception.expect(NumberFormatException.class);