Mson in MoneyMixin

This commit is contained in:
BuildTools 2016-03-08 05:33:45 +01:00 committed by Olof Larsson
parent 402e00a4e0
commit f92b042cca
6 changed files with 47 additions and 28 deletions

View File

@ -35,7 +35,7 @@ public class MsonAdapter implements JsonDeserializer<Mson>, JsonSerializer<Mson>
@Override
public Mson deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
{
return Mson.fromJson(json.getAsJsonObject());
return Mson.fromJson(json);
}
}

View File

@ -125,12 +125,12 @@ public class Money
// MOVE
// -------------------------------------------- //
public static boolean move(Object from, Object to, Object by, double amount, Collection<String> categories, String message)
public static boolean move(Object from, Object to, Object by, double amount, Collection<String> 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<String> categories, String message)
public static boolean spawn(Object to, Object by, double amount, Collection<String> 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<String> categories, String message)
public static boolean despawn(Object from, Object by, double amount, Collection<String> 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<String> categories, String message)
public static boolean set(Object account, Object by, double amount, Collection<String> 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);

View File

@ -44,26 +44,26 @@ public interface MoneyMixin
// MODIFY
// -------------------------------------------- //
public boolean move(String fromId, String toId, String byId, double amount, Collection<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> categories);
public boolean set(String accountId, String byId, double amount, String category);
public boolean set(String accountId, String byId, double amount);

View File

@ -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<String> 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<String> categories, String message)
public boolean spawn(String toId, String byId, double amount, Collection<String> 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<String> categories, String message)
public boolean despawn(String fromId, String byId, double amount, Collection<String> 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<String> categories, String message)
public boolean set(String accountId, String byId, double amount, Collection<String> 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);
}

View File

@ -147,7 +147,7 @@ public class MoneyMixinVault extends MoneyMixinAbstract
// -------------------------------------------- //
@Override
public boolean move(String fromId, String toId, String byId, double amount, Collection<String> categories, String message)
public boolean move(String fromId, String toId, String byId, double amount, Collection<String> categories, Object message)
{
Economy economy = this.getEconomy();

View File

@ -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,11 +1179,30 @@ public class Mson implements Serializable
{
return GSON.toJsonTree(this);
}
public static Mson fromJson(JsonObject json)
public static Mson fromJson(JsonElement json)
{
// 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;
public String toRaw()
{