From 00fa83c56ad9f3f3b06391a5be9c1a0c7eb01ef0 Mon Sep 17 00:00:00 2001 From: Phoenix616 Date: Mon, 16 Nov 2020 14:09:07 +0100 Subject: [PATCH] Improve UUID version handling (Fixes #382, #337) This adds a new config option ENSURE_CORRECT_PLAYERID which lets one disable the check whether or not a player's UUID version matches the server's online/offline mode UUID version. Due to potential issues with offline players which might occur when this isn't checked disabling this can't really be supported and any issues should first be tested if they still occur with this option enabled. This also forces the UUID to version 4 if the server runs in online mode as it should not be necessary in any normal setup to detect the UUID version dynamically in that case. (Dynamic detection is only necessary for offline mode which might potentially run behind a proxy) --- .../ChestShop/Configuration/Properties.java | 3 +++ .../com/Acrobot/ChestShop/UUIDs/NameManager.java | 14 ++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java b/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java index 61e7210..03424ce 100644 --- a/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java +++ b/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java @@ -191,6 +191,9 @@ public class Properties { @ConfigurationComment("How many decimal places are allowed at a maximum for prices?") public static int PRICE_PRECISION = 2; + @ConfigurationComment("This makes sure that the UUIDs of player shop accounts match the server's online-mode setting. Disabling this might lead to issues with offline players and is therefore unsupported!") + public static boolean ENSURE_CORRECT_PLAYERID = true; + @PrecededBySpace @ConfigurationComment("Should we block shops that sell things for more than they buy? (This prevents newbies from creating shops that would be exploited)") public static boolean BLOCK_SHOPS_WITH_SELL_PRICE_HIGHER_THAN_BUY_PRICE = true; diff --git a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java index e03c38a..fcc321c 100644 --- a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java +++ b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java @@ -79,7 +79,9 @@ 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(uuidVersion < 0 || id.version() == uuidVersion, "Invalid OfflinePlayer! " + id + " is not of server version " + uuidVersion); + 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) { @@ -191,7 +193,7 @@ public class NameManager implements Listener { // no account with that shortname was found, try to get an offline player with that name OfflinePlayer offlinePlayer = ChestShop.getBukkitServer().getOfflinePlayer(shortName); if (offlinePlayer != null && offlinePlayer.getName() != null && offlinePlayer.getUniqueId() != null - && offlinePlayer.getUniqueId().version() == uuidVersion) { + && (!Properties.ENSURE_CORRECT_PLAYERID || offlinePlayer.getUniqueId().version() == uuidVersion)) { account = storeUsername(new PlayerDTO(offlinePlayer.getUniqueId(), offlinePlayer.getName())); } else { invalidPlayers.put(shortName.toLowerCase(Locale.ROOT), true); @@ -415,8 +417,12 @@ public class NameManager implements Listener { } public static void load() { - if (getUuidVersion() < 0 && !Bukkit.getOnlinePlayers().isEmpty()) { - setUuidVersion(Bukkit.getOnlinePlayers().iterator().next().getUniqueId().version()); + if (getUuidVersion() < 0) { + if (Bukkit.getOnlineMode()) { + setUuidVersion(4); + } else if (!Bukkit.getOnlinePlayers().isEmpty()) { + setUuidVersion(Bukkit.getOnlinePlayers().iterator().next().getUniqueId().version()); + } } try { accounts = DaoCreator.getDaoAndCreateTable(Account.class);