diff --git a/src/com/massivecraft/mcore/MCore.java b/src/com/massivecraft/mcore/MCore.java index 5446ad11..e910abae 100644 --- a/src/com/massivecraft/mcore/MCore.java +++ b/src/com/massivecraft/mcore/MCore.java @@ -95,11 +95,6 @@ public class MCore extends MPlugin // FIELDS // -------------------------------------------- // - // Aspects - private Aspect moneyAspect; - public Aspect getMoneyAspect() { return this.moneyAspect; } - public Multiverse getMoneyMultiverse() { return this.getMoneyAspect().getMultiverse(); } - // Commands private CmdMCore outerCmdMCore; public CmdMCore getOuterCmdMCore() { return this.outerCmdMCore; } @@ -166,13 +161,6 @@ public class MCore extends MPlugin AspectColl.get().init(); MCoreConfColl.get().init(); - // Aspects - this.moneyAspect = AspectColl.get().get("mcore_money", true); - this.moneyAspect.register(); - this.moneyAspect.setDesc( - "The aspect used for how much money a player has" - ); - // Inject our command map with dynamic tweaks MCoreBukkitSimpleCommandMap.inject(); diff --git a/src/com/massivecraft/mcore/money/Money.java b/src/com/massivecraft/mcore/money/Money.java index 89b499be..0ff613e8 100644 --- a/src/com/massivecraft/mcore/money/Money.java +++ b/src/com/massivecraft/mcore/money/Money.java @@ -1,5 +1,7 @@ package com.massivecraft.mcore.money; +import java.util.Collection; + import com.massivecraft.mcore.util.MUtil; public class Money @@ -16,16 +18,9 @@ public class Money // EXTRACT // -------------------------------------------- // - public static String universe(Object universe) + public static String accountId(Object account) { - String ret = MUtil.extract(String.class, "moneyUniverse", universe); - if (ret == null) throw new IllegalArgumentException("extraction of universe from object failed"); - return ret; - } - - public static String accountId(Object accountId) - { - String ret = MUtil.extract(String.class, "accountId", accountId); + String ret = MUtil.extract(String.class, "accountId", account); if (ret == null) throw new IllegalArgumentException("extraction of accountId from object failed"); return ret; } @@ -34,126 +29,153 @@ public class Money // ENABLED // -------------------------------------------- // - public static boolean enabled(Object universe) + public static boolean enabled() { if (mixin == null) return false; - return mixin.enabled(universe(universe)); + return mixin.enabled(); } - public static boolean disabled(Object universe) + public static boolean disabled() { - return !enabled(universe); + return !enabled(); } // -------------------------------------------- // // FORMAT AND NAME // -------------------------------------------- // - public static String format(Object universe, double amount) + public static String format(double amount) { - if (disabled(universe)) return String.valueOf(amount); - return mixin.format(universe(universe), amount); + if (disabled()) return String.valueOf(amount); + return mixin.format(amount); } - public static String singular(Object universe) + public static String singular() { - if (disabled(universe)) return "singular"; - return mixin.singular(universe(universe)); + if (disabled()) return "singular"; + return mixin.singular(); } - public static String plural(Object universe) + public static String plural() { - if (disabled(universe)) return "plural"; - return mixin.plural(universe(universe)); + if (disabled()) return "plural"; + return mixin.plural(); } // -------------------------------------------- // - // EXISTS AND CREATE + // EXISTANCE // -------------------------------------------- // - public static boolean exists(Object universe, Object accountId) - { - if (disabled(universe)) return false; - return mixin.exists(universe(universe), accountId(accountId)); - } - public static boolean exists(Object account) { - return exists(account, account); - } - - public static boolean create(Object universe, Object accountId) - { - if (disabled(universe)) return false; - return mixin.create(universe(universe), accountId(accountId)); + if (disabled()) return false; + return mixin.exists(accountId(account)); } public static boolean create(Object account) { - return create(account, account); + if (disabled()) return false; + return mixin.create(accountId(account)); } // -------------------------------------------- // // CHECK // -------------------------------------------- // - public static double get(Object universe, Object accountId) - { - if (disabled(universe)) return 0D; - return mixin.get(universe(universe), accountId(accountId)); - } - public static double get(Object account) { - return get(account, account); - } - - public static boolean has(Object universe, Object accountId, double amount) - { - if (disabled(universe)) return false; - return mixin.has(universe(universe), accountId(accountId), amount); + if (disabled()) return 0D; + return mixin.get(accountId(account)); } public static boolean has(Object account, double amount) { - return has(account, account, amount); + if (disabled()) return false; + return mixin.has(accountId(account), amount); } // -------------------------------------------- // // MODIFY // -------------------------------------------- // - public static boolean set(Object universe, Object accountId, double amount) + // MOVE + + public static boolean move(double amount, Object cause, Object from, Object to, Collection categories) { - if (disabled(universe)) return false; - return mixin.set(universe(universe), accountId(accountId), amount); + if (disabled()) return false; + return mixin.move(amount, accountId(cause), accountId(from), accountId(to), categories); } - public static boolean set(Object account, double amount) + public static boolean move(double amount, Object cause, Object from, Object to, String... categories) { - return set(account, account, amount); + if (disabled()) return false; + return mixin.move(amount, accountId(cause), accountId(from), accountId(to), categories); } - public static boolean add(Object universe, Object accountId, double amount) + public static boolean move(double amount, Object cause, Object from, Object to) { - if (disabled(universe)) return false; - return mixin.add(universe(universe), accountId(accountId), amount); + if (disabled()) return false; + return mixin.move(amount, accountId(cause), accountId(from), accountId(to)); } - public static boolean add(Object account, double amount) + // SPAWN + + public static boolean spawn(double amount, Object cause, Object to, Collection categories) { - return add(account, account, amount); + if (disabled()) return false; + return mixin.spawn(amount, accountId(cause), accountId(to), categories); } - public static boolean subtract(Object universe, Object accountId, double amount) + public static boolean spawn(double amount, Object cause, Object to, String... categories) { - if (disabled(universe)) return false; - return mixin.subtract(universe(universe), accountId(accountId), amount); + if (disabled()) return false; + return mixin.spawn(amount, accountId(cause), accountId(to), categories); } - public static boolean subtract(Object account, double amount) + public static boolean spawn(double amount, Object cause, Object toId) { - return subtract(account, account, amount); + if (disabled()) return false; + return mixin.spawn(amount, accountId(cause), accountId(toId)); + } + + // DESPAWN + + public static boolean despawn(double amount, Object cause, Object from, Collection categories) + { + if (disabled()) return false; + return mixin.despawn(amount, accountId(cause), accountId(from), categories); + } + + public static boolean despawn(double amount, Object cause, Object from, String... categories) + { + if (disabled()) return false; + return mixin.despawn(amount, accountId(cause), accountId(from), categories); + } + + public static boolean despawn(double amount, Object cause, Object from) + { + if (disabled()) return false; + return mixin.despawn(amount, accountId(cause), accountId(from)); + } + + // SET + + public static boolean set(double amount, Object cause, Object account, Collection categories) + { + if (disabled()) return false; + return mixin.set(amount, accountId(cause), accountId(account), categories); + } + + public static boolean set(double amount, Object cause, Object account, String... categories) + { + if (disabled()) return false; + return mixin.set(amount, accountId(cause), accountId(account), categories); + } + + public static boolean set(double amount, Object cause, Object account) + { + if (disabled()) return false; + return mixin.set(amount, accountId(cause), accountId(account)); } } diff --git a/src/com/massivecraft/mcore/money/MoneyMixin.java b/src/com/massivecraft/mcore/money/MoneyMixin.java index 59789e1f..c1a368d3 100644 --- a/src/com/massivecraft/mcore/money/MoneyMixin.java +++ b/src/com/massivecraft/mcore/money/MoneyMixin.java @@ -1,42 +1,55 @@ package com.massivecraft.mcore.money; +import java.util.Collection; + public interface MoneyMixin { // -------------------------------------------- // // ENABLED // -------------------------------------------- // - public boolean enabled(String universe); + public boolean enabled(); // -------------------------------------------- // // FORMAT AND NAME // -------------------------------------------- // - public String format(String universe, double amount); - public String singular(String universe); - public String plural(String universe); + public String format(double amount); + public String singular(); + public String plural(); // -------------------------------------------- // - // EXISTS AND CREATE + // EXISTANCE // -------------------------------------------- // - public boolean exists(String universe, String accountId); - public boolean create(String universe, String accountId); + public boolean exists(String accountId); + public boolean create(String accountId); // -------------------------------------------- // // CHECK // -------------------------------------------- // - public double get(String universe, String accountId); - public boolean has(String universe, String accountId, double amount); - + public double get(String accountId); + public boolean has(String accountId, double amount); // -------------------------------------------- // // MODIFY // -------------------------------------------- // - public boolean set(String universe, String accountId, double amount); - public boolean add(String universe, String accountId, double amount); - public boolean subtract(String universe, String accountId, double amount); + public boolean move(double amount, String causeId, String fromId, String toId, Collection categories); + public boolean move(double amount, String causeId, String fromId, String toId, String... categories); + public boolean move(double amount, String causeId, String fromId, String toId); + + public boolean spawn(double amount, String causeId, String toId, Collection categories); + public boolean spawn(double amount, String causeId, String toId, String... categories); + public boolean spawn(double amount, String causeId, String toId); + + public boolean despawn(double amount, String causeId, String fromId, Collection categories); + public boolean despawn(double amount, String causeId, String fromId, String... categories); + public boolean despawn(double amount, String causeId, String fromId); + + public boolean set(double amount, String causeId, String accountId, Collection categories); + public boolean set(double amount, String causeId, String accountId, String... categories); + public boolean set(double amount, String causeId, String accountId); } diff --git a/src/com/massivecraft/mcore/money/MoneyMixinAbstract.java b/src/com/massivecraft/mcore/money/MoneyMixinAbstract.java index 8c691b48..be39ab4a 100644 --- a/src/com/massivecraft/mcore/money/MoneyMixinAbstract.java +++ b/src/com/massivecraft/mcore/money/MoneyMixinAbstract.java @@ -1,6 +1,84 @@ package com.massivecraft.mcore.money; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; + public abstract class MoneyMixinAbstract implements MoneyMixin { + // -------------------------------------------- // + // MODIFY + // -------------------------------------------- // + + // MOVE + + /*public boolean move(double amount, String causeId, String fromId, String toId, Collection categories) + { + // LOL this one shall be abstract still :3 + }*/ + + public boolean move(double amount, String causeId, String fromId, String toId, String... categories) + { + return this.move(amount, causeId, fromId, toId, Arrays.asList(categories)); + } + + public boolean move(double amount, String causeId, String fromId, String toId) + { + return this.move(amount, causeId, fromId, toId, new ArrayList()); + } + + // SPAWN + + public boolean spawn(double amount, String causeId, String toId, Collection categories) + { + // Based on Move + return this.move(amount, causeId, null, toId, categories); + } + + public boolean spawn(double amount, String causeId, String toId, String... categories) + { + return this.spawn(amount, causeId, toId, Arrays.asList(categories)); + } + + public boolean spawn(double amount, String causeId, String toId) + { + return this.spawn(amount, causeId, toId, new ArrayList()); + } + + // DESPAWN + + public boolean despawn(double amount, String causeId, String fromId, Collection categories) + { + // Based on Move + return this.move(amount, causeId, fromId, null, categories); + } + + public boolean despawn(double amount, String causeId, String fromId, String... categories) + { + return this.despawn(amount, causeId, fromId, Arrays.asList(categories)); + } + + public boolean despawn(double amount, String causeId, String fromId) + { + return this.despawn(amount, causeId, fromId, new ArrayList()); + } + + // SET + + public boolean set(double amount, String causeId, String accountId, Collection categories) + { + // Based on Move + return this.move(amount - this.get(accountId), causeId, null, accountId, categories); + } + + public boolean set(double amount, String causeId, String accountId, String... categories) + { + return this.set(amount, causeId, accountId, Arrays.asList(categories)); + } + + public boolean set(double amount, String causeId, String accountId) + { + return this.set(amount, causeId, accountId, new ArrayList()); + } } \ 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 c751320c..9b57fca7 100644 --- a/src/com/massivecraft/mcore/money/MoneyMixinVault.java +++ b/src/com/massivecraft/mcore/money/MoneyMixinVault.java @@ -1,5 +1,7 @@ package com.massivecraft.mcore.money; +import java.util.Collection; + import org.bukkit.Bukkit; import org.bukkit.plugin.RegisteredServiceProvider; @@ -7,6 +9,8 @@ import com.massivecraft.mcore.util.MUtil; + + import net.milkbowl.vault.economy.Economy; public class MoneyMixinVault extends MoneyMixinAbstract @@ -24,6 +28,7 @@ public class MoneyMixinVault extends MoneyMixinAbstract public void activate() { + if (Money.mixin() != null) return; RegisteredServiceProvider rsp = Bukkit.getServicesManager().getRegistration(Economy.class); if (rsp == null) return; this.economy = rsp.getProvider(); @@ -46,7 +51,7 @@ public class MoneyMixinVault extends MoneyMixinAbstract // -------------------------------------------- // @Override - public boolean enabled(String universe) + public boolean enabled() { return this.economy.isEnabled(); } @@ -56,19 +61,19 @@ public class MoneyMixinVault extends MoneyMixinAbstract // -------------------------------------------- // @Override - public String format(String universe, double amount) + public String format(double amount) { return this.economy.format(amount); } @Override - public String singular(String universe) + public String singular() { return this.economy.currencyNameSingular(); } @Override - public String plural(String universe) + public String plural() { return this.economy.currencyNamePlural(); } @@ -78,15 +83,15 @@ public class MoneyMixinVault extends MoneyMixinAbstract // -------------------------------------------- // @Override - public boolean exists(String universe, String accountId) + public boolean exists(String accountId) { - return this.economy.hasAccount(accountId, universe); + return this.economy.hasAccount(accountId); } @Override - public boolean create(String universe, String accountId) + public boolean create(String accountId) { - return this.ensureExists(universe, accountId); + return this.ensureExists(accountId); } // -------------------------------------------- // @@ -94,19 +99,17 @@ public class MoneyMixinVault extends MoneyMixinAbstract // -------------------------------------------- // @Override - public double get(String universe, String accountId) + public double get(String accountId) { - this.ensureExists(universe, accountId); - - return this.economy.getBalance(accountId, universe); + this.ensureExists(accountId); + return this.economy.getBalance(accountId); } @Override - public boolean has(String universe, String accountId, double amount) + public boolean has(String accountId, double amount) { - this.ensureExists(universe, accountId); - - return this.economy.has(accountId, universe, amount); + this.ensureExists(accountId); + return this.economy.has(accountId, amount); } // -------------------------------------------- // @@ -114,48 +117,63 @@ public class MoneyMixinVault extends MoneyMixinAbstract // -------------------------------------------- // @Override - public boolean set(String universe, String accountId, double amount) + public boolean move(double amount, String causeId, String fromId, String toId, Collection categories) { - double current = get(universe, accountId); - return add(universe, accountId, amount - current); - } - - @Override - public boolean add(String universe, String accountId, double amount) - { - if (amount < 0) return subtract(universe, accountId, -amount); + // Ensure positive direction + if (amount < 0) + { + amount *= -1; + String temp = fromId; + fromId = toId; + toId = temp; + } - this.ensureExists(universe, accountId); + // Ensure the accounts exist + if (fromId != null) this.ensureExists(fromId); + if (toId != null) this.ensureExists(toId); - return economy.depositPlayer(accountId, universe, amount).transactionSuccess(); - } - - @Override - public boolean subtract(String universe, String accountId, double amount) - { - if (amount < 0) return add(universe, accountId, -amount); + // Subtract From + if (fromId != null) + { + if (!economy.withdrawPlayer(fromId, amount).transactionSuccess()) + { + return false; + } + } - this.ensureExists(universe, accountId); + // Add To + if (toId != null) + { + if (!economy.depositPlayer(toId, amount).transactionSuccess()) + { + if (fromId != null) + { + // Undo the withdraw + economy.depositPlayer(fromId, amount); + } + return false; + } + } - return economy.withdrawPlayer(accountId, universe, amount).transactionSuccess(); + return true; } // -------------------------------------------- // // UTIL // -------------------------------------------- // - public boolean ensureExists(String universe, String accountId) + public boolean ensureExists(String accountId) { - if (this.economy.hasAccount(accountId, universe)) return true; + if (this.economy.hasAccount(accountId)) return true; - if (!this.economy.createPlayerAccount(accountId, universe)) return false; + if (!this.economy.createPlayerAccount(accountId)) return false; if (MUtil.isValidPlayerName(accountId)) return true; - double balance = this.economy.getBalance(accountId, universe); - economy.withdrawPlayer(accountId, universe, balance); + double balance = this.economy.getBalance(accountId); + economy.withdrawPlayer(accountId, balance); return true; } - -} \ No newline at end of file + +} diff --git a/src/com/massivecraft/mcore/util/MUtil.java b/src/com/massivecraft/mcore/util/MUtil.java index b925fb84..2ead319b 100644 --- a/src/com/massivecraft/mcore/util/MUtil.java +++ b/src/com/massivecraft/mcore/util/MUtil.java @@ -49,7 +49,6 @@ import com.massivecraft.mcore.EngineMainMCore; import com.massivecraft.mcore.MCore; import com.massivecraft.mcore.EngineWorldNameSet; import com.massivecraft.mcore.util.extractor.Extractor; -import com.massivecraft.mcore.util.extractor.ExtractorMoneyUniverse; import com.massivecraft.mcore.util.extractor.ExtractorPlayer; import com.massivecraft.mcore.util.extractor.ExtractorPlayerName; import com.massivecraft.mcore.util.extractor.ExtractorSender; @@ -644,7 +643,6 @@ public class MUtil registerExtractor(World.class, "world", ExtractorWorld.get()); registerExtractor(String.class, "worldName", ExtractorWorldName.get()); - registerExtractor(String.class, "moneyUniverse", ExtractorMoneyUniverse.get()); registerExtractor(String.class, "accountId", ExtractorPlayerName.get()); } diff --git a/src/com/massivecraft/mcore/util/extractor/ExtractorLogic.java b/src/com/massivecraft/mcore/util/extractor/ExtractorLogic.java index 77396142..a836d554 100644 --- a/src/com/massivecraft/mcore/util/extractor/ExtractorLogic.java +++ b/src/com/massivecraft/mcore/util/extractor/ExtractorLogic.java @@ -25,11 +25,8 @@ import org.bukkit.event.vehicle.VehicleEnterEvent; import org.bukkit.event.vehicle.VehicleEvent; import org.bukkit.event.vehicle.VehicleExitEvent; -import com.massivecraft.mcore.MCore; -import com.massivecraft.mcore.Multiverse; import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.store.SenderEntity; -import com.massivecraft.mcore.util.MUtil; import com.massivecraft.mcore.util.SenderUtil; public class ExtractorLogic @@ -163,34 +160,4 @@ public class ExtractorLogic return world.getName(); } - // -------------------------------------------- // - // MONEY UNIVERSE - // -------------------------------------------- // - - public static String moneyUniverse(String o) - { - Multiverse m = MCore.get().getMoneyMultiverse(); - if (m.containsUniverse(o)) return o; - return m.getUniverseForWorldName(o); - } - - public static String moneyUniverse(com.massivecraft.mcore.store.Entity o) - { - return o.getUniverse(); - } - - public static String moneyUniverseFromObject(Object o) - { - if (o instanceof String) return moneyUniverse((String)o); - if (o instanceof com.massivecraft.mcore.store.Entity) return moneyUniverse((com.massivecraft.mcore.store.Entity)o); - - String worldName = MUtil.extract(String.class, "worldName", o); - if (worldName != null) - { - return MCore.get().getMoneyMultiverse().getUniverseForWorldName(worldName); - } - - return null; - } - } diff --git a/src/com/massivecraft/mcore/util/extractor/ExtractorMoneyUniverse.java b/src/com/massivecraft/mcore/util/extractor/ExtractorMoneyUniverse.java deleted file mode 100644 index e82a07bd..00000000 --- a/src/com/massivecraft/mcore/util/extractor/ExtractorMoneyUniverse.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.massivecraft.mcore.util.extractor; - -public class ExtractorMoneyUniverse implements Extractor -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static ExtractorMoneyUniverse i = new ExtractorMoneyUniverse(); - public static ExtractorMoneyUniverse get() { return i; } - - // -------------------------------------------- // - // OVERRIDE: EXTRACTOR - // -------------------------------------------- // - - @Override - public Object extract(Object o) - { - return ExtractorLogic.moneyUniverseFromObject(o); - } - -}