forked from SteamWar/SteamWar
@@ -1,78 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2025 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.sql
|
|
||||||
|
|
||||||
import de.steamwar.sql.internal.useDb
|
|
||||||
import org.jetbrains.exposed.v1.core.VarCharColumnType
|
|
||||||
import org.jetbrains.exposed.v1.core.and
|
|
||||||
import org.jetbrains.exposed.v1.core.dao.id.CompositeID
|
|
||||||
import org.jetbrains.exposed.v1.core.dao.id.CompositeIdTable
|
|
||||||
import org.jetbrains.exposed.v1.core.dao.id.EntityID
|
|
||||||
import org.jetbrains.exposed.v1.core.eq
|
|
||||||
import org.jetbrains.exposed.v1.dao.CompositeEntity
|
|
||||||
import org.jetbrains.exposed.v1.dao.CompositeEntityClass
|
|
||||||
|
|
||||||
object PollAnswerTable: CompositeIdTable("PollAnswer") {
|
|
||||||
val userId = reference("UserID", SteamwarUserTable)
|
|
||||||
val question = varchar("Question", 150)
|
|
||||||
val answer = integer("Answer")
|
|
||||||
}
|
|
||||||
|
|
||||||
class PollAnswer(id: EntityID<CompositeID>): CompositeEntity(id) {
|
|
||||||
var userId by PollAnswerTable.userId
|
|
||||||
private set
|
|
||||||
var question by PollAnswerTable.question
|
|
||||||
private set
|
|
||||||
private var answerId by PollAnswerTable.answer
|
|
||||||
var answer: Int
|
|
||||||
get() = answerId
|
|
||||||
set(value) = useDb {
|
|
||||||
answerId = value
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object: CompositeEntityClass<PollAnswer>(PollAnswerTable) {
|
|
||||||
@JvmStatic
|
|
||||||
var currentPoll: String? = null
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun get(userId: Int) = useDb {
|
|
||||||
find { (PollAnswerTable.userId eq userId) and (PollAnswerTable.question eq currentPoll!!) }.firstOrNull()
|
|
||||||
?: new {
|
|
||||||
this.userId = EntityID(userId, SteamwarUserTable)
|
|
||||||
this.question = currentPoll!!
|
|
||||||
this.answerId = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun getCurrentResults(): Map<Int, Int> = useDb {
|
|
||||||
exec("SELECT Count(UserID) AS Times, Answer FROM PollAnswer WHERE Question = ? GROUP BY Answer ORDER BY Times ASC",
|
|
||||||
args = listOf(VarCharColumnType() to currentPoll!!)) {
|
|
||||||
val result = mutableMapOf<Int, Int>()
|
|
||||||
while (it.next()) {
|
|
||||||
result[it.getInt("Answer")] = it.getInt("Times")
|
|
||||||
}
|
|
||||||
result
|
|
||||||
} ?: emptyMap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun hasAnswered() = answerId != 0
|
|
||||||
}
|
|
||||||
@@ -68,18 +68,11 @@ public class Config {
|
|||||||
private boolean eventmode = false;
|
private boolean eventmode = false;
|
||||||
private Map<String, Server> servers = Collections.emptyMap();
|
private Map<String, Server> servers = Collections.emptyMap();
|
||||||
private List<String> broadcasts = Collections.emptyList();
|
private List<String> broadcasts = Collections.emptyList();
|
||||||
private Poll poll = null;
|
|
||||||
|
|
||||||
public RegisteredServer lobbyserver() {
|
public RegisteredServer lobbyserver() {
|
||||||
return VelocityCore.getProxy().getServer(lobbyserver).orElseThrow();
|
return VelocityCore.getProxy().getServer(lobbyserver).orElseThrow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
|
||||||
public static class Poll {
|
|
||||||
private String question;
|
|
||||||
private List<String> answers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public static class Server {
|
public static class Server {
|
||||||
private int spectatePort = 0;
|
private int spectatePort = 0;
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ import de.steamwar.velocitycore.commands.TeamCommand;
|
|||||||
import de.steamwar.velocitycore.discord.DiscordBot;
|
import de.steamwar.velocitycore.discord.DiscordBot;
|
||||||
import de.steamwar.velocitycore.discord.DiscordConfig;
|
import de.steamwar.velocitycore.discord.DiscordConfig;
|
||||||
import de.steamwar.velocitycore.listeners.BasicListener;
|
import de.steamwar.velocitycore.listeners.BasicListener;
|
||||||
import de.steamwar.velocitycore.listeners.PollSystem;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
|
||||||
@@ -135,7 +134,6 @@ public class VelocityCore implements ReloadablePlugin {
|
|||||||
schedule(TabCompletionCache::invalidateOldEntries).repeat(1, TimeUnit.SECONDS).schedule();
|
schedule(TabCompletionCache::invalidateOldEntries).repeat(1, TimeUnit.SECONDS).schedule();
|
||||||
|
|
||||||
initStaticServers();
|
initStaticServers();
|
||||||
PollSystem.init();
|
|
||||||
|
|
||||||
local = new Node.LocalNode();
|
local = new Node.LocalNode();
|
||||||
if(MAIN_SERVER) {
|
if(MAIN_SERVER) {
|
||||||
|
|||||||
@@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2025 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.velocitycore.commands;
|
|
||||||
|
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import de.steamwar.velocitycore.listeners.PollSystem;
|
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
import de.steamwar.command.TypeValidator;
|
|
||||||
import de.steamwar.messages.Chatter;
|
|
||||||
import de.steamwar.sql.PollAnswer;
|
|
||||||
|
|
||||||
@Linked
|
|
||||||
public class PollCommand extends SWCommand {
|
|
||||||
|
|
||||||
public PollCommand() {
|
|
||||||
super("poll");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register
|
|
||||||
public void genericCommand(@Validator Chatter sender) {
|
|
||||||
PollSystem.sendPoll(sender);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(noTabComplete = true)
|
|
||||||
public void answerPoll(@Validator Chatter sender, String answerString) {
|
|
||||||
int answer;
|
|
||||||
try {
|
|
||||||
answer = Integer.parseUnsignedInt(answerString);
|
|
||||||
if(answer < 1 || answer > PollSystem.answers())
|
|
||||||
throw new NumberFormatException();
|
|
||||||
}catch(NumberFormatException e){
|
|
||||||
sender.system("POLL_NO_ANSWER");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PollAnswer pollAnswer = PollAnswer.get(sender.user().getId());
|
|
||||||
if(pollAnswer.hasAnswered())
|
|
||||||
sender.system("POLL_ANSWER_REFRESH");
|
|
||||||
else
|
|
||||||
sender.system("POLL_ANSWER_NEW");
|
|
||||||
|
|
||||||
pollAnswer.setAnswer(answer);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ClassValidator(value = Chatter.class, local = true)
|
|
||||||
public TypeValidator<Chatter> noPoll() {
|
|
||||||
return PollSystem.noPoll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2025 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.velocitycore.commands;
|
|
||||||
|
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import de.steamwar.velocitycore.listeners.PollSystem;
|
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
import de.steamwar.command.TypeValidator;
|
|
||||||
import de.steamwar.messages.Chatter;
|
|
||||||
import de.steamwar.sql.PollAnswer;
|
|
||||||
import de.steamwar.sql.UserPerm;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Linked
|
|
||||||
public class PollresultCommand extends SWCommand {
|
|
||||||
|
|
||||||
public PollresultCommand() {
|
|
||||||
super("pollresult", UserPerm.MODERATION);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register
|
|
||||||
public void genericCommand(@Validator Chatter sender) {
|
|
||||||
Map<Integer, Integer> voted = PollAnswer.getCurrentResults();
|
|
||||||
sender.system("POLLRESULT_HEADER", voted.values().stream().reduce(Integer::sum).orElse(0), PollAnswer.getCurrentPoll());
|
|
||||||
for (Map.Entry<Integer, Integer> e: voted.entrySet()) {
|
|
||||||
sender.prefixless("POLLRESULT_LIST", PollSystem.getAnswer(e.getKey()), e.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ClassValidator(value = Chatter.class, local = true)
|
|
||||||
public TypeValidator<Chatter> noPoll() {
|
|
||||||
return PollSystem.noPoll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2025 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.velocitycore.listeners;
|
|
||||||
|
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
|
||||||
import com.velocitypowered.api.event.connection.PostLoginEvent;
|
|
||||||
import de.steamwar.velocitycore.Config;
|
|
||||||
import de.steamwar.velocitycore.VelocityCore;
|
|
||||||
import de.steamwar.command.TypeValidator;
|
|
||||||
import de.steamwar.messages.Chatter;
|
|
||||||
import de.steamwar.messages.Message;
|
|
||||||
import de.steamwar.sql.PollAnswer;
|
|
||||||
import net.kyori.adventure.text.event.ClickEvent;
|
|
||||||
|
|
||||||
public class PollSystem extends BasicListener {
|
|
||||||
|
|
||||||
public static void init() {
|
|
||||||
poll = VelocityCore.get().getConfig().getPoll();
|
|
||||||
if(poll == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(noCurrentPoll())
|
|
||||||
return;
|
|
||||||
|
|
||||||
PollAnswer.setCurrentPoll(poll.getQuestion());
|
|
||||||
new PollSystem();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Config.Poll poll = null;
|
|
||||||
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onPostLogin(PostLoginEvent event){
|
|
||||||
Chatter player = Chatter.of(event.getPlayer());
|
|
||||||
|
|
||||||
PollAnswer answer = PollAnswer.get(player.user().getId());
|
|
||||||
if(answer.hasAnswered())
|
|
||||||
return;
|
|
||||||
|
|
||||||
sendPoll(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendPoll(Chatter player) {
|
|
||||||
player.system("POLL_HEADER");
|
|
||||||
player.prefixless("POLL_HEADER2");
|
|
||||||
player.prefixless("POLL_QUESTION", poll.getQuestion());
|
|
||||||
|
|
||||||
for(int i = 1; i <= poll.getAnswers().size(); i++) {
|
|
||||||
player.prefixless("POLL_ANSWER", new Message("POLL_ANSWER_HOVER", poll.getAnswers().get(i-1)), ClickEvent.runCommand("/poll " + i), poll.getAnswers().get(i-1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean noCurrentPoll(){
|
|
||||||
return poll == null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TypeValidator<Chatter> noPoll() {
|
|
||||||
return (sender, value, messageSender) -> {
|
|
||||||
if (PollSystem.noCurrentPoll()) {
|
|
||||||
messageSender.send("POLL_NO_POLL");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int answers(){
|
|
||||||
return poll.getAnswers().size();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getAnswer(int i) {
|
|
||||||
return poll.getAnswers().get(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user