From ba75129d5735a4f8e34731940a70a120d3888754 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 28 Jun 2024 10:37:48 +0200 Subject: [PATCH] Fix DiscordRanks, TypeValidators Signed-off-by: Lixfel --- src/de/steamwar/velocitycore/ErrorLogger.java | 20 +++++++++---------- .../commands/ChallengeCommand.java | 8 ++++---- .../velocitycore/commands/DevCommand.java | 4 +++- .../velocitycore/commands/TeamCommand.java | 8 ++++---- .../discord/util/DiscordRanks.java | 2 +- .../velocitycore/listeners/PollSystem.java | 2 +- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/de/steamwar/velocitycore/ErrorLogger.java b/src/de/steamwar/velocitycore/ErrorLogger.java index 0da1ff0..99b06a8 100644 --- a/src/de/steamwar/velocitycore/ErrorLogger.java +++ b/src/de/steamwar/velocitycore/ErrorLogger.java @@ -30,8 +30,6 @@ import org.apache.logging.log4j.core.config.Property; import java.io.ByteArrayOutputStream; import java.io.PrintStream; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; public class ErrorLogger extends AbstractAppender { @@ -59,7 +57,7 @@ public class ErrorLogger extends AbstractAppender { return; String message = event.getMessage().getFormattedMessage(); - for(String reason : ignoreContains) + for(String reason : filteredMessages) if(message.contains(reason)) return; @@ -67,16 +65,16 @@ public class ErrorLogger extends AbstractAppender { if(event.getThrown() != null) event.getThrown().printStackTrace(new PrintStream(stacktraceOutput)); String stacktrace = stacktraceOutput.toString(); - if (stacktrace.contains("ErrorLogger")) - return; + for(String reason : filteredStacktraces) + if (stacktrace.contains(reason)) + return; SWException.log(message, stacktrace); } - private static final List ignoreContains; - - static { - List contains = new ArrayList<>(); - ignoreContains = Collections.unmodifiableList(contains); - } + private static final List filteredMessages = List.of(); + private static final List filteredStacktraces = List.of( + "ErrorLogger", + "Connection reset by peer" + ); } diff --git a/src/de/steamwar/velocitycore/commands/ChallengeCommand.java b/src/de/steamwar/velocitycore/commands/ChallengeCommand.java index 83795e2..d720f9d 100644 --- a/src/de/steamwar/velocitycore/commands/ChallengeCommand.java +++ b/src/de/steamwar/velocitycore/commands/ChallengeCommand.java @@ -72,21 +72,21 @@ public class ChallengeCommand extends SWCommand { public TypeValidator targetValidator() { return (sender, value, messageSender) -> { if (value == null) { - sender.system("CHALLENGE_OFFLINE"); + messageSender.send("CHALLENGE_OFFLINE"); return false; } if (sender == value) { - sender.system("CHALLENGE_SELF"); + messageSender.send("CHALLENGE_SELF"); return false; } if (IgnoreSystem.isIgnored(value.getUniqueId(), sender.user().getUUID())) { - sender.system("CHALLENGE_IGNORED"); + messageSender.send("CHALLENGE_IGNORED"); return false; } Subserver subserver = Subserver.getSubserver(value); if (subserver != null && subserver.getType() == Servertype.ARENA) { - sender.system("CHALLENGE_INARENA"); + messageSender.send("CHALLENGE_INARENA"); return false; } return true; diff --git a/src/de/steamwar/velocitycore/commands/DevCommand.java b/src/de/steamwar/velocitycore/commands/DevCommand.java index fc9b519..005e5fe 100644 --- a/src/de/steamwar/velocitycore/commands/DevCommand.java +++ b/src/de/steamwar/velocitycore/commands/DevCommand.java @@ -21,6 +21,7 @@ package de.steamwar.velocitycore.commands; import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.ServerInfo; +import de.steamwar.messages.Message; import de.steamwar.velocitycore.VelocityCore; import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommandUtils; @@ -80,7 +81,8 @@ public class DevCommand extends SWCommand { public TypeValidator punishmentGuardChecker() { return (sender, value, messageSender) -> { if (sender.user().isPunished(Punishment.PunishmentType.NoDevServer)) { - sender.system(PunishmentCommand.punishmentMessage(sender.user(), Punishment.PunishmentType.NoDevServer)); + Message message = PunishmentCommand.punishmentMessage(sender.user(), Punishment.PunishmentType.NoDevServer); + messageSender.send(message.format(), message.params()); return false; } return true; diff --git a/src/de/steamwar/velocitycore/commands/TeamCommand.java b/src/de/steamwar/velocitycore/commands/TeamCommand.java index a6fa700..32b65e9 100644 --- a/src/de/steamwar/velocitycore/commands/TeamCommand.java +++ b/src/de/steamwar/velocitycore/commands/TeamCommand.java @@ -521,7 +521,7 @@ public class TeamCommand extends SWCommand { public TypeValidator isNotInTeamValidator() { return (sender, value, messageSender) -> { if (sender.user().getTeam() != 0) { - sender.system("TEAM_IN_TEAM"); + messageSender.send("TEAM_IN_TEAM"); return false; } return true; @@ -532,7 +532,7 @@ public class TeamCommand extends SWCommand { public TypeValidator isInTeamValidator() { return (sender, value, messageSender) -> { if (sender.user().getTeam() == 0) { - sender.system("TEAM_NOT_IN_TEAM"); + messageSender.send("TEAM_NOT_IN_TEAM"); return false; } return true; @@ -544,11 +544,11 @@ public class TeamCommand extends SWCommand { return (sender, value, messageSender) -> { SteamwarUser user = sender.user(); if (user.getTeam() == 0) { - sender.system("TEAM_NOT_IN_TEAM"); + messageSender.send("TEAM_NOT_IN_TEAM"); return false; } if (!user.isLeader()) { - sender.system("TEAM_NOT_LEADER"); + messageSender.send("TEAM_NOT_LEADER"); return false; } return true; diff --git a/src/de/steamwar/velocitycore/discord/util/DiscordRanks.java b/src/de/steamwar/velocitycore/discord/util/DiscordRanks.java index 098dfa2..d96e9fe 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)) && guild.getRoleById(prefixRole) != null) + if (prefixRole != null && member.getRoles().stream().noneMatch(role -> role.getId().equals(prefixRole))) guild.addRoleToMember(member, guild.getRoleById(prefixRole)).queue(); }, e -> { if(e instanceof ErrorResponseException err && err.getErrorCode() == 10007) diff --git a/src/de/steamwar/velocitycore/listeners/PollSystem.java b/src/de/steamwar/velocitycore/listeners/PollSystem.java index 2b5a31a..c027869 100644 --- a/src/de/steamwar/velocitycore/listeners/PollSystem.java +++ b/src/de/steamwar/velocitycore/listeners/PollSystem.java @@ -74,7 +74,7 @@ public class PollSystem extends BasicListener { public static TypeValidator noPoll() { return (sender, value, messageSender) -> { if (PollSystem.noCurrentPoll()) { - sender.system("POLL_NO_POLL"); + messageSender.send("POLL_NO_POLL"); return false; } return true;