From e29fb553f0dd2e99045d2c70cb2f2216f3a53692 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 22 Aug 2022 20:25:36 +0200 Subject: [PATCH] Remove deprecated guard api --- .../bungeecore/commands/DevCommand.java | 27 ++++++++--------- .../bungeecore/commands/PollCommand.java | 21 +++++-------- .../commands/PollresultCommand.java | 22 ++++++-------- .../bungeecore/commands/TutorialCommand.java | 21 ++++--------- src/de/steamwar/command/GuardChecker.java | 30 ------------------- src/de/steamwar/command/SWCommand.java | 2 +- 6 files changed, 36 insertions(+), 87 deletions(-) delete mode 100644 src/de/steamwar/command/GuardChecker.java diff --git a/src/de/steamwar/bungeecore/commands/DevCommand.java b/src/de/steamwar/bungeecore/commands/DevCommand.java index 4f06408..5858a49 100644 --- a/src/de/steamwar/bungeecore/commands/DevCommand.java +++ b/src/de/steamwar/bungeecore/commands/DevCommand.java @@ -19,6 +19,7 @@ package de.steamwar.bungeecore.commands; +import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.command.*; @@ -42,7 +43,7 @@ public class DevCommand extends SWCommand { } @Register - public void simpleCommand(@Guard ProxiedPlayer player) { + public void simpleCommand(@Validator ProxiedPlayer player) { updateDevServers(); ChatSender sender = ChatSender.of(player); if (devServers.isEmpty()) { @@ -63,7 +64,7 @@ public class DevCommand extends SWCommand { } @Register - public void selectedCommand(@Guard ProxiedPlayer player, @Mapper("dev") String name) { + public void selectedCommand(@Validator ProxiedPlayer player, @Mapper("dev") String name) { updateDevServers(); ChatSender sender = ChatSender.of(player); ServerInfo info = devServers.get(name.toLowerCase()); @@ -75,20 +76,16 @@ public class DevCommand extends SWCommand { player.connect(info); } - @ClassGuard(value = ProxiedPlayer.class, local = true) - public GuardChecker punishmentGuardChecker() { - return (commandSender, guardCheckType, previousArguments, s) -> { - ChatSender sender = ChatSender.of(commandSender); - if (guardCheckType == GuardCheckType.COMMAND) { - if (sender.user().isPunishedWithMessage(sender, Punishment.PunishmentType.NoDevServer)) { - return GuardResult.DENIED; - } - } else { - if (sender.user().isPunished(Punishment.PunishmentType.NoDevServer)) { - return GuardResult.DENIED; - } + @ClassValidator(value = ProxiedPlayer.class, local = true) + public TypeValidator punishmentGuardChecker() { + return (sender, value, messageSender) -> { + SteamwarUser user = SteamwarUser.get(value); + if (user.isPunished(Punishment.PunishmentType.NoDevServer)) { + Message message = user.punishmentMessage(Punishment.PunishmentType.NoDevServer); + messageSender.send(message.getFormat(), message.getParams()); + return false; } - return GuardResult.ALLOWED; + return true; }; } diff --git a/src/de/steamwar/bungeecore/commands/PollCommand.java b/src/de/steamwar/bungeecore/commands/PollCommand.java index e6fb755..48400e5 100644 --- a/src/de/steamwar/bungeecore/commands/PollCommand.java +++ b/src/de/steamwar/bungeecore/commands/PollCommand.java @@ -23,11 +23,8 @@ import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.listeners.PollSystem; import de.steamwar.bungeecore.sql.PollAnswer; import de.steamwar.bungeecore.sql.SteamwarUser; -import de.steamwar.command.GuardCheckType; -import de.steamwar.command.GuardChecker; -import de.steamwar.command.GuardResult; import de.steamwar.command.SWCommand; -import net.md_5.bungee.api.CommandSender; +import de.steamwar.command.TypeValidator; import net.md_5.bungee.api.connection.ProxiedPlayer; public class PollCommand extends SWCommand { @@ -42,7 +39,7 @@ public class PollCommand extends SWCommand { } @Register(noTabComplete = true) - public void answerPoll(@Guard ProxiedPlayer player, String answerString) { + public void answerPoll(@Validator ProxiedPlayer player, String answerString) { int answer; try { answer = Integer.parseUnsignedInt(answerString); @@ -62,16 +59,14 @@ public class PollCommand extends SWCommand { pollAnswer.setAnswer(answer); } - @ClassGuard(value = ProxiedPlayer.class, local = true) - public GuardChecker noPoll() { - return (commandSender, guardCheckType, previousArguments, s) -> { + @ClassValidator(value = ProxiedPlayer.class, local = true) + public TypeValidator noPoll() { + return (sender, value, messageSender) -> { if(PollSystem.noCurrentPoll()){ - if (guardCheckType == GuardCheckType.COMMAND) { - Message.send("POLL_NO_POLL", commandSender); - } - return GuardResult.DENIED; + messageSender.send("POLL_NO_POLL"); + return false; } - return GuardResult.ALLOWED; + return true; }; } } diff --git a/src/de/steamwar/bungeecore/commands/PollresultCommand.java b/src/de/steamwar/bungeecore/commands/PollresultCommand.java index 4011f4c..554efcc 100644 --- a/src/de/steamwar/bungeecore/commands/PollresultCommand.java +++ b/src/de/steamwar/bungeecore/commands/PollresultCommand.java @@ -22,10 +22,8 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.listeners.PollSystem; import de.steamwar.bungeecore.sql.PollAnswer; -import de.steamwar.command.GuardCheckType; -import de.steamwar.command.GuardChecker; -import de.steamwar.command.GuardResult; import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeValidator; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.Map; @@ -37,7 +35,7 @@ public class PollresultCommand extends SWCommand { } @Register - public void genericCommand(@Guard ProxiedPlayer player) { + public void genericCommand(@Validator ProxiedPlayer player) { Map voted = PollAnswer.getCurrentResults(); Message.send("POLLRESULT_HEADER", player, voted.values().stream().reduce(Integer::sum).orElse(0), PollSystem.getQuestion()); for (Map.Entry e: voted.entrySet()) { @@ -45,16 +43,14 @@ public class PollresultCommand extends SWCommand { } } - @ClassGuard(value = ProxiedPlayer.class, local = true) - public GuardChecker noPoll() { - return (commandSender, guardCheckType, previousArguments, s) -> { - if(PollSystem.noCurrentPoll()){ - if (guardCheckType == GuardCheckType.COMMAND) { - Message.send("POLL_NO_POLL", commandSender); - } - return GuardResult.DENIED; + @ClassValidator(value = ProxiedPlayer.class, local = true) + public TypeValidator noPoll() { + return (sender, value, messageSender) -> { + if (PollSystem.noCurrentPoll()) { + messageSender.send("POLL_NO_POLL"); + return false; } - return GuardResult.ALLOWED; + return true; }; } } diff --git a/src/de/steamwar/bungeecore/commands/TutorialCommand.java b/src/de/steamwar/bungeecore/commands/TutorialCommand.java index e5e3134..72d0e2a 100644 --- a/src/de/steamwar/bungeecore/commands/TutorialCommand.java +++ b/src/de/steamwar/bungeecore/commands/TutorialCommand.java @@ -26,9 +26,8 @@ import de.steamwar.bungeecore.inventory.SWListInv; import de.steamwar.bungeecore.inventory.SWStreamInv; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.Tutorial; -import de.steamwar.command.GuardChecker; -import de.steamwar.command.GuardResult; import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeValidator; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -78,22 +77,14 @@ public class TutorialCommand extends SWCommand { } @Register("unreleased") - public void unreleased(@Guard("unreleased") ProxiedPlayer player) { + public void unreleased(@Validator("unreleased") ProxiedPlayer player) { openInventory(player, false, false); } - @Guard("unreleased") - public GuardChecker unreleasedChecker() { - return (commandSender, guardCheckType, previousArguments, s) -> { - if (commandSender instanceof ProxiedPlayer) { - if (SteamwarUser.get(((ProxiedPlayer) commandSender).getUniqueId()).getUserGroup().isTeamGroup()) { - return GuardResult.ALLOWED; - } else { - return GuardResult.DENIED_WITH_HELP; - } - } else { - return GuardResult.ALLOWED; - } + @Validator("unreleased") + public TypeValidator unreleasedChecker() { + return (sender, value, messageSender) -> { + return (SteamwarUser.get((value).getUniqueId()).getUserGroup().isTeamGroup()); }; } diff --git a/src/de/steamwar/command/GuardChecker.java b/src/de/steamwar/command/GuardChecker.java deleted file mode 100644 index 06c9110..0000000 --- a/src/de/steamwar/command/GuardChecker.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.command; - -import net.md_5.bungee.api.CommandSender; - -@FunctionalInterface -public interface GuardChecker extends AbstractGuardChecker { - /** - * While guarding the first parameter of the command the parameter s of this method is {@code null} - */ - GuardResult guard(CommandSender commandSender, GuardCheckType guardCheckType, String[] previousArguments, String s); -} diff --git a/src/de/steamwar/command/SWCommand.java b/src/de/steamwar/command/SWCommand.java index f8c3647..3938c61 100644 --- a/src/de/steamwar/command/SWCommand.java +++ b/src/de/steamwar/command/SWCommand.java @@ -149,7 +149,7 @@ public class SWCommand extends AbstractSWCommand { } if (args.length == 0 || atomicInteger.get() == commandList.size()) { commandList.forEach(subCommand -> { - if (subCommand.guardChecker == null || subCommand.guardChecker.guard(p, GuardCheckType.TAB_COMPLETE, new String[0], null) == GuardResult.ALLOWED) { + if (subCommand.validator == null || subCommand.validator.validate(p, p, (s, args1) -> {})) { send(chatSender, subCommand); } });