From f92b042ccabff347a2ffa84357ccf290bb43632d Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 8 Mar 2016 05:33:45 +0100 Subject: [PATCH] Mson in MoneyMixin --- .../massivecore/adapter/MsonAdapter.java | 2 +- .../massivecraft/massivecore/money/Money.java | 16 ++++++------ .../massivecore/money/MoneyMixin.java | 16 ++++++------ .../massivecore/money/MoneyMixinAbstract.java | 14 +++++------ .../massivecore/money/MoneyMixinVault.java | 2 +- .../massivecraft/massivecore/mson/Mson.java | 25 ++++++++++++++++--- 6 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/com/massivecraft/massivecore/adapter/MsonAdapter.java b/src/com/massivecraft/massivecore/adapter/MsonAdapter.java index 82bacde0..393798d2 100644 --- a/src/com/massivecraft/massivecore/adapter/MsonAdapter.java +++ b/src/com/massivecraft/massivecore/adapter/MsonAdapter.java @@ -35,7 +35,7 @@ public class MsonAdapter implements JsonDeserializer, JsonSerializer @Override public Mson deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - return Mson.fromJson(json.getAsJsonObject()); + return Mson.fromJson(json); } } diff --git a/src/com/massivecraft/massivecore/money/Money.java b/src/com/massivecraft/massivecore/money/Money.java index b65a4445..cd196c74 100644 --- a/src/com/massivecraft/massivecore/money/Money.java +++ b/src/com/massivecraft/massivecore/money/Money.java @@ -125,12 +125,12 @@ public class Money // MOVE // -------------------------------------------- // - public static boolean move(Object from, Object to, Object by, double amount, Collection categories, String message) + public static boolean move(Object from, Object to, Object by, double amount, Collection categories, Object message) { if (disabled()) return false; return mixin.move(accountId(from), accountId(to), accountId(by), amount, categories, message); } - public static boolean move(Object from, Object to, Object by, double amount, String category, String message) + public static boolean move(Object from, Object to, Object by, double amount, String category, Object message) { if (disabled()) return false; return mixin.move(accountId(from), accountId(to), accountId(by), amount, category, message); @@ -155,12 +155,12 @@ public class Money // SPAWN // -------------------------------------------- // - public static boolean spawn(Object to, Object by, double amount, Collection categories, String message) + public static boolean spawn(Object to, Object by, double amount, Collection categories, Object message) { if (disabled()) return false; return mixin.spawn(accountId(to), accountId(by), amount, categories, message); } - public static boolean spawn(Object to, Object by, double amount, String category, String message) + public static boolean spawn(Object to, Object by, double amount, String category, Object message) { if (disabled()) return false; return mixin.spawn(accountId(to), accountId(by), amount, category, message); @@ -185,12 +185,12 @@ public class Money // DESPAWN // -------------------------------------------- // - public static boolean despawn(Object from, Object by, double amount, Collection categories, String message) + public static boolean despawn(Object from, Object by, double amount, Collection categories, Object message) { if (disabled()) return false; return mixin.despawn(accountId(from), accountId(by), amount, categories, message); } - public static boolean despawn(Object from, Object by, double amount, String category, String message) + public static boolean despawn(Object from, Object by, double amount, String category, Object message) { if (disabled()) return false; return mixin.despawn(accountId(from), accountId(by), amount, category, message); @@ -215,12 +215,12 @@ public class Money // SET // -------------------------------------------- // - public static boolean set(Object account, Object by, double amount, Collection categories, String message) + public static boolean set(Object account, Object by, double amount, Collection categories, Object message) { if (disabled()) return false; return mixin.set(accountId(account), accountId(by), amount, categories, message); } - public static boolean set(Object account, Object by, double amount, String category, String message) + public static boolean set(Object account, Object by, double amount, String category, Object message) { if (disabled()) return false; return mixin.set(accountId(account), accountId(by), amount, category, message); diff --git a/src/com/massivecraft/massivecore/money/MoneyMixin.java b/src/com/massivecraft/massivecore/money/MoneyMixin.java index 7d654707..2584c06a 100644 --- a/src/com/massivecraft/massivecore/money/MoneyMixin.java +++ b/src/com/massivecraft/massivecore/money/MoneyMixin.java @@ -44,26 +44,26 @@ public interface MoneyMixin // MODIFY // -------------------------------------------- // - public boolean move(String fromId, String toId, String byId, double amount, Collection categories, String message); - public boolean move(String fromId, String toId, String byId, double amount, String category, String message); + public boolean move(String fromId, String toId, String byId, double amount, Collection categories, Object message); + public boolean move(String fromId, String toId, String byId, double amount, String category, Object message); public boolean move(String fromId, String toId, String byId, double amount, Collection categories); public boolean move(String fromId, String toId, String byId, double amount, String category); public boolean move(String fromId, String toId, String byId, double amount); - public boolean spawn(String toId, String byId, double amount, Collection categories, String message); - public boolean spawn(String toId, String byId, double amount, String category, String message); + public boolean spawn(String toId, String byId, double amount, Collection categories, Object message); + public boolean spawn(String toId, String byId, double amount, String category, Object message); public boolean spawn(String toId, String byId, double amount, Collection categories); public boolean spawn(String toId, String byId, double amount, String category); public boolean spawn(String toId, String byId, double amount); - public boolean despawn(String fromId, String byId, double amount, Collection categories, String message); - public boolean despawn(String fromId, String byId, double amount, String category, String message); + public boolean despawn(String fromId, String byId, double amount, Collection categories, Object message); + public boolean despawn(String fromId, String byId, double amount, String category, Object message); public boolean despawn(String fromId, String byId, double amount, Collection categories); public boolean despawn(String fromId, String byId, double amount, String category); public boolean despawn(String fromId, String byId, double amount); - public boolean set(String accountId, String byId, double amount, Collection categories, String message); - public boolean set(String accountId, String byId, double amount, String category, String message); + public boolean set(String accountId, String byId, double amount, Collection categories, Object message); + public boolean set(String accountId, String byId, double amount, String category, Object message); public boolean set(String accountId, String byId, double amount, Collection categories); public boolean set(String accountId, String byId, double amount, String category); public boolean set(String accountId, String byId, double amount); diff --git a/src/com/massivecraft/massivecore/money/MoneyMixinAbstract.java b/src/com/massivecraft/massivecore/money/MoneyMixinAbstract.java index 9cf6bd72..57011bcb 100644 --- a/src/com/massivecraft/massivecore/money/MoneyMixinAbstract.java +++ b/src/com/massivecraft/massivecore/money/MoneyMixinAbstract.java @@ -45,7 +45,7 @@ public abstract class MoneyMixinAbstract implements MoneyMixin // this is the abstract one // public boolean move(String fromId, String toId, String byId, double amount, Collection categories, String message); - public boolean move(String fromId, String toId, String byId, double amount, String category, String message) + public boolean move(String fromId, String toId, String byId, double amount, String category, Object message) { return this.move(fromId, toId, byId, amount, (category == null ? null : Collections.singletonList(category)), message); } @@ -66,11 +66,11 @@ public abstract class MoneyMixinAbstract implements MoneyMixin // SPAWN // -------------------------------------------- // - public boolean spawn(String toId, String byId, double amount, Collection categories, String message) + public boolean spawn(String toId, String byId, double amount, Collection categories, Object message) { return this.move(null, toId, byId, amount, categories, message); } - public boolean spawn(String toId, String byId, double amount, String category, String message) + public boolean spawn(String toId, String byId, double amount, String category, Object message) { return this.move(null, toId, byId, amount, category, message); } @@ -91,11 +91,11 @@ public abstract class MoneyMixinAbstract implements MoneyMixin // DESPAWN // -------------------------------------------- // - public boolean despawn(String fromId, String byId, double amount, Collection categories, String message) + public boolean despawn(String fromId, String byId, double amount, Collection categories, Object message) { return this.move(fromId, null, byId, amount, categories, message); } - public boolean despawn(String fromId, String byId, double amount, String category, String message) + public boolean despawn(String fromId, String byId, double amount, String category, Object message) { return this.move(fromId, null, byId, amount, category, message); } @@ -116,11 +116,11 @@ public abstract class MoneyMixinAbstract implements MoneyMixin // SET // -------------------------------------------- // - public boolean set(String accountId, String byId, double amount, Collection categories, String message) + public boolean set(String accountId, String byId, double amount, Collection categories, Object message) { return this.move(null, accountId, byId, amount - this.get(accountId), categories, message); } - public boolean set(String accountId, String byId, double amount, String category, String message) + public boolean set(String accountId, String byId, double amount, String category, Object message) { return this.move(null, accountId, byId, amount - this.get(accountId), category, message); } diff --git a/src/com/massivecraft/massivecore/money/MoneyMixinVault.java b/src/com/massivecraft/massivecore/money/MoneyMixinVault.java index 1dc7f75e..e657afeb 100644 --- a/src/com/massivecraft/massivecore/money/MoneyMixinVault.java +++ b/src/com/massivecraft/massivecore/money/MoneyMixinVault.java @@ -147,7 +147,7 @@ public class MoneyMixinVault extends MoneyMixinAbstract // -------------------------------------------- // @Override - public boolean move(String fromId, String toId, String byId, double amount, Collection categories, String message) + public boolean move(String fromId, String toId, String byId, double amount, Collection categories, Object message) { Economy economy = this.getEconomy(); diff --git a/src/com/massivecraft/massivecore/mson/Mson.java b/src/com/massivecraft/massivecore/mson/Mson.java index bcd18b15..35e481a0 100644 --- a/src/com/massivecraft/massivecore/mson/Mson.java +++ b/src/com/massivecraft/massivecore/mson/Mson.java @@ -26,7 +26,7 @@ import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.xlib.gson.Gson; import com.massivecraft.massivecore.xlib.gson.GsonBuilder; import com.massivecraft.massivecore.xlib.gson.JsonElement; -import com.massivecraft.massivecore.xlib.gson.JsonObject; +import com.massivecraft.massivecore.xlib.gson.JsonPrimitive; public class Mson implements Serializable { @@ -1179,9 +1179,28 @@ public class Mson implements Serializable { return GSON.toJsonTree(this); } - public static Mson fromJson(JsonObject json) + public static Mson fromJson(JsonElement json) { - return GSON.fromJson(json, Mson.class); + // Escape the null. + if (json.isJsonNull()) + { + return null; + } + + // If converting from an old system. + if (json.isJsonPrimitive() && ((JsonPrimitive) json).isString()) + { + return fromParsedMessage(json.getAsString()); + } + + // Just a normal mson. + if (json.isJsonObject()) + { + return GSON.fromJson(json, Mson.class); + } + + // Something is horribly wrong. + throw new IllegalArgumentException("Neither string nor object: " + json); } private transient String raw = null;