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() {
Plugin vaultPlugin = this.getServer().getPluginManager().getPlugin("Vault");
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;
}

View File

@ -1,6 +1,7 @@
package com.garbagemule.MobArena.things;
import com.garbagemule.MobArena.MobArena;
import net.milkbowl.vault.economy.Economy;
class MoneyThingParser implements ThingParser {
private static final String PREFIX_LONG = "money:";
@ -18,7 +19,11 @@ class MoneyThingParser implements ThingParser {
if (money == 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) {

View File

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