From 7bb4bff4850ec48e3da1df7ee55867e6912ee396 Mon Sep 17 00:00:00 2001 From: William Date: Sun, 7 May 2023 22:50:37 +0100 Subject: [PATCH] Make case conversion operations use the English locale --- .../listener/BukkitEventListener.java | 3 ++- .../husksync/migrator/LegacyMigrator.java | 4 ++-- .../husksync/migrator/MpdbMigrator.java | 5 ++-- .../net/william278/husksync/HuskSync.java | 2 +- .../husksync/command/EnderChestCommand.java | 3 ++- .../husksync/command/HuskSyncCommand.java | 9 +++----- .../husksync/command/InventoryCommand.java | 3 ++- .../husksync/command/UserDataCommand.java | 23 ++++++++----------- .../william278/husksync/config/Settings.java | 17 ++++++-------- .../husksync/data/DataSaveCause.java | 6 +++-- .../husksync/data/UserDataSnapshot.java | 9 +++----- .../husksync/database/MySqlDatabase.java | 5 +++- .../husksync/hook/PlanDataExtension.java | 3 ++- .../husksync/migrator/Migrator.java | 2 +- .../husksync/player/OnlineUser.java | 20 +++++++--------- .../husksync/redis/RedisKeyType.java | 4 +++- .../husksync/redis/RedisMessageType.java | 5 ++-- .../william278/husksync/util/DataDumper.java | 3 ++- .../husksync/player/DummyPlayer.java | 2 +- 19 files changed, 63 insertions(+), 65 deletions(-) diff --git a/bukkit/src/main/java/net/william278/husksync/listener/BukkitEventListener.java b/bukkit/src/main/java/net/william278/husksync/listener/BukkitEventListener.java index 2968e708..350c8a6f 100644 --- a/bukkit/src/main/java/net/william278/husksync/listener/BukkitEventListener.java +++ b/bukkit/src/main/java/net/william278/husksync/listener/BukkitEventListener.java @@ -31,6 +31,7 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import java.util.List; +import java.util.Locale; import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; @@ -163,7 +164,7 @@ public class BukkitEventListener extends EventListener implements BukkitJoinEven @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onPermissionCommand(@NotNull PlayerCommandPreprocessEvent event) { String[] commandArgs = event.getMessage().substring(1).split(" "); - String commandLabel = commandArgs[0].toLowerCase(); + String commandLabel = commandArgs[0].toLowerCase(Locale.ENGLISH); if (blacklistedCommands.contains(commandLabel)) { event.setCancelled(cancelPlayerEvent(event.getPlayer().getUniqueId())); diff --git a/bukkit/src/main/java/net/william278/husksync/migrator/LegacyMigrator.java b/bukkit/src/main/java/net/william278/husksync/migrator/LegacyMigrator.java index c16438ef..0faf6fbb 100644 --- a/bukkit/src/main/java/net/william278/husksync/migrator/LegacyMigrator.java +++ b/bukkit/src/main/java/net/william278/husksync/migrator/LegacyMigrator.java @@ -66,7 +66,7 @@ public class LegacyMigrator extends Migrator { connectionPool.setJdbcUrl(jdbcUrl); connectionPool.setUsername(sourceUsername); connectionPool.setPassword(sourcePassword); - connectionPool.setPoolName((getIdentifier() + "_migrator_pool").toUpperCase()); + connectionPool.setPoolName((getIdentifier() + "_migrator_pool").toUpperCase(Locale.ENGLISH)); plugin.log(Level.INFO, "Downloading raw data from the legacy database (this might take a while)..."); final List dataToMigrate = new ArrayList<>(); @@ -141,7 +141,7 @@ public class LegacyMigrator extends Migrator { @Override public void handleConfigurationCommand(@NotNull String[] args) { if (args.length == 2) { - if (switch (args[0].toLowerCase()) { + if (switch (args[0].toLowerCase(Locale.ENGLISH)) { case "host" -> { this.sourceHost = args[1]; yield true; diff --git a/bukkit/src/main/java/net/william278/husksync/migrator/MpdbMigrator.java b/bukkit/src/main/java/net/william278/husksync/migrator/MpdbMigrator.java index c83e9db5..85231871 100644 --- a/bukkit/src/main/java/net/william278/husksync/migrator/MpdbMigrator.java +++ b/bukkit/src/main/java/net/william278/husksync/migrator/MpdbMigrator.java @@ -17,6 +17,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicInteger; @@ -73,7 +74,7 @@ public class MpdbMigrator extends Migrator { connectionPool.setJdbcUrl(jdbcUrl); connectionPool.setUsername(sourceUsername); connectionPool.setPassword(sourcePassword); - connectionPool.setPoolName((getIdentifier() + "_migrator_pool").toUpperCase()); + connectionPool.setPoolName((getIdentifier() + "_migrator_pool").toUpperCase(Locale.ENGLISH)); plugin.log(Level.INFO, "Downloading raw data from the MySQLPlayerDataBridge database (this might take a while)..."); final List dataToMigrate = new ArrayList<>(); @@ -137,7 +138,7 @@ public class MpdbMigrator extends Migrator { @Override public void handleConfigurationCommand(@NotNull String[] args) { if (args.length == 2) { - if (switch (args[0].toLowerCase()) { + if (switch (args[0].toLowerCase(Locale.ENGLISH)) { case "host" -> { this.sourceHost = args[1]; yield true; diff --git a/common/src/main/java/net/william278/husksync/HuskSync.java b/common/src/main/java/net/william278/husksync/HuskSync.java index f6952d71..c0b4b508 100644 --- a/common/src/main/java/net/william278/husksync/HuskSync.java +++ b/common/src/main/java/net/william278/husksync/HuskSync.java @@ -1,6 +1,7 @@ package net.william278.husksync; import net.william278.desertwell.UpdateChecker; +import net.william278.desertwell.Version; import net.william278.husksync.config.Locales; import net.william278.husksync.config.Settings; import net.william278.husksync.data.DataAdapter; @@ -9,7 +10,6 @@ import net.william278.husksync.event.EventCannon; import net.william278.husksync.migrator.Migrator; import net.william278.husksync.player.OnlineUser; import net.william278.husksync.redis.RedisManager; -import net.william278.desertwell.Version; import org.jetbrains.annotations.NotNull; import java.io.File; diff --git a/common/src/main/java/net/william278/husksync/command/EnderChestCommand.java b/common/src/main/java/net/william278/husksync/command/EnderChestCommand.java index 055f6f41..596fac0e 100644 --- a/common/src/main/java/net/william278/husksync/command/EnderChestCommand.java +++ b/common/src/main/java/net/william278/husksync/command/EnderChestCommand.java @@ -12,6 +12,7 @@ import org.jetbrains.annotations.NotNull; import java.text.SimpleDateFormat; import java.util.List; +import java.util.Locale; import java.util.Optional; import java.util.UUID; import java.util.concurrent.CompletableFuture; @@ -31,7 +32,7 @@ public class EnderChestCommand extends CommandBase implements TabCompletable { .ifPresent(player::sendMessage); return; } - plugin.getDatabase().getUserByName(args[0].toLowerCase()).thenAccept(optionalUser -> + plugin.getDatabase().getUserByName(args[0].toLowerCase(Locale.ENGLISH)).thenAccept(optionalUser -> optionalUser.ifPresentOrElse(user -> { if (args.length == 2) { // View user data by specified UUID diff --git a/common/src/main/java/net/william278/husksync/command/HuskSyncCommand.java b/common/src/main/java/net/william278/husksync/command/HuskSyncCommand.java index 20dd59dc..585c844d 100644 --- a/common/src/main/java/net/william278/husksync/command/HuskSyncCommand.java +++ b/common/src/main/java/net/william278/husksync/command/HuskSyncCommand.java @@ -7,10 +7,7 @@ import net.william278.husksync.migrator.Migrator; import net.william278.husksync.player.OnlineUser; import org.jetbrains.annotations.NotNull; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Optional; +import java.util.*; import java.util.logging.Level; import java.util.stream.Collectors; @@ -53,7 +50,7 @@ public class HuskSyncCommand extends CommandBase implements TabCompletable, Cons sendAboutMenu(player); return; } - switch (args[0].toLowerCase()) { + switch (args[0].toLowerCase(Locale.ENGLISH)) { case "update", "version" -> { if (!player.hasPermission(Permission.COMMAND_HUSKSYNC_UPDATE.node)) { plugin.getLocales().getLocale("error_no_permission").ifPresent(player::sendMessage); @@ -91,7 +88,7 @@ public class HuskSyncCommand extends CommandBase implements TabCompletable, Cons plugin.log(Level.INFO, "Console usage: \"husksync \""); return; } - switch (args[0].toLowerCase()) { + switch (args[0].toLowerCase(Locale.ENGLISH)) { case "update", "version" -> plugin.getLatestVersionIfOutdated().thenAccept(newestVersion -> newestVersion.ifPresentOrElse(newVersion -> plugin.log(Level.WARNING, "An update is available for HuskSync, v" + newVersion diff --git a/common/src/main/java/net/william278/husksync/command/InventoryCommand.java b/common/src/main/java/net/william278/husksync/command/InventoryCommand.java index ba993e08..c07b5650 100644 --- a/common/src/main/java/net/william278/husksync/command/InventoryCommand.java +++ b/common/src/main/java/net/william278/husksync/command/InventoryCommand.java @@ -12,6 +12,7 @@ import org.jetbrains.annotations.NotNull; import java.text.SimpleDateFormat; import java.util.List; +import java.util.Locale; import java.util.Optional; import java.util.UUID; import java.util.concurrent.CompletableFuture; @@ -31,7 +32,7 @@ public class InventoryCommand extends CommandBase implements TabCompletable { .ifPresent(player::sendMessage); return; } - plugin.getDatabase().getUserByName(args[0].toLowerCase()).thenAccept(optionalUser -> + plugin.getDatabase().getUserByName(args[0].toLowerCase(Locale.ENGLISH)).thenAccept(optionalUser -> optionalUser.ifPresentOrElse(user -> { if (args.length == 2) { // View user data by specified UUID diff --git a/common/src/main/java/net/william278/husksync/command/UserDataCommand.java b/common/src/main/java/net/william278/husksync/command/UserDataCommand.java index a1821689..f59608ef 100644 --- a/common/src/main/java/net/william278/husksync/command/UserDataCommand.java +++ b/common/src/main/java/net/william278/husksync/command/UserDataCommand.java @@ -3,16 +3,13 @@ package net.william278.husksync.command; import net.william278.husksync.HuskSync; import net.william278.husksync.data.DataSaveCause; import net.william278.husksync.data.UserData; -import net.william278.husksync.util.DataSnapshotList; import net.william278.husksync.player.OnlineUser; import net.william278.husksync.util.DataDumper; +import net.william278.husksync.util.DataSnapshotList; import org.jetbrains.annotations.NotNull; import java.io.IOException; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.UUID; +import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.logging.Level; import java.util.stream.Collectors; @@ -34,7 +31,7 @@ public class UserDataCommand extends CommandBase implements TabCompletable { return; } - switch (args[0].toLowerCase()) { + switch (args[0].toLowerCase(Locale.ENGLISH)) { case "view" -> { if (args.length < 2) { plugin.getLocales().getLocale("error_invalid_syntax", @@ -47,7 +44,7 @@ public class UserDataCommand extends CommandBase implements TabCompletable { try { final UUID versionUuid = UUID.fromString(args[2]); CompletableFuture.runAsync(() -> plugin.getDatabase() - .getUserByName(username.toLowerCase()) + .getUserByName(username.toLowerCase(Locale.ENGLISH)) .thenAccept(optionalUser -> optionalUser .ifPresentOrElse(user -> plugin.getDatabase().getUserData(user, versionUuid) .thenAccept(data -> data.ifPresentOrElse( @@ -63,7 +60,7 @@ public class UserDataCommand extends CommandBase implements TabCompletable { } } else { CompletableFuture.runAsync(() -> plugin.getDatabase() - .getUserByName(username.toLowerCase()) + .getUserByName(username.toLowerCase(Locale.ENGLISH)) .thenAccept(optionalUser -> optionalUser .ifPresentOrElse(user -> plugin.getDatabase().getCurrentUserData(user) .thenAccept(latestData -> latestData.ifPresentOrElse( @@ -87,7 +84,7 @@ public class UserDataCommand extends CommandBase implements TabCompletable { } final String username = args[1]; CompletableFuture.runAsync(() -> plugin.getDatabase() - .getUserByName(username.toLowerCase()) + .getUserByName(username.toLowerCase(Locale.ENGLISH)) .thenAccept(optionalUser -> optionalUser.ifPresentOrElse( user -> plugin.getDatabase().getUserData(user).thenAccept(dataList -> { // Check if there is data to display @@ -133,7 +130,7 @@ public class UserDataCommand extends CommandBase implements TabCompletable { try { final UUID versionUuid = UUID.fromString(args[2]); CompletableFuture.runAsync(() -> plugin.getDatabase() - .getUserByName(username.toLowerCase()) + .getUserByName(username.toLowerCase(Locale.ENGLISH)) .thenAccept(optionalUser -> optionalUser.ifPresentOrElse( user -> plugin.getDatabase().deleteUserData(user, versionUuid).thenAccept(deleted -> { if (deleted) { @@ -172,7 +169,7 @@ public class UserDataCommand extends CommandBase implements TabCompletable { try { final UUID versionUuid = UUID.fromString(args[2]); CompletableFuture.runAsync(() -> plugin.getDatabase() - .getUserByName(username.toLowerCase()) + .getUserByName(username.toLowerCase(Locale.ENGLISH)) .thenAccept(optionalUser -> optionalUser.ifPresentOrElse( user -> plugin.getDatabase().getUserData(user, versionUuid).thenAccept(data -> { if (data.isEmpty()) { @@ -219,7 +216,7 @@ public class UserDataCommand extends CommandBase implements TabCompletable { try { final UUID versionUuid = UUID.fromString(args[2]); CompletableFuture.runAsync(() -> plugin.getDatabase() - .getUserByName(username.toLowerCase()) + .getUserByName(username.toLowerCase(Locale.ENGLISH)) .thenAccept(optionalUser -> optionalUser.ifPresentOrElse( user -> plugin.getDatabase().getUserData(user, versionUuid).thenAccept( optionalUserData -> optionalUserData.ifPresentOrElse(userData -> { @@ -267,7 +264,7 @@ public class UserDataCommand extends CommandBase implements TabCompletable { try { final UUID versionUuid = UUID.fromString(args[2]); CompletableFuture.runAsync(() -> plugin.getDatabase() - .getUserByName(username.toLowerCase()) + .getUserByName(username.toLowerCase(Locale.ENGLISH)) .thenAccept(optionalUser -> optionalUser.ifPresentOrElse( user -> plugin.getDatabase().getUserData(user, versionUuid).thenAccept( optionalUserData -> optionalUserData.ifPresentOrElse(userData -> { diff --git a/common/src/main/java/net/william278/husksync/config/Settings.java b/common/src/main/java/net/william278/husksync/config/Settings.java index c6874260..f43be676 100644 --- a/common/src/main/java/net/william278/husksync/config/Settings.java +++ b/common/src/main/java/net/william278/husksync/config/Settings.java @@ -5,10 +5,7 @@ import net.william278.annotaml.YamlFile; import net.william278.annotaml.YamlKey; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.util.*; /** * Plugin settings, read from config.yml @@ -182,7 +179,7 @@ public class Settings { @NotNull public String getTableName(@NotNull TableName tableName) { - return tableNames.getOrDefault(tableName.name().toLowerCase(), tableName.defaultName); + return tableNames.getOrDefault(tableName.name().toLowerCase(Locale.ENGLISH), tableName.defaultName); } public int getMySqlConnectionPoolSize() { @@ -262,7 +259,7 @@ public class Settings { } public boolean getSynchronizationFeature(@NotNull SynchronizationFeature feature) { - return getSynchronizationFeatures().getOrDefault(feature.name().toLowerCase(), feature.enabledByDefault); + return getSynchronizationFeatures().getOrDefault(feature.name().toLowerCase(Locale.ENGLISH), feature.enabledByDefault); } @NotNull @@ -273,7 +270,7 @@ public class Settings { @NotNull public EventPriority getEventPriority(@NotNull Settings.EventType eventType) { try { - return EventPriority.valueOf(synchronizationEventPriorities.get(eventType.name().toLowerCase())); + return EventPriority.valueOf(synchronizationEventPriorities.get(eventType.name().toLowerCase(Locale.ENGLISH))); } catch (IllegalArgumentException e) { e.printStackTrace(); return EventPriority.NORMAL; @@ -295,7 +292,7 @@ public class Settings { @NotNull private Map.Entry toEntry() { - return Map.entry(name().toLowerCase(), defaultName); + return Map.entry(name().toLowerCase(Locale.ENGLISH), defaultName); } @SuppressWarnings("unchecked") @@ -355,7 +352,7 @@ public class Settings { @NotNull private Map.Entry toEntry() { - return Map.entry(name().toLowerCase(), enabledByDefault); + return Map.entry(name().toLowerCase(Locale.ENGLISH), enabledByDefault); } @SuppressWarnings("unchecked") @@ -383,7 +380,7 @@ public class Settings { @NotNull private Map.Entry toEntry() { - return Map.entry(name().toLowerCase(), defaultPriority.name()); + return Map.entry(name().toLowerCase(Locale.ENGLISH), defaultPriority.name()); } diff --git a/common/src/main/java/net/william278/husksync/data/DataSaveCause.java b/common/src/main/java/net/william278/husksync/data/DataSaveCause.java index c99d7f71..66442d87 100644 --- a/common/src/main/java/net/william278/husksync/data/DataSaveCause.java +++ b/common/src/main/java/net/william278/husksync/data/DataSaveCause.java @@ -1,11 +1,13 @@ package net.william278.husksync.data; +import net.william278.husksync.api.BaseHuskSyncAPI; import net.william278.husksync.config.Locales; import net.william278.husksync.player.OnlineUser; -import net.william278.husksync.api.BaseHuskSyncAPI; import net.william278.husksync.player.User; import org.jetbrains.annotations.NotNull; +import java.util.Locale; + /** * Identifies the cause of a player data save. * @@ -103,7 +105,7 @@ public enum DataSaveCause { @NotNull public String getDisplayName() { - return Locales.truncate(name().toLowerCase(), 10); + return Locales.truncate(name().toLowerCase(Locale.ENGLISH), 10); } } diff --git a/common/src/main/java/net/william278/husksync/data/UserDataSnapshot.java b/common/src/main/java/net/william278/husksync/data/UserDataSnapshot.java index ce1982cc..16388abb 100644 --- a/common/src/main/java/net/william278/husksync/data/UserDataSnapshot.java +++ b/common/src/main/java/net/william278/husksync/data/UserDataSnapshot.java @@ -7,10 +7,7 @@ import net.william278.husksync.player.User; import org.jetbrains.annotations.NotNull; import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; -import java.util.StringJoiner; -import java.util.UUID; +import java.util.*; /** * Represents a uniquely versioned and timestamped snapshot of a user's data, including why it was saved. @@ -57,7 +54,7 @@ public record UserDataSnapshot(@NotNull UUID versionUUID, @NotNull Date versionT if (pinned()) { locales.getLocale("data_manager_pinned").ifPresent(user::sendMessage); } - locales.getLocale("data_manager_cause", cause().name().toLowerCase().replaceAll("_", " ")) + locales.getLocale("data_manager_cause", cause().name().toLowerCase(Locale.ENGLISH).replaceAll("_", " ")) .ifPresent(user::sendMessage); // User status data, if present in the snapshot @@ -67,7 +64,7 @@ public record UserDataSnapshot(@NotNull UUID versionUUID, @NotNull Date versionT Integer.toString((int) statusData.maxHealth), Integer.toString(statusData.hunger), Integer.toString(statusData.expLevel), - statusData.gameMode.toLowerCase())) + statusData.gameMode.toLowerCase(Locale.ENGLISH))) .ifPresent(user::sendMessage); // Advancement and statistic data, if both are present in the snapshot diff --git a/common/src/main/java/net/william278/husksync/database/MySqlDatabase.java b/common/src/main/java/net/william278/husksync/database/MySqlDatabase.java index 04d2e8c7..d555c696 100644 --- a/common/src/main/java/net/william278/husksync/database/MySqlDatabase.java +++ b/common/src/main/java/net/william278/husksync/database/MySqlDatabase.java @@ -3,7 +3,10 @@ package net.william278.husksync.database; import com.zaxxer.hikari.HikariDataSource; import net.william278.husksync.HuskSync; import net.william278.husksync.config.Settings; -import net.william278.husksync.data.*; +import net.william278.husksync.data.DataAdaptionException; +import net.william278.husksync.data.DataSaveCause; +import net.william278.husksync.data.UserData; +import net.william278.husksync.data.UserDataSnapshot; import net.william278.husksync.event.DataSaveEvent; import net.william278.husksync.player.User; import org.jetbrains.annotations.NotNull; diff --git a/common/src/main/java/net/william278/husksync/hook/PlanDataExtension.java b/common/src/main/java/net/william278/husksync/hook/PlanDataExtension.java index 48129ae3..53c03d65 100644 --- a/common/src/main/java/net/william278/husksync/hook/PlanDataExtension.java +++ b/common/src/main/java/net/william278/husksync/hook/PlanDataExtension.java @@ -16,6 +16,7 @@ import net.william278.husksync.player.User; import org.jetbrains.annotations.NotNull; import java.util.Date; +import java.util.Locale; import java.util.Optional; import java.util.UUID; import java.util.concurrent.CompletableFuture; @@ -212,7 +213,7 @@ public class PlanDataExtension implements DataExtension { plugin.getDatabase().getUserData(user).join().forEach(versionedUserData -> dataSnapshotsTable.addRow( versionedUserData.versionTimestamp().getTime(), versionedUserData.versionUUID().toString().split("-")[0], - versionedUserData.cause().name().toLowerCase().replaceAll("_", " "), + versionedUserData.cause().name().toLowerCase(Locale.ENGLISH).replaceAll("_", " "), versionedUserData.pinned() ? PINNED_HTML_STRING + "Pinned" : "Unpinned" ))); return dataSnapshotsTable.build(); diff --git a/common/src/main/java/net/william278/husksync/migrator/Migrator.java b/common/src/main/java/net/william278/husksync/migrator/Migrator.java index 97335a88..ebe19328 100644 --- a/common/src/main/java/net/william278/husksync/migrator/Migrator.java +++ b/common/src/main/java/net/william278/husksync/migrator/Migrator.java @@ -1,8 +1,8 @@ package net.william278.husksync.migrator; import net.william278.husksync.HuskSync; -import org.jetbrains.annotations.NotNull; import net.william278.husksync.data.UserData; +import org.jetbrains.annotations.NotNull; import java.util.concurrent.CompletableFuture; diff --git a/common/src/main/java/net/william278/husksync/player/OnlineUser.java b/common/src/main/java/net/william278/husksync/player/OnlineUser.java index 90154032..bd48d190 100644 --- a/common/src/main/java/net/william278/husksync/player/OnlineUser.java +++ b/common/src/main/java/net/william278/husksync/player/OnlineUser.java @@ -8,10 +8,7 @@ import net.william278.husksync.data.*; import net.william278.husksync.event.PreSyncEvent; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.UUID; +import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.logging.Level; @@ -43,12 +40,12 @@ public abstract class OnlineUser extends User { public final CompletableFuture setStatus(@NotNull StatusData statusData, @NotNull List statusDataFlags) { final Settings settings = new Settings(); - settings.getSynchronizationFeatures().put(Settings.SynchronizationFeature.HEALTH.name().toLowerCase(), statusDataFlags.contains(StatusDataFlag.SET_HEALTH)); - settings.getSynchronizationFeatures().put(Settings.SynchronizationFeature.MAX_HEALTH.name().toLowerCase(), statusDataFlags.contains(StatusDataFlag.SET_MAX_HEALTH)); - settings.getSynchronizationFeatures().put(Settings.SynchronizationFeature.HUNGER.name().toLowerCase(), statusDataFlags.contains(StatusDataFlag.SET_HUNGER)); - settings.getSynchronizationFeatures().put(Settings.SynchronizationFeature.EXPERIENCE.name().toLowerCase(), statusDataFlags.contains(StatusDataFlag.SET_EXPERIENCE)); - settings.getSynchronizationFeatures().put(Settings.SynchronizationFeature.INVENTORIES.name().toLowerCase(), statusDataFlags.contains(StatusDataFlag.SET_SELECTED_ITEM_SLOT)); - settings.getSynchronizationFeatures().put(Settings.SynchronizationFeature.LOCATION.name().toLowerCase(), statusDataFlags.contains(StatusDataFlag.SET_GAME_MODE) || statusDataFlags.contains(StatusDataFlag.SET_FLYING)); + settings.getSynchronizationFeatures().put(Settings.SynchronizationFeature.HEALTH.name().toLowerCase(Locale.ENGLISH), statusDataFlags.contains(StatusDataFlag.SET_HEALTH)); + settings.getSynchronizationFeatures().put(Settings.SynchronizationFeature.MAX_HEALTH.name().toLowerCase(Locale.ENGLISH), statusDataFlags.contains(StatusDataFlag.SET_MAX_HEALTH)); + settings.getSynchronizationFeatures().put(Settings.SynchronizationFeature.HUNGER.name().toLowerCase(Locale.ENGLISH), statusDataFlags.contains(StatusDataFlag.SET_HUNGER)); + settings.getSynchronizationFeatures().put(Settings.SynchronizationFeature.EXPERIENCE.name().toLowerCase(Locale.ENGLISH), statusDataFlags.contains(StatusDataFlag.SET_EXPERIENCE)); + settings.getSynchronizationFeatures().put(Settings.SynchronizationFeature.INVENTORIES.name().toLowerCase(Locale.ENGLISH), statusDataFlags.contains(StatusDataFlag.SET_SELECTED_ITEM_SLOT)); + settings.getSynchronizationFeatures().put(Settings.SynchronizationFeature.LOCATION.name().toLowerCase(Locale.ENGLISH), statusDataFlags.contains(StatusDataFlag.SET_GAME_MODE) || statusDataFlags.contains(StatusDataFlag.SET_FLYING)); return setStatus(statusData, settings); } @@ -59,8 +56,7 @@ public abstract class OnlineUser extends User { * @param settings settings, containing information about which features should be synced * @return a future returning void when complete */ - public abstract CompletableFuture setStatus(@NotNull StatusData statusData, - @NotNull Settings settings); + public abstract CompletableFuture setStatus(@NotNull StatusData statusData, @NotNull Settings settings); /** * Get the player's inventory {@link ItemData} contents diff --git a/common/src/main/java/net/william278/husksync/redis/RedisKeyType.java b/common/src/main/java/net/william278/husksync/redis/RedisKeyType.java index 1b38412a..eae2e2ac 100644 --- a/common/src/main/java/net/william278/husksync/redis/RedisKeyType.java +++ b/common/src/main/java/net/william278/husksync/redis/RedisKeyType.java @@ -2,6 +2,8 @@ package net.william278.husksync.redis; import org.jetbrains.annotations.NotNull; +import java.util.Locale; + public enum RedisKeyType { CACHE(60 * 60 * 24), DATA_UPDATE(10), @@ -15,6 +17,6 @@ public enum RedisKeyType { @NotNull public String getKeyPrefix() { - return RedisManager.KEY_NAMESPACE.toLowerCase() + ":" + RedisManager.clusterId.toLowerCase() + ":" + name().toLowerCase(); + return RedisManager.KEY_NAMESPACE.toLowerCase(Locale.ENGLISH) + ":" + RedisManager.clusterId.toLowerCase(Locale.ENGLISH) + ":" + name().toLowerCase(Locale.ENGLISH); } } diff --git a/common/src/main/java/net/william278/husksync/redis/RedisMessageType.java b/common/src/main/java/net/william278/husksync/redis/RedisMessageType.java index b35884be..f12d3dcd 100644 --- a/common/src/main/java/net/william278/husksync/redis/RedisMessageType.java +++ b/common/src/main/java/net/william278/husksync/redis/RedisMessageType.java @@ -3,6 +3,7 @@ package net.william278.husksync.redis; import org.jetbrains.annotations.NotNull; import java.util.Arrays; +import java.util.Locale; import java.util.Optional; public enum RedisMessageType { @@ -11,8 +12,8 @@ public enum RedisMessageType { @NotNull public String getMessageChannel() { - return RedisManager.KEY_NAMESPACE.toLowerCase() + ":" + RedisManager.clusterId.toLowerCase() - + ":" + name().toLowerCase(); + return RedisManager.KEY_NAMESPACE.toLowerCase(Locale.ENGLISH) + ":" + RedisManager.clusterId.toLowerCase(Locale.ENGLISH) + + ":" + name().toLowerCase(Locale.ENGLISH); } public static Optional getTypeFromChannel(@NotNull String messageChannel) { diff --git a/common/src/main/java/net/william278/husksync/util/DataDumper.java b/common/src/main/java/net/william278/husksync/util/DataDumper.java index 2a3aa8a6..a51a136e 100644 --- a/common/src/main/java/net/william278/husksync/util/DataDumper.java +++ b/common/src/main/java/net/william278/husksync/util/DataDumper.java @@ -13,6 +13,7 @@ import java.net.URL; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; +import java.util.Locale; import java.util.StringJoiner; import java.util.logging.Level; @@ -164,7 +165,7 @@ public class DataDumper { return new StringJoiner("_") .add(user.username) .add(new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(dataSnapshot.versionTimestamp())) - .add(dataSnapshot.cause().name().toLowerCase()) + .add(dataSnapshot.cause().name().toLowerCase(Locale.ENGLISH)) .add(dataSnapshot.versionUUID().toString().split("-")[0]) + ".json"; } diff --git a/common/src/test/java/net/william278/husksync/player/DummyPlayer.java b/common/src/test/java/net/william278/husksync/player/DummyPlayer.java index 895dbb0c..c3b34d01 100644 --- a/common/src/test/java/net/william278/husksync/player/DummyPlayer.java +++ b/common/src/test/java/net/william278/husksync/player/DummyPlayer.java @@ -1,9 +1,9 @@ package net.william278.husksync.player; import de.themoep.minedown.adventure.MineDown; +import net.william278.desertwell.Version; import net.william278.husksync.config.Settings; import net.william278.husksync.data.*; -import net.william278.desertwell.Version; import org.jetbrains.annotations.NotNull; import java.util.*;