Better handle invalid json
This commit is contained in:
parent
df3a3569f5
commit
c5871576ef
@ -10,7 +10,7 @@ import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class MoneyMixinVault extends MoneyMixinAbstract
|
||||
public class MoneyMixinVault extends MoneyMixinAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
@ -255,8 +255,8 @@ public class MoneyMixinVault extends MoneyMixinAbstract
|
||||
public static Object getEconomyObject(String accountId)
|
||||
{
|
||||
if (null == accountId) return null;
|
||||
// Because of Factions we have this crazy-workaround.
|
||||
// Where offlineplayers will be used when possible
|
||||
// Because of Factions we have this crazy-workaround
|
||||
// where offlineplayers will be used when possible
|
||||
// but otherwise names will.
|
||||
OfflinePlayer ret = IdUtil.getOfflinePlayer(accountId);
|
||||
if (ret != null) return ret;
|
||||
|
@ -14,7 +14,6 @@ import com.massivecraft.massivecore.mixin.MixinModification;
|
||||
import com.massivecraft.massivecore.store.migrator.MigratorUtil;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import com.mongodb.DB;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
@ -384,6 +383,11 @@ public class Coll<E extends Entity<E>> extends CollAbstract<E>
|
||||
this.logLoadError(id, "Raw data was JSON null. It seems you have a file containing just the word \"null\". Why would you do this?");
|
||||
return false;
|
||||
}
|
||||
if (raw == MStore.INVALID_JSON)
|
||||
{
|
||||
this.logLoadError(id, "Does not contain valid json.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.massivecraft.massivecore.store;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.massivecraft.massivecore.collections.MassiveMap;
|
||||
import com.massivecraft.massivecore.collections.MassiveSet;
|
||||
import com.massivecraft.massivecore.util.DiscUtil;
|
||||
@ -172,7 +173,14 @@ public class DriverFlatfile extends DriverAbstract
|
||||
content = content.trim();
|
||||
if (content.length() == 0) return null;
|
||||
|
||||
return new JsonParser().parse(content);
|
||||
try
|
||||
{
|
||||
return new JsonParser().parse(content);
|
||||
}
|
||||
catch (JsonSyntaxException ex)
|
||||
{
|
||||
return MStore.INVALID_JSON;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.massivecraft.massivecore.store;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.massivecraft.massivecore.ConfServer;
|
||||
import com.massivecraft.massivecore.entity.MassiveCoreMConf;
|
||||
|
||||
@ -18,6 +19,7 @@ public class MStore
|
||||
// This class also serves the purpose of containing database related constants.
|
||||
|
||||
public static final boolean DEBUG_ENABLED = false;
|
||||
public static final JsonObject INVALID_JSON = new JsonObject();
|
||||
|
||||
// -------------------------------------------- //
|
||||
// DRIVER REGISTRY
|
||||
|
Loading…
Reference in New Issue
Block a user