Add PollResult Command #153
@ -119,6 +119,7 @@ public class BungeeCore extends Plugin {
|
||||
new RankCommand();
|
||||
new IgnoreCommand();
|
||||
new UnIgnoreCommand();
|
||||
new PollresultCommand();
|
||||
|
||||
if(!EVENT_MODE){
|
||||
new WebregisterCommand();
|
||||
|
50
src/de/steamwar/bungeecore/commands/PollresultCommand.java
Normale Datei
50
src/de/steamwar/bungeecore/commands/PollresultCommand.java
Normale Datei
@ -0,0 +1,50 @@
|
||||
/*
|
||||
This file is a part of the SteamWar software.
|
||||
|
||||
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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 net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class PollresultCommand extends BasicCommand {
|
||||
|
||||
public PollresultCommand() {
|
||||
super("pollresult", "bungeecore.pollresults");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] strings) {
|
||||
if(!(sender instanceof ProxiedPlayer))
|
||||
return;
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
|
||||
Map<String, Integer> voted = PollAnswer.getCurrentResults();
|
||||
Message.send("POLLRESULT_HEADER", player, PollAnswer.getAllAnswered(), PollSystem.getQuestion());
|
||||
int i = 1;
|
||||
for (Map.Entry<String, Integer> e: voted.entrySet()) {
|
||||
Message.send("POLLRESULT_LIST", sender, i, e.getKey(), e.getValue());
|
||||
i++;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -78,4 +78,8 @@ public class PollSystem extends BasicListener {
|
||||
public static int answers(){
|
||||
return answers.size();
|
||||
}
|
||||
|
||||
public static String getAnswer(int i) {
|
||||
return answers.get(i);
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ import de.steamwar.bungeecore.listeners.PollSystem;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PollAnswer {
|
||||
|
||||
@ -53,6 +55,32 @@ public class PollAnswer {
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String, Integer> getCurrentResults() {
|
||||
ResultSet set = SQL.select("SELECT Count(UserID) AS Times, Answer FROM PollAnswer WHERE Question = ? GROUP BY Answer ORDER BY `Times` ASC", PollSystem.getQuestion());
|
||||
try {
|
||||
Map<String, Integer> retMap = new HashMap<>();
|
||||
while (set.next()) {
|
||||
retMap.put(PollSystem.getAnswer(set.getInt("Answer")), set.getInt("Times"));
|
||||
}
|
||||
return retMap;
|
||||
}catch (SQLException e) {
|
||||
BungeeCore.log("Unable to get PollAnswer", e);
|
||||
throw new SecurityException();
|
||||
Lixfel
hat
throw new SecurityException("Unable to get PollAnswer", e); Kein extra-loggen vorher, weil du möchtest nicht den Bungeelog nach Fehlern durchsuchen! throw new SecurityException("Unable to get PollAnswer", e);
Kein extra-loggen vorher, weil du möchtest nicht den Bungeelog nach Fehlern durchsuchen!
|
||||
}
|
||||
}
|
||||
|
||||
public static Integer getAllAnswered() {
|
||||
ResultSet set = SQL.select("SELECT Count(UserID) AS Times FROM PollAnswer");
|
||||
Lixfel
hat
Da sollte man evtl. noch nach WHERE Question = ? überprüfen. Da sollte man evtl. noch nach WHERE Question = ? überprüfen.
|
||||
try {
|
||||
if(!set.next())
|
||||
throw new SecurityException("Could not get PollAnswers");
|
||||
return set.getInt("Times");
|
||||
}catch (SQLException e) {
|
||||
BungeeCore.log("Unable to get PollAnswer", e);
|
||||
throw new SecurityException();
|
||||
Lixfel
hat
Genauso. Genauso.
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasAnswered(){
|
||||
return answer != 0;
|
||||
}
|
||||
|
@ -53,3 +53,7 @@ HELP_BAU_TESTARENA=§8/§ebau testarena §8- §7Starte eine Testarena
|
||||
HELP_BAU_TESTARENA_HOVER=§eTestarena starten
|
||||
HELP_BAU_BAU=§8/§ehelp bau §8- §7Hilfe zu nützlichen Werkzeugen
|
||||
HELP_BAU_BAU_HOVER=§eNützliche Zusatzfunktionen
|
||||
|
||||
#PollresultCommand
|
||||
POLLRESULT_HEADER=§e§lEs haben {0} abgestimmt auf die Frage: §f{1}
|
||||
Lixfel
hat
Das ganze würde ich nicht §e§l machen, das wäre etwas penetrant, eher §7§l oder nur §e. Dazu bitte nicht §f (Nicht im Farbschema!), wenn dann §7 Das ganze würde ich nicht §e§l machen, das wäre etwas penetrant, eher §7§l oder nur §e. Dazu bitte nicht §f (Nicht im Farbschema!), wenn dann §7
|
||||
POLLRESULT_LIST=§e{0}. §7{1} mit {2} stimmen
|
||||
Lixfel
hat
Bitte eher §e{2}§8: §7{1} Bitte eher §e{2}§8: §7{1}
|
In neuem Issue referenzieren
Einen Benutzer sperren
i ist nicht wirklich sinnvoll, kann man weglassen.