diff --git a/api/src/main/java/org/screamingsandals/bedwars/api/game/LocalGame.java b/api/src/main/java/org/screamingsandals/bedwars/api/game/LocalGame.java index 7afd7b040..aca1737b2 100644 --- a/api/src/main/java/org/screamingsandals/bedwars/api/game/LocalGame.java +++ b/api/src/main/java/org/screamingsandals/bedwars/api/game/LocalGame.java @@ -405,13 +405,6 @@ default boolean isActivated() { */ boolean isInEditMode(); - /** - * This methods allows you to save the arena to config (useful when using custom config options) - * - * @since 0.3.0 - */ - void saveToConfig(); - /** * Gets file with this game * diff --git a/api/src/main/java/org/screamingsandals/bedwars/api/game/LocalGameLoader.java b/api/src/main/java/org/screamingsandals/bedwars/api/game/LocalGameLoader.java index f9e09ff44..2d3c53e6d 100644 --- a/api/src/main/java/org/screamingsandals/bedwars/api/game/LocalGameLoader.java +++ b/api/src/main/java/org/screamingsandals/bedwars/api/game/LocalGameLoader.java @@ -23,32 +23,37 @@ import org.jetbrains.annotations.Nullable; import java.io.File; +import java.util.concurrent.CompletableFuture; /** * LocalGameLoader API to load or save a game to or from a file. + * * @author ScreamingSandals * @since 0.3.0 */ public interface LocalGameLoader { /** + * NOTE: The plugin may postpone the game loading to the next tick if it cannot locate the world on the first try. + * This operation runs synchronized with the game global thread, so do not try to invoke {@link CompletableFuture#get()} from that thread! * * @param file a file containing the game data - * @return a game instance populated from the given file, null otherwise + * @return a completable future returning game instance populated from the given file or null */ - @Nullable - default LocalGame loadGame(File file) { + default @NotNull CompletableFuture loadGame(@NotNull File file) { return loadGame(file, true); } /** + * NOTE: The plugin may postpone the game loading to the next tick if it cannot locate the world on the first try. + * This operation runs synchronized with the game global thread, so do not try to invoke {@link CompletableFuture#get()} from that thread! + * If the parameter {@code firstAttempt} is {@code false}, the plugin will not try to postpone the loading and will instead return already completed future. * * @param file a file containing the game data * @param firstAttempt provide true to attempt a sequential load after a failed one as a fix for world loading. - * @return a loaded game instance from the provided file, null otherwise + * @return a completable future returning loaded game instance from the provided file or null */ - @Nullable - LocalGame loadGame(File file, boolean firstAttempt); + @NotNull CompletableFuture loadGame(@NotNull File file, boolean firstAttempt); /** * diff --git a/plugin/bukkit/src/main/java/org/screamingsandals/bedwars/bukkit/BukkitPlatformService.java b/plugin/bukkit/src/main/java/org/screamingsandals/bedwars/bukkit/BukkitPlatformService.java index bf3e43906..34016d3b4 100644 --- a/plugin/bukkit/src/main/java/org/screamingsandals/bedwars/bukkit/BukkitPlatformService.java +++ b/plugin/bukkit/src/main/java/org/screamingsandals/bedwars/bukkit/BukkitPlatformService.java @@ -174,7 +174,7 @@ public void accept(@NotNull TaskBase taskBase) { // TODO: slib? @Override public void spawnEffect(@NotNull org.screamingsandals.lib.world.Location location, @NotNull String value) { - var particle = Effect.valueOf(value.toUpperCase()); + var particle = Effect.valueOf(value.toUpperCase(Locale.ROOT)); var bukkitLoc = location.as(Location.class); bukkitLoc.getWorld().playEffect(bukkitLoc, particle, 1); } diff --git a/plugin/common/src/main/java/org/screamingsandals/bedwars/BedWarsPlugin.java b/plugin/common/src/main/java/org/screamingsandals/bedwars/BedWarsPlugin.java index ab507795c..38eee52e3 100644 --- a/plugin/common/src/main/java/org/screamingsandals/bedwars/BedWarsPlugin.java +++ b/plugin/common/src/main/java/org/screamingsandals/bedwars/BedWarsPlugin.java @@ -75,6 +75,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Objects; import java.util.stream.Collectors; @@ -272,7 +273,7 @@ public void load() { @OnEnable public void enable() { - var snapshot = VersionInfo.VERSION.toLowerCase().contains("pre") || VersionInfo.VERSION.toLowerCase().contains("snapshot"); + var snapshot = VersionInfo.VERSION.toLowerCase(Locale.ROOT).contains("pre") || VersionInfo.VERSION.toLowerCase(Locale.ROOT).contains("snapshot"); Debug.init(pluginDescription.name()); Debug.setDebug(MainConfig.getInstance().node("debug").getBoolean()); diff --git a/plugin/common/src/main/java/org/screamingsandals/bedwars/boss/BossBarImpl.java b/plugin/common/src/main/java/org/screamingsandals/bedwars/boss/BossBarImpl.java index ec3ba4e01..9b0c32d28 100644 --- a/plugin/common/src/main/java/org/screamingsandals/bedwars/boss/BossBarImpl.java +++ b/plugin/common/src/main/java/org/screamingsandals/bedwars/boss/BossBarImpl.java @@ -33,6 +33,7 @@ import java.util.LinkedList; import java.util.List; +import java.util.Locale; @Getter public class BossBarImpl implements org.screamingsandals.bedwars.api.boss.BossBar { @@ -123,7 +124,7 @@ public void setColor(@NotNull Object color) { if (color instanceof BossBarColor) { boss.color((BossBarColor) color); } else { - boss.color(BossBarColor.valueOf(color.toString().toUpperCase())); + boss.color(BossBarColor.valueOf(color.toString().toUpperCase(Locale.ROOT))); } } @@ -137,7 +138,7 @@ public void setStyle(@NotNull Object division) { if (division instanceof BossBarDivision) { boss.division((BossBarDivision) division); } else { - var ov = division.toString().toUpperCase(); + var ov = division.toString().toUpperCase(Locale.ROOT); if (ov.equals("SOLID") || ov.equals("PROGRESS")) { ov = "NO_DIVISION"; } else if (ov.startsWith("SEGMENTED_")) { diff --git a/plugin/common/src/main/java/org/screamingsandals/bedwars/commands/ConfigCommandFactory.java b/plugin/common/src/main/java/org/screamingsandals/bedwars/commands/ConfigCommandFactory.java index 386d7329f..62c24160f 100644 --- a/plugin/common/src/main/java/org/screamingsandals/bedwars/commands/ConfigCommandFactory.java +++ b/plugin/common/src/main/java/org/screamingsandals/bedwars/commands/ConfigCommandFactory.java @@ -48,6 +48,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Locale; import java.util.function.BiConsumer; import java.util.function.Function; import java.util.stream.Collectors; @@ -74,7 +75,7 @@ public void construct() { .withSuggestionsProvider((c, s) -> makeSuggestion(c, true, ConfigurationContainerImpl::getJoinedRegisteredKeysForConfigCommand)) ) .handler(commandContext -> handleCommand(commandContext, true, (sender, container, configuredComponentName) -> { // Allow this without edit mode - var keyString = commandContext.get("key").toLowerCase(); + var keyString = commandContext.get("key").toLowerCase(Locale.ROOT); var keys = List.of(keyString.split("\\.")); var keyOpt = container.getRegisteredKeys() @@ -200,7 +201,7 @@ public void construct() { .withSuggestionsProvider((c, s) -> makeSuggestion(c, false, ConfigurationContainerImpl::getJoinedRegisteredKeysForConfigCommand)) ) .handler(commandContext -> handleCommand(commandContext, false, (sender, container) -> { - var keyString = commandContext.get("key").toLowerCase(); + var keyString = commandContext.get("key").toLowerCase(Locale.ROOT); var keys = List.of(keyString.split("\\.")); var keyOpt = container.getRegisteredKeys() @@ -244,7 +245,7 @@ public void construct() { argumentName -> StringArgument.newBuilder(argumentName) .greedy() .withSuggestionsProvider((commandContext, sender) -> makeSuggestion(commandContext, false, container -> { - var keys = List.of(commandContext.get("key").toLowerCase().split("\\.")); + var keys = List.of(commandContext.get("key").toLowerCase(Locale.ROOT).split("\\.")); var key = container.getRegisteredKeys() .stream() @@ -348,7 +349,7 @@ public void construct() { ) .argument(StringArgument.newBuilder("value") .withSuggestionsProvider((commandContext, sender) -> makeSuggestion(commandContext, false, container -> { - var keys = List.of(commandContext.get("key").toLowerCase().split("\\.")); + var keys = List.of(commandContext.get("key").toLowerCase(Locale.ROOT).split("\\.")); var key = container.getRegisteredKeys() .stream() @@ -367,7 +368,7 @@ public void construct() { ) .handler(commandContext -> handleCommand(commandContext, false, (sender, container) -> { String keyString = commandContext.get("key"); - var keys = List.of(keyString.toLowerCase().split("\\.")); + var keys = List.of(keyString.toLowerCase(Locale.ROOT).split("\\.")); String value = commandContext.get("value"); var keyOpt = container.getRegisteredKeys() @@ -386,7 +387,7 @@ public void construct() { } catch (Throwable ignored) { try { //noinspection unchecked - enumValue = Enum.valueOf((Class) key.getType(), value.toUpperCase()); + enumValue = Enum.valueOf((Class) key.getType(), value.toUpperCase(Locale.ROOT)); } catch (Throwable ignored2) { Message.of(LangKeys.ADMIN_ARENA_EDIT_ERRORS_INVALID_CONSTANT_ENUM_VALUE) .placeholder("value", value) @@ -434,7 +435,7 @@ private void generateCommands( ) .argument(argumentBuilder.apply("value")) .handler(commandContext -> handleCommand(commandContext, false, (sender, container) -> { - var keyString = commandContext.get("key").toLowerCase(); + var keyString = commandContext.get("key").toLowerCase(Locale.ROOT); var keys = List.of(keyString.split("\\.")); var value = commandContext.get("value"); @@ -471,7 +472,7 @@ private void generateCommands( .argument(argumentListBuilder.apply("value")) .handler(commandContext -> handleCommand(commandContext, false, (sender, container) -> { String keyString = commandContext.get("key"); - var keys = List.of(keyString.toLowerCase().split("\\.")); + var keys = List.of(keyString.toLowerCase(Locale.ROOT).split("\\.")); var value = commandContext.get("value"); var keyOpt = container.getRegisteredListKeys() @@ -512,7 +513,7 @@ private void generateCommands( .argument(argumentListBuilder.apply("value")) .handler(commandContext -> handleCommand(commandContext, false, (sender, container) -> { String keyString = commandContext.get("key"); - var keys = List.of(keyString.toLowerCase().split("\\.")); + var keys = List.of(keyString.toLowerCase(Locale.ROOT).split("\\.")); int position = commandContext.get("position"); var value = commandContext.get("value"); @@ -573,7 +574,7 @@ private void generateCommands( .argument(IntegerArgument.of("position")) .handler(commandContext -> handleCommand(commandContext, false, (sender, container) -> { String keyString = commandContext.get("key"); - var keys = List.of(keyString.toLowerCase().split("\\.")); + var keys = List.of(keyString.toLowerCase(Locale.ROOT).split("\\.")); int position = commandContext.get("position"); @SuppressWarnings("unchecked") @@ -619,7 +620,7 @@ private void generateCommands( .literal("clear", "c") .handler(commandContext -> handleCommand(commandContext, false, (sender, container) -> { String keyString = commandContext.get("key"); - var keys = List.of(keyString.toLowerCase().split("\\.")); + var keys = List.of(keyString.toLowerCase(Locale.ROOT).split("\\.")); var keyOpt = container.getRegisteredListKeys() .stream() diff --git a/plugin/common/src/main/java/org/screamingsandals/bedwars/commands/admin/SaveCommand.java b/plugin/common/src/main/java/org/screamingsandals/bedwars/commands/admin/SaveCommand.java index 375cd90e7..b487de495 100644 --- a/plugin/common/src/main/java/org/screamingsandals/bedwars/commands/admin/SaveCommand.java +++ b/plugin/common/src/main/java/org/screamingsandals/bedwars/commands/admin/SaveCommand.java @@ -25,6 +25,7 @@ import org.jetbrains.annotations.NotNull; import org.screamingsandals.bedwars.commands.AdminCommand; import org.screamingsandals.bedwars.game.GameManagerImpl; +import org.screamingsandals.bedwars.game.LocalGameLoaderImpl; import org.screamingsandals.bedwars.lang.LangKeys; import org.screamingsandals.lib.lang.Message; import org.screamingsandals.lib.sender.CommandSender; @@ -94,7 +95,7 @@ private void save(@NotNull CommandContext commandContext) { } if (warnings.isEmpty()) { - game.saveToConfig(); + LocalGameLoaderImpl.getInstance().saveGame(game); GameManagerImpl.getInstance().addGame(game); game.start(); sender.sendMessage(Message.of(LangKeys.ADMIN_ARENA_EDIT_SUCCESS_SAVED_AND_STARTED).placeholderRaw("game", game.getName()).defaultPrefix()); diff --git a/plugin/common/src/main/java/org/screamingsandals/bedwars/commands/admin/TeamCommand.java b/plugin/common/src/main/java/org/screamingsandals/bedwars/commands/admin/TeamCommand.java index ae9c819b7..1859ac7b6 100644 --- a/plugin/common/src/main/java/org/screamingsandals/bedwars/commands/admin/TeamCommand.java +++ b/plugin/common/src/main/java/org/screamingsandals/bedwars/commands/admin/TeamCommand.java @@ -548,7 +548,7 @@ public void construct(CommandManager manager, Command.BuildernewBuilder("countdown").withMin(1)) .handler(commandContext -> editMode(commandContext, (sender, game) -> { @@ -584,7 +584,7 @@ public void construct(CommandManager manager, Command.BuildernewBuilder("countdown").withMin(1)) .argument(EnumArgument.optional(TargetBlockSetModes.class, "mode", TargetBlockSetModes.LOOKING_AT)) diff --git a/plugin/common/src/main/java/org/screamingsandals/bedwars/game/GameImpl.java b/plugin/common/src/main/java/org/screamingsandals/bedwars/game/GameImpl.java index c011ebdd5..78078a98b 100644 --- a/plugin/common/src/main/java/org/screamingsandals/bedwars/game/GameImpl.java +++ b/plugin/common/src/main/java/org/screamingsandals/bedwars/game/GameImpl.java @@ -177,14 +177,6 @@ public class GameImpl implements LocalGame { @Setter(AccessLevel.PROTECTED) private boolean preparing = false; - public static GameImpl loadGame(File file) { - return loadGame(file, true); - } - - public static GameImpl loadGame(File file, boolean firstAttempt) { - return LocalGameLoaderImpl.getInstance().loadGame(file, firstAttempt); - } - public void removeEntity(Entity e) { if (ArenaUtils.isInArea(e.getLocation(), pos1, pos2)) { final var chunk = e.getLocation().getChunk(); @@ -761,11 +753,6 @@ public void internalLeavePlayer(BedWarsPlayer gamePlayer) { } } - @SneakyThrows - public void saveToConfig() { - LocalGameLoaderImpl.getInstance().saveGame(this); - } - public void start() { if (status == GameStatus.DISABLED) { preparing = true; diff --git a/plugin/common/src/main/java/org/screamingsandals/bedwars/game/GameManagerImpl.java b/plugin/common/src/main/java/org/screamingsandals/bedwars/game/GameManagerImpl.java index 14acec274..94837feb8 100644 --- a/plugin/common/src/main/java/org/screamingsandals/bedwars/game/GameManagerImpl.java +++ b/plugin/common/src/main/java/org/screamingsandals/bedwars/game/GameManagerImpl.java @@ -140,11 +140,12 @@ public void onPostEnable() { logger.debug("No arenas have been found!"); } else { results.forEach(file -> { - if (file.exists() && file.isFile() && !file.getName().toLowerCase().endsWith(".disabled")) { - var game = GameImpl.loadGame(file); - if (game != null) { - games.add(game); - } + if (file.exists() && file.isFile() && !file.getName().toLowerCase(Locale.ROOT).endsWith(".disabled")) { + LocalGameLoaderImpl.getInstance().loadGame(file, true).thenAccept(game -> { + if (game != null) { + games.add(game); + } + }); } }); } diff --git a/plugin/common/src/main/java/org/screamingsandals/bedwars/game/ItemSpawnerTypeImpl.java b/plugin/common/src/main/java/org/screamingsandals/bedwars/game/ItemSpawnerTypeImpl.java index cc00b527f..67e7162bb 100644 --- a/plugin/common/src/main/java/org/screamingsandals/bedwars/game/ItemSpawnerTypeImpl.java +++ b/plugin/common/src/main/java/org/screamingsandals/bedwars/game/ItemSpawnerTypeImpl.java @@ -36,6 +36,7 @@ import org.spongepowered.configurate.ConfigurationNode; import java.util.Arrays; +import java.util.Locale; import java.util.Objects; @AllArgsConstructor @@ -78,7 +79,7 @@ public ItemStack getItem(int amount) { } public static ItemSpawnerTypeImpl deserialize(String spawnerKey, ConfigurationNode node) { - spawnerKey = spawnerKey.toLowerCase(); + spawnerKey = spawnerKey.toLowerCase(Locale.ROOT); var name = node.node("name").getString(); var translate = node.node("translate").getString(); @@ -94,7 +95,7 @@ public static ItemSpawnerTypeImpl deserialize(String spawnerKey, ConfigurationNo if (split.length == 2) { try { var longValue = Long.parseLong(split[0]); - var unitName = split[1].toUpperCase().trim(); + var unitName = split[1].toUpperCase(Locale.ROOT).trim(); if (!unitName.endsWith("S")) { unitName += "S"; } diff --git a/plugin/common/src/main/java/org/screamingsandals/bedwars/game/LocalGameLoaderImpl.java b/plugin/common/src/main/java/org/screamingsandals/bedwars/game/LocalGameLoaderImpl.java index baa424ad0..7fc348df5 100644 --- a/plugin/common/src/main/java/org/screamingsandals/bedwars/game/LocalGameLoaderImpl.java +++ b/plugin/common/src/main/java/org/screamingsandals/bedwars/game/LocalGameLoaderImpl.java @@ -22,6 +22,7 @@ import com.onarandombox.MultiverseCore.api.Core; import lombok.SneakyThrows; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.screamingsandals.bedwars.BedWarsPlugin; import org.screamingsandals.bedwars.api.game.LocalGame; import org.screamingsandals.bedwars.api.game.LocalGameLoader; @@ -54,8 +55,10 @@ import java.io.File; import java.io.IOException; +import java.util.Locale; import java.util.Objects; import java.util.UUID; +import java.util.concurrent.CompletableFuture; @Service public class LocalGameLoaderImpl implements LocalGameLoader { @@ -65,11 +68,11 @@ public static LocalGameLoaderImpl getInstance() { } @Override - public GameImpl loadGame(File file, boolean firstAttempt) { + public @NotNull CompletableFuture<@Nullable GameImpl> loadGame(@NotNull File file, boolean firstAttempt) { try { final ConfigurationNode configMap = ConfigurateUtils.loadFileAsNode(file); if (configMap == null) { - return null; + return CompletableFuture.completedFuture(null); } var uid = configMap.node("uuid"); @@ -94,7 +97,7 @@ public GameImpl loadGame(File file, boolean firstAttempt) { Component.text("Arena " + uuid + " has the same unique id as another arena that's already loaded. Skipping!", Color.RED) ) ); - return null; + return CompletableFuture.completedFuture(null); } final var game = new GameImpl(uuid); @@ -130,7 +133,7 @@ public GameImpl loadGame(File file, boolean firstAttempt) { Component.text("Arena " + game.getName() + " can't be loaded, because world " + worldName + " is missing!", Color.RED) ) ); - return null; + return CompletableFuture.completedFuture(null); } } else if (firstAttempt) { Server.getConsoleSender().sendMessage( @@ -138,15 +141,16 @@ public GameImpl loadGame(File file, boolean firstAttempt) { Component.text("Arena " + game.getName() + " can't be loaded, because world " + worldName + " is missing! We will try it again after all plugins have loaded!", Color.YELLOW) ) ); - Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> loadGame(file, false), 10L, TaskerTime.TICKS); - return null; + var future = new CompletableFuture(); + Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> loadGame(file, false).thenAccept(future::complete), 10L, TaskerTime.TICKS); + return future; } else { Server.getConsoleSender().sendMessage( MiscUtils.BW_PREFIX.withAppendix( Component.text("Arena " + game.getName() + " can't be loaded, because world " + worldName + " is missing!", Color.RED) ) ); - return null; + return CompletableFuture.completedFuture(null); } } @@ -197,7 +201,7 @@ public GameImpl loadGame(File file, boolean firstAttempt) { Component.text("Arena " + game.getName() + " can't be loaded, because world " + spawnWorld + " is missing!", Color.RED) ) ); - return null; + return CompletableFuture.completedFuture(null); } } else if (firstAttempt) { Server.getConsoleSender().sendMessage( @@ -205,15 +209,16 @@ public GameImpl loadGame(File file, boolean firstAttempt) { Component.text("Arena " + game.getName() + " can't be loaded, because world " + spawnWorld + " is missing! We will try it again after all plugins have loaded!", Color.YELLOW) ) ); - Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> loadGame(file, false), 10L, TaskerTime.TICKS); - return null; + var future = new CompletableFuture(); + Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> loadGame(file, false).thenAccept(future::complete), 10L, TaskerTime.TICKS); + return future; } else { Server.getConsoleSender().sendMessage( MiscUtils.BW_PREFIX.withAppendix( Component.text("Arena " + game.getName() + " can't be loaded, because world " + spawnWorld + " is missing!", Color.RED) ) ); - return null; + return CompletableFuture.completedFuture(null); } } @@ -320,7 +325,7 @@ public GameImpl loadGame(File file, boolean firstAttempt) { var oldLobbyBossBarColor = configMap.node("lobbyBossBarColor"); var newLobbyBossBarColor = configMap.node("constant", "bossbar", "lobby", "color"); if (!oldLobbyBossBarColor.empty() && newLobbyBossBarColor.empty()) { - newLobbyBossBarColor.set(GameImpl.loadBossBarColor(oldLobbyBossBarColor.getString("default").toUpperCase())); + newLobbyBossBarColor.set(GameImpl.loadBossBarColor(oldLobbyBossBarColor.getString("default").toUpperCase(Locale.ROOT))); oldLobbyBossBarColor.set(null); } } @@ -330,14 +335,14 @@ public GameImpl loadGame(File file, boolean firstAttempt) { var oldGameBossBarColor = configMap.node("gameBossBarColor"); var newGameBossBarColor = configMap.node("constant", "bossbar", "game", "color"); if (!newGameBossBarColor.empty() && oldGameBossBarColor.empty()) { - newGameBossBarColor.set(GameImpl.loadBossBarColor(oldGameBossBarColor.getString("default").toUpperCase())); + newGameBossBarColor.set(GameImpl.loadBossBarColor(oldGameBossBarColor.getString("default").toUpperCase(Locale.ROOT))); oldGameBossBarColor.set(null); } } game.getConfigurationContainer().applyNode(configMap.node("constant")); - game.setArenaWeather(GameImpl.loadWeather(configMap.node("arenaWeather").getString("default").toUpperCase())); + game.setArenaWeather(GameImpl.loadWeather(configMap.node("arenaWeather").getString("default").toUpperCase(Locale.ROOT))); game.setPostGameWaiting(configMap.node("postGameWaiting").getInt(3)); @@ -364,16 +369,16 @@ public GameImpl loadGame(File file, boolean firstAttempt) { if (uid.empty()) { try { // because we didn't have uuid in the arena config file, we need to save the arena again - game.saveToConfig(); + saveGame(game); } catch (Throwable ignored) { } } - return game; + return CompletableFuture.completedFuture(game); } catch (Throwable throwable) { Debug.warn("Something went wrong while loading arena file " + file.getName() + ". Please report this to our Discord or GitHub!", true); throwable.printStackTrace(); - return null; + return CompletableFuture.completedFuture(null); } } diff --git a/plugin/common/src/main/java/org/screamingsandals/bedwars/inventories/GamesInventory.java b/plugin/common/src/main/java/org/screamingsandals/bedwars/inventories/GamesInventory.java index 783d3777e..9aafad6fa 100644 --- a/plugin/common/src/main/java/org/screamingsandals/bedwars/inventories/GamesInventory.java +++ b/plugin/common/src/main/java/org/screamingsandals/bedwars/inventories/GamesInventory.java @@ -77,7 +77,7 @@ public void loadInventory() { logger.debug("No games inventories have been found!"); } else { results.forEach(file -> { - if (file.exists() && file.isFile() && !file.getName().toLowerCase().endsWith(".disabled")) { + if (file.exists() && file.isFile() && !file.getName().toLowerCase(Locale.ROOT).endsWith(".disabled")) { final var dot = file.getName().indexOf("."); final var name = dot == -1 ? file.getName() : file.getName().substring(0, dot); final var siFormat = SimpleInventoriesCore.builder() @@ -155,7 +155,7 @@ private void onClick(PostClickEvent event) { properties.stream() .filter(Property::hasName) .forEach(property -> { - switch (property.getPropertyName().toLowerCase()) { + switch (property.getPropertyName().toLowerCase(Locale.ROOT)) { case "randomly_join": final var randomlyJoin = item.getFirstPropertyByName("randomly_join").orElseThrow(); final var games = randomlyJoin.getPropertyData().node("games"); diff --git a/plugin/common/src/main/java/org/screamingsandals/bedwars/lang/BedWarsLangService.java b/plugin/common/src/main/java/org/screamingsandals/bedwars/lang/BedWarsLangService.java index f004b48df..4a4a9ce8c 100644 --- a/plugin/common/src/main/java/org/screamingsandals/bedwars/lang/BedWarsLangService.java +++ b/plugin/common/src/main/java/org/screamingsandals/bedwars/lang/BedWarsLangService.java @@ -185,7 +185,7 @@ public void onEnable() { stream.filter(Files::isRegularFile) .forEach(file -> { var name = file.getFileName().toString(); - if (Files.exists(file) && Files.isRegularFile(file) && name.toLowerCase().endsWith(".json")) { + if (Files.exists(file) && Files.isRegularFile(file) && name.toLowerCase(Locale.ROOT).endsWith(".json")) { var matcher = LANGUAGE_PATTERN.matcher(name); if (matcher.find()) { try { diff --git a/plugin/common/src/main/java/org/screamingsandals/bedwars/sidebar/GameSidebar.java b/plugin/common/src/main/java/org/screamingsandals/bedwars/sidebar/GameSidebar.java index 4e6e5b6aa..fc942fe90 100644 --- a/plugin/common/src/main/java/org/screamingsandals/bedwars/sidebar/GameSidebar.java +++ b/plugin/common/src/main/java/org/screamingsandals/bedwars/sidebar/GameSidebar.java @@ -220,7 +220,7 @@ private void update() { game.getActiveTeams().forEach(team -> { if (teamedSidebar.getTeam(team.getName()) == null) { var t = teamedSidebar.team(team.getName()) - .color(ClientboundSetPlayerTeamPacket.TeamColor.valueOf(Color.nearestNamedTo(team.getColor().getTextColor()).toString().toUpperCase())) // TODO: a better way + .color(ClientboundSetPlayerTeamPacket.TeamColor.valueOf(Color.nearestNamedTo(team.getColor().getTextColor()).toString().toUpperCase(Locale.ROOT))) // TODO: a better way .friendlyFire(game.getConfigurationContainer().getOrDefault(GameConfigurationContainer.FRIENDLYFIRE, false)); if (game.getConfigurationContainer().getOrDefault(GameConfigurationContainer.USE_TEAM_LETTER_PREFIXES_BEFORE_PLAYER_NAMES, false)) { t.teamPrefix(Component.text().content(team.getName().charAt(0) + " ").color(team.getColor().getTextColor()).bold().build()); diff --git a/plugin/common/src/main/java/org/screamingsandals/bedwars/special/PopUpTowerImpl.java b/plugin/common/src/main/java/org/screamingsandals/bedwars/special/PopUpTowerImpl.java index a941de6e3..ab0fb6824 100644 --- a/plugin/common/src/main/java/org/screamingsandals/bedwars/special/PopUpTowerImpl.java +++ b/plugin/common/src/main/java/org/screamingsandals/bedwars/special/PopUpTowerImpl.java @@ -41,6 +41,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Locale; import java.util.Objects; import java.util.stream.Collectors; @@ -188,7 +189,7 @@ public void placeLadderRow(int length, Location loc, BlockFace face, BlockFace l if (!isLocationSafe(lastLoc)) { continue; } - var ladderType = Block.of("minecraft:ladder[facing=" + ladderFace.name().toLowerCase() + "]"); + var ladderType = Block.of("minecraft:ladder[facing=" + ladderFace.name().toLowerCase(Locale.ROOT) + "]"); ladder.block(ladderType); game.getRegion().removeBlockBuiltDuringGame(lastLoc); game.getRegion().addBuiltDuringGame(lastLoc); diff --git a/plugin/common/src/main/java/org/screamingsandals/bedwars/statistics/PlayerStatisticManager.java b/plugin/common/src/main/java/org/screamingsandals/bedwars/statistics/PlayerStatisticManager.java index 0b1d656ab..49b4d29c5 100644 --- a/plugin/common/src/main/java/org/screamingsandals/bedwars/statistics/PlayerStatisticManager.java +++ b/plugin/common/src/main/java/org/screamingsandals/bedwars/statistics/PlayerStatisticManager.java @@ -129,7 +129,7 @@ public void initialize() { var xpToLevel = MainConfig.getInstance().node("statistics", "xp-to-level").childrenMap(); for (var xpToL : xpToLevel.entrySet()) { - var key = xpToL.getKey().toString().toLowerCase().replace(" ", ""); + var key = xpToL.getKey().toString().toLowerCase(Locale.ROOT).replace(" ", ""); var value = xpToL.getValue().getInt(); if (value <= 0) { continue; // invalid diff --git a/plugin/common/src/main/java/org/screamingsandals/bedwars/variants/VariantImpl.java b/plugin/common/src/main/java/org/screamingsandals/bedwars/variants/VariantImpl.java index 510d3e20a..8779c84c0 100644 --- a/plugin/common/src/main/java/org/screamingsandals/bedwars/variants/VariantImpl.java +++ b/plugin/common/src/main/java/org/screamingsandals/bedwars/variants/VariantImpl.java @@ -38,6 +38,7 @@ import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.stream.Collectors; @RequiredArgsConstructor @@ -142,7 +143,7 @@ public List getItemSpawnerTypeNames() { @Override @Nullable public ItemSpawnerTypeImpl getItemSpawnerType(@NotNull String name) { - var finalName = name.toLowerCase(); + var finalName = name.toLowerCase(Locale.ROOT); var match = customSpawnerTypes.stream().filter(t -> t.getConfigKey().equals(finalName)).findFirst().orElse(null); if (match != null) { return match; diff --git a/plugin/common/src/main/java/org/screamingsandals/bedwars/variants/VariantManagerImpl.java b/plugin/common/src/main/java/org/screamingsandals/bedwars/variants/VariantManagerImpl.java index c4bd3e01a..6453b864f 100644 --- a/plugin/common/src/main/java/org/screamingsandals/bedwars/variants/VariantManagerImpl.java +++ b/plugin/common/src/main/java/org/screamingsandals/bedwars/variants/VariantManagerImpl.java @@ -34,6 +34,7 @@ import java.nio.file.Path; import java.util.LinkedList; import java.util.List; +import java.util.Locale; import java.util.Optional; import java.util.stream.Collectors; @@ -108,7 +109,7 @@ public void onPostEnable() { logger.debug("No variants have been found!"); } else { results.forEach(file -> { - if (file.exists() && file.isFile() && !file.getName().toLowerCase().endsWith(".disabled")) { + if (file.exists() && file.isFile() && !file.getName().toLowerCase(Locale.ROOT).endsWith(".disabled")) { var variant = VariantImpl.loadVariant(file); if (variant != null) { variants.add(variant);