Skip to content

Commit

Permalink
Fix landlord UUID/name handling
Browse files Browse the repository at this point in the history
Also changes handling of buyer/renter UUIDs and names, if the playerdata
of a player is not available anymore AreaShop will still be able to
display his name. Also unrenting/selling will still properly pay back
the player through Vault (by name instead of UUID).

Fixes #35
  • Loading branch information
NLthijs48 committed Jul 30, 2015
1 parent f76c1b8 commit 9f436a7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
12 changes: 9 additions & 3 deletions AreaShop/src/main/java/nl/evolutioncoding/areashop/AreaShop.java
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,14 @@ public String toName(String uuid) {
if(uuid == null) {
return "";
} else {
return this.toName(UUID.fromString(uuid));
UUID parsed = null;
try {
parsed = UUID.fromString(uuid);
} catch(IllegalArgumentException e) {}
if(parsed == null) {
return "";
}
return this.toName(parsed);
}
}
/**
Expand All @@ -880,9 +887,8 @@ public String toName(UUID uuid) {
String name = Bukkit.getOfflinePlayer(uuid).getName();
if(name != null) {
return name;
} else {
return uuid.toString();
}
return "";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public RegionState getState() {
* @return The UUID of the owner of this region
*/
public UUID getBuyer() {
String buyer = getStringSetting("buy.buyer");
String buyer = config.getString("buy.buyer");
if(buyer != null) {
try {
return UUID.fromString(buyer);
Expand Down Expand Up @@ -95,7 +95,7 @@ public void setBuyer(UUID buyer) {
public String getPlayerName() {
String result = plugin.toName(getBuyer());
if(result == null || result.isEmpty()) {
result = config.getString("buy.buyerName");
result = getStringSetting("buy.buyerName");
if(result == null || result.isEmpty()) {
result = "<UNKNOWN>";
}
Expand Down Expand Up @@ -306,16 +306,16 @@ public boolean buy(Player player) {
plugin.message(player, "buy-payError");
return false;
}
r = null;
OfflinePlayer oldOwnerPlayer = Bukkit.getOfflinePlayer(oldOwner);
if(oldOwnerPlayer != null) {
if(oldOwnerPlayer.getName() == null) {
r = plugin.getEconomy().depositPlayer(getPlayerName(), getWorldName(), getResellPrice());
} else {
r = plugin.getEconomy().depositPlayer(oldOwnerPlayer, getWorldName(), getResellPrice());
}
if(!r.transactionSuccess()) {
plugin.getLogger().warning("Something went wrong with paying '" + oldOwnerPlayer.getName() + "' " + getFormattedPrice() + " for his resell of region " + getName() + " to " + player.getName());
}
String oldOwnerName = getPlayerName();
if(oldOwnerPlayer != null && oldOwnerPlayer.getName() != null) {
r = plugin.getEconomy().depositPlayer(oldOwnerPlayer, getWorldName(), getResellPrice());
} else if (oldOwnerName != null) {
r = plugin.getEconomy().depositPlayer(oldOwnerName, getWorldName(), getResellPrice());
}
if(r == null || !r.transactionSuccess()) {
plugin.getLogger().warning("Something went wrong with paying '" + oldOwnerPlayer.getName() + "' " + getFormattedPrice() + " for his resell of region " + getName() + " to " + player.getName());
}
// Resell is done, disable that now
disableReselling();
Expand Down Expand Up @@ -352,7 +352,7 @@ public boolean buy(Player player) {
}
String landlordName = getLandlordName();
r = null;
if(landlordPlayer != null) {
if(landlordPlayer != null && landlordPlayer.getName() != null) {
r = plugin.getEconomy().depositPlayer(landlordPlayer, getWorldName(), getPrice());
} else if(landlordName != null) {
r = plugin.getEconomy().depositPlayer(landlordName, getWorldName(), getPrice());
Expand Down Expand Up @@ -420,10 +420,10 @@ public void sell(boolean giveMoneyBack) {
EconomyResponse response = null;
boolean error = false;
try {
if(player.getName() == null) {
response = plugin.getEconomy().depositPlayer(getPlayerName(), getWorldName(), moneyBack);
} else {
if(player != null && player.getName() != null) {
response = plugin.getEconomy().depositPlayer(player, getWorldName(), moneyBack);
} else if(getPlayerName() != null) {
response = plugin.getEconomy().depositPlayer(getPlayerName(), getWorldName(), moneyBack);
}
} catch(Exception e) {
error = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public RegionState getState() {
* @return The UUID of the renter
*/
public UUID getRenter() {
String renter = getStringSetting("rent.renter");
String renter = config.getString("rent.renter");
if(renter != null) {
try {
return UUID.fromString(renter);
Expand Down Expand Up @@ -480,12 +480,12 @@ public boolean rent(Player player) {
}
String landlordName = getLandlordName();
r = null;
if(landlordPlayer != null) {
if(landlordPlayer != null && landlordPlayer.getName() != null) {
r = plugin.getEconomy().depositPlayer(landlordPlayer, getWorldName(), getPrice());
} else if(landlordName != null) {
r = plugin.getEconomy().depositPlayer(landlordName, getWorldName(), getPrice());
}
if(r != null && !r.transactionSuccess()) {
if(r == null || !r.transactionSuccess()) {
plugin.getLogger().warning("Something went wrong with paying '" + landlordName + "' " + getFormattedPrice() + " for his rent of region " + getName() + " to " + player.getName());
}

Expand Down Expand Up @@ -570,15 +570,15 @@ public void unRent(boolean giveMoneyBack) {
EconomyResponse r = null;
boolean error = false;
try {
if(player.getName() == null) {
r = plugin.getEconomy().depositPlayer(getPlayerName(), getWorldName(), moneyBack);
} else {
if(player != null && player.getName() != null) {
r = plugin.getEconomy().depositPlayer(player, getWorldName(), moneyBack);
} else if(getPlayerName() != null) {
r = plugin.getEconomy().depositPlayer(getPlayerName(), getWorldName(), moneyBack);
}
} catch(Exception e) {
error = true;
}
if(error || r == null || !r.transactionSuccess()) {
if(error || r == null || !r.transactionSuccess() || error) {
plugin.getLogger().warning("Something went wrong with paying back to " + getPlayerName() + " money while unrenting region " + getName());
}
}
Expand Down

0 comments on commit 9f436a7

Please sign in to comment.