Update PollresultCommand #393
@ -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<String, Integer> voted = PollAnswer.getCurrentResults();
|
||||
Message.send("POLLRESULT_HEADER", player, voted.values().stream().reduce(Integer::sum).orElse(0), PollSystem.getQuestion());
|
||||
for (Map.Entry<String, Integer> 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;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren