geforkt von SteamWar/BungeeCore
Merge pull request 'Update PollCommand' (#392) from CommandPoll into master
Reviewed-on: SteamWar/BungeeCore#392 Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Commit
c1a721cf4d
@ -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;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren