From 93d56125137799725c8ccaf0fccdd7e8c9dba779 Mon Sep 17 00:00:00 2001 From: Thijs Wiefferink Date: Sat, 25 Jul 2015 16:56:41 +0200 Subject: [PATCH] Fix a bug with depositing to players that never joined Paying to players that never visited before will now fallback to using a name instead of UUID towards Vault, which prevents problems (for players that never visited, such as server accounts, you cannot get the name from the UUID via Bukkit). --- .../areashop/commands/AddCommand.java | 4 +-- .../areashop/commands/AddfriendCommand.java | 2 +- .../areashop/commands/SetlandlordCommand.java | 2 +- .../listeners/SignChangeListener.java | 4 +-- .../areashop/managers/LanguageManager.java | 2 +- .../areashop/regions/BuyRegion.java | 20 ++++++++++++--- .../areashop/regions/GeneralRegion.java | 8 ++++-- .../areashop/regions/RentRegion.java | 16 ++++++++++-- AreaShop/src/main/resources/config.yml | 25 +++++-------------- AreaShop/src/main/resources/default.yml | 14 +---------- AreaShop/src/main/resources/plugin.yml | 1 + 11 files changed, 52 insertions(+), 46 deletions(-) diff --git a/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/AddCommand.java b/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/AddCommand.java index 87ba0ce..6a3a384 100644 --- a/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/AddCommand.java +++ b/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/AddCommand.java @@ -153,7 +153,7 @@ public class AddCommand extends CommandAreaShop { RentRegion rent = new RentRegion(plugin, region.getId(), finalWorld); // Set landlord if(landlord) { - rent.setLandlord(finalPlayer.getUniqueId()); + rent.setLandlord(finalPlayer.getUniqueId(), finalPlayer.getName()); } // Run commands rent.runEventCommands(RegionEvent.CREATED, true); @@ -167,7 +167,7 @@ public class AddCommand extends CommandAreaShop { BuyRegion buy = new BuyRegion(plugin, region.getId(), finalWorld); // Set landlord if(landlord) { - buy.setLandlord(finalPlayer.getUniqueId()); + buy.setLandlord(finalPlayer.getUniqueId(), finalPlayer.getName()); } // Run commands buy.runEventCommands(RegionEvent.CREATED, true); diff --git a/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/AddfriendCommand.java b/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/AddfriendCommand.java index 67fbcc6..a5a1f7e 100644 --- a/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/AddfriendCommand.java +++ b/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/AddfriendCommand.java @@ -81,7 +81,7 @@ public class AddfriendCommand extends CommandAreaShop { return; } OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]); - if(!friend.hasPlayedBefore()) { + if(friend.getLastPlayed() == 0) { plugin.message(sender, "addfriend-notVisited", args[1]); return; } diff --git a/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/SetlandlordCommand.java b/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/SetlandlordCommand.java index c21a3d9..9468a34 100644 --- a/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/SetlandlordCommand.java +++ b/AreaShop/src/main/java/nl/evolutioncoding/areashop/commands/SetlandlordCommand.java @@ -72,7 +72,7 @@ public class SetlandlordCommand extends CommandAreaShop { plugin.message(player, "setlandlord-noRegion", args[2]); return; } - region.setLandlord(player.getUniqueId()); + region.setLandlord(player.getUniqueId(), args[1]); String playerName = player.getName(); if(playerName.isEmpty()) { playerName = args[1]; diff --git a/AreaShop/src/main/java/nl/evolutioncoding/areashop/listeners/SignChangeListener.java b/AreaShop/src/main/java/nl/evolutioncoding/areashop/listeners/SignChangeListener.java index 1ed28fa..25a81f4 100644 --- a/AreaShop/src/main/java/nl/evolutioncoding/areashop/listeners/SignChangeListener.java +++ b/AreaShop/src/main/java/nl/evolutioncoding/areashop/listeners/SignChangeListener.java @@ -144,7 +144,7 @@ public final class SignChangeListener implements Listener { || (player.hasPermission("areashop.createrent.member") && isMember))); if(landlord) { - rent.setLandlord(player.getUniqueId()); + rent.setLandlord(player.getUniqueId(), player.getName()); } if(priceSet) { rent.setPrice(price); @@ -257,7 +257,7 @@ public final class SignChangeListener implements Listener { || (player.hasPermission("areashop.createbuy.member") && isMember))); if(landlord) { - buy.setLandlord(player.getUniqueId()); + buy.setLandlord(player.getUniqueId(), player.getName()); } if(priceSet) { buy.setPrice(price); diff --git a/AreaShop/src/main/java/nl/evolutioncoding/areashop/managers/LanguageManager.java b/AreaShop/src/main/java/nl/evolutioncoding/areashop/managers/LanguageManager.java index 6005a56..c6d6d9e 100644 --- a/AreaShop/src/main/java/nl/evolutioncoding/areashop/managers/LanguageManager.java +++ b/AreaShop/src/main/java/nl/evolutioncoding/areashop/managers/LanguageManager.java @@ -21,7 +21,7 @@ import com.google.common.base.Charsets; public class LanguageManager { private AreaShop plugin = null; - private String languages[] = {"EN", "ZH_TW", "NL", "FI", "FR", "DE", "PL"}; + private String languages[] = {"EN", "NL", "FI", "DE", "FR", "PL", "ZH_TW"}; private HashMap currentLanguage, defaultLanguage; /** diff --git a/AreaShop/src/main/java/nl/evolutioncoding/areashop/regions/BuyRegion.java b/AreaShop/src/main/java/nl/evolutioncoding/areashop/regions/BuyRegion.java index fa62b25..fe44146 100644 --- a/AreaShop/src/main/java/nl/evolutioncoding/areashop/regions/BuyRegion.java +++ b/AreaShop/src/main/java/nl/evolutioncoding/areashop/regions/BuyRegion.java @@ -250,6 +250,7 @@ public class BuyRegion extends GeneralRegion { * @param player The player that wants to buy the region * @return true if it succeeded and false if not */ + @SuppressWarnings("deprecation") public boolean buy(Player player) { /* Check if the player has permission */ if(player.hasPermission("areashop.buy")) { @@ -307,7 +308,11 @@ public class BuyRegion extends GeneralRegion { } OfflinePlayer oldOwnerPlayer = Bukkit.getOfflinePlayer(oldOwner); if(oldOwnerPlayer != null) { - r = plugin.getEconomy().depositPlayer(oldOwnerPlayer, getWorldName(), getResellPrice()); + 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()); } @@ -344,7 +349,11 @@ public class BuyRegion extends GeneralRegion { if(getLandlord() != null) { OfflinePlayer landlord = Bukkit.getOfflinePlayer(getLandlord()); if(landlord != null) { - r = plugin.getEconomy().depositPlayer(landlord, getWorldName(), getPrice()); + if(landlord.getName() == null) { + r = plugin.getEconomy().depositPlayer(getLandlordName(), getWorldName(), getPrice()); + } else { + r = plugin.getEconomy().depositPlayer(landlord, getWorldName(), getPrice()); + } if(!r.transactionSuccess()) { plugin.getLogger().warning("Something went wrong with paying '" + landlord.getName() + "' " + getFormattedPrice() + " for his sell of region " + getName() + " to " + player.getName()); } @@ -395,6 +404,7 @@ public class BuyRegion extends GeneralRegion { * Sell a buyed region, get part of the money back * @param regionName */ + @SuppressWarnings("deprecation") public void sell(boolean giveMoneyBack) { // Run commands this.runEventCommands(RegionEvent.SOLD, true); @@ -409,7 +419,11 @@ public class BuyRegion extends GeneralRegion { EconomyResponse response = null; boolean error = false; try { - response = plugin.getEconomy().depositPlayer(Bukkit.getOfflinePlayer(getBuyer()), getWorldName(), moneyBack); + if(player.getName() == null) { + response = plugin.getEconomy().depositPlayer(getPlayerName(), getWorldName(), moneyBack); + } else { + response = plugin.getEconomy().depositPlayer(player, getWorldName(), moneyBack); + } } catch(Exception e) { error = true; } diff --git a/AreaShop/src/main/java/nl/evolutioncoding/areashop/regions/GeneralRegion.java b/AreaShop/src/main/java/nl/evolutioncoding/areashop/regions/GeneralRegion.java index 3ee820d..3377269 100644 --- a/AreaShop/src/main/java/nl/evolutioncoding/areashop/regions/GeneralRegion.java +++ b/AreaShop/src/main/java/nl/evolutioncoding/areashop/regions/GeneralRegion.java @@ -355,13 +355,17 @@ public abstract class GeneralRegion implements GeneralRegionInterface { * Set the landlord of this region (the player that receives all revenue of this region) * @param landlord The UUID of the player that should be set as landlord */ - public void setLandlord(UUID landlord) { + public void setLandlord(UUID landlord, String name) { if(landlord == null) { setSetting("general.landlord", null); setSetting("general.landlordName", null); } else { setSetting("general.landlord", landlord.toString()); - setSetting("general.landlordName", plugin.toName(landlord)); + String properName = plugin.toName(landlord); + if(properName != null) { + name = properName; + } + setSetting("general.landlordName", properName); } } diff --git a/AreaShop/src/main/java/nl/evolutioncoding/areashop/regions/RentRegion.java b/AreaShop/src/main/java/nl/evolutioncoding/areashop/regions/RentRegion.java index 3e935e0..400a4f8 100644 --- a/AreaShop/src/main/java/nl/evolutioncoding/areashop/regions/RentRegion.java +++ b/AreaShop/src/main/java/nl/evolutioncoding/areashop/regions/RentRegion.java @@ -394,6 +394,7 @@ public class RentRegion extends GeneralRegion { * @param regionName The name of the region you want to rent * @return true if it succeeded and false if not */ + @SuppressWarnings("deprecation") public boolean rent(Player player) { /* Check if the player has permission */ if(player.hasPermission("areashop.rent")) { @@ -476,7 +477,13 @@ public class RentRegion extends GeneralRegion { if(getLandlord() != null) { OfflinePlayer landlord = Bukkit.getOfflinePlayer(getLandlord()); if(landlord != null) { - r = plugin.getEconomy().depositPlayer(landlord, getWorldName(), getPrice()); + // If the landlord has no player.dat file anymore, then getName() returns null, + // therefor we deposit the money by the old cached name instead + if(landlord.getName() == null) { + r = plugin.getEconomy().depositPlayer(getLandlordName(), getWorldName(), getPrice()); + } else { + r = plugin.getEconomy().depositPlayer(landlord, getWorldName(), getPrice()); + } if(!r.transactionSuccess()) { plugin.getLogger().warning("Something went wrong with paying '" + landlord.getName() + "' " + getFormattedPrice() + " for his rent of region " + getName() + " to " + player.getName()); } @@ -551,6 +558,7 @@ public class RentRegion extends GeneralRegion { * Unrent a region, reset to unrented * @param regionName Region that should be unrented */ + @SuppressWarnings("deprecation") public void unRent(boolean giveMoneyBack) { // Run commands this.runEventCommands(RegionEvent.UNRENTED, true); @@ -562,7 +570,11 @@ public class RentRegion extends GeneralRegion { EconomyResponse r = null; boolean error = false; try { - r = plugin.getEconomy().depositPlayer(Bukkit.getOfflinePlayer(getRenter()), getWorldName(), moneyBack); + if(player.getName() == null) { + r = plugin.getEconomy().depositPlayer(getPlayerName(), getWorldName(), moneyBack); + } else { + r = plugin.getEconomy().depositPlayer(player, getWorldName(), moneyBack); + } } catch(Exception e) { error = true; } diff --git a/AreaShop/src/main/resources/config.yml b/AreaShop/src/main/resources/config.yml index 31744c6..fd49e0b 100644 --- a/AreaShop/src/main/resources/config.yml +++ b/AreaShop/src/main/resources/config.yml @@ -79,8 +79,8 @@ hours: [h, hour, hours, uur, uren] days: [d, day, days, dag, dagen] months: [M, month, months, maanden, maand] years: [y, year, years, jaar, jaren] - - + + # ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ # │ PERMISSION GROUPS: Assigned by giving players certain permissions │ # └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ @@ -97,7 +97,7 @@ limitGroups: rents: 1 buys: 1 - + # ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ # │ PROFILES: Assigned in general (default.yml), for a group (groups.yml) or individually (.yml) │ # └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ @@ -291,8 +291,8 @@ expirationWarningProfiles: "5 minutes": warnPlayer: true commands: - - + + # ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ # │ LIMITS AND TIMINGS: Options for limits and the frequencies for certain functions (be very careful with these!) │ # └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ @@ -347,17 +347,4 @@ nameupdate: ## Timings for adding regions to AreaShop ('/as stack') adding: ## Number of regions to add per tick - regionsPerTick: 2 - - - - - - - - - - - - - + regionsPerTick: 2 \ No newline at end of file diff --git a/AreaShop/src/main/resources/default.yml b/AreaShop/src/main/resources/default.yml index ca649c7..92fe552 100644 --- a/AreaShop/src/main/resources/default.yml +++ b/AreaShop/src/main/resources/default.yml @@ -74,16 +74,4 @@ buy: moneyBack: 100 ## Automatically sell the region after the specified number of minutes between the last login time of the buyer and the current time ## -1 mean never, 1440 is one day, 43200 is one month, 525600 is one year - inactiveTimeUntilSell: -1 - - - - - - - - - - - - \ No newline at end of file + inactiveTimeUntilSell: -1 \ No newline at end of file diff --git a/AreaShop/src/main/resources/plugin.yml b/AreaShop/src/main/resources/plugin.yml index 2392158..8fd989e 100644 --- a/AreaShop/src/main/resources/plugin.yml +++ b/AreaShop/src/main/resources/plugin.yml @@ -1,6 +1,7 @@ name: AreaShop main: nl.evolutioncoding.areashop.AreaShop version: ${project.version} +description: "Selling and renting WorldGuard regions to your players, highly configurable." depend: [Vault, WorldGuard, WorldEdit] softdepend: [Multiverse-Core] author: NLThijs48