From 07c7635ab4e48846a752b150c4950c7edeb1313a Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 19 Jun 2024 23:56:31 +0200 Subject: [PATCH] Fix some SonarLint Issues and Modernize Java --- .../src/de/steamwar/bungeecore/Bauserver.java | 5 ---- .../de/steamwar/bungeecore/Builderserver.java | 5 ---- .../src/de/steamwar/bungeecore/Subserver.java | 5 ---- src/de/steamwar/bungeecore/Node.java | 2 +- src/de/steamwar/bungeecore/ServerStarter.java | 4 +-- .../bungeecore/commands/ArenaCommand.java | 2 +- .../bungeecore/commands/BauCommand.java | 2 +- .../commands/BuilderCloudCommand.java | 4 +-- .../bungeecore/commands/CheckCommand.java | 3 +- .../bungeecore/commands/DevCommand.java | 2 +- .../bungeecore/commands/ListCommand.java | 9 +++--- .../bungeecore/commands/ModCommand.java | 2 +- .../bungeecore/commands/PlaytimeCommand.java | 2 +- .../commands/PunishmentCommand.java | 2 +- .../bungeecore/commands/ReplayCommand.java | 2 +- .../bungeecore/commands/TeamCommand.java | 10 +++---- .../bungeecore/commands/TutorialCommand.java | 4 +-- .../bungeecore/commands/VerifyCommand.java | 2 +- .../bungeecore/discord/DiscordBot.java | 6 ++-- .../discord/listeners/DiscordSchemUpload.java | 2 +- .../bungeecore/discord/util/AuthManager.java | 2 +- .../bungeecore/discord/util/DiscordRanks.java | 2 +- .../bungeecore/listeners/ChatListener.java | 6 ++-- .../bungeecore/listeners/IPSanitizer.java | 2 +- src/de/steamwar/bungeecore/mods/LabyMod.java | 10 +++---- src/de/steamwar/bungeecore/mods/Lunar.java | 5 +--- src/de/steamwar/bungeecore/mods/ModUtils.java | 4 +-- .../bungeecore/network/NetworkSender.java | 2 +- .../bungeecore/network/ServerMetaInfo.java | 9 +----- .../network/handlers/EloPlayerHandler.java | 27 ++++++++++-------- .../network/handlers/FightInfoHandler.java | 2 +- .../network/handlers/ImALobbyHandler.java | 2 +- .../handlers/InventoryCallbackHandler.java | 2 +- .../steamwar/bungeecore/tablist/Tablist.java | 2 +- .../bungeecore/tablist/TablistBuild.java | 2 +- .../bungeecore/tablist/TablistServer.java | 2 +- src/de/steamwar/command/SWCommand.java | 2 +- src/de/steamwar/messages/Chatter.java | 28 +++++++++---------- src/de/steamwar/messages/Message.java | 14 +--------- 39 files changed, 85 insertions(+), 115 deletions(-) diff --git a/Persistent/src/de/steamwar/bungeecore/Bauserver.java b/Persistent/src/de/steamwar/bungeecore/Bauserver.java index c5876f0..b861a1a 100644 --- a/Persistent/src/de/steamwar/bungeecore/Bauserver.java +++ b/Persistent/src/de/steamwar/bungeecore/Bauserver.java @@ -50,11 +50,6 @@ public class Bauserver extends Subserver { } } - @Override - protected void register() { - super.register(); - } - @Override protected void unregister() { synchronized (servers) { diff --git a/Persistent/src/de/steamwar/bungeecore/Builderserver.java b/Persistent/src/de/steamwar/bungeecore/Builderserver.java index c085bb9..abd5da6 100644 --- a/Persistent/src/de/steamwar/bungeecore/Builderserver.java +++ b/Persistent/src/de/steamwar/bungeecore/Builderserver.java @@ -49,11 +49,6 @@ public class Builderserver extends Subserver { } } - @Override - protected void register() { - super.register(); - } - @Override protected void unregister() { synchronized (servers) { diff --git a/Persistent/src/de/steamwar/bungeecore/Subserver.java b/Persistent/src/de/steamwar/bungeecore/Subserver.java index 830608c..50f2127 100644 --- a/Persistent/src/de/steamwar/bungeecore/Subserver.java +++ b/Persistent/src/de/steamwar/bungeecore/Subserver.java @@ -116,11 +116,6 @@ public class Subserver { this.thread.start(); } - @Deprecated(forRemoval = true) - public boolean hasStarted() { - return started; - } - public void sendPlayer(Player p) { if (!started) { p.sendActionBar(generateBar(0)); diff --git a/src/de/steamwar/bungeecore/Node.java b/src/de/steamwar/bungeecore/Node.java index b9e05ee..f840446 100644 --- a/src/de/steamwar/bungeecore/Node.java +++ b/src/de/steamwar/bungeecore/Node.java @@ -170,7 +170,7 @@ public abstract class Node { public RemoteNode(String hostname) { super(hostname); - VelocityCore.getLogger().log(Level.INFO, "Added node " + hostname); + VelocityCore.getLogger().log(Level.INFO, "Added node {0}", hostname); } @Override diff --git a/src/de/steamwar/bungeecore/ServerStarter.java b/src/de/steamwar/bungeecore/ServerStarter.java index 23ef00d..1d088ed 100644 --- a/src/de/steamwar/bungeecore/ServerStarter.java +++ b/src/de/steamwar/bungeecore/ServerStarter.java @@ -276,8 +276,8 @@ public class ServerStarter { arguments.put("checkpoint", checkpointDir.getPath()); if(checkpoint && checkpointDir.exists()) { - try { - new DataOutputStream(Files.newOutputStream(new File(checkpointDir, "port").toPath())).writeInt(port); + try(DataOutputStream out = new DataOutputStream(Files.newOutputStream(new File(checkpointDir, "port").toPath()))) { + out.writeInt(port); } catch (IOException e) { throw new SecurityException(e); } diff --git a/src/de/steamwar/bungeecore/commands/ArenaCommand.java b/src/de/steamwar/bungeecore/commands/ArenaCommand.java index a5f91bd..a4bee96 100644 --- a/src/de/steamwar/bungeecore/commands/ArenaCommand.java +++ b/src/de/steamwar/bungeecore/commands/ArenaCommand.java @@ -65,7 +65,7 @@ public class ArenaCommand extends SWCommand { public Collection tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) { List subserverList = Subserver.getServerList(); synchronized (subserverList) { - return subserverList.stream().filter(subserver -> subserver.getType() == Servertype.ARENA).map(subserver -> subserver.getServer().getName()).collect(Collectors.toList()); + return subserverList.stream().filter(subserver -> subserver.getType() == Servertype.ARENA).map(subserver -> subserver.getServer().getName()).toList(); } } }; diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index 27f4a6f..0693abc 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -183,7 +183,7 @@ public class BauCommand extends SWCommand { public Collection tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) { return BauweltMember.getMembers(sender.user().getId()).stream() .map(bauweltMember -> SteamwarUser.get(bauweltMember.getMemberID()).getUserName()) - .collect(Collectors.toList()); + .toList(); } }; } diff --git a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java index 4f6266e..042e136 100644 --- a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java +++ b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java @@ -115,7 +115,7 @@ public class BuilderCloudCommand extends SWCommand { if(folder == null || (files = folder.list()) == null) return Collections.emptyList(); - return Arrays.stream(files).filter(file -> new File(folder, file).isDirectory()).filter(file -> s.startsWith(".") || !file.startsWith(".")).collect(Collectors.toList()); + return Arrays.stream(files).filter(file -> new File(folder, file).isDirectory()).filter(file -> s.startsWith(".") || !file.startsWith(".")).toList(); } }; } @@ -150,7 +150,7 @@ public class BuilderCloudCommand extends SWCommand { if(folder == null || (files = folder.list()) == null) return Collections.emptyList(); - return Arrays.stream(files).filter(file -> new File(folder, file).isFile()).filter(file -> file.endsWith(".dat")).map(file -> file.substring(0, file.length() - 4)).collect(Collectors.toList()); + return Arrays.stream(files).filter(file -> new File(folder, file).isFile()).filter(file -> file.endsWith(".dat")).map(file -> file.substring(0, file.length() - 4)).toList(); } }; } diff --git a/src/de/steamwar/bungeecore/commands/CheckCommand.java b/src/de/steamwar/bungeecore/commands/CheckCommand.java index c1ab54b..b5e4fba 100644 --- a/src/de/steamwar/bungeecore/commands/CheckCommand.java +++ b/src/de/steamwar/bungeecore/commands/CheckCommand.java @@ -88,7 +88,8 @@ public class CheckCommand extends SWCommand { for (SchematicNode schematic : schematicList) { CheckSession current = currentSchems.get(schematic.getId()); long waitedMillis = Timestamp.from(Instant.now()).getTime() - schematic.getLastUpdate().getTime(); - String color = waitedMillis > 14400000 ? (waitedMillis > 86400000 ? "c" : "e") : "a"; + String ce = waitedMillis > 86400000 ? "c" : "e"; + String color = waitedMillis > 14400000 ? ce : "a"; long hours = waitedMillis / 3600000; long minutes = (waitedMillis - hours * 3600000) / 60000; Message waitTime = new Message("CHECK_LIST_WAIT", color, hours, (minutes < 10) ? "0" + minutes : minutes); diff --git a/src/de/steamwar/bungeecore/commands/DevCommand.java b/src/de/steamwar/bungeecore/commands/DevCommand.java index 5562945..e5cfcfe 100644 --- a/src/de/steamwar/bungeecore/commands/DevCommand.java +++ b/src/de/steamwar/bungeecore/commands/DevCommand.java @@ -51,7 +51,7 @@ public class DevCommand extends SWCommand { sender.system("DEV_NO_SERVER"); return; } else if (devServers.size() == 1) { - sender.getPlayer().createConnectionRequest(devServers.values().stream().findAny().get()).fireAndForget(); + devServers.values().stream().findAny().ifPresent(server -> sender.getPlayer().createConnectionRequest(server).fireAndForget()); return; } diff --git a/src/de/steamwar/bungeecore/commands/ListCommand.java b/src/de/steamwar/bungeecore/commands/ListCommand.java index 28ddc9e..9f5ed06 100644 --- a/src/de/steamwar/bungeecore/commands/ListCommand.java +++ b/src/de/steamwar/bungeecore/commands/ListCommand.java @@ -29,6 +29,7 @@ import de.steamwar.messages.Chatter; import java.util.ArrayList; import java.util.List; +import java.util.SortedMap; import java.util.TreeMap; import java.util.stream.Collectors; @@ -38,8 +39,8 @@ public class ListCommand extends SWCommand { super("list"); } - public static synchronized TreeMap> getCustomTablist(){ - TreeMap> playerMap = new TreeMap<>(); + public static synchronized SortedMap> getCustomTablist(){ + SortedMap> playerMap = new TreeMap<>(); for (Player player : VelocityCore.getProxy().getAllPlayers()) { ServerConnection pserver = player.getCurrentServer().orElse(null); if (pserver == null) @@ -58,8 +59,8 @@ public class ListCommand extends SWCommand { @Register public void list(Chatter sender) { - TreeMap> playerMap = getCustomTablist(); - for (String server : playerMap.navigableKeySet()) { + SortedMap> playerMap = getCustomTablist(); + for (String server : playerMap.keySet()) { String serverName = server; if (server.equals("Bau")) { serverName = sender.parseToLegacy("TABLIST_BAU"); diff --git a/src/de/steamwar/bungeecore/commands/ModCommand.java b/src/de/steamwar/bungeecore/commands/ModCommand.java index f5a89aa..dd9fd57 100644 --- a/src/de/steamwar/bungeecore/commands/ModCommand.java +++ b/src/de/steamwar/bungeecore/commands/ModCommand.java @@ -57,7 +57,7 @@ public class ModCommand extends SWCommand { openGui(player); }), page -> { Mod.ModType filtertype = playerFilterType.get(player.user().getUUID()); - return Mod.getAllModsFiltered(page,45, filtertype).stream().map(mod -> new SWListInv.SWListEntry<>(new SWItem("NAME_TAG", new Message("PLAIN_STRING", mod.getModName())).addLore(new Message("PLAIN_STRING", mod.getPlatform().name())), mod)).collect(Collectors.toList()); + return Mod.getAllModsFiltered(page,45, filtertype).stream().map(mod -> new SWListInv.SWListEntry<>(new SWItem("NAME_TAG", new Message("PLAIN_STRING", mod.getModName())).addLore(new Message("PLAIN_STRING", mod.getPlatform().name())), mod)).toList(); }); swStreamInv.addItem(52, new SWItem("NAME_TAG", new Message("MOD_TITLE_FILTER")), click -> { diff --git a/src/de/steamwar/bungeecore/commands/PlaytimeCommand.java b/src/de/steamwar/bungeecore/commands/PlaytimeCommand.java index a5be015..b3460e0 100644 --- a/src/de/steamwar/bungeecore/commands/PlaytimeCommand.java +++ b/src/de/steamwar/bungeecore/commands/PlaytimeCommand.java @@ -36,7 +36,7 @@ public class PlaytimeCommand extends SWCommand { SteamwarUser user = sender.user(); NumberFormat format = NumberFormat.getNumberInstance(user.getLocale()); format.setMaximumFractionDigits(2); - String formattedText = format.format((user.getOnlinetime() / (double) 3600)); + String formattedText = format.format((user.getOnlinetime() / 3600d)); sender.system("HOURS_PLAYED", formattedText); } diff --git a/src/de/steamwar/bungeecore/commands/PunishmentCommand.java b/src/de/steamwar/bungeecore/commands/PunishmentCommand.java index 492a61d..48e7b93 100644 --- a/src/de/steamwar/bungeecore/commands/PunishmentCommand.java +++ b/src/de/steamwar/bungeecore/commands/PunishmentCommand.java @@ -72,7 +72,7 @@ public class PunishmentCommand { } catch (NoSuchElementException e) { // ignore, player does not exist } catch (IOException e) { - VelocityCore.getLogger().log(Level.SEVERE, "Could not get offline player UUID " + playerName, e); + VelocityCore.getLogger().log(Level.SEVERE, "Could not get offline player UUID {0}".formatted(playerName), e); } return null; } diff --git a/src/de/steamwar/bungeecore/commands/ReplayCommand.java b/src/de/steamwar/bungeecore/commands/ReplayCommand.java index 8dc03ae..083c763 100644 --- a/src/de/steamwar/bungeecore/commands/ReplayCommand.java +++ b/src/de/steamwar/bungeecore/commands/ReplayCommand.java @@ -61,7 +61,7 @@ public class ReplayCommand extends SWCommand { } else { starter.arena(mode, map).start(); } - }, page -> Fight.getPage(page, 45).stream().map(fight -> new SWListInv.SWListEntry<>(getFightItem(fight), fight)).collect(Collectors.toList())).open(); + }, page -> Fight.getPage(page, 45).stream().map(fight -> new SWListInv.SWListEntry<>(getFightItem(fight), fight)).toList()).open(); } private SWItem getFightItem(Fight fight) { diff --git a/src/de/steamwar/bungeecore/commands/TeamCommand.java b/src/de/steamwar/bungeecore/commands/TeamCommand.java index bd67bd0..c0ff9fe 100644 --- a/src/de/steamwar/bungeecore/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/commands/TeamCommand.java @@ -236,7 +236,7 @@ public class TeamCommand extends SWCommand { return Team.get(sender.user().getTeam()).getMembers().stream() .map(SteamwarUser::get) .map(SteamwarUser::getUserName) - .collect(Collectors.toList()); + .toList(); } }; } @@ -290,7 +290,7 @@ public class TeamCommand extends SWCommand { @Register(value = "info", description = "TEAM_INFO_USAGE") public void info(Chatter sender, @ErrorMessage("UNKNOWN_TEAM") Team team){ - List users = team.getMembers().stream().map(SteamwarUser::get).collect(Collectors.toList()); + List users = team.getMembers().stream().map(SteamwarUser::get).toList(); sender.system("TEAM_INFO_TEAM", team.getTeamName(), team.getTeamColor(), team.getTeamKuerzel()); sender.prefixless("TEAM_INFO_LEADER", users.stream().filter(SteamwarUser::isLeader).count(), getMemberList(users, true)); @@ -484,7 +484,7 @@ public class TeamCommand extends SWCommand { if(notDuringEvent(sender)) return; - SWListInv inv = new SWListInv<>(sender, new Message("TEAM_COLOR_TITLE"), COLOR_CODES.entrySet().stream().map(entry -> new SWListInv.SWListEntry<>(new SWItem(new Message("PLAIN_STRING", "§" + entry.getKey() + team.getTeamKuerzel()), entry.getValue()), entry.getKey())).collect(Collectors.toList()), (click, element) -> {}); + SWListInv inv = new SWListInv<>(sender, new Message("TEAM_COLOR_TITLE"), COLOR_CODES.entrySet().stream().map(entry -> new SWListInv.SWListEntry<>(new SWItem(new Message("PLAIN_STRING", "§" + entry.getKey() + team.getTeamKuerzel()), entry.getValue()), entry.getKey())).toList(), (click, element) -> {}); inv.setCallback((click, element) -> { inv.close(); team.setTeamColor(element); @@ -512,7 +512,7 @@ public class TeamCommand extends SWCommand { @Override public Collection tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) { - return Event.getComing().stream().map(Event::getEventName).collect(Collectors.toList()); + return Event.getComing().stream().map(Event::getEventName).toList(); } }; } @@ -568,7 +568,7 @@ public class TeamCommand extends SWCommand { public Collection tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) { return Team.getAll().stream() .flatMap(team -> Stream.of(team.getTeamName(), team.getTeamKuerzel())) - .collect(Collectors.toList()); + .toList(); } }; } diff --git a/src/de/steamwar/bungeecore/commands/TutorialCommand.java b/src/de/steamwar/bungeecore/commands/TutorialCommand.java index 5d5a0c7..217e80f 100644 --- a/src/de/steamwar/bungeecore/commands/TutorialCommand.java +++ b/src/de/steamwar/bungeecore/commands/TutorialCommand.java @@ -106,7 +106,7 @@ public class TutorialCommand extends SWCommand { new ServerStarter().tutorial(sender.getPlayer(), tutorial).start(); }, - page -> (own ? Tutorial.getOwn(user.getId(), page, 45) : Tutorial.getPage(page, 45, released)).stream().map(tutorial -> new SWListInv.SWListEntry<>(getTutorialItem(tutorial, own), tutorial)).collect(Collectors.toList()) + page -> (own ? Tutorial.getOwn(user.getId(), page, 45) : Tutorial.getPage(page, 45, released)).stream().map(tutorial -> new SWListInv.SWListEntry<>(getTutorialItem(tutorial, own), tutorial)).toList() ).open(); } @@ -129,7 +129,7 @@ public class TutorialCommand extends SWCommand { private void rate(PlayerChatter sender, Tutorial tutorial) { int[] rates = new int[]{1, 2, 3, 4, 5}; - new SWListInv<>(sender, new Message("TUTORIAL_RATE_TITLE"), Arrays.stream(rates).mapToObj(rate -> new SWListInv.SWListEntry<>(new SWItem("NETHER_STAR", new Message("TUTORIAL_RATE", rate)), rate)).collect(Collectors.toList()), (click, rate) -> { + new SWListInv<>(sender, new Message("TUTORIAL_RATE_TITLE"), Arrays.stream(rates).mapToObj(rate -> new SWListInv.SWListEntry<>(new SWItem("NETHER_STAR", new Message("TUTORIAL_RATE", rate)), rate)).toList(), (click, rate) -> { tutorial.rate(sender.user().getId(), rate); SWInventory.close(sender); }).open(); diff --git a/src/de/steamwar/bungeecore/commands/VerifyCommand.java b/src/de/steamwar/bungeecore/commands/VerifyCommand.java index 9275cf5..283a32f 100644 --- a/src/de/steamwar/bungeecore/commands/VerifyCommand.java +++ b/src/de/steamwar/bungeecore/commands/VerifyCommand.java @@ -51,7 +51,7 @@ public class VerifyCommand extends SWCommand { User user = AuthManager.connectAuth(sender.user(), code); if(user != null) { - VelocityCore.getLogger().log(Level.INFO, sender.user().getUserName() + " Verified with Discorduser: " + user.getIdLong()); + VelocityCore.getLogger().log(Level.INFO, "{0} Verified with Discorduser: {1}".formatted(sender.user().getUserName(), user.getIdLong())); sender.system("VERIFY_SUCCESS", user.getAsTag()); } else { sender.system("VERIFY_INVALID"); diff --git a/src/de/steamwar/bungeecore/discord/DiscordBot.java b/src/de/steamwar/bungeecore/discord/DiscordBot.java index 0603785..57a6b3c 100644 --- a/src/de/steamwar/bungeecore/discord/DiscordBot.java +++ b/src/de/steamwar/bungeecore/discord/DiscordBot.java @@ -72,11 +72,11 @@ public class DiscordBot { } @Getter - private volatile DiscordChannel announcementChannel; + private DiscordChannel announcementChannel; @Getter - private volatile DiscordChatRoom ingameChat; + private DiscordChatRoom ingameChat; @Getter - private volatile DiscordChatRoom serverTeamChat; + private DiscordChatRoom serverTeamChat; @Getter private StaticMessageChannel eventChannel; diff --git a/src/de/steamwar/bungeecore/discord/listeners/DiscordSchemUpload.java b/src/de/steamwar/bungeecore/discord/listeners/DiscordSchemUpload.java index c80a3db..1d54a48 100644 --- a/src/de/steamwar/bungeecore/discord/listeners/DiscordSchemUpload.java +++ b/src/de/steamwar/bungeecore/discord/listeners/DiscordSchemUpload.java @@ -82,7 +82,7 @@ public class DiscordSchemUpload extends ListenerAdapter { } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (ExecutionException | IOException e) { - VelocityCore.getLogger().log(Level.SEVERE, "Could not upload schem \"" + name + "\" for user \"" + user.getUserName() + "\"", e); + VelocityCore.getLogger().log(Level.SEVERE, "Could not upload schem \"{0}\" for user \"{1}\"".formatted(name, user.getUserName()), e); sender.system("DC_SCHEMUPLOAD_ERROR", name); } } diff --git a/src/de/steamwar/bungeecore/discord/util/AuthManager.java b/src/de/steamwar/bungeecore/discord/util/AuthManager.java index 6ae8911..d1ec156 100644 --- a/src/de/steamwar/bungeecore/discord/util/AuthManager.java +++ b/src/de/steamwar/bungeecore/discord/util/AuthManager.java @@ -50,7 +50,7 @@ public class AuthManager { String code = Base64.getEncoder().encodeToString(randBytes); TOKENS.put(code, user); - VelocityCore.getLogger().log(Level.INFO, "Created Discord Auth-Token: " + code + " for: " + user.getAsTag()); + VelocityCore.getLogger().log(Level.INFO, "Created Discord Auth-Token: {0} for: {1}", new Object[] {code, user.getAsTag()}); VelocityCore.schedule(() -> TOKENS.remove(code)).delay(10, TimeUnit.MINUTES).schedule(); return code; } diff --git a/src/de/steamwar/bungeecore/discord/util/DiscordRanks.java b/src/de/steamwar/bungeecore/discord/util/DiscordRanks.java index 037b6d3..a4eb43a 100644 --- a/src/de/steamwar/bungeecore/discord/util/DiscordRanks.java +++ b/src/de/steamwar/bungeecore/discord/util/DiscordRanks.java @@ -52,7 +52,7 @@ public class DiscordRanks { if (member.getRoles().stream().noneMatch(role -> role.getId().equals(prefixRole))) guild.addRoleToMember(member, guild.getRoleById(prefixRole)).queue(); }, e -> { - if(e instanceof ErrorResponseException && ((ErrorResponseException) e).getErrorCode() == 10007) + if(e instanceof ErrorResponseException err && err.getErrorCode() == 10007) user.setDiscordId(null); }); } diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index c05a1fd..e918e89 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -46,7 +46,7 @@ import java.util.stream.Collectors; public class ChatListener extends BasicListener { - private static final List rankedModes = ArenaMode.getAllModes().stream().filter(ArenaMode::isRanked).map(ArenaMode::getSchemType).collect(Collectors.toList()); + private static final List rankedModes = ArenaMode.getAllModes().stream().filter(ArenaMode::isRanked).map(ArenaMode::getSchemType).toList(); @Subscribe public void onChatEvent(PlayerChatEvent e) { @@ -58,7 +58,7 @@ public class ChatListener extends BasicListener { if (message.contains("jndi:ldap")) { SteamwarUser user = SteamwarUser.get(player.getUniqueId()); PunishmentCommand.ban(user, Punishment.PERMA_TIME, "Versuchte Exploit-Ausnutzung", SteamwarUser.get(-1), true); - VelocityCore.getLogger().log(Level.SEVERE, user.getUserName() + " " + user.getId() + " wurde automatisch wegen jndi:ldap gebannt."); + VelocityCore.getLogger().log(Level.SEVERE, "{0} {1} wurde automatisch wegen jndi:ldap gebannt.", new Object[]{user.getUserName(), user.getId()}); return; } @@ -78,7 +78,7 @@ public class ChatListener extends BasicListener { private static boolean isCommand(Player player, String message) { String command = message.substring(1); boolean isCommand = message.startsWith("/") || (message.startsWith("7") && command.split(" ", 2)[0].matches("[7/]?[A-Za-z]+")); - if(isCommand && !VelocityCore.getProxy().getCommandManager().executeImmediatelyAsync(player, command).join()) { + if(isCommand && Boolean.FALSE.equals(VelocityCore.getProxy().getCommandManager().executeImmediatelyAsync(player, command).join())) { if(command.startsWith("7")) command = "/" + command.substring(1); message = "/" + command; diff --git a/src/de/steamwar/bungeecore/listeners/IPSanitizer.java b/src/de/steamwar/bungeecore/listeners/IPSanitizer.java index ef5c6fb..872c8dc 100644 --- a/src/de/steamwar/bungeecore/listeners/IPSanitizer.java +++ b/src/de/steamwar/bungeecore/listeners/IPSanitizer.java @@ -46,7 +46,7 @@ public class IPSanitizer extends BasicListener { @Subscribe public void loginEvent(PreLoginEvent e) { - VelocityCore.getLogger().log(Level.INFO, e.getConnection().getRemoteAddress() + " has logged in with user name " + e.getUsername()); + VelocityCore.getLogger().log(Level.INFO, "{0} has logged in with user name {1}".formatted(e.getConnection().getRemoteAddress(), e.getUsername())); remoteAddress.set(Hostname.getInitialInboundConnection((LoginInboundConnection) e.getConnection()).getConnection(), sanitized); } } diff --git a/src/de/steamwar/bungeecore/mods/LabyMod.java b/src/de/steamwar/bungeecore/mods/LabyMod.java index 766366b..16cad5c 100644 --- a/src/de/steamwar/bungeecore/mods/LabyMod.java +++ b/src/de/steamwar/bungeecore/mods/LabyMod.java @@ -75,11 +75,11 @@ public class LabyMod { if(message.has("mods")) { VelocityCore.getLogger().log(Level.WARNING, () -> "LabyMod External Mods for debugging: " + message.getAsJsonArray("mods")); - for(JsonElement element : message.getAsJsonArray("mods")) { - JsonObject addon = element.getAsJsonObject(); - //TODO observe: FORGE and FABRIC mods available, do they always and with .jar? (would equal new mod platform) - //mods.add(Mod.getOrCreate(addon.get("name").getAsString().replace(".jar", ""), Mod.Platform.FORGE)); - } + //for(JsonElement element : message.getAsJsonArray("mods")) { + // JsonObject addon = element.getAsJsonObject(); + // //TODO observe: FORGE and FABRIC mods available, do they always and with .jar? (would equal new mod platform) + // //mods.add(Mod.getOrCreate(addon.get("name").getAsString().replace(".jar", ""), Mod.Platform.FORGE)); + //} } ModUtils.handleMods(player, mods); diff --git a/src/de/steamwar/bungeecore/mods/Lunar.java b/src/de/steamwar/bungeecore/mods/Lunar.java index cdcea27..eba88c8 100644 --- a/src/de/steamwar/bungeecore/mods/Lunar.java +++ b/src/de/steamwar/bungeecore/mods/Lunar.java @@ -82,8 +82,7 @@ public class Lunar { for(ModMessage mod : handshake.getInstalledModsList()) { switch(mod.getType()) { - case TYPE_FABRIC_INTERNAL: - case TYPE_FORGE_INTERNAL: + case TYPE_FABRIC_INTERNAL, TYPE_FORGE_INTERNAL: // Controlled with ModSettings break; case TYPE_FABRIC_EXTERNAL: @@ -92,8 +91,6 @@ public class Lunar { case TYPE_FORGE_EXTERNAL: mods.add(Mod.getOrCreate(mod.getName(), Mod.Platform.FORGE)); break; - case TYPE_UNSPECIFIED: - case UNRECOGNIZED: default: VelocityCore.getLogger().log(Level.INFO, () -> player.getUsername() + " uses Lunar mod with unknown type " + mod); break; diff --git a/src/de/steamwar/bungeecore/mods/ModUtils.java b/src/de/steamwar/bungeecore/mods/ModUtils.java index 055849b..bded582 100644 --- a/src/de/steamwar/bungeecore/mods/ModUtils.java +++ b/src/de/steamwar/bungeecore/mods/ModUtils.java @@ -54,7 +54,7 @@ public class ModUtils { Chatter sender = Chatter.of(uuid); SteamwarUser user = sender.user(); playerModMap.put(uuid,new ArrayList<>(mods)); - VelocityCore.getLogger().log(Level.INFO, user.getUserName() + " declares mods: " + mods.stream().map(mod -> mod.getPlatform() + ":" + mod.getModName()).collect(Collectors.joining(" "))); + VelocityCore.getLogger().log(Level.INFO, "{0} declares mods: {1}", new Object[]{user.getUserName(), mods.stream().map(mod -> mod.getPlatform() + ":" + mod.getModName()).collect(Collectors.joining(" "))}); ModType max = ModType.YELLOW; Iterator it = mods.iterator(); @@ -83,7 +83,7 @@ public class ModUtils { if(max == ModType.RED) { PunishmentCommand.ban(user, Timestamp.from(Instant.now().plus(7, ChronoUnit.DAYS)), message, SteamwarUser.get(-1), false); - VelocityCore.getLogger().log(Level.SEVERE, user.getUserName() + " " + user.getId() + " wurde automatisch wegen der Mods " + modList + " gebannt."); + VelocityCore.getLogger().log(Level.SEVERE, "{0} {1} wurde automatisch wegen der Mods {2} gebannt.", new Object[]{user.getUserName(), user.getId(), modList}); } disconnect.accept(LegacyComponentSerializer.legacySection().deserialize(message)); diff --git a/src/de/steamwar/bungeecore/network/NetworkSender.java b/src/de/steamwar/bungeecore/network/NetworkSender.java index 0fc11fc..7895606 100644 --- a/src/de/steamwar/bungeecore/network/NetworkSender.java +++ b/src/de/steamwar/bungeecore/network/NetworkSender.java @@ -34,7 +34,7 @@ public class NetworkSender { @SneakyThrows public static void send(Player player, NetworkPacket packet) { - player.getCurrentServer().map(server -> server.sendPluginMessage(swBridge, packet.serialize())); + player.getCurrentServer().ifPresent(server -> server.sendPluginMessage(swBridge, packet.serialize())); } public static void send(RegisteredServer server, NetworkPacket packet) { diff --git a/src/de/steamwar/bungeecore/network/ServerMetaInfo.java b/src/de/steamwar/bungeecore/network/ServerMetaInfo.java index 324b0c6..38d70ee 100644 --- a/src/de/steamwar/bungeecore/network/ServerMetaInfo.java +++ b/src/de/steamwar/bungeecore/network/ServerMetaInfo.java @@ -21,12 +21,5 @@ package de.steamwar.bungeecore.network; import com.velocitypowered.api.proxy.ServerConnection; import de.steamwar.network.packets.MetaInfos; -import lombok.AllArgsConstructor; -import lombok.Getter; -@Getter -@AllArgsConstructor -public class ServerMetaInfo implements MetaInfos { - - private final ServerConnection sender; -} +public record ServerMetaInfo(ServerConnection sender) implements MetaInfos {} diff --git a/src/de/steamwar/bungeecore/network/handlers/EloPlayerHandler.java b/src/de/steamwar/bungeecore/network/handlers/EloPlayerHandler.java index bf71fb4..acf40f7 100644 --- a/src/de/steamwar/bungeecore/network/handlers/EloPlayerHandler.java +++ b/src/de/steamwar/bungeecore/network/handlers/EloPlayerHandler.java @@ -31,6 +31,7 @@ import lombok.RequiredArgsConstructor; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.title.Title; +import org.jetbrains.annotations.NotNull; import java.time.Duration; import java.util.*; @@ -173,17 +174,7 @@ public class EloPlayerHandler extends PacketHandler { if (player == null) return; - String finalOldEmblem = (oldEmblem.isEmpty() ? "/" : oldEmblem).trim(); - String finalNewEmblem = (newEmblem.isEmpty() ? "/" : newEmblem).trim(); - - IntFunction getRankup = i -> { - if (oldEmblem.equals(newEmblem)) return "§8" + finalOldEmblem; - if (i < 8) return "§8" + finalOldEmblem; - if (i < 16) return "§8" + finalOldEmblem + arrowColor + " >"; - if (i < 24) return "§8" + finalOldEmblem + arrowColor + " >>"; - if (i < 32) return "§8" + finalOldEmblem + arrowColor + " >>>"; - return "§8" + finalOldEmblem + arrowColor + " >>> §8" + finalNewEmblem; - }; + IntFunction getRankup = getEmblemTransition(oldEmblem, newEmblem, arrowColor); String color = ((eloGain > 0) ? "§a+" : (eloGain == 0 ? "§7" : "§c")); @@ -199,6 +190,20 @@ public class EloPlayerHandler extends PacketHandler { } } + private static @NotNull IntFunction getEmblemTransition(String oldEmblem, String newEmblem, String arrowColor) { + String finalOldEmblem = (oldEmblem.isEmpty() ? "/" : oldEmblem).trim(); + String finalNewEmblem = (newEmblem.isEmpty() ? "/" : newEmblem).trim(); + + return i -> { + if (oldEmblem.equals(newEmblem)) return "§8" + finalOldEmblem; + if (i < 8) return "§8" + finalOldEmblem; + if (i < 16) return "§8" + finalOldEmblem + arrowColor + " >"; + if (i < 24) return "§8" + finalOldEmblem + arrowColor + " >>"; + if (i < 32) return "§8" + finalOldEmblem + arrowColor + " >>>"; + return "§8" + finalOldEmblem + arrowColor + " >>> §8" + finalNewEmblem; + }; + } + private Player player(int userId) { return VelocityCore.getProxy().getPlayer(SteamwarUser.get(userId).getUUID()).orElse(null); } diff --git a/src/de/steamwar/bungeecore/network/handlers/FightInfoHandler.java b/src/de/steamwar/bungeecore/network/handlers/FightInfoHandler.java index 796c565..faabcc0 100644 --- a/src/de/steamwar/bungeecore/network/handlers/FightInfoHandler.java +++ b/src/de/steamwar/bungeecore/network/handlers/FightInfoHandler.java @@ -44,7 +44,7 @@ public class FightInfoHandler extends PacketHandler { @Handler public void handle(FightInfoPacket packet) { - RegisteredServer server = ((ServerMetaInfo) packet.getMetaInfos()).getSender().getServer(); + RegisteredServer server = ((ServerMetaInfo) packet.getMetaInfos()).sender().getServer(); FightInfoPacket lobbyPacket = packet.withServerName(server.getServerInfo().getName()); diff --git a/src/de/steamwar/bungeecore/network/handlers/ImALobbyHandler.java b/src/de/steamwar/bungeecore/network/handlers/ImALobbyHandler.java index 90b0449..23a1e39 100644 --- a/src/de/steamwar/bungeecore/network/handlers/ImALobbyHandler.java +++ b/src/de/steamwar/bungeecore/network/handlers/ImALobbyHandler.java @@ -27,6 +27,6 @@ public class ImALobbyHandler extends PacketHandler { @Handler public void handle(ImALobbyPacket packet) { - FightInfoHandler.addLobby(((ServerMetaInfo) packet.getMetaInfos()).getSender().getServer()); + FightInfoHandler.addLobby(((ServerMetaInfo) packet.getMetaInfos()).sender().getServer()); } } diff --git a/src/de/steamwar/bungeecore/network/handlers/InventoryCallbackHandler.java b/src/de/steamwar/bungeecore/network/handlers/InventoryCallbackHandler.java index bc023da..ae1a789 100644 --- a/src/de/steamwar/bungeecore/network/handlers/InventoryCallbackHandler.java +++ b/src/de/steamwar/bungeecore/network/handlers/InventoryCallbackHandler.java @@ -44,7 +44,7 @@ public class InventoryCallbackHandler extends PacketHandler { if(!inventoryHashMap.containsKey(owner.getId())) { Chatter.of(owner).system("UPDATE_INTERRUPTION"); if(type == InventoryCallbackPacket.CallbackType.CLICK) { - NetworkSender.send((Player) ((ServerMetaInfo) packet.getMetaInfos()).getSender(), new CloseInventoryPacket(owner.getId())); + NetworkSender.send((Player) ((ServerMetaInfo) packet.getMetaInfos()).sender(), new CloseInventoryPacket(owner.getId())); } return; } diff --git a/src/de/steamwar/bungeecore/tablist/Tablist.java b/src/de/steamwar/bungeecore/tablist/Tablist.java index fbef8e8..4f9e638 100644 --- a/src/de/steamwar/bungeecore/tablist/Tablist.java +++ b/src/de/steamwar/bungeecore/tablist/Tablist.java @@ -177,7 +177,7 @@ public class Tablist extends ChannelInboundHandlerAdapter { sendTabPacket(current, null); current.clear(); synchronized (directTabItems) { - sendNpcPacket(npcs.stream().map(npc -> directTabItems.get(npc).getProfile().getName()).collect(Collectors.toList()), true); + sendNpcPacket(npcs.stream().map(npc -> directTabItems.get(npc).getProfile().getName()).toList(), true); npcs.clear(); } diff --git a/src/de/steamwar/bungeecore/tablist/TablistBuild.java b/src/de/steamwar/bungeecore/tablist/TablistBuild.java index 55aae44..31aaf69 100644 --- a/src/de/steamwar/bungeecore/tablist/TablistBuild.java +++ b/src/de/steamwar/bungeecore/tablist/TablistBuild.java @@ -44,7 +44,7 @@ public class TablistBuild implements TablistPart { continue; servers.add(server); - players.put(server, server.getPlayersConnected().stream().sorted(((p1, p2) -> p1.getUsername().compareToIgnoreCase(p2.getUsername()))).map(Item::new).collect(Collectors.toList())); + players.put(server, server.getPlayersConnected().stream().sorted(((p1, p2) -> p1.getUsername().compareToIgnoreCase(p2.getUsername()))).map(Item::new).toList()); } servers.sort((s1, s2) -> s1.getServerInfo().getName().compareToIgnoreCase(s2.getServerInfo().getName())); } diff --git a/src/de/steamwar/bungeecore/tablist/TablistServer.java b/src/de/steamwar/bungeecore/tablist/TablistServer.java index c93924a..9bb7456 100644 --- a/src/de/steamwar/bungeecore/tablist/TablistServer.java +++ b/src/de/steamwar/bungeecore/tablist/TablistServer.java @@ -46,7 +46,7 @@ public class TablistServer implements TablistPart { private final List players; public TablistServer(RegisteredServer server) { - this(server, server.getPlayersConnected().stream().sorted((p1, p2) -> p1.getUsername().compareToIgnoreCase(p2.getUsername())).map(TablistPart.Item::new).collect(Collectors.toList())); + this(server, server.getPlayersConnected().stream().sorted((p1, p2) -> p1.getUsername().compareToIgnoreCase(p2.getUsername())).map(TablistPart.Item::new).toList()); } public TablistServer(RegisteredServer server, FightInfoPacket info) { diff --git a/src/de/steamwar/command/SWCommand.java b/src/de/steamwar/command/SWCommand.java index 00de7ae..968e124 100644 --- a/src/de/steamwar/command/SWCommand.java +++ b/src/de/steamwar/command/SWCommand.java @@ -177,7 +177,7 @@ public class SWCommand extends AbstractSWCommand { chatter.prefixless(s, new Message("PLAIN_STRING", hover), ClickEvent.suggestCommand("/" + name + " " + String.join(" ", subCommand.subCommand))); } } catch (Exception e) { - VelocityCore.getLogger().log(Level.WARNING, "Failed to send description of registered method '" + subCommand.method + "' with description '" + Arrays.toString(subCommand.description) + "'", e); + VelocityCore.getLogger().log(Level.WARNING, "Failed to send description of registered method '{0}' with description '{1}'".formatted(subCommand.method, Arrays.toString(subCommand.description)), e); } } } diff --git a/src/de/steamwar/messages/Chatter.java b/src/de/steamwar/messages/Chatter.java index 14b9c9d..c9961e6 100644 --- a/src/de/steamwar/messages/Chatter.java +++ b/src/de/steamwar/messages/Chatter.java @@ -158,23 +158,23 @@ public interface Chatter { String pattern = ""; if(prefixed) pattern = resourceBundle.getObject("PREFIX") + " "; - pattern += (String)resourceBundle.getObject(message.getFormat()); + pattern += (String)resourceBundle.getObject(message.format()); MessageFormat format = new MessageFormat(pattern, locale); - Object[] params = message.getParams(); + Object[] params = message.params(); for (int i = 0; i < params.length; i++) { - if(params[i] instanceof Message) { - params[i] = parseToLegacy((Message) params[i]); - } else if(params[i] instanceof Date) { - params[i] = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale).format((Date) params[i]); - } else if(params[i] instanceof SteamwarUser) { - params[i] = ((SteamwarUser) params[i]).getUserName(); - } else if(params[i] instanceof Player) { - params[i] = ((Player) params[i]).getUsername(); - } else if(params[i] instanceof Chatter) { - params[i] = ((Chatter) params[i]).user().getUserName(); - } else if(params[i] instanceof Function) { - params[i] = ((Function) params[i]).apply(this); + if(params[i] instanceof Message msg) { + params[i] = parseToLegacy(msg); + } else if(params[i] instanceof Date date) { + params[i] = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale).format(date); + } else if(params[i] instanceof SteamwarUser user) { + params[i] = user.getUserName(); + } else if(params[i] instanceof Player player) { + params[i] = player.getUsername(); + } else if(params[i] instanceof Chatter chatter) { + params[i] = chatter.user().getUserName(); + } else if(params[i] instanceof Function func) { + params[i] = func.apply(this); } } return LegacyComponentSerializer.legacySection().deserialize(format.format(params)); diff --git a/src/de/steamwar/messages/Message.java b/src/de/steamwar/messages/Message.java index dc375f3..3394c27 100644 --- a/src/de/steamwar/messages/Message.java +++ b/src/de/steamwar/messages/Message.java @@ -19,16 +19,4 @@ package de.steamwar.messages; -import lombok.Getter; - -@Getter -public class Message { - - private final String format; - private final Object[] params; - - public Message(String format, Object... params) { - this.format = format; - this.params = params; - } -} \ No newline at end of file +public record Message(String format, Object... params) { } \ No newline at end of file