From a7541dc0c31bf398133914b45bcb204b56edb7ee Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 16 Jun 2022 10:57:12 +0200 Subject: [PATCH] Update PollresultCommand --- .../commands/PollresultCommand.java | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/PollresultCommand.java b/src/de/steamwar/bungeecore/commands/PollresultCommand.java index df77cb8..4011f4c 100644 --- a/src/de/steamwar/bungeecore/commands/PollresultCommand.java +++ b/src/de/steamwar/bungeecore/commands/PollresultCommand.java @@ -22,33 +22,39 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.listeners.PollSystem; import de.steamwar.bungeecore.sql.PollAnswer; -import net.md_5.bungee.api.CommandSender; +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.connection.ProxiedPlayer; import java.util.Map; -public class PollresultCommand extends BasicCommand { +public class PollresultCommand extends SWCommand { public PollresultCommand() { super("pollresult", "bungeecore.pollresults"); } - @Override - public void execute(CommandSender sender, String[] strings) { - if(!(sender instanceof ProxiedPlayer)) - return; - - if(PollSystem.noCurrentPoll()) { - Message.send("POLLRESULT_NOPOLL", sender); - return; - } - - ProxiedPlayer player = (ProxiedPlayer) sender; - + @Register + public void genericCommand(@Guard 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()) { - Message.send("POLLRESULT_LIST", sender, e.getKey(), e.getValue()); + Message.send("POLLRESULT_LIST", player, e.getKey(), e.getValue()); } } + + @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; + } + return GuardResult.ALLOWED; + }; + } }