SteamWar/BungeeCore
Archiviert
13
2

WIP CommonDB
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2023-02-17 11:47:58 +01:00
Ursprung 871e45ffbb
Commit be6538c78d
13 geänderte Dateien mit 13 neuen und 195 gelöschten Zeilen

@ -1 +1 @@
Subproject commit d439ecb8d01d576310766e497c970bce7eb1db2f Subproject commit 3e1c4e9059ef2400c79aaa5089eaafca075640c6

Datei anzeigen

@ -34,6 +34,7 @@ import de.steamwar.command.SWCommandUtils;
import de.steamwar.command.SWTypeMapperCreator; import de.steamwar.command.SWTypeMapperCreator;
import de.steamwar.command.TabCompletionCache; import de.steamwar.command.TabCompletionCache;
import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeMapper;
import de.steamwar.sql.Team;
import de.steamwar.sql.internal.Statement; import de.steamwar.sql.internal.Statement;
import net.md_5.bungee.BungeeCord; import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
@ -200,7 +201,7 @@ public class BungeeCore extends Plugin {
getProxy().getScheduler().schedule(this, () -> { getProxy().getScheduler().schedule(this, () -> {
SteamwarUser.clearCache(); SteamwarUser.clearCache();
UserElo.clearCache(); UserElo.clearCache();
Team.clearCache(); Team.clear();
}, 1, 1, TimeUnit.HOURS); }, 1, 1, TimeUnit.HOURS);
if (SteamwarDiscordBotConfig.loaded) { if (SteamwarDiscordBotConfig.loaded) {

Datei anzeigen

@ -21,7 +21,7 @@ package de.steamwar.bungeecore;
import de.steamwar.bungeecore.sql.EventFight; import de.steamwar.bungeecore.sql.EventFight;
import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.Team; import de.steamwar.sql.Team;
import de.steamwar.sql.Event; import de.steamwar.sql.Event;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;

Datei anzeigen

@ -2,7 +2,7 @@ package de.steamwar.bungeecore;
import de.steamwar.bungeecore.sql.EventFight; import de.steamwar.bungeecore.sql.EventFight;
import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.Team; import de.steamwar.sql.Team;
import de.steamwar.bungeecore.sql.Tutorial; import de.steamwar.bungeecore.sql.Tutorial;
import de.steamwar.messages.ChatSender; import de.steamwar.messages.ChatSender;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;

Datei anzeigen

@ -21,7 +21,7 @@ package de.steamwar.bungeecore.bot.commands;
import de.steamwar.sql.Event; import de.steamwar.sql.Event;
import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.Team; import de.steamwar.sql.Team;
import de.steamwar.sql.TeamTeilnahme; import de.steamwar.sql.TeamTeilnahme;
import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Emoji; import net.dv8tion.jda.api.entities.Emoji;

Datei anzeigen

@ -21,7 +21,7 @@ package de.steamwar.bungeecore.bot.commands;
import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.Punishment;
import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.Team; import de.steamwar.sql.Team;
import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.OptionType;

Datei anzeigen

@ -22,7 +22,7 @@ package de.steamwar.bungeecore.bot.listeners;
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
import de.steamwar.bungeecore.bot.events.EventManager; import de.steamwar.bungeecore.bot.events.EventManager;
import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.Team; import de.steamwar.sql.Team;
import de.steamwar.sql.TeamTeilnahme; import de.steamwar.sql.TeamTeilnahme;
import de.steamwar.sql.Event; import de.steamwar.sql.Event;
import net.dv8tion.jda.api.events.interaction.SelectionMenuEvent; import net.dv8tion.jda.api.events.interaction.SelectionMenuEvent;

Datei anzeigen

@ -21,7 +21,7 @@ package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.sql.EventFight; import de.steamwar.bungeecore.sql.EventFight;
import de.steamwar.bungeecore.sql.Team; import de.steamwar.sql.Team;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeMapper;
import de.steamwar.sql.Event; import de.steamwar.sql.Event;

Datei anzeigen

@ -25,7 +25,7 @@ import de.steamwar.bungeecore.inventory.SWItem;
import de.steamwar.bungeecore.inventory.SWListInv; import de.steamwar.bungeecore.inventory.SWListInv;
import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.Punishment;
import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.Team; import de.steamwar.sql.Team;
import de.steamwar.sql.TeamTeilnahme; import de.steamwar.sql.TeamTeilnahme;
import de.steamwar.messages.ChatSender; import de.steamwar.messages.ChatSender;
import de.steamwar.sql.Event; import de.steamwar.sql.Event;

Datei anzeigen

@ -23,7 +23,7 @@ import de.steamwar.bungeecore.*;
import de.steamwar.sql.BauweltMember; import de.steamwar.sql.BauweltMember;
import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.Punishment;
import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.Team; import de.steamwar.sql.Team;
import de.steamwar.bungeecore.util.BauLock; import de.steamwar.bungeecore.util.BauLock;
import de.steamwar.bungeecore.util.Chat19; import de.steamwar.bungeecore.util.Chat19;
import de.steamwar.messages.ChatSender; import de.steamwar.messages.ChatSender;

Datei anzeigen

@ -26,6 +26,7 @@ import de.steamwar.bungeecore.sql.*;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.command.SWCommandUtils; import de.steamwar.command.SWCommandUtils;
import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeMapper;
import de.steamwar.sql.Team;
import de.steamwar.sql.UserGroup; import de.steamwar.sql.UserGroup;
import lombok.Getter; import lombok.Getter;
import net.md_5.bungee.BungeeCord; import net.md_5.bungee.BungeeCord;

Datei anzeigen

@ -26,6 +26,7 @@ import de.steamwar.bungeecore.sql.*;
import de.steamwar.bungeecore.util.Chat19; import de.steamwar.bungeecore.util.Chat19;
import de.steamwar.messages.ChatSender; import de.steamwar.messages.ChatSender;
import de.steamwar.network.packets.server.PingPacket; import de.steamwar.network.packets.server.PingPacket;
import de.steamwar.sql.Team;
import de.steamwar.sql.UserGroup; import de.steamwar.sql.UserGroup;
import net.md_5.bungee.api.*; import net.md_5.bungee.api.*;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;

Datei anzeigen

@ -1,185 +0,0 @@
/*
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.sql;
import de.steamwar.sql.TeamTeilnahme;
import de.steamwar.sql.internal.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
public class Team {
private static final Statement insert = new Statement("INSERT INTO Team (TeamKuerzel, TeamName) VALUES (?, ?)");
private static final Statement delete = new Statement("UPDATE Team SET TeamDeleted = 1 WHERE TeamID = ?");
private static final Statement update = new Statement("INSERT INTO Team (TeamID, TeamKuerzel, TeamName, TeamColor, Address, Port) VALUES (?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE TeamName = VALUES(TeamName), TeamKuerzel = VALUES(TeamKuerzel), TeamColor = VALUES(TeamColor), Address = VALUES(Address), Port = VALUES(Port)");
private static final Statement getSize = new Statement("SELECT COUNT(id) FROM UserData WHERE Team = ?");
private static final Statement getMembers = new Statement("SELECT id FROM UserData WHERE Team = ?");
private static final Statement byId = new Statement("SELECT * FROM Team WHERE TeamID = ?");
private static final Statement byName = new Statement("SELECT * FROM Team WHERE (lower(TeamName) = ? OR lower(TeamKuerzel) = ?) AND NOT TeamDeleted");
private static final Statement all = new Statement("SELECT * FROM Team WHERE NOT TeamDeleted");
private static final List<Team> teamCache = new LinkedList<>();
private static final Team pub = new Team(0, "PUB", "Öffentlich", "8", null, 25565);
private final int teamId;
private String teamKuerzel;
private String teamName;
private String teamColor;
private String address;
private int port;
private Team(int id, String kuerzel, String name, String color, String address, int port){
teamId = id;
teamKuerzel = kuerzel;
teamName = name;
teamColor = color;
if (id != 0) {
teamCache.add(this);
}
this.address = address;
this.port = port;
}
private Team(ResultSet rs) throws SQLException {
this(rs.getInt("TeamID"), rs.getString("TeamKuerzel"), rs.getString("TeamName"), rs.getString("TeamColor"), rs.getString("Address"), rs.getInt("Port"));
}
public static void create(String kuerzel, String name){
insert.update(kuerzel, name);
}
public static Team get(int id){
if(id == -1)
return new Team(-1, "?", "?", "8", null, 25565);
if(id == 0)
return pub;
for(Team team : teamCache)
if(team.teamId == id)
return team;
return byId.select(rs -> {
rs.next();
return new Team(rs);
}, id);
}
public static Team get(String name){
for(Team team : teamCache)
if(team.teamName.equalsIgnoreCase(name) || team.teamKuerzel.equalsIgnoreCase(name))
return team;
return byName.select(rs -> {
if(rs.next())
return new Team(rs);
return null;
}, name.toLowerCase(), name.toLowerCase());
}
public static List<Team> getAll(){
clearCache();
return all.select(rs -> {
while(rs.next())
new Team(rs);
return teamCache;
});
}
public static void clearCache(){
teamCache.clear();
}
private void updateDB(){
update.update(teamId, teamKuerzel, teamName, teamColor, address, port);
}
public int getTeamId() {
return teamId;
}
public String getTeamKuerzel() {
return teamKuerzel;
}
public void setTeamKuerzel(String teamKuerzel) {
this.teamKuerzel = teamKuerzel;
updateDB();
}
public String getTeamName() {
return teamName;
}
public void setTeamName(String teamName) {
this.teamName = teamName;
updateDB();
}
public String getTeamColor() {
return teamColor;
}
public void setTeamColor(String teamColor) {
this.teamColor = teamColor;
updateDB();
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
updateDB();
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
updateDB();
}
public int size(){
return getSize.select(rs -> {
rs.next();
return rs.getInt("COUNT(id)");
}, teamId);
}
public void disband(SteamwarUser user){
user.setLeader(false);
delete.update(teamId);
teamCache.remove(this);
TeamTeilnahme.deleteFuture(teamId);
}
public List<Integer> getMembers(){
return getMembers.select(rs -> {
List<Integer> members = new ArrayList<>();
while(rs.next())
members.add(rs.getInt("id"));
return members;
}, teamId);
}
}