From fd14666880b904b0ad98e0141358812c1af2cda2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 15 Jun 2022 20:18:31 +0200 Subject: [PATCH] Update PollCommand --- .../bungeecore/commands/PollCommand.java | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/PollCommand.java b/src/de/steamwar/bungeecore/commands/PollCommand.java index 3a84f50b..e6fb7550 100644 --- a/src/de/steamwar/bungeecore/commands/PollCommand.java +++ b/src/de/steamwar/bungeecore/commands/PollCommand.java @@ -23,35 +23,29 @@ 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 net.md_5.bungee.api.connection.ProxiedPlayer; -public class PollCommand extends BasicCommand { +public class PollCommand extends SWCommand { public PollCommand() { - super("poll", ""); + super("poll"); } - @Override - public void execute(CommandSender sender, String[] args) { - if(!(sender instanceof ProxiedPlayer)) - return; - - ProxiedPlayer player = (ProxiedPlayer) sender; - - if(PollSystem.noCurrentPoll()){ - Message.send("POLL_NO_POLL", player); - return; - } - - if(args.length == 0){ - PollSystem.sendPoll(player); - return; - } + @Register + public void genericCommand(@Guard ProxiedPlayer player) { + PollSystem.sendPoll(player); + } + @Register(noTabComplete = true) + public void answerPoll(@Guard ProxiedPlayer player, String answerString) { int answer; try { - answer = Integer.parseUnsignedInt(args[0]); + answer = Integer.parseUnsignedInt(answerString); if(answer < 1 || answer > PollSystem.answers()) throw new NumberFormatException(); }catch(NumberFormatException e){ @@ -67,4 +61,17 @@ public class PollCommand extends BasicCommand { pollAnswer.setAnswer(answer); } + + @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; + }; + } }