SteamWar/BungeeCore
Archiviert
13
2

Update PollresultCommand
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2022-06-16 10:57:12 +02:00
Ursprung 8a21d5c93d
Commit a7541dc0c3

Datei anzeigen

@ -22,33 +22,39 @@ package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.Message; 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 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 net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.Map; import java.util.Map;
public class PollresultCommand extends BasicCommand { public class PollresultCommand extends SWCommand {
public PollresultCommand() { public PollresultCommand() {
super("pollresult", "bungeecore.pollresults"); super("pollresult", "bungeecore.pollresults");
} }
@Override @Register
public void execute(CommandSender sender, String[] strings) { public void genericCommand(@Guard ProxiedPlayer player) {
if(!(sender instanceof ProxiedPlayer))
return;
if(PollSystem.noCurrentPoll()) {
Message.send("POLLRESULT_NOPOLL", sender);
return;
}
ProxiedPlayer player = (ProxiedPlayer) sender;
Map<String, Integer> voted = PollAnswer.getCurrentResults(); Map<String, Integer> voted = PollAnswer.getCurrentResults();
Message.send("POLLRESULT_HEADER", player, voted.values().stream().reduce(Integer::sum).orElse(0), PollSystem.getQuestion()); Message.send("POLLRESULT_HEADER", player, voted.values().stream().reduce(Integer::sum).orElse(0), PollSystem.getQuestion());
for (Map.Entry<String, Integer> e: voted.entrySet()) { 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;
};
}
} }