diff --git a/TNE/src/net/tnemc/core/common/api/Economy_TheNewEconomy.java b/TNE/src/net/tnemc/core/common/api/Economy_TheNewEconomy.java index 1907d2ab..06fa7074 100644 --- a/TNE/src/net/tnemc/core/common/api/Economy_TheNewEconomy.java +++ b/TNE/src/net/tnemc/core/common/api/Economy_TheNewEconomy.java @@ -73,7 +73,7 @@ public boolean hasAccount(String username) { @Override public boolean hasAccount(OfflinePlayer offlinePlayer) { - return api.hasAccount(offlinePlayer.getUniqueId().toString()); + return api.hasAccount(offlinePlayer.getUniqueId()); } @Override @@ -83,7 +83,7 @@ public boolean hasAccount(String username, String world) { @Override public boolean hasAccount(OfflinePlayer offlinePlayer, String world) { - return api.hasAccount(offlinePlayer.getUniqueId().toString()); + return api.hasAccount(offlinePlayer.getUniqueId()); } @Override @@ -93,6 +93,9 @@ public double getBalance(String username) { @Override public double getBalance(OfflinePlayer offlinePlayer) { + TNE.debug("Economy_TheNewEconomy.getBalance(offlinePlayer)"); + TNE.debug("username: " + offlinePlayer.getName()); + TNE.debug("id: " + offlinePlayer.getUniqueId().toString()); return api.getHoldings(offlinePlayer.getUniqueId().toString(), TNE.instance().defaultWorld).doubleValue(); } @@ -103,6 +106,15 @@ public double getBalance(String username, String world) { @Override public double getBalance(OfflinePlayer offlinePlayer, String world) { + TNE.debug("Economy_TheNewEconomy.getBalance(offlinePlayer, world)"); + TNE.debug("username: " + offlinePlayer.getName()); + TNE.debug("id: " + offlinePlayer.getUniqueId().toString()); + TNE.debug("world: " + world); + + if(offlinePlayer.getName().contains("faction-")) { + return getBalance(offlinePlayer.getName(), world); + } + return api.getHoldings(offlinePlayer.getUniqueId().toString(), world).doubleValue(); } @@ -111,6 +123,7 @@ public boolean has(String username, double amount) { TNE.debug("Economy_TheNewEconomy.has(username, amount)"); TNE.debug("username: " + username); TNE.debug("Amount: " + amount); + return has(username, TNE.instance().defaultWorld, amount); } @@ -123,7 +136,12 @@ public boolean has(OfflinePlayer offlinePlayer, double amount) { if(offlinePlayer.isOnline()) { world = offlinePlayer.getPlayer().getWorld().getName(); } - return has(offlinePlayer.getName(), world, amount); + + if(offlinePlayer.getName().contains("faction-")) { + return has(offlinePlayer.getName(), world, amount); + } + + return has(offlinePlayer.getUniqueId().toString(), world, amount); } @Override @@ -139,9 +157,14 @@ public boolean has(String username, String world, double amount) { public boolean has(OfflinePlayer offlinePlayer, String world, double amount) { TNE.debug("Economy_TheNewEconomy.has(offlinePlayer, world, amount)"); TNE.debug("username: " + offlinePlayer.getName()); + TNE.debug("id: " + offlinePlayer.getUniqueId().toString()); TNE.debug("world: " + world); TNE.debug("Amount: " + amount); - return has(offlinePlayer.getName(), world, amount); + + if(offlinePlayer.getName().contains("faction-")) { + return has(offlinePlayer.getName(), world, amount); + } + return has(offlinePlayer.getUniqueId().toString(), world, amount); } @Override @@ -151,6 +174,10 @@ public EconomyResponse withdrawPlayer(String username, double amount) { if(player != null) { world = player.getWorld().getName(); } + TNE.debug("Economy_TheNewEconomy.withdrawPlayer(username, amount)"); + TNE.debug("username: " + username); + TNE.debug("world: " + world); + TNE.debug("Amount: " + amount); return withdrawPlayer(username, world, amount); } @@ -160,11 +187,26 @@ public EconomyResponse withdrawPlayer(OfflinePlayer offlinePlayer, double amount if(offlinePlayer.isOnline()) { world = offlinePlayer.getPlayer().getWorld().getName(); } - return withdrawPlayer(offlinePlayer.getName(), world, amount); + + TNE.debug("Economy_TheNewEconomy.withdrawPlayer(offlinePlayer, amount)"); + TNE.debug("username: " + offlinePlayer.getName()); + TNE.debug("id: " + offlinePlayer.getUniqueId().toString()); + TNE.debug("world: " + world); + TNE.debug("Amount: " + amount); + + if(offlinePlayer.getName().contains("faction-")) { + return withdrawPlayer(offlinePlayer.getName(), world, amount); + } + + return withdrawPlayer(offlinePlayer.getUniqueId().toString(), world, amount); } @Override public EconomyResponse withdrawPlayer(String username, String world, double amount) { + TNE.debug("Economy_TheNewEconomy.withdrawPlayer(username, world, amount)"); + TNE.debug("username: " + username); + TNE.debug("world: " + world); + TNE.debug("Amount: " + amount); if(TNE.maintenance) return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Economy is in maintenance mode."); if(!hasAccount(username)) { return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "That account does not exist!"); @@ -185,11 +227,19 @@ public EconomyResponse withdrawPlayer(String username, String world, double amou @Override public EconomyResponse withdrawPlayer(OfflinePlayer offlinePlayer, String world, double amount) { - return withdrawPlayer(offlinePlayer.getName(), world, amount); + TNE.debug("Economy_TheNewEconomy.withdrawPlayer(offlinePlayer, world, amount)"); + TNE.debug("username: " + offlinePlayer.getName()); + TNE.debug("id: " + offlinePlayer.getUniqueId().toString()); + TNE.debug("world: " + world); + TNE.debug("Amount: " + amount); + return withdrawPlayer(offlinePlayer.getUniqueId().toString(), world, amount); } @Override public EconomyResponse depositPlayer(String username, double amount) { + TNE.debug("Economy_TheNewEconomy.depositPlayer(username, amount)"); + TNE.debug("username: " + username); + TNE.debug("Amount: " + amount); String world = TNE.instance().defaultWorld; final Player player = Bukkit.getPlayer(username); if(player != null) { @@ -204,11 +254,25 @@ public EconomyResponse depositPlayer(OfflinePlayer offlinePlayer, double amount) if(offlinePlayer.isOnline()) { offlinePlayer.getPlayer().getWorld().getName(); } + TNE.debug("Economy_TheNewEconomy.depositPlayer(offlinePlayer, amount)"); + TNE.debug("username: " + offlinePlayer.getName()); + TNE.debug("id: " + offlinePlayer.getUniqueId().toString()); + TNE.debug("world: " + world); + TNE.debug("Amount: " + amount); + + if(offlinePlayer.getName().contains("faction-")) { + return depositPlayer(offlinePlayer.getName(), world, amount); + } + return depositPlayer(offlinePlayer.getUniqueId(), world, amount); } @Override public EconomyResponse depositPlayer(String username, String world, double amount) { + TNE.debug("Economy_TheNewEconomy.depositPlayer(username, world, amount)"); + TNE.debug("username: " + username); + TNE.debug("world: " + world); + TNE.debug("Amount: " + amount); if(TNE.maintenance) return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Economy is in maintenance mode."); if(!hasAccount(username)) { return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "That account does not exist!"); @@ -225,6 +289,16 @@ public EconomyResponse depositPlayer(String username, String world, double amoun @Override public EconomyResponse depositPlayer(OfflinePlayer offlinePlayer, String world, double amount) { + TNE.debug("Economy_TheNewEconomy.depositPlayer(offlinePlayer, world, amount)"); + TNE.debug("username: " + offlinePlayer.getName()); + TNE.debug("id: " + offlinePlayer.getUniqueId().toString()); + TNE.debug("world: " + world); + TNE.debug("Amount: " + amount); + + if(offlinePlayer.getName().contains("faction-")) { + return depositPlayer(offlinePlayer.getName(), world, amount); + } + return depositPlayer(offlinePlayer.getUniqueId(), world, amount); } @@ -310,7 +384,7 @@ public boolean createPlayerAccount(String username) { @Override public boolean createPlayerAccount(OfflinePlayer offlinePlayer) { - return api.createAccount(IDFinder.getID(offlinePlayer).toString()); + return api.createAccount(offlinePlayer.getUniqueId(), offlinePlayer.getName()); } @Override @@ -320,6 +394,6 @@ public boolean createPlayerAccount(String username, String world) { @Override public boolean createPlayerAccount(OfflinePlayer offlinePlayer, String world) { - return api.createAccount(IDFinder.getID(offlinePlayer).toString()); + return api.createAccount(offlinePlayer.getUniqueId(), offlinePlayer.getName()); } } \ No newline at end of file diff --git a/TNE/src/net/tnemc/core/common/api/TNEAPI.java b/TNE/src/net/tnemc/core/common/api/TNEAPI.java index 474b7688..50f3ee21 100644 --- a/TNE/src/net/tnemc/core/common/api/TNEAPI.java +++ b/TNE/src/net/tnemc/core/common/api/TNEAPI.java @@ -227,6 +227,16 @@ public boolean createAccount(UUID identifier) { return TNE.manager().createAccount(identifier, IDFinder.getUsername(identifier.toString())); } + /** + * Attempts to create an account for this identifier. This method should be used for player accounts. + * @param identifier The {@link UUID} of the account. + * @param username The username to use + * @return True if an account was created, else false. + */ + public boolean createAccount(UUID identifier, String username) { + return TNE.manager().createAccount(identifier, username); + } + /** * This is a shortcut method that combines getAccount with createAccount. This method should be used for non-player * Accounts.