SteamWar/BungeeCore
Archiviert
13
2

Fix some SonarLint Issues and Modernize Java #517

Zusammengeführt
Lixfel hat 3 Commits von modernize nach velocity 2024-06-20 22:20:50 +02:00 zusammengeführt
39 geänderte Dateien mit 85 neuen und 115 gelöschten Zeilen
Nur Änderungen aus Commit 07c7635ab4 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -50,11 +50,6 @@ public class Bauserver extends Subserver {
}
}
@Override
protected void register() {
super.register();
}
@Override
protected void unregister() {
synchronized (servers) {

Datei anzeigen

@ -49,11 +49,6 @@ public class Builderserver extends Subserver {
}
}
@Override
protected void register() {
super.register();
}
@Override
protected void unregister() {
synchronized (servers) {

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -65,7 +65,7 @@ public class ArenaCommand extends SWCommand {
public Collection<String> tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) {
List<Subserver> 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();
}
}
};

Datei anzeigen

@ -183,7 +183,7 @@ public class BauCommand extends SWCommand {
public Collection<String> 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();
}
};
}

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -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<String, List<Player>> getCustomTablist(){
TreeMap<String, List<Player>> playerMap = new TreeMap<>();
public static synchronized SortedMap<String, List<Player>> getCustomTablist(){
SortedMap<String, List<Player>> 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<String, List<Player>> playerMap = getCustomTablist();
for (String server : playerMap.navigableKeySet()) {
SortedMap<String, List<Player>> playerMap = getCustomTablist();
for (String server : playerMap.keySet()) {
String serverName = server;
if (server.equals("Bau")) {
serverName = sender.parseToLegacy("TABLIST_BAU");

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -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<SteamwarUser> users = team.getMembers().stream().map(SteamwarUser::get).collect(Collectors.toList());
List<SteamwarUser> 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<String> 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<String> 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<String> 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<String> tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) {
return Team.getAll().stream()
.flatMap(team -> Stream.of(team.getTeamName(), team.getTeamKuerzel()))
.collect(Collectors.toList());
.toList();
}
};
}

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -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()});
Lixfel markierte diese Unterhaltung als gelöst Veraltet
Veraltet
Review

Das new Object[] Zeugs halte ich für so viel unschöneren Code... bitte umarbeiten.

Das new Object[] Zeugs halte ich für so viel unschöneren Code... bitte umarbeiten.
VelocityCore.schedule(() -> TOKENS.remove(code)).delay(10, TimeUnit.MINUTES).schedule();
return code;
}

Datei anzeigen

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

Datei anzeigen

@ -46,7 +46,7 @@ import java.util.stream.Collectors;
public class ChatListener extends BasicListener {
private static final List<String> rankedModes = ArenaMode.getAllModes().stream().filter(ArenaMode::isRanked).map(ArenaMode::getSchemType).collect(Collectors.toList());
private static final List<String> 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()});
Lixfel markierte diese Unterhaltung als gelöst Veraltet
Veraltet
Review

.

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -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(" "))});
Lixfel markierte diese Unterhaltung als gelöst Veraltet
Veraltet
Review

.

.
ModType max = ModType.YELLOW;
Iterator<Mod> 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});
Lixfel markierte diese Unterhaltung als gelöst Veraltet
Veraltet
Review

.

.
}
disconnect.accept(LegacyComponentSerializer.legacySection().deserialize(message));

Datei anzeigen

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

Datei anzeigen

@ -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 {}

Datei anzeigen

@ -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;
Lixfel markierte diese Unterhaltung als gelöst Veraltet
Veraltet
Review

Sr, was mir hier gerade wieder eingefallen ist: NotNull und Nullable sind ganz böse (müssen weg). In IntelliJ hast du das Jetbrains-Package, der Buildserver eher weniger... Deswegen bitte rausentfernen.

Sr, was mir hier gerade wieder eingefallen ist: NotNull und Nullable sind ganz böse (müssen weg). In IntelliJ hast du das Jetbrains-Package, der Buildserver eher weniger... Deswegen bitte rausentfernen.
Veraltet
Review

War hier die einzige Stelle.

War hier die einzige Stelle.
Veraltet
Review

Ist durch JDA auch im Build-Path, sollte also auch in der CI-Bauen, kanns aber entfernen.

Ist durch JDA auch im Build-Path, sollte also auch in der CI-Bauen, kanns aber entfernen.
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<String> 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<String> 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<String> 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);
}

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -46,7 +46,7 @@ public class TablistServer implements TablistPart {
private final List<Item> 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) {

Datei anzeigen

@ -177,7 +177,7 @@ public class SWCommand extends AbstractSWCommand<Chatter> {
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);
}
}
}

Datei anzeigen

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

Datei anzeigen

@ -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;
}
}
public record Message(String format, Object... params) { }