Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
Band-aide patch factionsUUID issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorfromhell committed Aug 3, 2020
1 parent e464217 commit eea88da
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 8 deletions.
90 changes: 82 additions & 8 deletions TNE/src/net/tnemc/core/common/api/Economy_TheNewEconomy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -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);
}

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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);
}

Expand All @@ -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!");
Expand All @@ -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) {
Expand All @@ -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!");
Expand All @@ -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);
}

Expand Down Expand Up @@ -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
Expand All @@ -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());
}
}
10 changes: 10 additions & 0 deletions TNE/src/net/tnemc/core/common/api/TNEAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit eea88da

Please sign in to comment.