From 84652500619f62bb6a45177ff8f0c6c9863b1189 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Fri, 6 Dec 2013 15:03:58 +0100 Subject: [PATCH] Decided I dislike var-args and money transactions should have an optional freetext message. --- src/com/massivecraft/mcore/money/Money.java | 78 ++++++++++++----- .../massivecraft/mcore/money/MoneyMixin.java | 16 +++- .../mcore/money/MoneyMixinAbstract.java | 83 ++++++++++++------- .../mcore/money/MoneyMixinVault.java | 5 +- 4 files changed, 125 insertions(+), 57 deletions(-) diff --git a/src/com/massivecraft/mcore/money/Money.java b/src/com/massivecraft/mcore/money/Money.java index 6a01f63f..baef124e 100644 --- a/src/com/massivecraft/mcore/money/Money.java +++ b/src/com/massivecraft/mcore/money/Money.java @@ -99,83 +99,119 @@ public class Money } // -------------------------------------------- // - // MODIFY + // MOVE // -------------------------------------------- // - // MOVE - + public static boolean move(Object from, Object to, Object by, double amount, Collection categories, String 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) + { + if (disabled()) return false; + return mixin.move(accountId(from), accountId(to), accountId(by), amount, category, message); + } public static boolean move(Object from, Object to, Object by, double amount, Collection categories) { if (disabled()) return false; return mixin.move(accountId(from), accountId(to), accountId(by), amount, categories); } - - public static boolean move(Object from, Object to, Object by, double amount, String... categories) + public static boolean move(Object from, Object to, Object by, double amount, String category) { if (disabled()) return false; - return mixin.move(accountId(from), accountId(to), accountId(by), amount, categories); + return mixin.move(accountId(from), accountId(to), accountId(by), amount, category); } - public static boolean move(Object from, Object to, Object by, double amount) { if (disabled()) return false; return mixin.move(accountId(from), accountId(to), accountId(by), amount); } + // -------------------------------------------- // // SPAWN + // -------------------------------------------- // + public static boolean spawn(Object to, Object by, double amount, Collection categories, String 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) + { + if (disabled()) return false; + return mixin.spawn(accountId(to), accountId(by), amount, category, message); + } public static boolean spawn(Object to, Object by, double amount, Collection categories) { if (disabled()) return false; return mixin.spawn(accountId(to), accountId(by), amount, categories); } - - public static boolean spawn(Object to, Object by, double amount, String... categories) + public static boolean spawn(Object to, Object by, double amount, String category) { if (disabled()) return false; - return mixin.spawn(accountId(to), accountId(by), amount, categories); + return mixin.spawn(accountId(to), accountId(by), amount, category); } - - public static boolean spawn(Object toId, Object by, double amount) + public static boolean spawn(Object to, Object by, double amount) { if (disabled()) return false; - return mixin.spawn(accountId(toId), accountId(by), amount); + return mixin.spawn(accountId(to), accountId(by), amount); } + // -------------------------------------------- // // DESPAWN + // -------------------------------------------- // + public static boolean despawn(Object from, Object by, double amount, Collection categories, String 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) + { + if (disabled()) return false; + return mixin.despawn(accountId(from), accountId(by), amount, category, message); + } public static boolean despawn(Object from, Object by, double amount, Collection categories) { if (disabled()) return false; return mixin.despawn(accountId(from), accountId(by), amount, categories); } - - public static boolean despawn(Object from, Object by, double amount, String... categories) + public static boolean despawn(Object from, Object by, double amount, String category) { if (disabled()) return false; - return mixin.despawn(accountId(from), accountId(by), amount, categories); + return mixin.despawn(accountId(from), accountId(by), amount, category); } - public static boolean despawn(Object from, Object by, double amount) { if (disabled()) return false; return mixin.despawn(accountId(from), accountId(by), amount); } + // -------------------------------------------- // // SET + // -------------------------------------------- // + public static boolean set(Object account, Object by, double amount, Collection categories, String 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) + { + if (disabled()) return false; + return mixin.set(accountId(account), accountId(by), amount, category, message); + } public static boolean set(Object account, Object by, double amount, Collection categories) { if (disabled()) return false; return mixin.set(accountId(account), accountId(by), amount, categories); } - - public static boolean set(Object account, Object by, double amount, String... categories) + public static boolean set(Object account, Object by, double amount, String category) { if (disabled()) return false; - return mixin.set(accountId(account), accountId(by), amount, categories); + return mixin.set(accountId(account), accountId(by), amount, category); } - public static boolean set(Object account, Object by, double amount) { if (disabled()) return false; diff --git a/src/com/massivecraft/mcore/money/MoneyMixin.java b/src/com/massivecraft/mcore/money/MoneyMixin.java index 51233402..fb99e76d 100644 --- a/src/com/massivecraft/mcore/money/MoneyMixin.java +++ b/src/com/massivecraft/mcore/money/MoneyMixin.java @@ -36,20 +36,28 @@ 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); - public boolean move(String fromId, String toId, String byId, double amount, 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 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); - public boolean spawn(String toId, String byId, double amount, 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 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); - public boolean despawn(String fromId, String byId, double amount, 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 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); - public boolean set(String accountId, String byId, double amount, String... 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/mcore/money/MoneyMixinAbstract.java b/src/com/massivecraft/mcore/money/MoneyMixinAbstract.java index 536794a9..66a77f72 100644 --- a/src/com/massivecraft/mcore/money/MoneyMixinAbstract.java +++ b/src/com/massivecraft/mcore/money/MoneyMixinAbstract.java @@ -7,81 +7,102 @@ import java.util.Collection; public abstract class MoneyMixinAbstract implements MoneyMixin { // -------------------------------------------- // - // MODIFY + // MOVE // -------------------------------------------- // - // MOVE - // 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) + { + return this.move(fromId, toId, byId, amount, Arrays.asList(category), message); + } public boolean move(String fromId, String toId, String byId, double amount, Collection categories) { - // TODO Auto-generated method stub - return false; - }*/ - - public boolean move(String fromId, String toId, String byId, double amount, String... categories) - { - return this.move(fromId, toId, byId, amount, Arrays.asList(categories)); + return this.move(fromId, toId, byId, amount, categories, null); + } + public boolean move(String fromId, String toId, String byId, double amount, String category) + { + return this.move(fromId, toId, byId, amount, Arrays.asList(category), null); } - public boolean move(String fromId, String toId, String byId, double amount) { - return this.move(fromId, toId, byId, amount, new ArrayList()); + return this.move(fromId, toId, byId, amount, new ArrayList(), null); } + // -------------------------------------------- // // SPAWN + // -------------------------------------------- // + public boolean spawn(String toId, String byId, double amount, Collection categories, String message) + { + return this.move(null, toId, byId, amount, categories, message); + } + public boolean spawn(String toId, String byId, double amount, String category, String message) + { + return this.move(null, toId, byId, amount, category, message); + } public boolean spawn(String toId, String byId, double amount, Collection categories) { - // Based on Move return this.move(null, toId, byId, amount, categories); } - - public boolean spawn(String toId, String byId, double amount, String... categories) + public boolean spawn(String toId, String byId, double amount, String category) { - return this.spawn(toId, byId, amount, Arrays.asList(categories)); + return this.move(null, toId, byId, amount, category); } - public boolean spawn(String toId, String byId, double amount) { - return this.spawn(toId, byId, amount, new ArrayList()); + return this.move(null, toId, byId, amount); } + // -------------------------------------------- // // DESPAWN + // -------------------------------------------- // + public boolean despawn(String fromId, String byId, double amount, Collection categories, String message) + { + return this.move(fromId, null, byId, amount, categories, message); + } + public boolean despawn(String fromId, String byId, double amount, String category, String message) + { + return this.move(fromId, null, byId, amount, category, message); + } public boolean despawn(String fromId, String byId, double amount, Collection categories) { - // Based on Move return this.move(fromId, null, byId, amount, categories); } - - public boolean despawn(String fromId, String byId, double amount, String... categories) + public boolean despawn(String fromId, String byId, double amount, String category) { - return this.despawn(fromId, byId, amount, Arrays.asList(categories)); + return this.move(fromId, null, byId, amount, category); } - public boolean despawn(String fromId, String byId, double amount) { - return this.despawn(fromId, byId, amount, new ArrayList()); + return this.move(fromId, null, byId, amount); } + // -------------------------------------------- // // SET + // -------------------------------------------- // + public boolean set(String accountId, String byId, double amount, Collection categories, String 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) + { + return this.move(null, accountId, byId, amount - this.get(accountId), category, message); + } public boolean set(String accountId, String byId, double amount, Collection categories) { - // Based on Move return this.move(null, accountId, byId, amount - this.get(accountId), categories); } - - public boolean set(String accountId, String byId, double amount, String... categories) + public boolean set(String accountId, String byId, double amount, String category) { - return this.set(accountId, byId, amount, Arrays.asList(categories)); + return this.move(null, accountId, byId, amount - this.get(accountId), category); } - public boolean set(String accountId, String byId, double amount) { - return this.set(accountId, byId, amount, new ArrayList()); + return this.move(null, accountId, byId, amount - this.get(accountId)); } } \ No newline at end of file diff --git a/src/com/massivecraft/mcore/money/MoneyMixinVault.java b/src/com/massivecraft/mcore/money/MoneyMixinVault.java index 8c0a7b60..a1e469ee 100644 --- a/src/com/massivecraft/mcore/money/MoneyMixinVault.java +++ b/src/com/massivecraft/mcore/money/MoneyMixinVault.java @@ -11,6 +11,7 @@ import com.massivecraft.mcore.util.MUtil; + import net.milkbowl.vault.economy.Economy; public class MoneyMixinVault extends MoneyMixinAbstract @@ -117,7 +118,7 @@ public class MoneyMixinVault extends MoneyMixinAbstract // -------------------------------------------- // @Override - public boolean move(String fromId, String toId, String byId, double amount, Collection categories) + public boolean move(String fromId, String toId, String byId, double amount, Collection categories, String message) { // Ensure positive direction if (amount < 0) @@ -176,4 +177,6 @@ public class MoneyMixinVault extends MoneyMixinAbstract return true; } + + }