geforkt von SteamWar/BungeeCore
WIP CommonDB
Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Ursprung
871e45ffbb
Commit
be6538c78d
@ -1 +1 @@
|
||||
Subproject commit d439ecb8d01d576310766e497c970bce7eb1db2f
|
||||
Subproject commit 3e1c4e9059ef2400c79aaa5089eaafca075640c6
|
@ -34,6 +34,7 @@ import de.steamwar.command.SWCommandUtils;
|
||||
import de.steamwar.command.SWTypeMapperCreator;
|
||||
import de.steamwar.command.TabCompletionCache;
|
||||
import de.steamwar.command.TypeMapper;
|
||||
import de.steamwar.sql.Team;
|
||||
import de.steamwar.sql.internal.Statement;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
@ -200,7 +201,7 @@ public class BungeeCore extends Plugin {
|
||||
getProxy().getScheduler().schedule(this, () -> {
|
||||
SteamwarUser.clearCache();
|
||||
UserElo.clearCache();
|
||||
Team.clearCache();
|
||||
Team.clear();
|
||||
}, 1, 1, TimeUnit.HOURS);
|
||||
|
||||
if (SteamwarDiscordBotConfig.loaded) {
|
||||
|
@ -21,7 +21,7 @@ package de.steamwar.bungeecore;
|
||||
|
||||
import de.steamwar.bungeecore.sql.EventFight;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import de.steamwar.bungeecore.sql.Team;
|
||||
import de.steamwar.sql.Team;
|
||||
import de.steamwar.sql.Event;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
|
@ -2,7 +2,7 @@ package de.steamwar.bungeecore;
|
||||
|
||||
import de.steamwar.bungeecore.sql.EventFight;
|
||||
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.messages.ChatSender;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
@ -21,7 +21,7 @@ package de.steamwar.bungeecore.bot.commands;
|
||||
|
||||
import de.steamwar.sql.Event;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import de.steamwar.bungeecore.sql.Team;
|
||||
import de.steamwar.sql.Team;
|
||||
import de.steamwar.sql.TeamTeilnahme;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.entities.Emoji;
|
||||
|
@ -21,7 +21,7 @@ package de.steamwar.bungeecore.bot.commands;
|
||||
|
||||
import de.steamwar.bungeecore.sql.Punishment;
|
||||
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.events.interaction.SlashCommandEvent;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
|
@ -22,7 +22,7 @@ package de.steamwar.bungeecore.bot.listeners;
|
||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||
import de.steamwar.bungeecore.bot.events.EventManager;
|
||||
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.Event;
|
||||
import net.dv8tion.jda.api.events.interaction.SelectionMenuEvent;
|
||||
|
@ -21,7 +21,7 @@ package de.steamwar.bungeecore.commands;
|
||||
|
||||
import de.steamwar.bungeecore.Message;
|
||||
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.TypeMapper;
|
||||
import de.steamwar.sql.Event;
|
||||
|
@ -25,7 +25,7 @@ import de.steamwar.bungeecore.inventory.SWItem;
|
||||
import de.steamwar.bungeecore.inventory.SWListInv;
|
||||
import de.steamwar.bungeecore.sql.Punishment;
|
||||
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.messages.ChatSender;
|
||||
import de.steamwar.sql.Event;
|
||||
|
@ -23,7 +23,7 @@ import de.steamwar.bungeecore.*;
|
||||
import de.steamwar.sql.BauweltMember;
|
||||
import de.steamwar.bungeecore.sql.Punishment;
|
||||
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.Chat19;
|
||||
import de.steamwar.messages.ChatSender;
|
||||
|
@ -26,6 +26,7 @@ import de.steamwar.bungeecore.sql.*;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.SWCommandUtils;
|
||||
import de.steamwar.command.TypeMapper;
|
||||
import de.steamwar.sql.Team;
|
||||
import de.steamwar.sql.UserGroup;
|
||||
import lombok.Getter;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
|
@ -26,6 +26,7 @@ import de.steamwar.bungeecore.sql.*;
|
||||
import de.steamwar.bungeecore.util.Chat19;
|
||||
import de.steamwar.messages.ChatSender;
|
||||
import de.steamwar.network.packets.server.PingPacket;
|
||||
import de.steamwar.sql.Team;
|
||||
import de.steamwar.sql.UserGroup;
|
||||
import net.md_5.bungee.api.*;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren