Skip to content

Commit

Permalink
Fixup system locale issues
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Dec 19, 2024
1 parent 0a0af90 commit 6600f54
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.bukkit.scoreboard.ScoreboardManager;
import org.bukkit.scoreboard.Team;

import java.util.Locale;
import java.util.Objects;
import java.util.Random;
import java.util.logging.Level;
Expand All @@ -56,7 +57,7 @@ public void onPlayerJoin(PlayerJoinEvent event) {
}

if (plugin.isForceGamemode()) {
player.setGameMode(GameMode.valueOf(plugin.getForcedGamemode().toUpperCase()));
player.setGameMode(GameMode.valueOf(plugin.getForcedGamemode().toUpperCase(Locale.ROOT)));
}

if (plugin.isHidePlayers()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ default void onCommand(CommandSourceWrapper sender, String[] args, PistonQueuePl
return;
}

switch (args[0].toLowerCase()) {
switch (args[0].toLowerCase(Locale.ROOT)) {
case "version":
sendLine(sender);
sender.sendMessage(component().text("PistonQueue").color(TextColorWrapper.GOLD));
Expand Down Expand Up @@ -104,20 +104,20 @@ default void onCommand(CommandSourceWrapper sender, String[] args, PistonQueuePl
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());

if (args[2].toLowerCase().endsWith("d")) {
int d = Integer.parseInt(args[2].toLowerCase().replace("d", ""));
if (args[2].toLowerCase(Locale.ROOT).endsWith("d")) {
int d = Integer.parseInt(args[2].toLowerCase(Locale.ROOT).replace("d", ""));

calendar.add(Calendar.DAY_OF_WEEK, d);
} else if (args[2].toLowerCase().endsWith("h")) {
int h = Integer.parseInt(args[2].toLowerCase().replace("h", ""));
} else if (args[2].toLowerCase(Locale.ROOT).endsWith("h")) {
int h = Integer.parseInt(args[2].toLowerCase(Locale.ROOT).replace("h", ""));

calendar.add(Calendar.HOUR_OF_DAY, h);
} else if (args[2].toLowerCase().endsWith("m")) {
int m = Integer.parseInt(args[2].toLowerCase().replace("m", ""));
} else if (args[2].toLowerCase(Locale.ROOT).endsWith("m")) {
int m = Integer.parseInt(args[2].toLowerCase(Locale.ROOT).replace("m", ""));

calendar.add(Calendar.MINUTE, m);
} else if (args[2].toLowerCase().endsWith("s")) {
int s = Integer.parseInt(args[2].toLowerCase().replace("s", ""));
} else if (args[2].toLowerCase(Locale.ROOT).endsWith("s")) {
int s = Integer.parseInt(args[2].toLowerCase(Locale.ROOT).replace("s", ""));

calendar.add(Calendar.SECOND, s);
} else {
Expand Down Expand Up @@ -223,13 +223,13 @@ default List<String> onTab(String[] args, PermissibleWrapper wrapper, PistonQueu

if (args.length == 1) {
for (String string : commands) {
if (string.toLowerCase().startsWith(args[0].toLowerCase()))
if (string.toLowerCase(Locale.ROOT).startsWith(args[0].toLowerCase(Locale.ROOT)))
completions.add(string);
}

if (wrapper.hasPermission(Config.ADMIN_PERMISSION)) {
for (String string : adminCommands) {
if (string.toLowerCase().startsWith(args[0].toLowerCase()))
if (string.toLowerCase(Locale.ROOT).startsWith(args[0].toLowerCase(Locale.ROOT)))
completions.add(string);
}
}
Expand All @@ -249,7 +249,7 @@ default List<String> onTab(String[] args, PermissibleWrapper wrapper, PistonQueu

default void addPlayers(List<String> completions, String[] args, PistonQueuePlugin proxy) {
for (PlayerWrapper player : proxy.getPlayers()) {
if (player.getName().toLowerCase().startsWith(args[1].toLowerCase()))
if (player.getName().toLowerCase(Locale.ROOT).startsWith(args[1].toLowerCase(Locale.ROOT)))
completions.add(player.getName());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import net.pistonmaster.pistonqueue.shared.config.Config;
import net.pistonmaster.pistonqueue.shared.queue.QueueType;

import java.util.Locale;

public final class PistonMOTDPlaceholder implements PlaceholderParser {
public PistonMOTDPlaceholder() {
PlaceholderUtil.registerParser(this);
Expand All @@ -32,7 +34,7 @@ public PistonMOTDPlaceholder() {
@Override
public String parseString(String s) {
for (QueueType type : Config.QUEUE_TYPES) {
s = s.replace("%pistonqueue_" + type.getName().toLowerCase() + "%", String.valueOf(type.getQueueMap().size()));
s = s.replace("%pistonqueue_" + type.getName().toLowerCase(Locale.ROOT) + "%", String.valueOf(type.getQueueMap().size()));
}
return s;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ default void sendCustomData() {
outOnlineQueue.writeUTF("onlineQueue");
outOnlineQueue.writeInt(Config.QUEUE_TYPES.length);
for (QueueType queueType : Config.QUEUE_TYPES) {
outOnlineQueue.writeUTF(queueType.getName().toLowerCase());
outOnlineQueue.writeUTF(queueType.getName().toLowerCase(Locale.ROOT));
outOnlineQueue.writeInt(queueType.getQueueMap().size());
}

Expand All @@ -231,7 +231,7 @@ default void sendCustomData() {
outOnlineTarget.writeUTF("onlineTarget");
outOnlineTarget.writeInt(Config.QUEUE_TYPES.length);
for (QueueType queueType : Config.QUEUE_TYPES) {
outOnlineTarget.writeUTF(queueType.getName().toLowerCase());
outOnlineTarget.writeUTF(queueType.getName().toLowerCase(Locale.ROOT));
outOnlineTarget.writeInt(queueType.getPlayersWithTypeInTarget().get());
}

Expand Down Expand Up @@ -316,7 +316,7 @@ default void loadConfig(Path file) throws IOException {
String value = "";

for (String str : text) {
if (str.toLowerCase().startsWith(Config.class.getPackage().getName().toLowerCase())) {
if (str.toLowerCase(Locale.ROOT).startsWith(Config.class.getPackage().getName().toLowerCase(Locale.ROOT))) {
value = str;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ protected void onPostLogin(PlayerWrapper player) {
protected void onKick(PQKickedFromServerEvent event) {
if (Config.IF_TARGET_DOWN_SEND_TO_QUEUE && event.getKickedFrom().equals(Config.TARGET_SERVER)) {
String kickReason = event.getKickReason()
.map(s -> s.toLowerCase(Locale.ENGLISH))
.map(s -> s.toLowerCase(Locale.ROOT))
.orElse("unknown reason");

Config.DOWN_WORD_LIST.stream()
.filter(word -> kickReason.contains(word.toLowerCase(Locale.ENGLISH)))
.filter(word -> kickReason.contains(word.toLowerCase(Locale.ROOT)))
.findFirst()
.ifPresent(word -> {
event.setCancelServer(Config.QUEUE_SERVER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.pistonmaster.pistonqueue.shared.queue.QueueType;

import java.time.Duration;
import java.util.Locale;

public final class SharedChatUtils {
private SharedChatUtils() {
Expand All @@ -39,7 +40,7 @@ public static String formatDuration(String str, Duration duration, int position)
public static String parseText(String text) {
text = text.replace("%server_name%", Config.SERVER_NAME);
for (QueueType type : Config.QUEUE_TYPES) {
text = text.replace("%" + type.getName().toLowerCase() + "%", String.valueOf(type.getQueueMap().size()));
text = text.replace("%" + type.getName().toLowerCase(Locale.ROOT) + "%", String.valueOf(type.getQueueMap().size()));
}
text = text.replace("%position%", "None");
text = text.replace("%wait%", "None");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private StorageTool() {
* @return true if player got shadow-banned and if already shadow-banned false.
*/
public static boolean shadowBanPlayer(String playerName, Date date) {
playerName = playerName.toLowerCase(Locale.ENGLISH);
playerName = playerName.toLowerCase(Locale.ROOT);
manageBan(playerName);

if (dataConfig.node(playerName).virtual()) {
Expand All @@ -72,7 +72,7 @@ public static boolean shadowBanPlayer(String playerName, Date date) {
* @return true if a player got un-shadow-banned and false if he wasn't shadow-banned.
*/
public static boolean unShadowBanPlayer(String playerName) {
playerName = playerName.toLowerCase(Locale.ENGLISH);
playerName = playerName.toLowerCase(Locale.ROOT);
if (!dataConfig.node(playerName).virtual()) {
try {
dataConfig.node(playerName).set(null);
Expand All @@ -89,18 +89,18 @@ public static boolean unShadowBanPlayer(String playerName) {
}

public static boolean isShadowBanned(String playerName) {
playerName = playerName.toLowerCase(Locale.ENGLISH);
playerName = playerName.toLowerCase(Locale.ROOT);
manageBan(playerName);

return !dataConfig.node(playerName).virtual();
}

private static void manageBan(String playerName) {
playerName = playerName.toLowerCase(Locale.ENGLISH);
playerName = playerName.toLowerCase(Locale.ROOT);
Date now = new Date();

if (!dataConfig.node(playerName).virtual()) {
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", new Locale("us"));
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.of("en"));

try {
Date date = sdf.parse(dataConfig.node(playerName).getString());
Expand Down

0 comments on commit 6600f54

Please sign in to comment.