SteamWar/BungeeCore
Archiviert
13
2

Merge pull request 'Update PollCommand' (#392) from CommandPoll into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #392
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2022-06-16 13:24:40 +02:00
Commit c1a721cf4d

Datei anzeigen

@ -23,35 +23,29 @@ import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.listeners.PollSystem; import de.steamwar.bungeecore.listeners.PollSystem;
import de.steamwar.bungeecore.sql.PollAnswer; import de.steamwar.bungeecore.sql.PollAnswer;
import de.steamwar.bungeecore.sql.SteamwarUser; 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.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
public class PollCommand extends BasicCommand { public class PollCommand extends SWCommand {
public PollCommand() { public PollCommand() {
super("poll", ""); super("poll");
} }
@Override @Register
public void execute(CommandSender sender, String[] args) { public void genericCommand(@Guard ProxiedPlayer player) {
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); PollSystem.sendPoll(player);
return;
} }
@Register(noTabComplete = true)
public void answerPoll(@Guard ProxiedPlayer player, String answerString) {
int answer; int answer;
try { try {
answer = Integer.parseUnsignedInt(args[0]); answer = Integer.parseUnsignedInt(answerString);
if(answer < 1 || answer > PollSystem.answers()) if(answer < 1 || answer > PollSystem.answers())
throw new NumberFormatException(); throw new NumberFormatException();
}catch(NumberFormatException e){ }catch(NumberFormatException e){
@ -67,4 +61,17 @@ public class PollCommand extends BasicCommand {
pollAnswer.setAnswer(answer); 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;
};
}
} }