Make econ work with Factions again
This commit is contained in:
parent
2204cd2321
commit
4f27928e85
@ -25,7 +25,6 @@ public class Money
|
||||
if (account == null) return null;
|
||||
|
||||
// ... but if something is supplied we must manage to extract an id.
|
||||
// NOTE: This ID is the name for now, later all money plugins will probably support UUIDs.
|
||||
String ret = MUtil.extract(String.class, "accountId", account);
|
||||
if (ret == null) throw new IllegalArgumentException("extraction of accountId from object failed: " + account.toString());
|
||||
return ret;
|
||||
|
@ -115,7 +115,13 @@ public class MoneyMixinVault extends MoneyMixinAbstract
|
||||
@Override
|
||||
public boolean exists(String accountId)
|
||||
{
|
||||
return this.getEconomy().hasAccount(getOfflinePlayer(accountId));
|
||||
Object econObject = getEconomyObject(accountId);
|
||||
OfflinePlayer op = econObject instanceof OfflinePlayer ? (OfflinePlayer) econObject : null;
|
||||
String name = econObject instanceof String ? (String) econObject : null;
|
||||
|
||||
if (op != null) return this.getEconomy().hasAccount(op);
|
||||
if (name != null) return this.getEconomy().hasAccount(name);
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -132,14 +138,28 @@ public class MoneyMixinVault extends MoneyMixinAbstract
|
||||
public double get(String accountId)
|
||||
{
|
||||
this.ensureExists(accountId);
|
||||
return this.getEconomy().getBalance(getOfflinePlayer(accountId));
|
||||
|
||||
Object econObject = getEconomyObject(accountId);
|
||||
OfflinePlayer op = econObject instanceof OfflinePlayer ? (OfflinePlayer) econObject : null;
|
||||
String name = econObject instanceof String ? (String) econObject : null;
|
||||
|
||||
if (op != null) return this.getEconomy().getBalance(op);
|
||||
if (name != null) return this.getEconomy().getBalance(name);
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(String accountId, double amount)
|
||||
{
|
||||
this.ensureExists(accountId);
|
||||
return this.getEconomy().has(getOfflinePlayer(accountId), amount);
|
||||
|
||||
Object econObject = getEconomyObject(accountId);
|
||||
OfflinePlayer op = econObject instanceof OfflinePlayer ? (OfflinePlayer) econObject : null;
|
||||
String name = econObject instanceof String ? (String) econObject : null;
|
||||
|
||||
if (op != null) return this.getEconomy().has(op, amount);
|
||||
if (name != null) return this.getEconomy().has(name, amount);
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@ -201,23 +221,33 @@ public class MoneyMixinVault extends MoneyMixinAbstract
|
||||
{
|
||||
Economy economy = this.getEconomy();
|
||||
|
||||
if (economy.hasAccount(getOfflinePlayer(accountId))) return true;
|
||||
Object econObject = getEconomyObject(accountId);
|
||||
OfflinePlayer op = econObject instanceof OfflinePlayer ? (OfflinePlayer) econObject : null;
|
||||
String name = econObject instanceof String ? (String) econObject : null;
|
||||
|
||||
if (!economy.createPlayerAccount(getOfflinePlayer(accountId))) return false;
|
||||
if (op != null && economy.hasAccount(op)) return true;
|
||||
if (name != null && economy.hasAccount(name)) return true;
|
||||
|
||||
if (op != null && !economy.createPlayerAccount(op)) return false;
|
||||
if (name != null && !economy.createPlayerAccount(name)) return false;
|
||||
|
||||
if (MUtil.isUuid(accountId)) return true;
|
||||
|
||||
double balance = economy.getBalance(getOfflinePlayer(accountId));
|
||||
economy.withdrawPlayer(getOfflinePlayer(accountId), balance);
|
||||
// What is this for???
|
||||
//double balance = economy.getBalance(getOfflinePlayer(accountId));
|
||||
//economy.withdrawPlayer(getOfflinePlayer(accountId), balance);
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static OfflinePlayer getOfflinePlayer(String accountId)
|
||||
public static Object getEconomyObject(String accountId)
|
||||
{
|
||||
// Because of Factions we have this crazy-workaround.
|
||||
// Where offlineplayers will be used when possible
|
||||
// but otherwise names will.
|
||||
OfflinePlayer ret = IdUtil.getOfflinePlayer(accountId);
|
||||
if (ret == null) throw new RuntimeException("couldn't get offlineplayer for: " + accountId);
|
||||
return ret;
|
||||
if (ret != null) return ret;
|
||||
else return accountId;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user