Removing universe support in the Money mixin. The feature is to advanced and was never fully supported through Vault anyways.
This commit is contained in:
parent
84a19883ff
commit
3749074463
@ -95,11 +95,6 @@ public class MCore extends MPlugin
|
|||||||
// FIELDS
|
// FIELDS
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
// Aspects
|
|
||||||
private Aspect moneyAspect;
|
|
||||||
public Aspect getMoneyAspect() { return this.moneyAspect; }
|
|
||||||
public Multiverse getMoneyMultiverse() { return this.getMoneyAspect().getMultiverse(); }
|
|
||||||
|
|
||||||
// Commands
|
// Commands
|
||||||
private CmdMCore outerCmdMCore;
|
private CmdMCore outerCmdMCore;
|
||||||
public CmdMCore getOuterCmdMCore() { return this.outerCmdMCore; }
|
public CmdMCore getOuterCmdMCore() { return this.outerCmdMCore; }
|
||||||
@ -166,13 +161,6 @@ public class MCore extends MPlugin
|
|||||||
AspectColl.get().init();
|
AspectColl.get().init();
|
||||||
MCoreConfColl.get().init();
|
MCoreConfColl.get().init();
|
||||||
|
|
||||||
// Aspects
|
|
||||||
this.moneyAspect = AspectColl.get().get("mcore_money", true);
|
|
||||||
this.moneyAspect.register();
|
|
||||||
this.moneyAspect.setDesc(
|
|
||||||
"<i>The aspect used for how much money a player has"
|
|
||||||
);
|
|
||||||
|
|
||||||
// Inject our command map with dynamic tweaks
|
// Inject our command map with dynamic tweaks
|
||||||
MCoreBukkitSimpleCommandMap.inject();
|
MCoreBukkitSimpleCommandMap.inject();
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.massivecraft.mcore.money;
|
package com.massivecraft.mcore.money;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
import com.massivecraft.mcore.util.MUtil;
|
import com.massivecraft.mcore.util.MUtil;
|
||||||
|
|
||||||
public class Money
|
public class Money
|
||||||
@ -16,16 +18,9 @@ public class Money
|
|||||||
// EXTRACT
|
// EXTRACT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public static String universe(Object universe)
|
public static String accountId(Object account)
|
||||||
{
|
{
|
||||||
String ret = MUtil.extract(String.class, "moneyUniverse", universe);
|
String ret = MUtil.extract(String.class, "accountId", account);
|
||||||
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);
|
|
||||||
if (ret == null) throw new IllegalArgumentException("extraction of accountId from object failed");
|
if (ret == null) throw new IllegalArgumentException("extraction of accountId from object failed");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -34,126 +29,153 @@ public class Money
|
|||||||
// ENABLED
|
// ENABLED
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public static boolean enabled(Object universe)
|
public static boolean enabled()
|
||||||
{
|
{
|
||||||
if (mixin == null) return false;
|
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
|
// FORMAT AND NAME
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public static String format(Object universe, double amount)
|
public static String format(double amount)
|
||||||
{
|
{
|
||||||
if (disabled(universe)) return String.valueOf(amount);
|
if (disabled()) return String.valueOf(amount);
|
||||||
return mixin.format(universe(universe), amount);
|
return mixin.format(amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String singular(Object universe)
|
public static String singular()
|
||||||
{
|
{
|
||||||
if (disabled(universe)) return "singular";
|
if (disabled()) return "singular";
|
||||||
return mixin.singular(universe(universe));
|
return mixin.singular();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String plural(Object universe)
|
public static String plural()
|
||||||
{
|
{
|
||||||
if (disabled(universe)) return "plural";
|
if (disabled()) return "plural";
|
||||||
return mixin.plural(universe(universe));
|
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)
|
public static boolean exists(Object account)
|
||||||
{
|
{
|
||||||
return exists(account, account);
|
if (disabled()) return false;
|
||||||
}
|
return mixin.exists(accountId(account));
|
||||||
|
|
||||||
public static boolean create(Object universe, Object accountId)
|
|
||||||
{
|
|
||||||
if (disabled(universe)) return false;
|
|
||||||
return mixin.create(universe(universe), accountId(accountId));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean create(Object account)
|
public static boolean create(Object account)
|
||||||
{
|
{
|
||||||
return create(account, account);
|
if (disabled()) return false;
|
||||||
|
return mixin.create(accountId(account));
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// CHECK
|
// 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)
|
public static double get(Object account)
|
||||||
{
|
{
|
||||||
return get(account, account);
|
if (disabled()) return 0D;
|
||||||
}
|
return mixin.get(accountId(account));
|
||||||
|
|
||||||
public static boolean has(Object universe, Object accountId, double amount)
|
|
||||||
{
|
|
||||||
if (disabled(universe)) return false;
|
|
||||||
return mixin.has(universe(universe), accountId(accountId), amount);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean has(Object account, double amount)
|
public static boolean has(Object account, double amount)
|
||||||
{
|
{
|
||||||
return has(account, account, amount);
|
if (disabled()) return false;
|
||||||
|
return mixin.has(accountId(account), amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// MODIFY
|
// 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<String> categories)
|
||||||
{
|
{
|
||||||
if (disabled(universe)) return false;
|
if (disabled()) return false;
|
||||||
return mixin.set(universe(universe), accountId(accountId), amount);
|
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;
|
if (disabled()) return false;
|
||||||
return mixin.add(universe(universe), accountId(accountId), amount);
|
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<String> 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;
|
if (disabled()) return false;
|
||||||
return mixin.subtract(universe(universe), accountId(accountId), amount);
|
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<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, 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<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, 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,42 +1,55 @@
|
|||||||
package com.massivecraft.mcore.money;
|
package com.massivecraft.mcore.money;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
public interface MoneyMixin
|
public interface MoneyMixin
|
||||||
{
|
{
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// ENABLED
|
// ENABLED
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public boolean enabled(String universe);
|
public boolean enabled();
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// FORMAT AND NAME
|
// FORMAT AND NAME
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public String format(String universe, double amount);
|
public String format(double amount);
|
||||||
public String singular(String universe);
|
public String singular();
|
||||||
public String plural(String universe);
|
public String plural();
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// EXISTS AND CREATE
|
// EXISTANCE
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public boolean exists(String universe, String accountId);
|
public boolean exists(String accountId);
|
||||||
public boolean create(String universe, String accountId);
|
public boolean create(String accountId);
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// CHECK
|
// CHECK
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public double get(String universe, String accountId);
|
public double get(String accountId);
|
||||||
public boolean has(String universe, String accountId, double amount);
|
public boolean has(String accountId, double amount);
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// MODIFY
|
// MODIFY
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
public boolean set(String universe, String accountId, double amount);
|
public boolean move(double amount, String causeId, String fromId, String toId, Collection<String> categories);
|
||||||
public boolean add(String universe, String accountId, double amount);
|
public boolean move(double amount, String causeId, String fromId, String toId, String... categories);
|
||||||
public boolean subtract(String universe, String accountId, double amount);
|
public boolean move(double amount, String causeId, String fromId, String toId);
|
||||||
|
|
||||||
|
public boolean spawn(double amount, String causeId, String toId, Collection<String> 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<String> 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<String> categories);
|
||||||
|
public boolean set(double amount, String causeId, String accountId, String... categories);
|
||||||
|
public boolean set(double amount, String causeId, String accountId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,84 @@
|
|||||||
package com.massivecraft.mcore.money;
|
package com.massivecraft.mcore.money;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
public abstract class MoneyMixinAbstract implements MoneyMixin
|
public abstract class MoneyMixinAbstract implements MoneyMixin
|
||||||
{
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// MODIFY
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
// MOVE
|
||||||
|
|
||||||
|
/*public boolean move(double amount, String causeId, String fromId, String toId, Collection<String> 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<String>());
|
||||||
|
}
|
||||||
|
|
||||||
|
// SPAWN
|
||||||
|
|
||||||
|
public boolean spawn(double amount, String causeId, String toId, Collection<String> 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<String>());
|
||||||
|
}
|
||||||
|
|
||||||
|
// DESPAWN
|
||||||
|
|
||||||
|
public boolean despawn(double amount, String causeId, String fromId, Collection<String> 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<String>());
|
||||||
|
}
|
||||||
|
|
||||||
|
// SET
|
||||||
|
|
||||||
|
public boolean set(double amount, String causeId, String accountId, Collection<String> 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<String>());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package com.massivecraft.mcore.money;
|
package com.massivecraft.mcore.money;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
|
||||||
@ -7,6 +9,8 @@ import com.massivecraft.mcore.util.MUtil;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
|
||||||
public class MoneyMixinVault extends MoneyMixinAbstract
|
public class MoneyMixinVault extends MoneyMixinAbstract
|
||||||
@ -24,6 +28,7 @@ public class MoneyMixinVault extends MoneyMixinAbstract
|
|||||||
|
|
||||||
public void activate()
|
public void activate()
|
||||||
{
|
{
|
||||||
|
if (Money.mixin() != null) return;
|
||||||
RegisteredServiceProvider<Economy> rsp = Bukkit.getServicesManager().getRegistration(Economy.class);
|
RegisteredServiceProvider<Economy> rsp = Bukkit.getServicesManager().getRegistration(Economy.class);
|
||||||
if (rsp == null) return;
|
if (rsp == null) return;
|
||||||
this.economy = rsp.getProvider();
|
this.economy = rsp.getProvider();
|
||||||
@ -46,7 +51,7 @@ public class MoneyMixinVault extends MoneyMixinAbstract
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean enabled(String universe)
|
public boolean enabled()
|
||||||
{
|
{
|
||||||
return this.economy.isEnabled();
|
return this.economy.isEnabled();
|
||||||
}
|
}
|
||||||
@ -56,19 +61,19 @@ public class MoneyMixinVault extends MoneyMixinAbstract
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String format(String universe, double amount)
|
public String format(double amount)
|
||||||
{
|
{
|
||||||
return this.economy.format(amount);
|
return this.economy.format(amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String singular(String universe)
|
public String singular()
|
||||||
{
|
{
|
||||||
return this.economy.currencyNameSingular();
|
return this.economy.currencyNameSingular();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String plural(String universe)
|
public String plural()
|
||||||
{
|
{
|
||||||
return this.economy.currencyNamePlural();
|
return this.economy.currencyNamePlural();
|
||||||
}
|
}
|
||||||
@ -78,15 +83,15 @@ public class MoneyMixinVault extends MoneyMixinAbstract
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
@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
|
@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
|
@Override
|
||||||
public double get(String universe, String accountId)
|
public double get(String accountId)
|
||||||
{
|
{
|
||||||
this.ensureExists(universe, accountId);
|
this.ensureExists(accountId);
|
||||||
|
return this.economy.getBalance(accountId);
|
||||||
return this.economy.getBalance(accountId, universe);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean has(String universe, String accountId, double amount)
|
public boolean has(String accountId, double amount)
|
||||||
{
|
{
|
||||||
this.ensureExists(universe, accountId);
|
this.ensureExists(accountId);
|
||||||
|
return this.economy.has(accountId, amount);
|
||||||
return this.economy.has(accountId, universe, amount);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -114,46 +117,61 @@ public class MoneyMixinVault extends MoneyMixinAbstract
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean set(String universe, String accountId, double amount)
|
public boolean move(double amount, String causeId, String fromId, String toId, Collection<String> categories)
|
||||||
{
|
{
|
||||||
double current = get(universe, accountId);
|
// Ensure positive direction
|
||||||
return add(universe, accountId, amount - current);
|
if (amount < 0)
|
||||||
|
{
|
||||||
|
amount *= -1;
|
||||||
|
String temp = fromId;
|
||||||
|
fromId = toId;
|
||||||
|
toId = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// Ensure the accounts exist
|
||||||
public boolean add(String universe, String accountId, double amount)
|
if (fromId != null) this.ensureExists(fromId);
|
||||||
|
if (toId != null) this.ensureExists(toId);
|
||||||
|
|
||||||
|
// Subtract From
|
||||||
|
if (fromId != null)
|
||||||
{
|
{
|
||||||
if (amount < 0) return subtract(universe, accountId, -amount);
|
if (!economy.withdrawPlayer(fromId, amount).transactionSuccess())
|
||||||
|
{
|
||||||
this.ensureExists(universe, accountId);
|
return false;
|
||||||
|
}
|
||||||
return economy.depositPlayer(accountId, universe, amount).transactionSuccess();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// Add To
|
||||||
public boolean subtract(String universe, String accountId, double amount)
|
if (toId != null)
|
||||||
{
|
{
|
||||||
if (amount < 0) return add(universe, accountId, -amount);
|
if (!economy.depositPlayer(toId, amount).transactionSuccess())
|
||||||
|
{
|
||||||
|
if (fromId != null)
|
||||||
|
{
|
||||||
|
// Undo the withdraw
|
||||||
|
economy.depositPlayer(fromId, amount);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.ensureExists(universe, accountId);
|
return true;
|
||||||
|
|
||||||
return economy.withdrawPlayer(accountId, universe, amount).transactionSuccess();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// UTIL
|
// 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;
|
if (MUtil.isValidPlayerName(accountId)) return true;
|
||||||
|
|
||||||
double balance = this.economy.getBalance(accountId, universe);
|
double balance = this.economy.getBalance(accountId);
|
||||||
economy.withdrawPlayer(accountId, universe, balance);
|
economy.withdrawPlayer(accountId, balance);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,6 @@ import com.massivecraft.mcore.EngineMainMCore;
|
|||||||
import com.massivecraft.mcore.MCore;
|
import com.massivecraft.mcore.MCore;
|
||||||
import com.massivecraft.mcore.EngineWorldNameSet;
|
import com.massivecraft.mcore.EngineWorldNameSet;
|
||||||
import com.massivecraft.mcore.util.extractor.Extractor;
|
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.ExtractorPlayer;
|
||||||
import com.massivecraft.mcore.util.extractor.ExtractorPlayerName;
|
import com.massivecraft.mcore.util.extractor.ExtractorPlayerName;
|
||||||
import com.massivecraft.mcore.util.extractor.ExtractorSender;
|
import com.massivecraft.mcore.util.extractor.ExtractorSender;
|
||||||
@ -644,7 +643,6 @@ public class MUtil
|
|||||||
registerExtractor(World.class, "world", ExtractorWorld.get());
|
registerExtractor(World.class, "world", ExtractorWorld.get());
|
||||||
registerExtractor(String.class, "worldName", ExtractorWorldName.get());
|
registerExtractor(String.class, "worldName", ExtractorWorldName.get());
|
||||||
|
|
||||||
registerExtractor(String.class, "moneyUniverse", ExtractorMoneyUniverse.get());
|
|
||||||
registerExtractor(String.class, "accountId", ExtractorPlayerName.get());
|
registerExtractor(String.class, "accountId", ExtractorPlayerName.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,11 +25,8 @@ import org.bukkit.event.vehicle.VehicleEnterEvent;
|
|||||||
import org.bukkit.event.vehicle.VehicleEvent;
|
import org.bukkit.event.vehicle.VehicleEvent;
|
||||||
import org.bukkit.event.vehicle.VehicleExitEvent;
|
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.ps.PS;
|
||||||
import com.massivecraft.mcore.store.SenderEntity;
|
import com.massivecraft.mcore.store.SenderEntity;
|
||||||
import com.massivecraft.mcore.util.MUtil;
|
|
||||||
import com.massivecraft.mcore.util.SenderUtil;
|
import com.massivecraft.mcore.util.SenderUtil;
|
||||||
|
|
||||||
public class ExtractorLogic
|
public class ExtractorLogic
|
||||||
@ -163,34 +160,4 @@ public class ExtractorLogic
|
|||||||
return world.getName();
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user