Don't do perform economy actions on nameless offline players

An offline player is nameless if the player has not played on the server
before.

Unfortunately, all of the major economy plugins don't UUID-based
transactions, and instead forward all of the UUIDs through
Bukkit.getOfflinePlayer(UUID).getName()
This commit is contained in:
eueln 2015-01-10 15:12:06 -06:00
parent b52805f7a4
commit 6d6a04e383

View File

@ -156,12 +156,18 @@ public class Econ {
if (isUUID(from.getAccountId())) { if (isUUID(from.getAccountId())) {
fromAcc = Bukkit.getOfflinePlayer(UUID.fromString(from.getAccountId())); fromAcc = Bukkit.getOfflinePlayer(UUID.fromString(from.getAccountId()));
if (fromAcc.getName() == null) {
return false;
}
} else { } else {
fromAcc = Bukkit.getOfflinePlayer(from.getAccountId()); fromAcc = Bukkit.getOfflinePlayer(from.getAccountId());
} }
if (isUUID(to.getAccountId())) { if (isUUID(to.getAccountId())) {
toAcc = Bukkit.getOfflinePlayer(UUID.fromString(to.getAccountId())); toAcc = Bukkit.getOfflinePlayer(UUID.fromString(to.getAccountId()));
if (toAcc.getName() == null) {
return false;
}
} else { } else {
toAcc = Bukkit.getOfflinePlayer(to.getAccountId()); toAcc = Bukkit.getOfflinePlayer(to.getAccountId());
} }
@ -249,7 +255,12 @@ public class Econ {
double currentBalance; double currentBalance;
if (isUUID(ep.getAccountId())) { if (isUUID(ep.getAccountId())) {
currentBalance = econ.getBalance(Bukkit.getOfflinePlayer(UUID.fromString(ep.getAccountId()))); OfflinePlayer offline = Bukkit.getOfflinePlayer(UUID.fromString(ep.getAccountId()));
if (offline.getName() != null) {
currentBalance = econ.getBalance(Bukkit.getOfflinePlayer(UUID.fromString(ep.getAccountId())));
} else {
currentBalance = 0;
}
} else { } else {
currentBalance = econ.getBalance(ep.getAccountId()); currentBalance = econ.getBalance(ep.getAccountId());
} }
@ -276,6 +287,9 @@ public class Econ {
if (isUUID(ep.getAccountId())) { if (isUUID(ep.getAccountId())) {
acc = Bukkit.getOfflinePlayer(UUID.fromString(ep.getAccountId())); acc = Bukkit.getOfflinePlayer(UUID.fromString(ep.getAccountId()));
if (acc.getName() == null) {
return false;
}
} else { } else {
acc = Bukkit.getOfflinePlayer(ep.getAccountId()); acc = Bukkit.getOfflinePlayer(ep.getAccountId());
} }
@ -376,17 +390,17 @@ public class Econ {
private static final DecimalFormat format = new DecimalFormat("#,###"); private static final DecimalFormat format = new DecimalFormat("#,###");
public static String getFriendlyBalance(UUID uuid) { public static String getFriendlyBalance(UUID uuid) {
return format.format(econ.getBalance(Bukkit.getOfflinePlayer(uuid))); OfflinePlayer offline = Bukkit.getOfflinePlayer(uuid);
}
public static String getFriendlyBalance(FPlayer player) {
OfflinePlayer offline = Bukkit.getOfflinePlayer(UUID.fromString(player.getId()));
if (offline.getName() == null) { if (offline.getName() == null) {
return "0"; return "0";
} }
return format.format(econ.getBalance(offline)); return format.format(econ.getBalance(offline));
} }
public static String getFriendlyBalance(FPlayer player) {
return getFriendlyBalance(UUID.fromString(player.getId()));
}
public static boolean setBalance(String account, double amount) { public static boolean setBalance(String account, double amount) {
double current = econ.getBalance(account); double current = econ.getBalance(account);
if (current > amount) { if (current > amount) {