From c803fe27962449ecb4077b612c5646d694a7c582 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 28 Jun 2024 10:12:30 +0200 Subject: [PATCH] Fix DC Command regex, DC Ranks, no current server Signed-off-by: Lixfel --- src/de/steamwar/messages/Chatter.java | 3 ++- src/de/steamwar/velocitycore/discord/DiscordBot.java | 2 +- .../discord/listeners/DiscordTicketHandler.java | 6 +++--- src/de/steamwar/velocitycore/discord/util/DiscordRanks.java | 2 +- src/de/steamwar/velocitycore/tablist/TablistBuild.java | 3 ++- src/de/steamwar/velocitycore/tablist/TablistServer.java | 2 +- 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/de/steamwar/messages/Chatter.java b/src/de/steamwar/messages/Chatter.java index d61a20d..c657130 100644 --- a/src/de/steamwar/messages/Chatter.java +++ b/src/de/steamwar/messages/Chatter.java @@ -23,6 +23,7 @@ import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.event.ResultedEvent; import com.velocitypowered.api.event.connection.LoginEvent; import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.ServerConnection; import de.steamwar.persistent.Servertype; import de.steamwar.persistent.Subserver; import de.steamwar.velocitycore.VelocityCore; @@ -62,7 +63,7 @@ public interface Chatter { static ChatterGroup globalChat() { return new ChatterGroup(Stream.concat(Stream.of(Chatter.console()), allPlayers().filter(player -> { Subserver subserver = Subserver.getSubserver(player); - return subserver == null || !(subserver.getType() == Servertype.ARENA && subserver.getServer() == player.getCurrentServer().get().getServerInfo()); + return subserver == null || !(subserver.getType() == Servertype.ARENA && subserver.getServer() == player.getCurrentServer().map(ServerConnection::getServerInfo).orElse(null)); }).map(Chatter::of))); } diff --git a/src/de/steamwar/velocitycore/discord/DiscordBot.java b/src/de/steamwar/velocitycore/discord/DiscordBot.java index 3015046..17cdf6a 100644 --- a/src/de/steamwar/velocitycore/discord/DiscordBot.java +++ b/src/de/steamwar/velocitycore/discord/DiscordBot.java @@ -187,7 +187,7 @@ public class DiscordBot { updateCommands .addCommands(getCommands() .keySet().stream() - .filter(command -> command.matches("^[\\w-]+$.")) + .filter(command -> command.matches("^[\\w-]+$")) .map(command -> new CommandData(command, "SteamWar Command").addOptions(new OptionData(OptionType.STRING, ARGUMENT_NAME, "SteamWar arguments", false))) .toArray(CommandData[]::new)) .complete(); diff --git a/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java b/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java index 921eba9..90da59a 100644 --- a/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java +++ b/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java @@ -92,11 +92,11 @@ public class DiscordTicketHandler extends ListenerAdapter { .append(" ") .append("**").append(message.getAuthor().getName()).append("**: ") .append(message.getContentRaw()) - .append("\n\n"); + .append("\n"); if(!message.getAttachments().isEmpty()) { message.getAttachments().forEach(attachment -> stringBuilder.append(attachment.getUrl())); - stringBuilder.append("\n\n"); + stringBuilder.append("\n"); } return stringBuilder; @@ -158,7 +158,7 @@ public class DiscordTicketHandler extends ListenerAdapter { //ignored } - receivers.system("DISCORD_TICKET_MESSAGE", new Message("DISCORD_TICKET_HOVER"), ClickEvent.openUrl(event.getMessage().getJumpUrl()), event.getChannel().getName(), event.getAuthor().getName(), event.getMessage().getContentRaw()); + receivers.prefixless("DISCORD_TICKET_MESSAGE", new Message("DISCORD_TICKET_HOVER"), ClickEvent.openUrl(event.getMessage().getJumpUrl()), event.getChannel().getName(), event.getAuthor().getName(), event.getMessage().getContentRaw()); } } } diff --git a/src/de/steamwar/velocitycore/discord/util/DiscordRanks.java b/src/de/steamwar/velocitycore/discord/util/DiscordRanks.java index 3a392bd..098dfa2 100644 --- a/src/de/steamwar/velocitycore/discord/util/DiscordRanks.java +++ b/src/de/steamwar/velocitycore/discord/util/DiscordRanks.java @@ -49,7 +49,7 @@ public class DiscordRanks { .filter(role -> !role.getId().equals(prefixRole)) .forEach(role -> guild.removeRoleFromMember(member, role).queue()); - if (member.getRoles().stream().noneMatch(role -> role.getId().equals(prefixRole))) + if (member.getRoles().stream().noneMatch(role -> role.getId().equals(prefixRole)) && guild.getRoleById(prefixRole) != null) guild.addRoleToMember(member, guild.getRoleById(prefixRole)).queue(); }, e -> { if(e instanceof ErrorResponseException err && err.getErrorCode() == 10007) diff --git a/src/de/steamwar/velocitycore/tablist/TablistBuild.java b/src/de/steamwar/velocitycore/tablist/TablistBuild.java index 7a233cb..26e2283 100644 --- a/src/de/steamwar/velocitycore/tablist/TablistBuild.java +++ b/src/de/steamwar/velocitycore/tablist/TablistBuild.java @@ -20,6 +20,7 @@ package de.steamwar.velocitycore.tablist; import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.ServerConnection; import com.velocitypowered.api.proxy.server.RegisteredServer; import de.steamwar.persistent.Servertype; import de.steamwar.persistent.Subserver; @@ -55,7 +56,7 @@ public class TablistBuild implements TablistPart { @Override public void print(Chatter viewer, Player player, List tablist, List direct) { - RegisteredServer server = player.getCurrentServer().orElseThrow().getServer(); + RegisteredServer server = player.getCurrentServer().map(ServerConnection::getServer).orElse(null); if(players.keySet().stream().anyMatch(info -> server != info)) { tablist.add(new Item(null, "", TablistServer.GRAY)); tablist.add(new Item(null, viewer.parseToLegacy("TABLIST_BAU"), TablistServer.LIGHT_GRAY)); diff --git a/src/de/steamwar/velocitycore/tablist/TablistServer.java b/src/de/steamwar/velocitycore/tablist/TablistServer.java index b650400..6601f2c 100644 --- a/src/de/steamwar/velocitycore/tablist/TablistServer.java +++ b/src/de/steamwar/velocitycore/tablist/TablistServer.java @@ -69,7 +69,7 @@ public class TablistServer implements TablistPart { @Override public void print(Chatter viewer, Player player, List tablist, List direct) { - boolean onServer = player.getCurrentServer().orElseThrow().getServer() == server; + boolean onServer = player.getCurrentServer().map(ServerConnection::getServer).orElse(null) == server; List items = onServer ? direct : tablist; if(!onServer) {