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)
This commit is contained in:
Phoenix616 2020-11-16 14:09:07 +01:00
parent cbb605df81
commit 00fa83c56a
No known key found for this signature in database
GPG Key ID: 40E2321E71738EB0
2 changed files with 13 additions and 4 deletions

View File

@ -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;

View File

@ -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);