SteamWar/BungeeCore
Archiviert
13
2

Update PollCommand #392

Zusammengeführt
Lixfel hat 1 Commits von CommandPoll nach master 2022-06-16 13:24:41 +02:00 zusammengeführt
Nur Änderungen aus Commit fd14666880 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -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;
};
}
}