From 22d3f262f5206f0ad47d4af45f7783269455b7d6 Mon Sep 17 00:00:00 2001 From: Phoenix616 Date: Thu, 28 Jan 2021 15:26:23 +0100 Subject: [PATCH] Improve NameManager OfflinePlayer and UUID version handling (#383) This also removes the deprecated methods which might interact with the changed methods in unintended ways from the NameManager and the PreTransactionEvent. --- pom.xml | 2 +- .../ChestShop/Events/PreTransactionEvent.java | 20 ---- .../Acrobot/ChestShop/UUIDs/NameManager.java | 110 +----------------- 3 files changed, 6 insertions(+), 126 deletions(-) diff --git a/pom.xml b/pom.xml index 60924c4..44b63a3 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.acrobot.chestshop chestshop - 3.11.1-SNAPSHOT + 3.12-SNAPSHOT Chest-and-sign shop plugin for Bukkit ChestShop diff --git a/src/main/java/com/Acrobot/ChestShop/Events/PreTransactionEvent.java b/src/main/java/com/Acrobot/ChestShop/Events/PreTransactionEvent.java index ab68827..b541d0b 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/PreTransactionEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/PreTransactionEvent.java @@ -149,26 +149,6 @@ public class PreTransactionEvent extends Event implements Cancellable { this.ownerAccount = ownerAccount; } - /** - * @return Shop's owner - * @deprecated Use {@link #getOwnerAccount} - */ - @Deprecated - public OfflinePlayer getOwner() { - return Bukkit.getOfflinePlayer(ownerAccount.getUuid()); - } - - /** - * Sets the shop's owner - * - * @param owner Shop owner - * @deprecated Use {@link #setOwnerAccount(Account)} - */ - @Deprecated - public void setOwner(OfflinePlayer owner) { - this.ownerAccount = NameManager.getOrCreateAccount(owner); - } - /** * @return Owner's inventory */ diff --git a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java index fcc321c..10e74f8 100644 --- a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java +++ b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java @@ -65,6 +65,10 @@ public class NameManager implements Listener { * @throws IllegalArgumentException when an invalid player object was passed */ public static Account getOrCreateAccount(OfflinePlayer player) { + Validate.notNull(player.getName(), "Name of player " + player.getUniqueId() + " is null?"); + Validate.isTrue(!(player instanceof Player) || !Properties.ENSURE_CORRECT_PLAYERID || uuidVersion < 0 || player.getUniqueId().version() == uuidVersion, + "Invalid OfflinePlayer! " + player.getUniqueId() + " has version " + player.getUniqueId().version() + " and not server version " + uuidVersion + ". " + + "If you believe that is an error and your setup allows such UUIDs then set the ENSURE_CORRECT_PLAYERID config option to false."); return getOrCreateAccount(player.getUniqueId(), player.getName()); } @@ -79,9 +83,6 @@ public class NameManager implements Listener { public static Account getOrCreateAccount(UUID id, String name) { Validate.notNull(id, "UUID of player is null?"); Validate.notNull(name, "Name of player " + id + " is null?"); - Validate.isTrue(!Properties.ENSURE_CORRECT_PLAYERID || uuidVersion < 0 || id.version() == uuidVersion, - "Invalid OfflinePlayer! " + id + " has version " + id.version() + " and not server version " + uuidVersion + ". " + - "If you believe that is an error and your setup allows such UUIDs then set the ENSURE_CORRECT_PLAYERID config option to false."); Account account = getAccount(id); if (account == null) { @@ -161,6 +162,7 @@ public class NameManager implements Listener { * @throws IllegalArgumentException if the username is empty * @deprecated Use the {@link AccountQueryEvent} instead! */ + @Deprecated public static Account getAccountFromShortName(String shortName) { return getAccountFromShortName(shortName, true); } @@ -202,19 +204,6 @@ public class NameManager implements Listener { return account; } - /** - * Get the information from the last time a player logged in that previously used the shortened name - * - * @param shortName The name of the player to get the last account for - * @return The last account or null if none was found - * @throws IllegalArgumentException if the username is empty - * @deprecated Use the {@link AccountQueryEvent} instead! - */ - @Deprecated - public static Account getLastAccountFromShortName(String shortName) { - return getLastAccountFromShortName(shortName, true); - } - /** * Get the information from the last time a player logged in that previously used the shortened name * @@ -231,87 +220,6 @@ public class NameManager implements Listener { return null; } - /** - * Get the UUID from a player's (non-shortened) username - * - * @param username The player's username - * @return The UUID or null if the UUID can't be found or an error occurred - * @deprecated Use {@link NameManager#getAccount(String)} - */ - @Deprecated - public static UUID getUUID(String username) { - Validate.notEmpty(username, "username cannot be null or empty!"); - Player player = Bukkit.getPlayer(username); - if (player != null) { - return player.getUniqueId(); - } - Account account = getAccount(username); - if (account != null) { - return account.getUuid(); - } - OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(username); - if (offlinePlayer != null && offlinePlayer.hasPlayedBefore() && offlinePlayer.getUniqueId() != null) { - return offlinePlayer.getUniqueId(); - } - return null; - } - - /** - * Get the username from a player's UUID - * - * @param uuid The UUID of the player - * @return The username that is stored or null if none was found - * @deprecated Use {@link NameManager#getAccount(UUID)} - */ - @Deprecated - public static String getUsername(UUID uuid) { - Player player = Bukkit.getPlayer(uuid); - if (player != null) { - return player.getName(); - } - Account account = getAccount(uuid); - if (account != null) { - return account.getName(); - } - OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid); - if (offlinePlayer != null && offlinePlayer.hasPlayedBefore() && offlinePlayer.getName() != null) { - return offlinePlayer.getName(); - } - return null; - } - - /** - * Get the full username from another username that might be shortened - * - * @param shortName The name of the player to get the full username for - * @return The full username or null if none was found - * @throws IllegalArgumentException if the username is not a shortened name and longer than 15 chars - * @deprecated Use {@link NameManager#getAccountFromShortName(String)} - */ - @Deprecated - public static String getFullUsername(String shortName) { - AccountQueryEvent accountQueryEvent = new AccountQueryEvent(shortName); - Bukkit.getPluginManager().callEvent(accountQueryEvent); - Account account = accountQueryEvent.getAccount(); - if (account != null) { - return account.getName(); - } - return null; - } - - /** - * Get the short username from a full username - * - * @param fullName The name of the player to get the short username for - * @return The short username or null if none was found - * @deprecated Use {@link NameManager#getAccount(String)} - */ - @Deprecated - public static String getShortUsername(String fullName) { - Account account = getAccount(fullName); - return account != null ? account.getShortName() : null; - } - /** * Store the username of a player into the database and the username-uuid cache * @@ -369,14 +277,6 @@ public class NameManager implements Listener { return shortenedName; } - /** - * @deprecated Use {@link #canUseName(Player, Permission, String)} to provide specific information about how the player wants to use the name - */ - @Deprecated - public static boolean canUseName(Player player, String name) { - return canUseName(player, OTHER_NAME, name); - } - public static boolean canUseName(Player player, Permission base, String name) { if (ChestShopSign.isAdminShop(name)) { return Permission.has(player, Permission.ADMIN_SHOP);