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