geforkt von SteamWar/BungeeCore
Merge branch 'master' into noBauPassthrough
# Conflicts: # src/de/steamwar/bungeecore/listeners/ChatListener.java
Dieser Commit ist enthalten in:
Commit
7bd15ec63f
39
pom.xml
39
pom.xml
@ -35,10 +35,31 @@
|
|||||||
<target>8</target>
|
<target>8</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
<finalName>bungeecore</finalName>
|
<finalName>bungeecore</finalName>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>dv8tion</id>
|
||||||
|
<name>m2-dv8tion</name>
|
||||||
|
<url>https://m2.dv8tion.net/releases</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>steamwar</groupId>
|
<groupId>steamwar</groupId>
|
||||||
@ -61,5 +82,23 @@
|
|||||||
<scope>system</scope>
|
<scope>system</scope>
|
||||||
<systemPath>${main.basedir}/lib/BungeeTabListPlus.jar</systemPath>
|
<systemPath>${main.basedir}/lib/BungeeTabListPlus.jar</systemPath>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.dv8tion</groupId>
|
||||||
|
<artifactId>JDA</artifactId>
|
||||||
|
<version>4.3.0_299</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>club.minnced</groupId>
|
||||||
|
<artifactId>opus-java</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.20</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
@ -19,16 +19,19 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore;
|
package de.steamwar.bungeecore;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||||
|
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||||
import de.steamwar.bungeecore.commands.*;
|
import de.steamwar.bungeecore.commands.*;
|
||||||
import de.steamwar.bungeecore.comms.SpigotReceiver;
|
import de.steamwar.bungeecore.comms.SpigotReceiver;
|
||||||
import de.steamwar.bungeecore.listeners.*;
|
import de.steamwar.bungeecore.listeners.*;
|
||||||
import de.steamwar.bungeecore.listeners.mods.ModLoaderBlocker;
|
|
||||||
import de.steamwar.bungeecore.listeners.mods.Forge;
|
import de.steamwar.bungeecore.listeners.mods.Forge;
|
||||||
import de.steamwar.bungeecore.listeners.mods.LabyMod;
|
import de.steamwar.bungeecore.listeners.mods.LabyMod;
|
||||||
|
import de.steamwar.bungeecore.listeners.mods.ModLoaderBlocker;
|
||||||
import de.steamwar.bungeecore.listeners.mods.WorldDownloader;
|
import de.steamwar.bungeecore.listeners.mods.WorldDownloader;
|
||||||
import de.steamwar.bungeecore.sql.SQL;
|
import de.steamwar.bungeecore.sql.Statement;
|
||||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
import de.steamwar.bungeecore.sql.Team;
|
import de.steamwar.bungeecore.sql.Team;
|
||||||
|
import net.dv8tion.jda.api.JDA;
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
@ -108,6 +111,7 @@ public class BungeeCore extends Plugin {
|
|||||||
new DenyCommand("watchcat", "wc");
|
new DenyCommand("watchcat", "wc");
|
||||||
new TeamCommand();
|
new TeamCommand();
|
||||||
new ServerTeamchatCommand();
|
new ServerTeamchatCommand();
|
||||||
|
new DevCommand();
|
||||||
new EventCommand();
|
new EventCommand();
|
||||||
new EventreloadCommand();
|
new EventreloadCommand();
|
||||||
new EventRescheduleCommand();
|
new EventRescheduleCommand();
|
||||||
@ -121,6 +125,9 @@ public class BungeeCore extends Plugin {
|
|||||||
new UnIgnoreCommand();
|
new UnIgnoreCommand();
|
||||||
new PollresultCommand();
|
new PollresultCommand();
|
||||||
new ResourcereloadCommand();
|
new ResourcereloadCommand();
|
||||||
|
new ListCommand();
|
||||||
|
new StatCommand();
|
||||||
|
new VerifyCommand();
|
||||||
|
|
||||||
if(!EVENT_MODE){
|
if(!EVENT_MODE){
|
||||||
new BauCommand();
|
new BauCommand();
|
||||||
@ -145,12 +152,20 @@ public class BungeeCore extends Plugin {
|
|||||||
SteamwarUser.clearCache();
|
SteamwarUser.clearCache();
|
||||||
Team.clearCache();
|
Team.clearCache();
|
||||||
}, 1, 1, TimeUnit.HOURS);
|
}, 1, 1, TimeUnit.HOURS);
|
||||||
|
|
||||||
|
new SteamwarDiscordBot();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable(){
|
public void onDisable(){
|
||||||
ErrorLogger.stop();
|
ErrorLogger.stop();
|
||||||
SQL.close();
|
Statement.close();
|
||||||
|
try {
|
||||||
|
SteamwarDiscordBot.instance().getJda().shutdownNow();
|
||||||
|
SteamwarDiscordBot.instance().getJda().awaitStatus(JDA.Status.SHUTDOWN);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Ignored
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BungeeCore get() {
|
public static BungeeCore get() {
|
||||||
@ -245,13 +260,14 @@ public class BungeeCore extends Plugin {
|
|||||||
Persistent.setChatPrefix(CHAT_PREFIX);
|
Persistent.setChatPrefix(CHAT_PREFIX);
|
||||||
Persistent.setLobbyServer(LOBBY_SERVER);
|
Persistent.setLobbyServer(LOBBY_SERVER);
|
||||||
|
|
||||||
SQL.connect(
|
Statement.connect(
|
||||||
config.getString("db.url"),
|
config.getString("db.url"),
|
||||||
config.getString("db.username"),
|
config.getString("db.username"),
|
||||||
config.getString("db.password")
|
config.getString("db.password")
|
||||||
);
|
);
|
||||||
|
|
||||||
ArenaMode.init(config.getSection("games"));
|
ArenaMode.init(config.getSection("games"));
|
||||||
|
SteamwarDiscordBotConfig.loadConfig(config.getSection("discord"));
|
||||||
|
|
||||||
final Configuration servers = config.getSection("servers");
|
final Configuration servers = config.getSection("servers");
|
||||||
for(final String serverName : servers.getKeys()){
|
for(final String serverName : servers.getKeys()){
|
||||||
|
96
src/de/steamwar/bungeecore/LoadEvaluation.java
Normale Datei
96
src/de/steamwar/bungeecore/LoadEvaluation.java
Normale Datei
@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 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;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
public class LoadEvaluation {
|
||||||
|
private LoadEvaluation(){}
|
||||||
|
|
||||||
|
private static final File meminfo = new File("/proc/meminfo");
|
||||||
|
|
||||||
|
public static double getRamPercentage() {
|
||||||
|
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(meminfo)))) {
|
||||||
|
String memTotal = bufferedReader.readLine().replaceAll(" +", " ");
|
||||||
|
bufferedReader.readLine();
|
||||||
|
String memAvailable = bufferedReader.readLine().replaceAll(" +", " ");
|
||||||
|
|
||||||
|
long memTotalLong = getNumber(memTotal);
|
||||||
|
long memAvailableLong = getNumber(memAvailable);
|
||||||
|
return (memTotalLong - memAvailableLong) / (double) memTotalLong;
|
||||||
|
} catch (IOException e) {
|
||||||
|
return 1D;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double getRemoteRamPercentage(String remote) {
|
||||||
|
try {
|
||||||
|
// Attention:
|
||||||
|
// memInfo.sh needs to contain: cat /proc/meminfo
|
||||||
|
Process process = new ProcessBuilder("ssh", remote, "\"./memInfo.sh\"").start();
|
||||||
|
process.waitFor();
|
||||||
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||||
|
String memTotal = bufferedReader.readLine().replaceAll(" +", " ");
|
||||||
|
bufferedReader.readLine();
|
||||||
|
String memAvailable = bufferedReader.readLine().replaceAll(" +", " ");
|
||||||
|
|
||||||
|
long memTotalLong = getNumber(memTotal);
|
||||||
|
long memAvailableLong = getNumber(memAvailable);
|
||||||
|
return (memTotalLong - memAvailableLong) / (double) memTotalLong;
|
||||||
|
} catch (IOException e) {
|
||||||
|
return 1D;
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
return 1D;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double getCPULoad() {
|
||||||
|
try {
|
||||||
|
Process process = new ProcessBuilder("bash", "-c", "cat <(grep 'cpu ' /proc/stat) <(sleep 1 && grep 'cpu ' /proc/stat) | awk -v RS=\"\" '{printf \"%.2f\\n\", ($13-$2+$15-$4)*100/($13-$2+$15-$4+$16-$5)}'").start();
|
||||||
|
process.waitFor();
|
||||||
|
return Double.parseDouble(new BufferedReader(new InputStreamReader(process.getInputStream())).readLine()) / 100.0;
|
||||||
|
} catch (IOException e) {
|
||||||
|
return 1D;
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
return 1D;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double getRemoteCPULoad(String remote) {
|
||||||
|
try {
|
||||||
|
// Attention:
|
||||||
|
// cpuLoad.sh needs to contain: cat <(grep 'cpu ' /proc/stat) <(sleep 1 && grep 'cpu ' /proc/stat) | awk -v RS="" '{printf "%.2f\n", ($13-$2+$15-$4)*100/($13-$2+$15-$4+$16-$5)}'
|
||||||
|
Process process = new ProcessBuilder("ssh", remote, "\"./cpuLoad.sh\"").start();
|
||||||
|
process.waitFor();
|
||||||
|
return Double.parseDouble(new BufferedReader(new InputStreamReader(process.getInputStream())).readLine()) / 100.0;
|
||||||
|
} catch (IOException e) {
|
||||||
|
return 1D;
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
return 1D;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static long getNumber(String s) {
|
||||||
|
return Long.parseLong(s.split(" ")[1]);
|
||||||
|
}
|
||||||
|
}
|
@ -89,7 +89,7 @@ public class SubserverSystem {
|
|||||||
* @return
|
* @return
|
||||||
* The new started subserver.
|
* The new started subserver.
|
||||||
*/
|
*/
|
||||||
public static Subserver startArena(ArenaMode modus, String map, int eventFightID, int checkSchemID, int prepareSchemID, String serverName, String mapName, UUID player1, UUID player2, boolean ranked){
|
public static synchronized Subserver startArena(ArenaMode modus, String map, int eventFightID, int checkSchemID, int prepareSchemID, String serverName, String mapName, UUID player1, UUID player2, boolean ranked){
|
||||||
//Generate missing parameters
|
//Generate missing parameters
|
||||||
int port = freePort(FIRST_ARENA_PORT);
|
int port = freePort(FIRST_ARENA_PORT);
|
||||||
|
|
||||||
@ -118,8 +118,10 @@ public class SubserverSystem {
|
|||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File directory = new File(SERVER_PATH, modus.getFolder());
|
||||||
List<String> cmd = serverStartCommand(
|
List<String> cmd = serverStartCommand(
|
||||||
modus.serverJar(),
|
modus.serverJar(),
|
||||||
|
directory,
|
||||||
worldDir,
|
worldDir,
|
||||||
mapName,
|
mapName,
|
||||||
port,
|
port,
|
||||||
@ -135,7 +137,7 @@ public class SubserverSystem {
|
|||||||
|
|
||||||
//Start server
|
//Start server
|
||||||
ProcessBuilder process = new ProcessBuilder(cmd);
|
ProcessBuilder process = new ProcessBuilder(cmd);
|
||||||
process.directory(new File(SERVER_PATH, modus.getFolder()));
|
process.directory(directory);
|
||||||
|
|
||||||
String finalMapName = mapName;
|
String finalMapName = mapName;
|
||||||
if(eventFightID == -1)
|
if(eventFightID == -1)
|
||||||
@ -177,7 +179,7 @@ public class SubserverSystem {
|
|||||||
startArena(m, map, -1, checkSchemId, prepareSchemId, p.getName() + "s Bau", p.getName(), p.getUniqueId(), null, false).sendPlayer(p);
|
startArena(m, map, -1, checkSchemId, prepareSchemId, p.getName() + "s Bau", p.getName(), p.getUniqueId(), null, false).sendPlayer(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sendToBau(ProxiedPlayer p, UUID owner, String prototype, String worldFolder, String serverJar, String worldDir, String worldName, String xmx, String serverName){
|
private static synchronized void sendToBau(ProxiedPlayer p, UUID owner, String prototype, String worldFolder, String serverJar, String worldDir, String worldName, String xmx, String serverName){
|
||||||
if(bauRunning(p, owner))
|
if(bauRunning(p, owner))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -185,8 +187,10 @@ public class SubserverSystem {
|
|||||||
copyBauweltIfRequired(p, prototype, worldFolder + worldName);
|
copyBauweltIfRequired(p, prototype, worldFolder + worldName);
|
||||||
int port = freePort(4000);
|
int port = freePort(4000);
|
||||||
|
|
||||||
|
File directory = new File(SERVER_PATH, serverName);
|
||||||
List<String> cmd = serverStartCommand(
|
List<String> cmd = serverStartCommand(
|
||||||
serverJar,
|
serverJar,
|
||||||
|
directory,
|
||||||
worldDir,
|
worldDir,
|
||||||
worldName,
|
worldName,
|
||||||
port,
|
port,
|
||||||
@ -195,7 +199,7 @@ public class SubserverSystem {
|
|||||||
|
|
||||||
//Start server
|
//Start server
|
||||||
ProcessBuilder process = new ProcessBuilder(cmd);
|
ProcessBuilder process = new ProcessBuilder(cmd);
|
||||||
process.directory(new File(SERVER_PATH, serverName));
|
process.directory(directory);
|
||||||
|
|
||||||
new Bauserver(user.getUserName() + "s Bau", owner, port, process, () -> {}).sendPlayer(p);
|
new Bauserver(user.getUserName() + "s Bau", owner, port, process, () -> {}).sendPlayer(p);
|
||||||
}
|
}
|
||||||
@ -231,9 +235,30 @@ public class SubserverSystem {
|
|||||||
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/bau addmember " + p.getName()));
|
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/bau addmember " + p.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<String> serverStartCommand(String serverJar, String worldDir, String levelName, int port, String xmx, String... dParams){
|
private static List<String> serverStartCommand(String serverJar, File directory, String worldDir, String levelName, int port, String xmx, String... dParams){
|
||||||
List<String> cmd = new ArrayList<>();
|
List<String> cmd = new ArrayList<>();
|
||||||
boolean jdk11 = serverJar.contains("1.15.2");
|
boolean jdk11 = serverJar.contains("1.15.2");
|
||||||
|
|
||||||
|
boolean fallback = false;
|
||||||
|
if (!steamwarStartAvailable()) {
|
||||||
|
cmd.add("ssh");
|
||||||
|
cmd.add("-L");
|
||||||
|
cmd.add(port + ":localhost:" + port);
|
||||||
|
if (remoteStartAvailable("lx")) {
|
||||||
|
cmd.add("lx");
|
||||||
|
} else if (remoteStartAvailable("az")) {
|
||||||
|
cmd.add("az");
|
||||||
|
} else {
|
||||||
|
fallback = true;
|
||||||
|
}
|
||||||
|
cmd.add("cd");
|
||||||
|
cmd.add(directory.getPath());
|
||||||
|
cmd.add(";");
|
||||||
|
}
|
||||||
|
if (fallback) {
|
||||||
|
cmd.clear();
|
||||||
|
}
|
||||||
|
|
||||||
if(jdk11)
|
if(jdk11)
|
||||||
cmd.add("/usr/lib/jvm/java-11-openjdk-amd64/bin/java");
|
cmd.add("/usr/lib/jvm/java-11-openjdk-amd64/bin/java");
|
||||||
else
|
else
|
||||||
@ -259,6 +284,14 @@ public class SubserverSystem {
|
|||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean steamwarStartAvailable(){
|
||||||
|
return LoadEvaluation.getCPULoad() < 0.7 && LoadEvaluation.getRamPercentage() < 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean remoteStartAvailable(String remote) {
|
||||||
|
return LoadEvaluation.getRemoteCPULoad(remote) < 0.7 && LoadEvaluation.getRemoteRamPercentage(remote) < 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean bauRunning(ProxiedPlayer p, UUID owner){
|
private static boolean bauRunning(ProxiedPlayer p, UUID owner){
|
||||||
for(Subserver subserver : Subserver.getServerList()){
|
for(Subserver subserver : Subserver.getServerList()){
|
||||||
if(subserver.getType() == Servertype.BAUSERVER && ((Bauserver)subserver).getOwner().equals(owner)){
|
if(subserver.getType() == Servertype.BAUSERVER && ((Bauserver)subserver).getOwner().equals(owner)){
|
||||||
|
86
src/de/steamwar/bungeecore/bot/AuthManager.java
Normale Datei
86
src/de/steamwar/bungeecore/bot/AuthManager.java
Normale Datei
@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
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.bot;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.BungeeCore;
|
||||||
|
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||||
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
|
import net.dv8tion.jda.api.MessageBuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.Emoji;
|
||||||
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
|
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
||||||
|
import net.dv8tion.jda.api.interactions.components.Button;
|
||||||
|
import net.md_5.bungee.api.scheduler.ScheduledTask;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class AuthManager {
|
||||||
|
|
||||||
|
private static final Map<String, Long> TOKENS = new HashMap<>();
|
||||||
|
private static final Random rand = new Random();
|
||||||
|
|
||||||
|
public static String createDiscordAuthToken(Member member) {
|
||||||
|
if(TOKENS.containsValue(member.getIdLong())) return null;
|
||||||
|
|
||||||
|
byte[] randBytes = new byte[16];
|
||||||
|
rand.nextBytes(randBytes);
|
||||||
|
randBytes[0] = 'D';
|
||||||
|
randBytes[1] = 'C';
|
||||||
|
String code = Base64.getEncoder().encodeToString(randBytes);
|
||||||
|
|
||||||
|
TOKENS.put(code, member.getIdLong());
|
||||||
|
BungeeCore.log("Created Discord Auth-Token: " + code + " for: " + member.getUser().getAsTag());
|
||||||
|
ScheduledTask[] task = new ScheduledTask[1];
|
||||||
|
task[0] = BungeeCore.get().getProxy().getScheduler().schedule(BungeeCore.get(), () -> {
|
||||||
|
TOKENS.remove(code);
|
||||||
|
task[0].cancel();
|
||||||
|
}, 10, 10, TimeUnit.MINUTES);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Member connectAuth(SteamwarUser user, String code) {
|
||||||
|
if (TOKENS.containsKey(code)) {
|
||||||
|
Member member = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).retrieveMemberById(TOKENS.get(code).longValue()).complete();
|
||||||
|
if(member == null) return null;
|
||||||
|
user.setDiscordId(member.getId());
|
||||||
|
MessageBuilder builder = new MessageBuilder();
|
||||||
|
builder.setContent(":white_check_mark: Dein Discord Konto wurde mit **" + user.getUserName() + "** verknüpft");
|
||||||
|
builder.setActionRows(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389")), Button.danger("invalid", "Ich war das nicht")));
|
||||||
|
|
||||||
|
try {
|
||||||
|
member.getUser().openPrivateChannel().complete().sendMessage(builder.build()).complete();
|
||||||
|
if (member.getNickname() == null) {
|
||||||
|
try {
|
||||||
|
member.getGuild().modifyNickname(member, user.getUserName()).complete();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TOKENS.remove(code);
|
||||||
|
return member;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
153
src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java
Normale Datei
153
src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java
Normale Datei
@ -0,0 +1,153 @@
|
|||||||
|
/*
|
||||||
|
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.bot;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.BungeeCore;
|
||||||
|
import de.steamwar.bungeecore.bot.commands.*;
|
||||||
|
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||||
|
import de.steamwar.bungeecore.bot.events.EventManager;
|
||||||
|
import de.steamwar.bungeecore.bot.events.SchematicsManager;
|
||||||
|
import de.steamwar.bungeecore.bot.listeners.*;
|
||||||
|
import de.steamwar.bungeecore.bot.util.DiscordRolesMessage;
|
||||||
|
import de.steamwar.bungeecore.bot.util.DiscordRulesMessage;
|
||||||
|
import de.steamwar.bungeecore.bot.util.DiscordTicketMessage;
|
||||||
|
import de.steamwar.bungeecore.sql.Event;
|
||||||
|
import lombok.Getter;
|
||||||
|
import net.dv8tion.jda.api.JDA;
|
||||||
|
import net.dv8tion.jda.api.JDABuilder;
|
||||||
|
import net.dv8tion.jda.api.OnlineStatus;
|
||||||
|
import net.dv8tion.jda.api.entities.Activity;
|
||||||
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
|
import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction;
|
||||||
|
import net.dv8tion.jda.api.utils.MemberCachePolicy;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
|
||||||
|
import javax.security.auth.login.LoginException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class SteamwarDiscordBot {
|
||||||
|
|
||||||
|
private static SteamwarDiscordBot INSTANCE;
|
||||||
|
|
||||||
|
public static SteamwarDiscordBot instance() {
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private AnnouncementListener announcementListener;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private IngameChatListener ingameChatListener;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private ServerTeamChatListener serverTeamChatListener;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final JDA jda;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private static Map<String, BasicDiscordCommand> discordCommandMap = new HashMap<>();
|
||||||
|
|
||||||
|
public SteamwarDiscordBot() {
|
||||||
|
INSTANCE = this;
|
||||||
|
JDABuilder builder = JDABuilder.createDefault(SteamwarDiscordBotConfig.TOKEN);
|
||||||
|
builder.setStatus(OnlineStatus.ONLINE);
|
||||||
|
builder.setMemberCachePolicy(MemberCachePolicy.ONLINE);
|
||||||
|
try {
|
||||||
|
jda = builder.build();
|
||||||
|
} catch (LoginException e) {
|
||||||
|
throw new SecurityException("Could not Login: " + SteamwarDiscordBotConfig.TOKEN, e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
jda.awaitReady();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
activity();
|
||||||
|
EventManager.update();
|
||||||
|
SchematicsManager.update();
|
||||||
|
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
|
||||||
|
activity();
|
||||||
|
EventManager.update();
|
||||||
|
SchematicsManager.update();
|
||||||
|
}, 30, 30, TimeUnit.SECONDS);
|
||||||
|
DiscordRolesMessage.sendMessage();
|
||||||
|
DiscordRulesMessage.sendMessage();
|
||||||
|
DiscordTicketMessage.sendMessage();
|
||||||
|
|
||||||
|
new RolesInteractionButtonListener();
|
||||||
|
new DiscordTicketListener();
|
||||||
|
new DiscordAuthListener();
|
||||||
|
announcementListener = new AnnouncementListener();
|
||||||
|
ingameChatListener = new IngameChatListener();
|
||||||
|
serverTeamChatListener = new ServerTeamChatListener();
|
||||||
|
new SlashCommandListener();
|
||||||
|
|
||||||
|
jda.retrieveCommands().complete().forEach(command -> jda.deleteCommandById(command.getId()).complete());
|
||||||
|
|
||||||
|
Guild guild = jda.getGuildById(SteamwarDiscordBotConfig.GUILD);
|
||||||
|
guild.retrieveCommands().complete().forEach(command -> guild.deleteCommandById(command.getId()).complete());
|
||||||
|
CommandListUpdateAction commands = jda.getGuildById(SteamwarDiscordBotConfig.GUILD).updateCommands();
|
||||||
|
addCommand(commands, new MuteCommand());
|
||||||
|
addCommand(commands, new BanCommand());
|
||||||
|
addCommand(commands, new WhoisCommand());
|
||||||
|
addCommand(commands, new TeamCommand());
|
||||||
|
addCommand(commands, new ListCommand());
|
||||||
|
addCommand(commands, new UnbanCommand());
|
||||||
|
commands.complete();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addCommand(CommandListUpdateAction commands, BasicDiscordCommand basicDiscordCommand) {
|
||||||
|
commands.addCommands(basicDiscordCommand);
|
||||||
|
discordCommandMap.put(basicDiscordCommand.getName(), basicDiscordCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int index = 0;
|
||||||
|
|
||||||
|
private void activity() {
|
||||||
|
switch (index) {
|
||||||
|
case 0:
|
||||||
|
Event event = Event.get();
|
||||||
|
if (event != null) {
|
||||||
|
jda.getPresence().setActivity(Activity.competing("dem Event " + event.getEventName()));
|
||||||
|
} else {
|
||||||
|
jda.getPresence().setActivity(Activity.playing("auf SteamWar.de"));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
int count = BungeeCore.get().getProxy().getOnlineCount();
|
||||||
|
if (count == 1) {
|
||||||
|
jda.getPresence().setActivity(Activity.playing("mit 1 Spieler"));
|
||||||
|
} else {
|
||||||
|
jda.getPresence().setActivity(Activity.playing("mit " + count + " Spielern"));
|
||||||
|
}
|
||||||
|
index = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addListener(ListenerAdapter listenerAdapter) {
|
||||||
|
jda.addEventListener(listenerAdapter);
|
||||||
|
}
|
||||||
|
}
|
65
src/de/steamwar/bungeecore/bot/commands/BanCommand.java
Normale Datei
65
src/de/steamwar/bungeecore/bot/commands/BanCommand.java
Normale Datei
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* 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.bot.commands;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.Message;
|
||||||
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
public class BanCommand extends BasicDiscordCommand {
|
||||||
|
|
||||||
|
public BanCommand() {
|
||||||
|
super("ban", "Banne einen Nutzer, wenn du die Rechte hast.");
|
||||||
|
|
||||||
|
addOption(OptionType.STRING, "user", "Der Benutzer", true);
|
||||||
|
addOption(OptionType.STRING, "time", "Bis Wann", true);
|
||||||
|
addOption(OptionType.STRING, "reason", "Warum", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(SlashCommandEvent event) {
|
||||||
|
if (!testPermission(event)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SteamwarUser sender = SteamwarUser.get(event.getMember().getIdLong());
|
||||||
|
SteamwarUser target = SteamwarUser.getOrCreateOfflinePlayer(event.getOption("user").getAsString());
|
||||||
|
if (target == null) {
|
||||||
|
event.reply("Angegebener User invalide").setEphemeral(true).complete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Timestamp time = de.steamwar.bungeecore.commands.BanCommand.parseTime(null, event.getOption("time").getAsString());
|
||||||
|
if (time == null) {
|
||||||
|
event.reply("Angegebene Zeit invalide").setEphemeral(true).complete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String msg = event.getOption("reason").getAsString();
|
||||||
|
boolean isPerma = event.getOption("time").getAsString().equals("perma");
|
||||||
|
|
||||||
|
target.ban(time, msg, sender.getId(), isPerma);
|
||||||
|
Message.team("BAN_TEAM_BANNED", new Message("PREFIX"), target.getUserName(), sender.getUserName(), new Message((isPerma ? "BAN_PERMA" : "BAN_UNTIL"), time), msg);
|
||||||
|
event.reply("Erfolgreich " + target.getUserName() + (isPerma ? " permanent" : " bis " + time) + " gebannt").setEphemeral(true).complete();
|
||||||
|
}
|
||||||
|
}
|
54
src/de/steamwar/bungeecore/bot/commands/BasicDiscordCommand.java
Normale Datei
54
src/de/steamwar/bungeecore/bot/commands/BasicDiscordCommand.java
Normale Datei
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* 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.bot.commands;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
|
import de.steamwar.bungeecore.sql.UserGroup;
|
||||||
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
|
||||||
|
|
||||||
|
public abstract class BasicDiscordCommand extends CommandData {
|
||||||
|
|
||||||
|
protected BasicDiscordCommand(String name, String description) {
|
||||||
|
super(name, description);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void run(SlashCommandEvent event);
|
||||||
|
|
||||||
|
protected SteamwarUser getSteamwarUser(SlashCommandEvent event) {
|
||||||
|
Member member = event.getMember();
|
||||||
|
SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong());
|
||||||
|
if (steamwarUser == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return steamwarUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean testPermission(SlashCommandEvent event) {
|
||||||
|
Member member = event.getMember();
|
||||||
|
SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong());
|
||||||
|
if (steamwarUser == null || (!steamwarUser.getUserGroup().isTeamGroup() && steamwarUser.getUserGroup() != UserGroup.Builder)) {
|
||||||
|
event.reply("Du hast für " + event.getName() + " keine Rechte oder es existiert keine Verknüpfung für dich.").setEphemeral(true).complete();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
43
src/de/steamwar/bungeecore/bot/commands/ListCommand.java
Normale Datei
43
src/de/steamwar/bungeecore/bot/commands/ListCommand.java
Normale Datei
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* 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.bot.commands;
|
||||||
|
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
||||||
|
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class ListCommand extends BasicDiscordCommand {
|
||||||
|
|
||||||
|
public ListCommand() {
|
||||||
|
super("list", "Gebe eine Liste aller online Spieler");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(SlashCommandEvent event) {
|
||||||
|
de.steamwar.bungeecore.commands.ListCommand.updateCustomTablist();
|
||||||
|
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||||
|
embedBuilder.setTitle("List");
|
||||||
|
de.steamwar.bungeecore.commands.ListCommand.getPlayerMap().forEach((s, proxiedPlayers) -> {
|
||||||
|
embedBuilder.addField(s, proxiedPlayers.stream().map(player -> "`" + player.getName() + "`").collect(Collectors.joining(", ")), true);
|
||||||
|
});
|
||||||
|
event.replyEmbeds(embedBuilder.build()).setEphemeral(true).complete();
|
||||||
|
}
|
||||||
|
}
|
66
src/de/steamwar/bungeecore/bot/commands/MuteCommand.java
Normale Datei
66
src/de/steamwar/bungeecore/bot/commands/MuteCommand.java
Normale Datei
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* 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.bot.commands;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.Message;
|
||||||
|
import de.steamwar.bungeecore.commands.BanCommand;
|
||||||
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
public class MuteCommand extends BasicDiscordCommand {
|
||||||
|
|
||||||
|
public MuteCommand() {
|
||||||
|
super("mute", "Mute einen Nutzer, wenn du die Rechte hast.");
|
||||||
|
|
||||||
|
addOption(OptionType.STRING, "user", "Der Benutzer", true);
|
||||||
|
addOption(OptionType.STRING, "time", "Bis Wann", true);
|
||||||
|
addOption(OptionType.STRING, "reason", "Warum", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(SlashCommandEvent event) {
|
||||||
|
if (!testPermission(event)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SteamwarUser sender = SteamwarUser.get(event.getMember().getIdLong());
|
||||||
|
SteamwarUser target = SteamwarUser.getOrCreateOfflinePlayer(event.getOption("user").getAsString());
|
||||||
|
if (target == null) {
|
||||||
|
event.reply("Angegebener User invalide").setEphemeral(true).complete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Timestamp time = BanCommand.parseTime(null, event.getOption("time").getAsString());
|
||||||
|
if (time == null) {
|
||||||
|
event.reply("Angegebene Zeit invalide").setEphemeral(true).complete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String msg = event.getOption("reason").getAsString();
|
||||||
|
boolean isPerma = event.getOption("time").getAsString().equals("perma");
|
||||||
|
|
||||||
|
target.mute(time, msg, sender.getId(), isPerma);
|
||||||
|
Message.team("MUTE_TEAM_MUTED", new Message("PREFIX"), target.getUserName(), sender.getUserName(), new Message((isPerma ? "BAN_PERMA" : "BAN_UNTIL"), time), msg);
|
||||||
|
event.reply("Erfolgreich " + target.getUserName() + (isPerma ? " permanent" : " bis " + time) + " gemutet").setEphemeral(true).complete();
|
||||||
|
}
|
||||||
|
}
|
96
src/de/steamwar/bungeecore/bot/commands/TeamCommand.java
Normale Datei
96
src/de/steamwar/bungeecore/bot/commands/TeamCommand.java
Normale Datei
@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* 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.bot.commands;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.sql.Event;
|
||||||
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
|
import de.steamwar.bungeecore.sql.Team;
|
||||||
|
import de.steamwar.bungeecore.sql.TeamTeilnahme;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.Emoji;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class TeamCommand extends BasicDiscordCommand {
|
||||||
|
|
||||||
|
public TeamCommand() {
|
||||||
|
super("team", "Alle Team bezogenen Befehle");
|
||||||
|
|
||||||
|
addSubcommands(new SubcommandData("info", "Infos über das Team oder deins")
|
||||||
|
.addOption(OptionType.STRING, "team", "Name oder Kuerzel", false)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Emoji emoji = Emoji.fromUnicode("U+1F7E2");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(SlashCommandEvent event) {
|
||||||
|
SteamwarUser steamwarUser = getSteamwarUser(event);
|
||||||
|
|
||||||
|
if (event.getSubcommandName() != null) {
|
||||||
|
switch (event.getSubcommandName()) {
|
||||||
|
case "info":
|
||||||
|
OptionMapping optionMapping = event.getOption("team");
|
||||||
|
Team team;
|
||||||
|
if (optionMapping == null) {
|
||||||
|
if (steamwarUser == null) {
|
||||||
|
event.reply("Dein Discord ist nicht verknüpft").setEphemeral(true).complete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (steamwarUser.getTeam() == 0) {
|
||||||
|
event.reply("Du bist in keinem Team").setEphemeral(true).complete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
team = Team.get(steamwarUser.getTeam());
|
||||||
|
} else {
|
||||||
|
team = Team.get(optionMapping.getAsString());
|
||||||
|
}
|
||||||
|
if (team == null) {
|
||||||
|
event.reply("Unbekanntes Team").setEphemeral(true).complete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||||
|
embedBuilder.setTitle("Team: " + team.getTeamName() + " [" + team.getTeamKuerzel() + "]");
|
||||||
|
embedBuilder.setColor(Color.GRAY);
|
||||||
|
List<SteamwarUser> members = team.getMembers().stream().map(SteamwarUser::get).collect(Collectors.toList());
|
||||||
|
|
||||||
|
embedBuilder.addField("Leader", members.stream().filter(SteamwarUser::isLeader).map(user -> "`" + (isOnline(user) ? emoji.getAsMention() : "") + user.getUserName() + "`").collect(Collectors.joining(" ")), false);
|
||||||
|
embedBuilder.addField("Member", members.stream().filter(user -> !user.isLeader()).map(user -> "`" + (isOnline(user) ? emoji.getAsMention() : "") + user.getUserName() + "`").collect(Collectors.joining(" ")), false);
|
||||||
|
embedBuilder.addField("Events", "`" + TeamTeilnahme.getEvents(team.getTeamId()).stream().map(Event::getEventName).collect(Collectors.joining("` `")) + "`", false);
|
||||||
|
event.replyEmbeds(embedBuilder.build()).setEphemeral(true).complete();
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
event.reply("Unbekannter Befehl").setEphemeral(true).complete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isOnline(SteamwarUser user) {
|
||||||
|
return ProxyServer.getInstance().getPlayer(user.getUuid()) != null;
|
||||||
|
}
|
||||||
|
}
|
59
src/de/steamwar/bungeecore/bot/commands/UnbanCommand.java
Normale Datei
59
src/de/steamwar/bungeecore/bot/commands/UnbanCommand.java
Normale Datei
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* 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.bot.commands;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.Message;
|
||||||
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class UnbanCommand extends BasicDiscordCommand {
|
||||||
|
|
||||||
|
public UnbanCommand() {
|
||||||
|
super("unban", "Entbannt einen Nutzer, wenn du die Rechte hast.");
|
||||||
|
|
||||||
|
addOption(OptionType.STRING, "user", "Der Benutzer", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(SlashCommandEvent event) {
|
||||||
|
if (!testPermission(event)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SteamwarUser sender = SteamwarUser.get(event.getMember().getIdLong());
|
||||||
|
SteamwarUser target = SteamwarUser.getOrCreateOfflinePlayer(event.getOption("user").getAsString());
|
||||||
|
if (target == null) {
|
||||||
|
event.reply("Angegebener User invalide").setEphemeral(true).complete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!target.isBanned()) {
|
||||||
|
event.reply("Angegebener User ist nicht gebannt").setEphemeral(true).complete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
target.ban(Timestamp.from(new Date().toInstant()), "Unban", sender.getId(), false);
|
||||||
|
event.reply("Erfolgreich " + target.getUserName() + " entbannt").setEphemeral(true).complete();
|
||||||
|
}
|
||||||
|
}
|
94
src/de/steamwar/bungeecore/bot/commands/WhoisCommand.java
Normale Datei
94
src/de/steamwar/bungeecore/bot/commands/WhoisCommand.java
Normale Datei
@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* 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.bot.commands;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.sql.Punishment;
|
||||||
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
|
import de.steamwar.bungeecore.sql.Team;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class WhoisCommand extends BasicDiscordCommand {
|
||||||
|
|
||||||
|
public WhoisCommand() {
|
||||||
|
super("whois", "Der whois Befehl");
|
||||||
|
|
||||||
|
addOption(OptionType.STRING, "user", "Der Benutzer", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(SlashCommandEvent event) {
|
||||||
|
if (!testPermission(event)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String s = event.getOption("user").getAsString();
|
||||||
|
|
||||||
|
SteamwarUser user = SteamwarUser.get(s);
|
||||||
|
if (user == null) {
|
||||||
|
try {
|
||||||
|
int id = Integer.parseInt(s);
|
||||||
|
user = SteamwarUser.get(id);
|
||||||
|
} catch (NumberFormatException ignored) {
|
||||||
|
// Ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (user == null) {
|
||||||
|
try {
|
||||||
|
long id = Long.parseLong(s);
|
||||||
|
user = SteamwarUser.get(id);
|
||||||
|
} catch (NumberFormatException ignored) {
|
||||||
|
// Ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user == null) {
|
||||||
|
event.reply("Der angegebene Spieler ist unbekannt").setEphemeral(true).complete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||||
|
embedBuilder.setTitle("Whois: " + user.getUserName());
|
||||||
|
StringBuilder st = new StringBuilder();
|
||||||
|
st.append("UUID: ").append(user.getUuid()).append("\n");
|
||||||
|
st.append("ID: ").append(user.getId()).append("\n");
|
||||||
|
if (user.getDiscordId() != null) {
|
||||||
|
st.append("DiscordID: ").append(user.getDiscordId()).append("\n");
|
||||||
|
}
|
||||||
|
Timestamp timestamp = user.getFirstjoin();
|
||||||
|
st.append("Beigetreten am: ").append(timestamp == null ? "0000-00-00 00:00:00" : timestamp.toString()).append("\n");
|
||||||
|
st.append("Online Time: ").append(new DecimalFormat("###.##").format(user.getOnlinetime() / (double) 3600)).append("h\n");
|
||||||
|
Team team = Team.get(user.getTeam());
|
||||||
|
st.append("Team: [").append(team.getTeamKuerzel()).append("] ").append(team.getTeamName());
|
||||||
|
embedBuilder.addField("Daten:", st.toString(), false);
|
||||||
|
|
||||||
|
List<Punishment> punishmentList = Punishment.getAllPunishmentsOfPlayer(user.getId());
|
||||||
|
for (Punishment punishment : punishmentList) {
|
||||||
|
embedBuilder.addField(punishment.getType().name() + " von " + SteamwarUser.get(punishment.getPunisher()).getUserName(), "Von: " + punishment.getBantime(punishment.getStartTime(), false) + "\nBis: " + punishment.getBantime(punishment.getEndTime(), punishment.isPerma()) + "\nGrund: " + punishment.getReason(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
event.replyEmbeds(embedBuilder.build()).setEphemeral(true).complete();
|
||||||
|
}
|
||||||
|
}
|
39
src/de/steamwar/bungeecore/bot/config/DiscordRole.java
Normale Datei
39
src/de/steamwar/bungeecore/bot/config/DiscordRole.java
Normale Datei
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
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.bot.config;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import net.dv8tion.jda.api.entities.Emoji;
|
||||||
|
import net.dv8tion.jda.api.interactions.components.Button;
|
||||||
|
import net.dv8tion.jda.api.interactions.components.ButtonStyle;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class DiscordRole {
|
||||||
|
|
||||||
|
private String emoji;
|
||||||
|
private String label;
|
||||||
|
private String roleId;
|
||||||
|
|
||||||
|
public Button toButton() {
|
||||||
|
return Button.of(ButtonStyle.SECONDARY, roleId, label, Emoji.fromUnicode(emoji));
|
||||||
|
}
|
||||||
|
}
|
36
src/de/steamwar/bungeecore/bot/config/DiscordRulesLink.java
Normale Datei
36
src/de/steamwar/bungeecore/bot/config/DiscordRulesLink.java
Normale Datei
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
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.bot.config;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import net.dv8tion.jda.api.interactions.components.Button;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class DiscordRulesLink {
|
||||||
|
|
||||||
|
private String label;
|
||||||
|
private String link;
|
||||||
|
|
||||||
|
public Button toButton() {
|
||||||
|
return Button.link(link, label);
|
||||||
|
}
|
||||||
|
}
|
41
src/de/steamwar/bungeecore/bot/config/DiscordTicketType.java
Normale Datei
41
src/de/steamwar/bungeecore/bot/config/DiscordTicketType.java
Normale Datei
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
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.bot.config;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import net.dv8tion.jda.api.entities.Emoji;
|
||||||
|
import net.dv8tion.jda.api.interactions.components.Button;
|
||||||
|
import net.dv8tion.jda.api.interactions.components.ButtonStyle;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class DiscordTicketType {
|
||||||
|
|
||||||
|
private String key;
|
||||||
|
private String emoji;
|
||||||
|
private String label;
|
||||||
|
private String color;
|
||||||
|
private String preMessage;
|
||||||
|
|
||||||
|
public Button toButton() {
|
||||||
|
return Button.of(ButtonStyle.valueOf(color), key, Emoji.fromUnicode(emoji)).withLabel(label);
|
||||||
|
}
|
||||||
|
}
|
114
src/de/steamwar/bungeecore/bot/config/SteamwarDiscordBotConfig.java
Normale Datei
114
src/de/steamwar/bungeecore/bot/config/SteamwarDiscordBotConfig.java
Normale Datei
@ -0,0 +1,114 @@
|
|||||||
|
/*
|
||||||
|
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.bot.config;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.sql.UserGroup;
|
||||||
|
import net.md_5.bungee.config.Configuration;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class SteamwarDiscordBotConfig {
|
||||||
|
|
||||||
|
public static String TOKEN;
|
||||||
|
public static String GUILD;
|
||||||
|
public static String ANNOUNCEMENTS_CHANNEL;
|
||||||
|
public static String EVENTS_CHANNEL;
|
||||||
|
public static String INGAME_CHANNEL;
|
||||||
|
public static String SERVER_TEAM_CHANNEL;
|
||||||
|
public static String SCHEMATICS_CHANNEL;
|
||||||
|
public static String ROLES_CHANNEL;
|
||||||
|
public static String ROLES_BASE_MESSAGE;
|
||||||
|
public static String ROLES_ADDED;
|
||||||
|
public static String ROLES_REMOVED;
|
||||||
|
public static List<DiscordRole> ROLES;
|
||||||
|
public static String RULES_CHANNEL;
|
||||||
|
public static String RULES_TITLE;
|
||||||
|
public static List<String> RULES_RULES;
|
||||||
|
public static List<DiscordRulesLink> RULES_LINKS;
|
||||||
|
public static String TICKET_CATEGORY;
|
||||||
|
public static String TICKET_CHANNEL;
|
||||||
|
public static String TICKET_MESSAGE;
|
||||||
|
public static String TICKET_CREATED;
|
||||||
|
public static String TICKET_LOG;
|
||||||
|
public static Map<String, DiscordTicketType> TICKET_TYPES;
|
||||||
|
public static Map<UserGroup, String> RANKS;
|
||||||
|
|
||||||
|
public static void loadConfig(Configuration config) {
|
||||||
|
TOKEN = config.getString("token");
|
||||||
|
GUILD = config.getString("guild");
|
||||||
|
ANNOUNCEMENTS_CHANNEL = config.getString("announcements-channel");
|
||||||
|
EVENTS_CHANNEL = config.getString("events-channel");
|
||||||
|
INGAME_CHANNEL = config.getString("ingame-channel");
|
||||||
|
SERVER_TEAM_CHANNEL = config.getString("server-team-channel");
|
||||||
|
SCHEMATICS_CHANNEL = config.getString("schematics-channel");
|
||||||
|
Configuration rolesSection = config.getSection("roles-claim");
|
||||||
|
ROLES_CHANNEL = rolesSection.getString("channel");
|
||||||
|
ROLES_BASE_MESSAGE = rolesSection.getString("base");
|
||||||
|
ROLES_ADDED = rolesSection.getString("added");
|
||||||
|
ROLES_REMOVED = rolesSection.getString("removed");
|
||||||
|
ROLES = new ArrayList<>();
|
||||||
|
|
||||||
|
for (String roles : rolesSection.getSection("roles").getKeys()) {
|
||||||
|
Configuration role = rolesSection.getSection("roles").getSection(roles);
|
||||||
|
ROLES.add(new DiscordRole(role.getString("emoji"),
|
||||||
|
role.getString("label"),
|
||||||
|
role.getString("roleId")));
|
||||||
|
}
|
||||||
|
|
||||||
|
Configuration rulesSection = config.getSection("rules");
|
||||||
|
RULES_CHANNEL = rulesSection.getString("channel");
|
||||||
|
RULES_TITLE = rulesSection.getString("title");
|
||||||
|
RULES_RULES = rulesSection.getStringList("rules");
|
||||||
|
|
||||||
|
RULES_LINKS = new ArrayList<>();
|
||||||
|
|
||||||
|
for (String links : rulesSection.getSection("links").getKeys()) {
|
||||||
|
Configuration link = rulesSection.getSection("links").getSection(links);
|
||||||
|
RULES_LINKS.add(new DiscordRulesLink(link.getString("label"),
|
||||||
|
link.getString("url")));
|
||||||
|
}
|
||||||
|
|
||||||
|
Configuration ticketSection = config.getSection("tickets");
|
||||||
|
TICKET_CATEGORY = ticketSection.getString("category");
|
||||||
|
TICKET_CHANNEL = ticketSection.getString("channel");
|
||||||
|
TICKET_MESSAGE = ticketSection.getString("message");
|
||||||
|
TICKET_CREATED = ticketSection.getString("created");
|
||||||
|
TICKET_LOG = ticketSection.getString("log");
|
||||||
|
TICKET_TYPES = new HashMap<>();
|
||||||
|
|
||||||
|
for (String types : ticketSection.getSection("types").getKeys()) {
|
||||||
|
Configuration type = ticketSection.getSection("types").getSection(types);
|
||||||
|
TICKET_TYPES.put(types, new DiscordTicketType(types,
|
||||||
|
type.getString("emoji"),
|
||||||
|
type.getString("label"),
|
||||||
|
type.getString("color"),
|
||||||
|
type.getString("pre")));
|
||||||
|
}
|
||||||
|
|
||||||
|
RANKS = new HashMap<>();
|
||||||
|
Configuration ranksSections = config.getSection("ranks");
|
||||||
|
for (String type : ranksSections.getKeys()) {
|
||||||
|
RANKS.put(UserGroup.getUsergroup(type), ranksSections.getString(type));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
128
src/de/steamwar/bungeecore/bot/events/EventManager.java
Normale Datei
128
src/de/steamwar/bungeecore/bot/events/EventManager.java
Normale Datei
@ -0,0 +1,128 @@
|
|||||||
|
/*
|
||||||
|
* 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.bot.events;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||||
|
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||||
|
import de.steamwar.bungeecore.sql.Event;
|
||||||
|
import de.steamwar.bungeecore.sql.EventFight;
|
||||||
|
import de.steamwar.bungeecore.sql.Team;
|
||||||
|
import de.steamwar.bungeecore.sql.TeamTeilnahme;
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.MessageBuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import net.dv8tion.jda.api.entities.TextChannel;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class EventManager {
|
||||||
|
|
||||||
|
private Message message;
|
||||||
|
private TextChannel textChannel;
|
||||||
|
|
||||||
|
static {
|
||||||
|
textChannel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.EVENTS_CHANNEL);
|
||||||
|
assert textChannel != null;
|
||||||
|
if(textChannel.hasLatestMessage()) {
|
||||||
|
message = textChannel.getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update() {
|
||||||
|
if (Event.get() == null) {
|
||||||
|
updateComing();
|
||||||
|
} else {
|
||||||
|
updateCurrent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateComing() {
|
||||||
|
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||||
|
embedBuilder.setColor(Color.GRAY);
|
||||||
|
embedBuilder.setTitle("Zukünftige Events");
|
||||||
|
embedBuilder.setAuthor("SteamWar", "https://www.steamwar.de");
|
||||||
|
|
||||||
|
Timestamp now = Timestamp.from(Instant.now());
|
||||||
|
Event.getComing().forEach(event -> {
|
||||||
|
StringBuilder st = new StringBuilder();
|
||||||
|
if (event.getDeadline().after(now)) {
|
||||||
|
st.append("Deadline: <t:").append(event.getDeadline().getTime() / 1000).append(":R>\n");
|
||||||
|
}
|
||||||
|
st.append("Start: <t:").append(event.getStart().getTime() / 1000).append(":R>");
|
||||||
|
String teilname = TeamTeilnahme.getTeams(event.getEventID()).stream().map(Team::getTeamKuerzel).collect(Collectors.joining(", "));
|
||||||
|
if (!teilname.isEmpty()) {
|
||||||
|
st.append("\nAngemeldete Teams: ").append(teilname);
|
||||||
|
}
|
||||||
|
embedBuilder.addField(event.getEventName(), st.toString(), false);
|
||||||
|
});
|
||||||
|
|
||||||
|
MessageBuilder messageBuilder = new MessageBuilder();
|
||||||
|
messageBuilder.setEmbeds(embedBuilder.build());
|
||||||
|
if (message == null) {
|
||||||
|
message = textChannel.sendMessage(messageBuilder.build()).complete();
|
||||||
|
} else {
|
||||||
|
message.editMessage(messageBuilder.build()).complete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateCurrent() {
|
||||||
|
Event event = Event.get();
|
||||||
|
if (event == null) return;
|
||||||
|
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||||
|
embedBuilder.setColor(Color.GRAY);
|
||||||
|
embedBuilder.setTitle("Event: " + event.getEventName());
|
||||||
|
embedBuilder.setAuthor("SteamWar", "https://www.steamwar.de");
|
||||||
|
|
||||||
|
Instant now = Instant.now();
|
||||||
|
EventFight.getEvent(event.getEventID()).forEach(eventFight -> {
|
||||||
|
Team teamBlue = Team.get(eventFight.getTeamBlue());
|
||||||
|
Team teamRed = Team.get(eventFight.getTeamRed());
|
||||||
|
|
||||||
|
StringBuilder st = new StringBuilder();
|
||||||
|
st.append("Fightbeginn: <t:").append(eventFight.getStartTime().getTime() / 1000).append(":R>");
|
||||||
|
if(now.isAfter(eventFight.getStartTime().toInstant().plus(35, ChronoUnit.MINUTES))) {
|
||||||
|
st.append("\n");
|
||||||
|
if (eventFight.getErgebnis() == 1) {
|
||||||
|
st.append("Sieg ").append(teamBlue.getTeamKuerzel());
|
||||||
|
} else if (eventFight.getErgebnis() == 2) {
|
||||||
|
st.append("Sieg ").append(teamRed.getTeamKuerzel());
|
||||||
|
} else {
|
||||||
|
st.append("Unentschieden");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
embedBuilder.addField(teamBlue.getTeamKuerzel() + " vs. " + teamRed.getTeamKuerzel(), st.toString(), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
MessageBuilder messageBuilder = new MessageBuilder();
|
||||||
|
messageBuilder.setEmbeds(embedBuilder.build());
|
||||||
|
if (message == null) {
|
||||||
|
message = textChannel.sendMessage(messageBuilder.build()).complete();
|
||||||
|
} else {
|
||||||
|
message.editMessage(messageBuilder.build()).complete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
73
src/de/steamwar/bungeecore/bot/events/SchematicsManager.java
Normale Datei
73
src/de/steamwar/bungeecore/bot/events/SchematicsManager.java
Normale Datei
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* 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.bot.events;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||||
|
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||||
|
import de.steamwar.bungeecore.commands.CheckCommand;
|
||||||
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.MessageBuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import net.dv8tion.jda.api.entities.TextChannel;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class SchematicsManager {
|
||||||
|
|
||||||
|
private Message message;
|
||||||
|
private TextChannel textChannel;
|
||||||
|
|
||||||
|
static {
|
||||||
|
textChannel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.SCHEMATICS_CHANNEL);
|
||||||
|
assert textChannel != null;
|
||||||
|
if(textChannel.hasLatestMessage()) {
|
||||||
|
message = textChannel.getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update() {
|
||||||
|
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||||
|
embedBuilder.setColor(Color.GRAY);
|
||||||
|
embedBuilder.setTitle("Check List");
|
||||||
|
embedBuilder.setAuthor("SteamWar", "https://www.steamwar.de");
|
||||||
|
|
||||||
|
CheckCommand.getSchemsToCheck().forEach(schematic -> {
|
||||||
|
StringBuilder st = new StringBuilder();
|
||||||
|
st.append("Typ: ").append(schematic.getSchemType().getKuerzel());
|
||||||
|
st.append("\nVon: ").append(SteamwarUser.get(schematic.getSchemOwner()).getUserName());
|
||||||
|
String checker = CheckCommand.getChecker(schematic);
|
||||||
|
if (checker != null) {
|
||||||
|
st.append("\nWird Geprüft von: ").append(checker);
|
||||||
|
}
|
||||||
|
embedBuilder.addField(schematic.getSchemName(), st.toString(), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
MessageBuilder messageBuilder = new MessageBuilder();
|
||||||
|
messageBuilder.setEmbeds(embedBuilder.build());
|
||||||
|
if (message == null) {
|
||||||
|
message = textChannel.sendMessage(messageBuilder.build()).complete();
|
||||||
|
} else {
|
||||||
|
message.editMessage(messageBuilder.build()).queue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
50
src/de/steamwar/bungeecore/bot/listeners/AnnouncementListener.java
Normale Datei
50
src/de/steamwar/bungeecore/bot/listeners/AnnouncementListener.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.bot.listeners;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.Message;
|
||||||
|
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||||
|
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||||
|
import net.dv8tion.jda.api.MessageBuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.TextChannel;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class AnnouncementListener extends BasicDiscordListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
|
||||||
|
if (!event.getChannel().getId().equals(SteamwarDiscordBotConfig.ANNOUNCEMENTS_CHANNEL)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.getAuthor().isBot()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Message.broadcast("ALERT", event.getMessage().getContentDisplay());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void announce(String message) {
|
||||||
|
TextChannel textChannel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.ANNOUNCEMENTS_CHANNEL);
|
||||||
|
assert textChannel != null;
|
||||||
|
MessageBuilder messageBuilder = new MessageBuilder();
|
||||||
|
messageBuilder.append(message.replace("&", ""));
|
||||||
|
textChannel.sendMessage(messageBuilder.build()).complete();
|
||||||
|
}
|
||||||
|
}
|
30
src/de/steamwar/bungeecore/bot/listeners/BasicDiscordListener.java
Normale Datei
30
src/de/steamwar/bungeecore/bot/listeners/BasicDiscordListener.java
Normale Datei
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
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.bot.listeners;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||||
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
|
|
||||||
|
public abstract class BasicDiscordListener extends ListenerAdapter {
|
||||||
|
|
||||||
|
BasicDiscordListener() {
|
||||||
|
SteamwarDiscordBot.instance().addListener(this);
|
||||||
|
}
|
||||||
|
}
|
59
src/de/steamwar/bungeecore/bot/listeners/DiscordAuthListener.java
Normale Datei
59
src/de/steamwar/bungeecore/bot/listeners/DiscordAuthListener.java
Normale Datei
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
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.bot.listeners;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.bot.AuthManager;
|
||||||
|
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||||
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
|
import net.dv8tion.jda.api.entities.ChannelType;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.GenericComponentInteractionCreateEvent;
|
||||||
|
import net.dv8tion.jda.api.interactions.InteractionType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class DiscordAuthListener extends BasicDiscordListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGenericComponentInteractionCreate(@NotNull GenericComponentInteractionCreateEvent event) {
|
||||||
|
if(event.getType() == InteractionType.COMPONENT) {
|
||||||
|
if(event.getChannel().getId().equals(SteamwarDiscordBotConfig.RULES_CHANNEL) && event.getComponentId().equals("auth")) {
|
||||||
|
String authMessage = AuthManager.createDiscordAuthToken(event.getMember());
|
||||||
|
if(authMessage != null) {
|
||||||
|
event.reply("Gebe innerhalb der nächsten 10 Minuten ``/verify " + authMessage + "`` auf dem Minecraft Server ein").setEphemeral(true).complete();
|
||||||
|
} else {
|
||||||
|
event.reply("Du hast bereits einen Code am laufen").setEphemeral(true).complete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(event.getComponentId().equals("tada") && event.getChannelType() == ChannelType.PRIVATE) {
|
||||||
|
event.reply(":tada:").setEphemeral(false).complete();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(event.getComponentId().equals("invalid") && event.getChannelType() == ChannelType.PRIVATE) {
|
||||||
|
SteamwarUser user = SteamwarUser.get(event.getUser().getIdLong());
|
||||||
|
if(user == null) {
|
||||||
|
event.reply(":question: Da ist keine verknüpfung?").setEphemeral(false).complete();
|
||||||
|
} else {
|
||||||
|
user.setDiscordId(null);
|
||||||
|
event.reply(":x: Die Verknüpfung wurde beendet").setEphemeral(false).complete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
144
src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java
Normale Datei
144
src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java
Normale Datei
@ -0,0 +1,144 @@
|
|||||||
|
/*
|
||||||
|
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.bot.listeners;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.BungeeCore;
|
||||||
|
import de.steamwar.bungeecore.Message;
|
||||||
|
import de.steamwar.bungeecore.bot.config.DiscordTicketType;
|
||||||
|
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||||
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.MessageBuilder;
|
||||||
|
import net.dv8tion.jda.api.Permission;
|
||||||
|
import net.dv8tion.jda.api.entities.*;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.GenericComponentInteractionCreateEvent;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
import net.dv8tion.jda.api.interactions.InteractionType;
|
||||||
|
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
||||||
|
import net.dv8tion.jda.api.interactions.components.Button;
|
||||||
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
public class DiscordTicketListener extends BasicDiscordListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGenericComponentInteractionCreate(@NotNull GenericComponentInteractionCreateEvent event) {
|
||||||
|
if(event.getType() == InteractionType.COMPONENT && event.getChannelType() == ChannelType.TEXT && event.getTextChannel().getParent() != null && event.getTextChannel().getParent().getId().equals(SteamwarDiscordBotConfig.TICKET_CATEGORY)) {
|
||||||
|
if(event.getTextChannel().getId().equals(SteamwarDiscordBotConfig.TICKET_CHANNEL) && SteamwarDiscordBotConfig.TICKET_TYPES.containsKey(event.getComponentId())) {
|
||||||
|
DiscordTicketType ticketType = SteamwarDiscordBotConfig.TICKET_TYPES.get(event.getComponentId());
|
||||||
|
Category ct = event.getGuild().getCategoryById(SteamwarDiscordBotConfig.TICKET_CATEGORY);
|
||||||
|
SteamwarUser swUser = SteamwarUser.get(event.getUser().getIdLong());
|
||||||
|
TextChannel ticketChannel = ct.createTextChannel((swUser == null?event.getUser().getName():swUser.getUserName()) + "-" + event.getComponentId() + "-" + System.currentTimeMillis() % 1000).complete();
|
||||||
|
ticketChannel.createPermissionOverride(event.getMember()).setAllow(Permission.VIEW_CHANNEL,
|
||||||
|
Permission.MESSAGE_WRITE,
|
||||||
|
Permission.MESSAGE_ATTACH_FILES,
|
||||||
|
Permission.MESSAGE_ADD_REACTION,
|
||||||
|
Permission.MESSAGE_READ,
|
||||||
|
Permission.MESSAGE_EMBED_LINKS,
|
||||||
|
Permission.MESSAGE_HISTORY).complete();
|
||||||
|
ticketChannel.getManager().setTopic(event.getUser().getId()).complete();
|
||||||
|
|
||||||
|
MessageBuilder messageBuilder = new MessageBuilder();
|
||||||
|
EmbedBuilder builder = new EmbedBuilder();
|
||||||
|
builder.setDescription(ticketType.getPreMessage());
|
||||||
|
builder.setTitle("Steamwar Ticket");
|
||||||
|
builder.setColor(Color.GREEN);
|
||||||
|
|
||||||
|
Button closeButton = Button.danger("close-" + ticketChannel.getName(), "Schließen").withEmoji(Emoji.fromUnicode("U+26A0"));
|
||||||
|
messageBuilder.setEmbeds(builder.build());
|
||||||
|
messageBuilder.setActionRows(ActionRow.of(closeButton));
|
||||||
|
|
||||||
|
ticketChannel.sendMessage(messageBuilder.build()).complete();
|
||||||
|
event.reply(SteamwarDiscordBotConfig.TICKET_CREATED.replace("%channel%", ticketChannel.getAsMention())).setEphemeral(true).complete();
|
||||||
|
Message.team("DISCORD_TICKET_NEW", ticketChannel.getName());
|
||||||
|
} else if(event.getComponentId().startsWith("close-")) {
|
||||||
|
TextChannel logChannel = event.getGuild().getTextChannelById(SteamwarDiscordBotConfig.TICKET_LOG);
|
||||||
|
|
||||||
|
MessageBuilder builder = new MessageBuilder();
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
new LinkedList<>(event.getTextChannel().getIterableHistory().complete()).descendingIterator().forEachRemaining(message -> {
|
||||||
|
if(message.getAuthor().isSystem() || message.getAuthor().isBot()) return;
|
||||||
|
stringBuilder.append("<t:").append(message.getTimeCreated().toInstant().getEpochSecond()).append("> ")
|
||||||
|
.append("**")
|
||||||
|
.append(message.getAuthor().getName())
|
||||||
|
.append("**: ")
|
||||||
|
.append(message.getContentRaw());
|
||||||
|
if(!message.getAttachments().isEmpty()) {
|
||||||
|
stringBuilder.append("\n")
|
||||||
|
.append("Files: ").append("\n");
|
||||||
|
message.getAttachments().forEach(attachment -> stringBuilder.append(attachment.getUrl()).append("\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuilder.append("\n");
|
||||||
|
});
|
||||||
|
|
||||||
|
stringBuilder.append("\n");
|
||||||
|
stringBuilder.append("<t:").append(Instant.now().getEpochSecond()).append("> ")
|
||||||
|
.append("**").append(event.getUser().getName()).append("**: ")
|
||||||
|
.append("Ticket geschlossen");
|
||||||
|
|
||||||
|
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||||
|
embedBuilder.setColor(Color.GREEN);
|
||||||
|
User user = event.getJDA().retrieveUserById(event.getTextChannel().getTopic()).complete();
|
||||||
|
SteamwarUser swuser = SteamwarUser.get(user.getIdLong());
|
||||||
|
|
||||||
|
embedBuilder.setAuthor(user.getName(), swuser==null?"https://steamwar.de/":("https://steamwar.de/users/" + swuser.getUserName().toLowerCase() + "/"), user.getAvatarUrl());
|
||||||
|
embedBuilder.setTimestamp(Instant.now());
|
||||||
|
embedBuilder.setTitle(event.getTextChannel().getName());
|
||||||
|
embedBuilder.setDescription(stringBuilder);
|
||||||
|
|
||||||
|
builder.setEmbeds(embedBuilder.build());
|
||||||
|
|
||||||
|
logChannel.sendMessage(builder.build()).complete();
|
||||||
|
|
||||||
|
Message.team("DISCORD_TICKET_CLOSED", event.getTextChannel().getName());
|
||||||
|
event.getTextChannel().delete().reason("Closed").complete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
|
||||||
|
if(event.getChannel().getParent() != null && event.getChannel().getParent().getId().equals(SteamwarDiscordBotConfig.TICKET_CATEGORY)) {
|
||||||
|
if(!event.getChannel().getId().equals(SteamwarDiscordBotConfig.TICKET_CHANNEL) && !event.getChannel().getId().equals(SteamwarDiscordBotConfig.TICKET_LOG)) {
|
||||||
|
BungeeCore.get().getProxy().getPlayers().forEach(player -> {
|
||||||
|
if(event.getAuthor().isBot() || event.getAuthor().isSystem()) return;
|
||||||
|
SteamwarUser user = SteamwarUser.get(player);
|
||||||
|
if(user.getDiscordId() == null) {
|
||||||
|
if(user.getUserGroup().isTeamGroup()) {
|
||||||
|
Message.sendPrefixless("DISCORD_TICKET_MESSAGE", player, "Zur nachricht", new ClickEvent(ClickEvent.Action.OPEN_URL, event.getMessage().getJumpUrl()), event.getChannel().getName(), event.getAuthor().getName(), event.getMessage().getContentRaw());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(event.getAuthor().getId().equals(user.getDiscordId())) return;
|
||||||
|
Member member = event.getGuild().retrieveMemberById(user.getDiscordId()).complete();
|
||||||
|
if(member.hasPermission(event.getChannel().getManager().getChannel(), Permission.MESSAGE_WRITE)) {
|
||||||
|
Message.sendPrefixless("DISCORD_TICKET_MESSAGE", player, "Zur nachricht", new ClickEvent(ClickEvent.Action.OPEN_URL, event.getMessage().getJumpUrl()), event.getChannel().getName(), event.getAuthor().getName(), event.getMessage().getContentRaw());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
68
src/de/steamwar/bungeecore/bot/listeners/IngameChatListener.java
Normale Datei
68
src/de/steamwar/bungeecore/bot/listeners/IngameChatListener.java
Normale Datei
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* 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.bot.listeners;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||||
|
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||||
|
import de.steamwar.bungeecore.listeners.ChatListener;
|
||||||
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
|
import de.steamwar.bungeecore.sql.UserGroup;
|
||||||
|
import net.dv8tion.jda.api.MessageBuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
|
import net.dv8tion.jda.api.entities.TextChannel;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class IngameChatListener extends BasicDiscordListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
|
||||||
|
if (!event.getChannel().getId().equals(SteamwarDiscordBotConfig.INGAME_CHANNEL)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.getAuthor().isBot()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Member member = event.getMember();
|
||||||
|
SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong());
|
||||||
|
if (steamwarUser == null || event.getMessage().getContentRaw().length() > 250) {
|
||||||
|
event.getMessage().delete().complete();
|
||||||
|
} else {
|
||||||
|
String s = event.getMessage().getContentDisplay();
|
||||||
|
if (steamwarUser.getUserGroup() == UserGroup.Member && (s.contains("http") || s.contains("www"))) {
|
||||||
|
event.getMessage().delete().complete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (steamwarUser.isMuted() || steamwarUser.isBanned()) {
|
||||||
|
event.getMessage().delete().complete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ChatListener.discordChat(steamwarUser, event.getMessage().getContentDisplay().replaceAll("§[a-f0-9]", "").replace('\n', ' '));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(String message) {
|
||||||
|
TextChannel textChannel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.INGAME_CHANNEL);
|
||||||
|
assert textChannel != null;
|
||||||
|
MessageBuilder messageBuilder = new MessageBuilder();
|
||||||
|
messageBuilder.append(message.replace("&", "").replace("@everyone", "`@everyone`").replace("@here", "`@here`").replaceAll("<[@#]!?\\d+>", "`$0`"));
|
||||||
|
textChannel.sendMessage(messageBuilder.build()).queue();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
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.bot.listeners;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||||
|
import net.dv8tion.jda.api.entities.ChannelType;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.GenericComponentInteractionCreateEvent;
|
||||||
|
import net.dv8tion.jda.api.interactions.InteractionType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class RolesInteractionButtonListener extends BasicDiscordListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGenericComponentInteractionCreate(@NotNull GenericComponentInteractionCreateEvent event) {
|
||||||
|
if(event.getType() == InteractionType.COMPONENT && event.getChannelType() == ChannelType.TEXT && event.getTextChannel().getId().equals(SteamwarDiscordBotConfig.ROLES_CHANNEL) && SteamwarDiscordBotConfig.ROLES.stream().anyMatch(discordRole -> discordRole.getRoleId().equals(event.getComponentId()))) {
|
||||||
|
if (event.getMember().getRoles().stream().anyMatch(role -> role.getId().equals(event.getComponentId()))) {
|
||||||
|
event.getGuild().removeRoleFromMember(event.getMember(), event.getGuild().getRoleById(event.getComponentId())).complete();
|
||||||
|
event.reply(SteamwarDiscordBotConfig.ROLES_REMOVED.replace("%role%", event.getGuild().getRoleById(event.getComponentId()).getAsMention())).setEphemeral(true).complete();
|
||||||
|
} else {
|
||||||
|
event.getGuild().addRoleToMember(event.getMember(), event.getGuild().getRoleById(event.getComponentId())).complete();
|
||||||
|
event.reply(SteamwarDiscordBotConfig.ROLES_ADDED.replace("%role%", event.getGuild().getRoleById(event.getComponentId()).getAsMention())).setEphemeral(true).complete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
59
src/de/steamwar/bungeecore/bot/listeners/ServerTeamChatListener.java
Normale Datei
59
src/de/steamwar/bungeecore/bot/listeners/ServerTeamChatListener.java
Normale Datei
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* 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.bot.listeners;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||||
|
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||||
|
import de.steamwar.bungeecore.commands.ServerTeamchatCommand;
|
||||||
|
import de.steamwar.bungeecore.listeners.ChatListener;
|
||||||
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
|
import net.dv8tion.jda.api.MessageBuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
|
import net.dv8tion.jda.api.entities.TextChannel;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class ServerTeamChatListener extends BasicDiscordListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
|
||||||
|
if (!event.getChannel().getId().equals(SteamwarDiscordBotConfig.SERVER_TEAM_CHANNEL)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.getAuthor().isBot()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Member member = event.getMember();
|
||||||
|
SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong());
|
||||||
|
if (steamwarUser == null) {
|
||||||
|
event.getMessage().delete().complete();
|
||||||
|
} else {
|
||||||
|
ServerTeamchatCommand.sendToTeam(event.getMessage().getContentRaw(), steamwarUser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(String message) {
|
||||||
|
TextChannel textChannel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.SERVER_TEAM_CHANNEL);
|
||||||
|
assert textChannel != null;
|
||||||
|
MessageBuilder messageBuilder = new MessageBuilder();
|
||||||
|
messageBuilder.append(message.replace("&", ""));
|
||||||
|
textChannel.sendMessage(messageBuilder.build()).queue();
|
||||||
|
}
|
||||||
|
}
|
32
src/de/steamwar/bungeecore/bot/listeners/SlashCommandListener.java
Normale Datei
32
src/de/steamwar/bungeecore/bot/listeners/SlashCommandListener.java
Normale Datei
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* 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.bot.listeners;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||||
|
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class SlashCommandListener extends BasicDiscordListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSlashCommand(@NotNull SlashCommandEvent event) {
|
||||||
|
SteamwarDiscordBot.getDiscordCommandMap().get(event.getName()).run(event);
|
||||||
|
}
|
||||||
|
}
|
67
src/de/steamwar/bungeecore/bot/util/DiscordRanks.java
Normale Datei
67
src/de/steamwar/bungeecore/bot/util/DiscordRanks.java
Normale Datei
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* 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.bot.util;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||||
|
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||||
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
|
import de.steamwar.bungeecore.sql.UserGroup;
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
|
import net.dv8tion.jda.api.entities.Role;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class DiscordRanks {
|
||||||
|
|
||||||
|
public void update(SteamwarUser steamwarUser) {
|
||||||
|
if (steamwarUser.getDiscordId() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Guild guild = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD);
|
||||||
|
Member member = guild.retrieveMemberById(steamwarUser.getDiscordId()).complete();
|
||||||
|
if (member == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Role> roleList = member.getRoles();
|
||||||
|
Set<String> strings = new HashSet<>(SteamwarDiscordBotConfig.RANKS.values());
|
||||||
|
String needed = SteamwarDiscordBotConfig.RANKS.get(steamwarUser.getUserGroup());
|
||||||
|
for (Role role : roleList) {
|
||||||
|
if (!strings.contains(role.getId())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (role.getId().equals(needed)) {
|
||||||
|
needed = "";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
guild.removeRoleFromMember(member, role).complete();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (needed != null && !needed.isEmpty()) {
|
||||||
|
guild.addRoleToMember(member, guild.getRoleById(needed)).complete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
58
src/de/steamwar/bungeecore/bot/util/DiscordRolesMessage.java
Normale Datei
58
src/de/steamwar/bungeecore/bot/util/DiscordRolesMessage.java
Normale Datei
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
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.bot.util;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||||
|
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
import net.dv8tion.jda.api.MessageBuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import net.dv8tion.jda.api.entities.TextChannel;
|
||||||
|
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
||||||
|
import net.dv8tion.jda.api.interactions.components.Button;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class DiscordRolesMessage {
|
||||||
|
|
||||||
|
|
||||||
|
public void sendMessage() {
|
||||||
|
TextChannel channel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.ROLES_CHANNEL);
|
||||||
|
assert channel != null;
|
||||||
|
Message message = null;
|
||||||
|
if(channel.hasLatestMessage()) {
|
||||||
|
message = channel.getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBuilder builder = new MessageBuilder();
|
||||||
|
builder.setContent(SteamwarDiscordBotConfig.ROLES_BASE_MESSAGE);
|
||||||
|
List<Button> buttons = new ArrayList<>();
|
||||||
|
SteamwarDiscordBotConfig.ROLES.forEach(discordRole -> buttons.add(discordRole.toButton()));
|
||||||
|
builder.setActionRows(ActionRow.of(buttons));
|
||||||
|
|
||||||
|
if (message != null) {
|
||||||
|
message.editMessage(builder.build()).complete();
|
||||||
|
} else {
|
||||||
|
channel.sendMessage(builder.build()).complete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
68
src/de/steamwar/bungeecore/bot/util/DiscordRulesMessage.java
Normale Datei
68
src/de/steamwar/bungeecore/bot/util/DiscordRulesMessage.java
Normale Datei
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
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.bot.util;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||||
|
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.MessageBuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.Emoji;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import net.dv8tion.jda.api.entities.TextChannel;
|
||||||
|
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
||||||
|
import net.dv8tion.jda.api.interactions.components.Button;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class DiscordRulesMessage {
|
||||||
|
|
||||||
|
public void sendMessage() {
|
||||||
|
TextChannel channel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.RULES_CHANNEL);
|
||||||
|
assert channel != null;
|
||||||
|
Message message = null;
|
||||||
|
if(channel.hasLatestMessage()) {
|
||||||
|
message = channel.getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
EmbedBuilder builder = new EmbedBuilder();
|
||||||
|
builder.setDescription(SteamwarDiscordBotConfig.RULES_RULES.stream().reduce((s, s2) -> s + "\n" + s2).get());
|
||||||
|
builder.setColor(Color.GRAY);
|
||||||
|
builder.setAuthor("SteamWar", "https://www.steamwar.de");
|
||||||
|
builder.setTitle(SteamwarDiscordBotConfig.RULES_TITLE);
|
||||||
|
|
||||||
|
List<Button> buttons = new ArrayList<>();
|
||||||
|
SteamwarDiscordBotConfig.RULES_LINKS.forEach(discordRulesLink -> buttons.add(discordRulesLink.toButton()));
|
||||||
|
|
||||||
|
Button authButton = Button.primary("auth", Emoji.fromUnicode("U+2705")).withLabel("Minecraft verknüpfen");
|
||||||
|
|
||||||
|
MessageBuilder messageBuilder = new MessageBuilder();
|
||||||
|
messageBuilder.setEmbeds(builder.build());
|
||||||
|
messageBuilder.setActionRows(ActionRow.of(buttons), ActionRow.of(authButton));
|
||||||
|
if (message != null) {
|
||||||
|
message.editMessage(messageBuilder.build()).complete();
|
||||||
|
} else {
|
||||||
|
channel.sendMessage(messageBuilder.build()).complete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
79
src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java
Normale Datei
79
src/de/steamwar/bungeecore/bot/util/DiscordSchemAlert.java
Normale Datei
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
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.bot.util;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||||
|
import de.steamwar.bungeecore.sql.Schematic;
|
||||||
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.MessageBuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.Emoji;
|
||||||
|
import net.dv8tion.jda.api.entities.User;
|
||||||
|
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
||||||
|
import net.dv8tion.jda.api.interactions.components.Button;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class DiscordSchemAlert {
|
||||||
|
|
||||||
|
public void sendDecline(Schematic schematic, SteamwarUser user, String reason) {
|
||||||
|
if(user.getDiscordId() != null) {
|
||||||
|
User dcUser = SteamwarDiscordBot.instance().getJda().retrieveUserById(user.getDiscordId()).complete();
|
||||||
|
EmbedBuilder builder = new EmbedBuilder();
|
||||||
|
builder.setAuthor("SteamWar", "https://steamwar.de", "https://cdn.discordapp.com/app-icons/869606970099904562/60c884000407c02671d91d8e7182b8a1.png");
|
||||||
|
builder.setColor(Color.RED);
|
||||||
|
builder.setTitle("SteamWar-Schematic Info");
|
||||||
|
builder.setDescription("Deine Schematic **" + schematic.getSchemName() + "** wurde abgelehnt. **Grund:** \n" + reason);
|
||||||
|
builder.setTimestamp(Instant.now());
|
||||||
|
|
||||||
|
MessageBuilder messageBuilder = new MessageBuilder();
|
||||||
|
messageBuilder.setEmbeds(builder.build());
|
||||||
|
try {
|
||||||
|
dcUser.openPrivateChannel().complete().sendMessage(messageBuilder.build()).queue();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendAccept(Schematic schematic, SteamwarUser user) {
|
||||||
|
if(user.getDiscordId() != null) {
|
||||||
|
User dcUser = SteamwarDiscordBot.instance().getJda().retrieveUserById(user.getDiscordId()).complete();
|
||||||
|
EmbedBuilder builder = new EmbedBuilder();
|
||||||
|
builder.setAuthor("SteamWar", "https://steamwar.de", "https://cdn.discordapp.com/app-icons/869606970099904562/60c884000407c02671d91d8e7182b8a1.png");
|
||||||
|
builder.setColor(Color.GREEN);
|
||||||
|
builder.setTitle("SteamWar-Schematic Info");
|
||||||
|
builder.setDescription("Deine Schematic **" + schematic.getSchemName() + "** wurde angenommen.");
|
||||||
|
builder.setTimestamp(Instant.now());
|
||||||
|
|
||||||
|
MessageBuilder messageBuilder = new MessageBuilder();
|
||||||
|
messageBuilder.setEmbeds(builder.build());
|
||||||
|
messageBuilder.setActionRows(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389"))));
|
||||||
|
try {
|
||||||
|
dcUser.openPrivateChannel().complete().sendMessage(messageBuilder.build()).queue();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
64
src/de/steamwar/bungeecore/bot/util/DiscordTicketMessage.java
Normale Datei
64
src/de/steamwar/bungeecore/bot/util/DiscordTicketMessage.java
Normale Datei
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
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.bot.util;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||||
|
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.MessageBuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import net.dv8tion.jda.api.entities.TextChannel;
|
||||||
|
import net.dv8tion.jda.api.interactions.components.ActionRow;
|
||||||
|
import net.dv8tion.jda.api.interactions.components.Button;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class DiscordTicketMessage {
|
||||||
|
|
||||||
|
public void sendMessage() {
|
||||||
|
TextChannel channel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.TICKET_CHANNEL);
|
||||||
|
assert channel != null;
|
||||||
|
Message message = null;
|
||||||
|
if(channel.hasLatestMessage()) {
|
||||||
|
message = channel.getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
EmbedBuilder builder = new EmbedBuilder();
|
||||||
|
builder.setDescription(SteamwarDiscordBotConfig.TICKET_MESSAGE);
|
||||||
|
builder.setTitle("Steamwar-Tickets");
|
||||||
|
builder.setColor(Color.RED);
|
||||||
|
|
||||||
|
List<Button> buttons = new ArrayList<>();
|
||||||
|
SteamwarDiscordBotConfig.TICKET_TYPES.forEach((s, discordTicketType) -> buttons.add(discordTicketType.toButton()));
|
||||||
|
|
||||||
|
MessageBuilder messageBuilder = new MessageBuilder();
|
||||||
|
messageBuilder.setEmbeds(builder.build());
|
||||||
|
messageBuilder.setActionRows(ActionRow.of(buttons));
|
||||||
|
if (message != null) {
|
||||||
|
message.editMessage(messageBuilder.build()).complete();
|
||||||
|
} else {
|
||||||
|
channel.sendMessage(messageBuilder.build()).complete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -20,6 +20,7 @@
|
|||||||
package de.steamwar.bungeecore.commands;
|
package de.steamwar.bungeecore.commands;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.Message;
|
import de.steamwar.bungeecore.Message;
|
||||||
|
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
|
||||||
@ -36,6 +37,33 @@ public class AlertCommand extends BasicCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Message.broadcast("ALERT", ChatColor.translateAlternateColorCodes('&', String.join(" ", args)));
|
String s;
|
||||||
|
boolean discordAnnounce = false;
|
||||||
|
if (args[0].equals("-discord")) {
|
||||||
|
if (args.length == 1) {
|
||||||
|
Message.send("USAGE_ALERT", sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
discordAnnounce = true;
|
||||||
|
s = join(1, args);
|
||||||
|
} else {
|
||||||
|
s = join(0, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
Message.broadcast("ALERT", ChatColor.translateAlternateColorCodes('&', s));
|
||||||
|
if (discordAnnounce) {
|
||||||
|
SteamwarDiscordBot.instance().getAnnouncementListener().announce(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String join(int startIndex, String... strings) {
|
||||||
|
StringBuilder st = new StringBuilder();
|
||||||
|
for (int i = startIndex; i < strings.length; i++) {
|
||||||
|
if (i != startIndex) {
|
||||||
|
st.append(" ");
|
||||||
|
}
|
||||||
|
st.append(strings[i]);
|
||||||
|
}
|
||||||
|
return st.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,9 @@ public class BanCommand extends BasicCommand {
|
|||||||
Date parsedDate = dateFormat.parse(arg.split("_")[0]);
|
Date parsedDate = dateFormat.parse(arg.split("_")[0]);
|
||||||
return new java.sql.Timestamp(parsedDate.getTime());
|
return new java.sql.Timestamp(parsedDate.getTime());
|
||||||
}catch(ParseException exception){
|
}catch(ParseException exception){
|
||||||
|
if (sender != null) {
|
||||||
Message.send("INVALID_TIME", sender);
|
Message.send("INVALID_TIME", sender);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package de.steamwar.bungeecore.commands;
|
package de.steamwar.bungeecore.commands;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.*;
|
import de.steamwar.bungeecore.*;
|
||||||
|
import de.steamwar.bungeecore.bot.util.DiscordSchemAlert;
|
||||||
import de.steamwar.bungeecore.listeners.ConnectionListener;
|
import de.steamwar.bungeecore.listeners.ConnectionListener;
|
||||||
import de.steamwar.bungeecore.sql.CheckedSchematic;
|
import de.steamwar.bungeecore.sql.CheckedSchematic;
|
||||||
import de.steamwar.bungeecore.sql.Schematic;
|
import de.steamwar.bungeecore.sql.Schematic;
|
||||||
@ -110,7 +111,7 @@ public class CheckCommand extends BasicCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Schematic> getSchemsToCheck(){
|
public static List<Schematic> getSchemsToCheck(){
|
||||||
List<Schematic> schematicList = new LinkedList<>();
|
List<Schematic> schematicList = new LinkedList<>();
|
||||||
|
|
||||||
for (SchematicType type : SchematicType.values()) {
|
for (SchematicType type : SchematicType.values()) {
|
||||||
@ -120,6 +121,11 @@ public class CheckCommand extends BasicCommand {
|
|||||||
return schematicList;
|
return schematicList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getChecker(Schematic schematic) {
|
||||||
|
if (currentSchems.get(schematic.getSchemID()) == null) return null;
|
||||||
|
return currentSchems.get(schematic.getSchemID()).checker.getName();
|
||||||
|
}
|
||||||
|
|
||||||
private void list(ProxiedPlayer player) {
|
private void list(ProxiedPlayer player) {
|
||||||
List<Schematic> schematicList = getSchemsToCheck();
|
List<Schematic> schematicList = getSchemsToCheck();
|
||||||
|
|
||||||
@ -288,8 +294,11 @@ public class CheckCommand extends BasicCommand {
|
|||||||
CheckedSchematic.create(schematic.getSchemName(), schematic.getSchemOwner(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "freigegeben");
|
CheckedSchematic.create(schematic.getSchemName(), schematic.getSchemOwner(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "freigegeben");
|
||||||
SteamwarUser user = SteamwarUser.get(schematic.getSchemOwner());
|
SteamwarUser user = SteamwarUser.get(schematic.getSchemOwner());
|
||||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid());
|
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid());
|
||||||
if(player != null)
|
if(player != null) {
|
||||||
Message.send("CHECK_ACCEPTED", player, schematic.getSchemType().name(), schematic.getSchemName());
|
Message.send("CHECK_ACCEPTED", player, schematic.getSchemType().name(), schematic.getSchemName());
|
||||||
|
} else {
|
||||||
|
DiscordSchemAlert.sendAccept(schematic, user);
|
||||||
|
}
|
||||||
Message.team("CHECK_ACCEPTED_TEAM", schematic.getSchemName(), user.getUserName());
|
Message.team("CHECK_ACCEPTED_TEAM", schematic.getSchemName(), user.getUserName());
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
@ -299,8 +308,11 @@ public class CheckCommand extends BasicCommand {
|
|||||||
CheckedSchematic.create(schematic.getSchemName(), schematic.getSchemOwner(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), reason);
|
CheckedSchematic.create(schematic.getSchemName(), schematic.getSchemOwner(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), reason);
|
||||||
SteamwarUser user = SteamwarUser.get(schematic.getSchemOwner());
|
SteamwarUser user = SteamwarUser.get(schematic.getSchemOwner());
|
||||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid());
|
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid());
|
||||||
if(player != null)
|
if(player != null) {
|
||||||
Message.send("CHECK_DECLINED", player, schematic.getSchemType().name(), schematic.getSchemName(), reason);
|
Message.send("CHECK_DECLINED", player, schematic.getSchemType().name(), schematic.getSchemName(), reason);
|
||||||
|
} else {
|
||||||
|
DiscordSchemAlert.sendDecline(schematic, user, reason);
|
||||||
|
}
|
||||||
Message.team("CHECK_DECLINED_TEAM", schematic.getSchemName(), user.getUserName(), reason);
|
Message.team("CHECK_DECLINED_TEAM", schematic.getSchemName(), user.getUserName(), reason);
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
97
src/de/steamwar/bungeecore/commands/DevCommand.java
Normale Datei
97
src/de/steamwar/bungeecore/commands/DevCommand.java
Normale Datei
@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* 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 net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class DevCommand extends BasicCommand {
|
||||||
|
|
||||||
|
private final File DevServerDir = new File("/configs/DevServer");
|
||||||
|
|
||||||
|
public DevCommand() {
|
||||||
|
super("dev", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(CommandSender sender, String[] args) {
|
||||||
|
if (!(sender instanceof ProxiedPlayer)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String[] devServer = DevServerDir.list();
|
||||||
|
if (devServer == null || devServer.length == 0) {
|
||||||
|
Message.send("DEV_NO_SERVER", sender);
|
||||||
|
} else if (devServer.length == 1) {
|
||||||
|
String[] server = devServer[0].split("\\.");
|
||||||
|
sendToServer((ProxiedPlayer) sender, server[0], Integer.parseInt(server[1]));
|
||||||
|
} else {
|
||||||
|
if (args.length == 0) {
|
||||||
|
send(devServer, (ProxiedPlayer) sender, s -> s.equalsIgnoreCase(sender.getName()), () -> Message.send("DEV_UNKNOWN_SERVER", sender));
|
||||||
|
} else {
|
||||||
|
send(devServer, (ProxiedPlayer) sender, args[0]::equalsIgnoreCase, () -> Message.send("DEV_NO_SERVER", sender));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void send(String[] devServer, ProxiedPlayer sender, Predicate<String> test, Runnable error) {
|
||||||
|
for (String s : devServer) {
|
||||||
|
String[] server = s.split("\\.");
|
||||||
|
if (test.test(server[0])) {
|
||||||
|
sendToServer(sender, server[0], Integer.parseInt(server[1]));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
error.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendToServer(ProxiedPlayer proxiedPlayer, String name, int port) {
|
||||||
|
InetSocketAddress address = new InetSocketAddress("127.0.0.1", port);
|
||||||
|
ServerInfo serverInfo = ProxyServer.getInstance().constructServerInfo("Dev-" + name, address, "SteamWar.de - Subserver", false);
|
||||||
|
proxiedPlayer.connect(serverInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
||||||
|
if (!(sender instanceof ProxiedPlayer)) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
String[] devSever = DevServerDir.list();
|
||||||
|
if (devSever == null) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
if (args.length > 1) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
return Arrays.stream(devSever).map(s -> s.split("\\.")).map(s -> s[0]).filter(s -> {
|
||||||
|
if (args.length == 0) return true;
|
||||||
|
return s.startsWith(args[0]);
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
}
|
77
src/de/steamwar/bungeecore/commands/ListCommand.java
Normale Datei
77
src/de/steamwar/bungeecore/commands/ListCommand.java
Normale Datei
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* 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.Servertype;
|
||||||
|
import de.steamwar.bungeecore.Subserver;
|
||||||
|
import lombok.Getter;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.connection.Server;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class ListCommand extends BasicCommand {
|
||||||
|
|
||||||
|
public ListCommand() {
|
||||||
|
super("list", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private static final TreeMap<String, List<ProxiedPlayer>> playerMap = new TreeMap<>();
|
||||||
|
|
||||||
|
public static synchronized void updateCustomTablist(){
|
||||||
|
//Calculate server-player-map
|
||||||
|
playerMap.clear();
|
||||||
|
for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
|
||||||
|
Server pserver = player.getServer();
|
||||||
|
if (pserver == null) //Happens temporarily
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ServerInfo server = pserver.getInfo();
|
||||||
|
String serverName = server.getName();
|
||||||
|
|
||||||
|
Subserver subserver = Subserver.getSubserver(server);
|
||||||
|
if (subserver != null && subserver.getType() == Servertype.BAUSERVER) {
|
||||||
|
playerMap.computeIfAbsent("Bau", s -> new ArrayList<>()).add(player);
|
||||||
|
} else {
|
||||||
|
playerMap.computeIfAbsent(serverName, s -> new ArrayList<>()).add(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
playerMap.forEach((server, players) -> players.sort((proxiedPlayer, t1) -> proxiedPlayer.getName().compareToIgnoreCase(t1.getName())));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(CommandSender commandSender, String[] strings) {
|
||||||
|
updateCustomTablist();
|
||||||
|
for (String server : playerMap.navigableKeySet()) {
|
||||||
|
if (server.equals("Bau")) {
|
||||||
|
server = Message.parse("TABLIST_BAU", commandSender);
|
||||||
|
}
|
||||||
|
Message.send("LIST_COMMAND", commandSender, server, playerMap.get(server).stream().map(CommandSender::getName).collect(Collectors.joining(", ")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -46,7 +46,7 @@ public class PollresultCommand extends BasicCommand {
|
|||||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||||
|
|
||||||
Map<String, Integer> voted = PollAnswer.getCurrentResults();
|
Map<String, Integer> voted = PollAnswer.getCurrentResults();
|
||||||
Message.send("POLLRESULT_HEADER", player, PollAnswer.getAllAnswered(), PollSystem.getQuestion());
|
Message.send("POLLRESULT_HEADER", player, voted.values().stream().reduce(Integer::sum), 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", sender, e.getKey(), e.getValue());
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,9 @@
|
|||||||
package de.steamwar.bungeecore.commands;
|
package de.steamwar.bungeecore.commands;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.Message;
|
import de.steamwar.bungeecore.Message;
|
||||||
|
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||||
import de.steamwar.bungeecore.listeners.ChatListener;
|
import de.steamwar.bungeecore.listeners.ChatListener;
|
||||||
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
@ -49,10 +51,20 @@ public class ServerTeamchatCommand extends BasicCommand {
|
|||||||
String msg = msgBuilder.toString();
|
String msg = msgBuilder.toString();
|
||||||
msg = ChatColor.translateAlternateColorCodes('&', msg);
|
msg = ChatColor.translateAlternateColorCodes('&', msg);
|
||||||
|
|
||||||
|
SteamwarDiscordBot.instance().getServerTeamChatListener().send("<t:" + (System.currentTimeMillis() / 1000) + "> " + (player.getName() + "» " + msg).replaceAll("§[a-f0-9r]", ""));
|
||||||
sendToTeam(msg, player);
|
sendToTeam(msg, player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void sendToTeam(String message, SteamwarUser sender){
|
||||||
|
for (ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
|
||||||
|
if ((target.hasPermission("bungeecore.teamchat"))
|
||||||
|
&& target.getChatMode() == ProxiedPlayer.ChatMode.SHOWN){
|
||||||
|
Message.sendPrefixless("STC_FORMAT", target, sender.getUserName(), ChatListener.parseAtMessage(message, "§r", target));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void sendToTeam(String message, ProxiedPlayer sender){
|
public static void sendToTeam(String message, ProxiedPlayer sender){
|
||||||
for (ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
|
for (ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
|
||||||
if ((target.hasPermission("bungeecore.teamchat"))
|
if ((target.hasPermission("bungeecore.teamchat"))
|
||||||
|
69
src/de/steamwar/bungeecore/commands/StatCommand.java
Normale Datei
69
src/de/steamwar/bungeecore/commands/StatCommand.java
Normale Datei
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
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.LoadEvaluation;
|
||||||
|
import de.steamwar.bungeecore.Message;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class StatCommand extends BasicCommand {
|
||||||
|
|
||||||
|
public StatCommand() {
|
||||||
|
super("stat", "bungeecore.softreload", "stats");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(CommandSender sender, String[] args) {
|
||||||
|
try {
|
||||||
|
Process process = new ProcessBuilder("ps", "x").start();
|
||||||
|
process.waitFor();
|
||||||
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||||
|
Map<String, Integer> serverCounts = new HashMap<>();
|
||||||
|
bufferedReader.lines().forEach(s -> {
|
||||||
|
if (!s.contains("--port")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String server = "SW";
|
||||||
|
if (s.contains("ssh -L")) {
|
||||||
|
server = s.substring(s.indexOf("ssh -L") + 6).split(" ")[2];
|
||||||
|
}
|
||||||
|
serverCounts.put(server, serverCounts.computeIfAbsent(server, s1 -> 0) + 1);
|
||||||
|
});
|
||||||
|
serverCounts.forEach((s, integer) -> {
|
||||||
|
if (s.equals("SW")) {
|
||||||
|
Message.send("STAT_SERVER", sender, s, LoadEvaluation.getRamPercentage(), LoadEvaluation.getCPULoad(), integer);
|
||||||
|
} else {
|
||||||
|
Message.send("STAT_SERVER", sender, s.toUpperCase(), LoadEvaluation.getRemoteRamPercentage(s), LoadEvaluation.getRemoteCPULoad(s), integer);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (serverCounts.isEmpty()) {
|
||||||
|
Message.send("NO_STATS", sender);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new SecurityException(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -177,7 +177,7 @@ public class TeamCommand extends BasicCommand {
|
|||||||
if(checkTeamName(player, team, args[2]))
|
if(checkTeamName(player, team, args[2]))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Team.create(args[1], args[2], user);
|
Team.create(args[1], args[2]);
|
||||||
user.setTeam(Team.get(args[1]).getTeamId());
|
user.setTeam(Team.get(args[1]).getTeamId());
|
||||||
user.setLeader(true);
|
user.setLeader(true);
|
||||||
Message.send("TEAM_CREATE_CREATED", player, args[2]);
|
Message.send("TEAM_CREATE_CREATED", player, args[2]);
|
||||||
|
60
src/de/steamwar/bungeecore/commands/VerifyCommand.java
Normale Datei
60
src/de/steamwar/bungeecore/commands/VerifyCommand.java
Normale Datei
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
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.BungeeCore;
|
||||||
|
import de.steamwar.bungeecore.Message;
|
||||||
|
import de.steamwar.bungeecore.bot.AuthManager;
|
||||||
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
|
public class VerifyCommand extends BasicCommand {
|
||||||
|
|
||||||
|
public VerifyCommand() {
|
||||||
|
super("verify", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(CommandSender sender, String[] strings) {
|
||||||
|
if(strings.length < 1) {
|
||||||
|
Message.send("VERIFY_USAGE", sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
byte[] bytes = Base64.getDecoder().decode(strings[0]);
|
||||||
|
if(bytes.length != 16) {
|
||||||
|
Message.send("VERIFY_INVALID", sender);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(bytes[0] == 'D' && bytes[1] == 'C') {
|
||||||
|
Member member = AuthManager.connectAuth(SteamwarUser.get(sender.getName()), strings[0]);
|
||||||
|
if(member != null) {
|
||||||
|
BungeeCore.log(sender.getName() + " Verified with Discorduser: " + member.getIdLong());
|
||||||
|
Message.send("VERIFY_SUCCESS", sender, member.getUser().getAsTag());
|
||||||
|
} else {
|
||||||
|
Message.send("VERIFY_INVALID", sender);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Message.send("VERIFY_INVALID", sender);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -54,6 +54,14 @@ public class WhoisCommand extends BasicCommand {
|
|||||||
user = SteamwarUser.get(id);
|
user = SteamwarUser.get(id);
|
||||||
}catch (NumberFormatException ignored) {}
|
}catch (NumberFormatException ignored) {}
|
||||||
}
|
}
|
||||||
|
if (user == null) {
|
||||||
|
try {
|
||||||
|
long id = Long.parseLong(args[0]);
|
||||||
|
user = SteamwarUser.get(id);
|
||||||
|
} catch (NumberFormatException ignored) {
|
||||||
|
// Ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(user == null) {
|
if(user == null) {
|
||||||
Message.send("UNKNOWN_PLAYER", player);
|
Message.send("UNKNOWN_PLAYER", player);
|
||||||
@ -67,6 +75,9 @@ public class WhoisCommand extends BasicCommand {
|
|||||||
Message.send("WHOIS_USERNAME", player, user.getUserName());
|
Message.send("WHOIS_USERNAME", player, user.getUserName());
|
||||||
Message.send("WHOIS_UUID", player, Message.parse("WHOIS_UUID_HOVER", player), new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, user.getUuid().toString()), user.getUuid().toString());
|
Message.send("WHOIS_UUID", player, Message.parse("WHOIS_UUID_HOVER", player), new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, user.getUuid().toString()), user.getUuid().toString());
|
||||||
Message.send("WHOIS_ID", player, user.getId());
|
Message.send("WHOIS_ID", player, user.getId());
|
||||||
|
if (user.getDiscordId() != null) {
|
||||||
|
Message.send("WHOIS_DISCORD_ID", player, user.getDiscordId());
|
||||||
|
}
|
||||||
Timestamp firstJoin = user.getFirstjoin();
|
Timestamp firstJoin = user.getFirstjoin();
|
||||||
if(firstJoin == null)
|
if(firstJoin == null)
|
||||||
Message.send("WHOIS_JOINED_FIRST", player, "0000-00-00 00:00:00");
|
Message.send("WHOIS_JOINED_FIRST", player, "0000-00-00 00:00:00");
|
||||||
|
@ -19,10 +19,9 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore.listeners;
|
package de.steamwar.bungeecore.listeners;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
import de.steamwar.bungeecore.*;
|
||||||
import de.steamwar.bungeecore.Message;
|
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||||
import de.steamwar.bungeecore.Servertype;
|
import de.steamwar.bungeecore.bot.listeners.IngameChatListener;
|
||||||
import de.steamwar.bungeecore.Subserver;
|
|
||||||
import de.steamwar.bungeecore.commands.TpCommand;
|
import de.steamwar.bungeecore.commands.TpCommand;
|
||||||
import de.steamwar.bungeecore.comms.packets.PingPacket;
|
import de.steamwar.bungeecore.comms.packets.PingPacket;
|
||||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
@ -50,6 +49,8 @@ public class ChatListener extends BasicListener {
|
|||||||
sanitize7(e);
|
sanitize7(e);
|
||||||
if(e.getMessage().startsWith("/"))
|
if(e.getMessage().startsWith("/"))
|
||||||
onCommand(e);
|
onCommand(e);
|
||||||
|
else if(e.getMessage().startsWith("+"))
|
||||||
|
onPlusMessage(e);
|
||||||
else
|
else
|
||||||
onChat(e);
|
onChat(e);
|
||||||
}
|
}
|
||||||
@ -63,6 +64,10 @@ public class ChatListener extends BasicListener {
|
|||||||
e.setMessage("/" + e.getMessage().substring(1));
|
e.setMessage("/" + e.getMessage().substring(1));
|
||||||
}else if(begin.startsWith("77") && begin.substring(2).matches("[A-Za-z]+")){
|
}else if(begin.startsWith("77") && begin.substring(2).matches("[A-Za-z]+")){
|
||||||
e.setMessage("//" + e.getMessage().substring(2));
|
e.setMessage("//" + e.getMessage().substring(2));
|
||||||
|
}else if(begin.startsWith("7/") && begin.substring(2).matches("[A-Za-z]+")){
|
||||||
|
e.setMessage("//" + e.getMessage().substring(2));
|
||||||
|
}else if(begin.startsWith("/7") && begin.substring(2).matches("[A-Za-z]+")){
|
||||||
|
e.setMessage("//" + e.getMessage().substring(2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,6 +115,20 @@ public class ChatListener extends BasicListener {
|
|||||||
scheduler.schedule(BungeeCore.get(), () -> Message.sendPrefixless("MSG_FORMAT", sender, "YoyoNow", sender.getDisplayName(), Message.parse("CHAT_YOYONOW_4", sender)), 12, TimeUnit.SECONDS);
|
scheduler.schedule(BungeeCore.get(), () -> Message.sendPrefixless("MSG_FORMAT", sender, "YoyoNow", sender.getDisplayName(), Message.parse("CHAT_YOYONOW_4", sender)), 12, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onPlusMessage(ChatEvent e) {
|
||||||
|
ProxiedPlayer p = (ProxiedPlayer) e.getSender();
|
||||||
|
Subserver subserver = Subserver.getSubserver(p);
|
||||||
|
if(subserver instanceof Bauserver) {
|
||||||
|
String[] smolArgs = e.getMessage().substring(1).split(" ");
|
||||||
|
String[] args = new String[smolArgs.length + 1];
|
||||||
|
args[0] = "";
|
||||||
|
System.arraycopy(smolArgs, 0, args, 1, smolArgs.length);
|
||||||
|
localChat(e, args);
|
||||||
|
} else {
|
||||||
|
onChat(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void onChat(ChatEvent e){
|
private void onChat(ChatEvent e){
|
||||||
if(e.getSender() instanceof ProxiedPlayer){
|
if(e.getSender() instanceof ProxiedPlayer){
|
||||||
ProxiedPlayer sender = (ProxiedPlayer) e.getSender();
|
ProxiedPlayer sender = (ProxiedPlayer) e.getSender();
|
||||||
@ -147,11 +166,36 @@ public class ChatListener extends BasicListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void discordChat(SteamwarUser user, String message){
|
||||||
|
String name = "§r" + user.getUserName() + "§r";
|
||||||
|
if (user.getUserGroup() != UserGroup.Member) {
|
||||||
|
name = user.getUserGroup().getColorCode() + user.getUserGroup().name() + " " + user.getUserName() + "§r";
|
||||||
|
}
|
||||||
|
String chatcolor = user.getUserGroup().getChatColorCode();
|
||||||
|
|
||||||
|
if(user.getUserGroup() != UserGroup.Member || user.getTeam() == 12 || user.getTeam() == 285 || user.getTeam() == 54)
|
||||||
|
message = ChatColor.translateAlternateColorCodes('&', message);
|
||||||
|
|
||||||
|
String msg = name + "§7»" + chatcolor + " " + message;
|
||||||
|
if(user.getTeam() != 0){
|
||||||
|
Team team = Team.get(user.getTeam());
|
||||||
|
msg = "§" + team.getTeamColor() + team.getTeamKuerzel() + " §r" + msg;
|
||||||
|
}
|
||||||
|
msg = "§7Discord §r" + msg;
|
||||||
|
|
||||||
|
for(ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
|
||||||
|
Subserver targetServer = Subserver.getSubserver(target);
|
||||||
|
if(!(targetServer == null || targetServer.getType() != Servertype.ARENA || targetServer.getServer() != target.getServer().getInfo())) continue;
|
||||||
|
|
||||||
|
BungeeCore.send(target, ChatMessageType.CHAT, parseAtMessage(msg, chatcolor, target));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void publicChat(SteamwarUser user, ProxiedPlayer sender, String message){
|
private void publicChat(SteamwarUser user, ProxiedPlayer sender, String message){
|
||||||
String name = sender.getDisplayName();
|
String name = sender.getDisplayName();
|
||||||
String chatcolor = user.getUserGroup().getChatColorCode();
|
String chatcolor = user.getUserGroup().getChatColorCode();
|
||||||
|
|
||||||
if(user.getUserGroup() != UserGroup.Member)
|
if(user.getUserGroup() != UserGroup.Member || user.getTeam() == 12 || user.getTeam() == 285 || user.getTeam() == 54)
|
||||||
message = ChatColor.translateAlternateColorCodes('&', message);
|
message = ChatColor.translateAlternateColorCodes('&', message);
|
||||||
|
|
||||||
String msg = name + "§7»" + chatcolor + " " + message;
|
String msg = name + "§7»" + chatcolor + " " + message;
|
||||||
@ -160,6 +204,7 @@ public class ChatListener extends BasicListener {
|
|||||||
msg = "§" + team.getTeamColor() + team.getTeamKuerzel() + " §r" + msg;
|
msg = "§" + team.getTeamColor() + team.getTeamKuerzel() + " §r" + msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SteamwarDiscordBot.instance().getIngameChatListener().send("<t:" + (System.currentTimeMillis() / 1000) + "> " + msg.replaceAll("§[a-f0-9r]", ""));
|
||||||
for(ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
|
for(ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
|
||||||
Subserver targetServer = Subserver.getSubserver(target);
|
Subserver targetServer = Subserver.getSubserver(target);
|
||||||
if(!(targetServer == null || targetServer.getType() != Servertype.ARENA || targetServer.getServer() != target.getServer().getInfo())) continue;
|
if(!(targetServer == null || targetServer.getType() != Servertype.ARENA || targetServer.getServer() != target.getServer().getInfo())) continue;
|
||||||
|
@ -23,6 +23,7 @@ import de.steamwar.bungeecore.BungeeCore;
|
|||||||
import de.steamwar.bungeecore.Message;
|
import de.steamwar.bungeecore.Message;
|
||||||
import de.steamwar.bungeecore.Servertype;
|
import de.steamwar.bungeecore.Servertype;
|
||||||
import de.steamwar.bungeecore.Subserver;
|
import de.steamwar.bungeecore.Subserver;
|
||||||
|
import de.steamwar.bungeecore.bot.util.DiscordRanks;
|
||||||
import de.steamwar.bungeecore.commands.ChallengeCommand;
|
import de.steamwar.bungeecore.commands.ChallengeCommand;
|
||||||
import de.steamwar.bungeecore.commands.CheckCommand;
|
import de.steamwar.bungeecore.commands.CheckCommand;
|
||||||
import de.steamwar.bungeecore.commands.MsgCommand;
|
import de.steamwar.bungeecore.commands.MsgCommand;
|
||||||
@ -94,6 +95,8 @@ public class ConnectionListener extends BasicListener {
|
|||||||
Message.broadcast("JOIN_FIRST", player.getName());
|
Message.broadcast("JOIN_FIRST", player.getName());
|
||||||
newPlayers.remove(player.getUniqueId());
|
newPlayers.remove(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DiscordRanks.update(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** To redirect players to the lobby in case of server closure. */
|
/** To redirect players to the lobby in case of server closure. */
|
||||||
|
@ -27,6 +27,7 @@ import de.steamwar.bungeecore.Message;
|
|||||||
import de.steamwar.bungeecore.Servertype;
|
import de.steamwar.bungeecore.Servertype;
|
||||||
import de.steamwar.bungeecore.Subserver;
|
import de.steamwar.bungeecore.Subserver;
|
||||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
|
import de.steamwar.bungeecore.sql.Team;
|
||||||
import de.steamwar.bungeecore.sql.UserGroup;
|
import de.steamwar.bungeecore.sql.UserGroup;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
@ -41,6 +42,7 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class TablistManager extends BasicListener {
|
public class TablistManager extends BasicListener {
|
||||||
|
|
||||||
@ -69,13 +71,9 @@ public class TablistManager extends BasicListener {
|
|||||||
|
|
||||||
private void calculateSize() {
|
private void calculateSize() {
|
||||||
size = -1;
|
size = -1;
|
||||||
for(Map.Entry<String, List<ProxiedPlayer>> server : playerMap.entrySet())
|
size += playerMap.size() * 2 + ProxyServer.getInstance().getPlayers().size();
|
||||||
size += 2 + server.getValue().size();
|
|
||||||
|
|
||||||
size = (size + 19) / 20;
|
size = (size + 19) / 20;
|
||||||
|
if(size > 5) size = 5;
|
||||||
if(size > 5)
|
|
||||||
size = 5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void updateCustomTablist(){
|
private synchronized void updateCustomTablist(){
|
||||||
@ -90,15 +88,10 @@ public class TablistManager extends BasicListener {
|
|||||||
String serverName = server.getName();
|
String serverName = server.getName();
|
||||||
|
|
||||||
Subserver subserver = Subserver.getSubserver(server);
|
Subserver subserver = Subserver.getSubserver(server);
|
||||||
List<ProxiedPlayer> players;
|
|
||||||
if (subserver != null && subserver.getType() == Servertype.BAUSERVER) {
|
if (subserver != null && subserver.getType() == Servertype.BAUSERVER) {
|
||||||
players = playerMap.getOrDefault("Bau", new ArrayList<>());
|
playerMap.computeIfAbsent("Bau", s -> new ArrayList<>()).add(player);
|
||||||
players.add(player);
|
|
||||||
playerMap.putIfAbsent("Bau", players);
|
|
||||||
} else {
|
} else {
|
||||||
players = playerMap.getOrDefault(serverName, new ArrayList<>());
|
playerMap.computeIfAbsent(serverName, s -> new ArrayList<>()).add(player);
|
||||||
players.add(player);
|
|
||||||
playerMap.putIfAbsent(serverName, players);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
playerMap.forEach((server, players) -> players.sort((proxiedPlayer, t1) -> proxiedPlayer.getName().compareToIgnoreCase(t1.getName())));
|
playerMap.forEach((server, players) -> players.sort((proxiedPlayer, t1) -> proxiedPlayer.getName().compareToIgnoreCase(t1.getName())));
|
||||||
@ -131,15 +124,13 @@ public class TablistManager extends BasicListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String calcHeader(ProxiedPlayer player){
|
private String calcHeader(ProxiedPlayer player){
|
||||||
int phase = (seconds % 16) / 4;
|
int phase = (seconds % 16) / 3;
|
||||||
switch(phase){
|
switch(phase){
|
||||||
case 0:
|
case 0:
|
||||||
return Message.parse("TABLIST_PHASE_0", player, ProxyServer.getInstance().getPlayers().size());
|
|
||||||
case 1:
|
|
||||||
return Message.parse("TABLIST_PHASE_1", player);
|
return Message.parse("TABLIST_PHASE_1", player);
|
||||||
case 2:
|
case 1:
|
||||||
return Message.parse("TABLIST_PHASE_2", player);
|
return Message.parse("TABLIST_PHASE_2", player);
|
||||||
case 3:
|
case 2:
|
||||||
default:
|
default:
|
||||||
return Message.parse("TABLIST_PHASE_DEFAULT", player);
|
return Message.parse("TABLIST_PHASE_DEFAULT", player);
|
||||||
}
|
}
|
||||||
@ -157,13 +148,21 @@ public class TablistManager extends BasicListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void refresh(){
|
private void refresh(){
|
||||||
|
if (player.getServer() == null) {
|
||||||
try {
|
return;
|
||||||
|
}
|
||||||
ServerInfo currentServer = player.getServer().getInfo();
|
ServerInfo currentServer = player.getServer().getInfo();
|
||||||
setHeader(calcHeader(player));
|
setHeader(calcHeader(player));
|
||||||
setFooter("§e" + currentServer.getName() + " " + getPing() + "§8ms");
|
// TABLIST_FOOTER=§e{0} {1}§8ms §eSpieler§8: §7{2}
|
||||||
|
setFooter("§e" + currentServer.getName() + " " + getPing() + "§8ms §eSpieler§8: §7" + ProxyServer.getInstance().getPlayers().size());
|
||||||
setSize(size, 20);
|
setSize(size, 20);
|
||||||
|
|
||||||
|
if (size >= 5) {
|
||||||
|
refreshSlim(currentServer);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (String server : playerMap.navigableKeySet()) {
|
for (String server : playerMap.navigableKeySet()) {
|
||||||
if (i > 0){
|
if (i > 0){
|
||||||
@ -174,24 +173,85 @@ public class TablistManager extends BasicListener {
|
|||||||
server = Message.parse("TABLIST_BAU", player);
|
server = Message.parse("TABLIST_BAU", player);
|
||||||
setSlot(i%20, i/20, gray, "§7§l" + server, 1000);
|
setSlot(i%20, i/20, gray, "§7§l" + server, 1000);
|
||||||
i++;
|
i++;
|
||||||
for (ProxiedPlayer p : playerMap.get(server)){
|
i = update(currentServer, playerMap.get(server), i);
|
||||||
boolean sameServer = currentServer == p.getServer().getInfo();
|
|
||||||
setSlot(i % 20, i / 20, BungeeTabListPlusAPI.getIconFromPlayer(p), getTablistName(p, sameServer), (sameServer ? 1 : 500));
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (i < size*20){
|
finish(i);
|
||||||
setSlot(i%20, i/20, darkGray, "", 1000);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}catch(IndexOutOfBoundsException | NullPointerException e){
|
}catch(IndexOutOfBoundsException | NullPointerException e){
|
||||||
//Ignore IndexOutOfBoundsException
|
//Ignore IndexOutOfBoundsException
|
||||||
//Ignore NPE, happens sometimes (only 1s long) when somebody is joining, server switching or disconnecting
|
//Ignore NPE, happens sometimes (only 1s long) when somebody is joining, server switching or disconnecting
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getTablistName(ProxiedPlayer p, boolean sameServer) {
|
private void refreshSlim(ServerInfo currentServer) {
|
||||||
|
try {
|
||||||
|
int i = 0;
|
||||||
|
boolean spacer = true;
|
||||||
|
for (String server : playerMap.navigableKeySet()) {
|
||||||
|
if (i > 0 && spacer) {
|
||||||
|
setSlot(i%20, i/20, darkGray, "", 1000);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
spacer = true;
|
||||||
|
Team team = getTeam(player);
|
||||||
|
List<ProxiedPlayer> players = playerMap.get(server)
|
||||||
|
.stream()
|
||||||
|
.filter(p -> (p.getServer() != null && p.getServer().getInfo() == currentServer) || SteamwarUser.get(p).getUserGroup() != UserGroup.Member || (team != null && team == getTeam(p)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
Subserver subserver = Subserver.getSubserver(player);
|
||||||
|
if (server.equals("Bau")) {
|
||||||
|
if (subserver != null && subserver.getType() == Servertype.BAUSERVER) {
|
||||||
|
players = playerMap.get(server);
|
||||||
|
}
|
||||||
|
server = Message.parse("TABLIST_BAU", player);
|
||||||
|
}
|
||||||
|
if (subserver != null && subserver.getType() == Servertype.ARENA && playerMap.get(server).size() == 1) {
|
||||||
|
players = playerMap.get(server);
|
||||||
|
}
|
||||||
|
|
||||||
|
int increment = playerMap.get(server).size() - players.size();
|
||||||
|
if (players.isEmpty()) {
|
||||||
|
server += " §7(" + increment + ")";
|
||||||
|
spacer = false;
|
||||||
|
} else if (increment != 0) {
|
||||||
|
server += " §7(+" + increment + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
setSlot(i%20, i/20, gray, "§7§l" + server, 1000);
|
||||||
|
i++;
|
||||||
|
i = update(currentServer, players, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
finish(i);
|
||||||
|
}catch(IndexOutOfBoundsException | NullPointerException e){
|
||||||
|
//Ignore IndexOutOfBoundsException
|
||||||
|
//Ignore NPE, happens sometimes (only 1s long) when somebody is joining, server switching or disconnecting
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int update(ServerInfo currentServer, List<ProxiedPlayer> players, int i) {
|
||||||
|
for (ProxiedPlayer p : players){
|
||||||
|
boolean sameServer = currentServer == p.getServer().getInfo();
|
||||||
|
setSlot(i % 20, i / 20, BungeeTabListPlusAPI.getIconFromPlayer(p), getTablistName(p), (sameServer ? 1 : 500));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void finish(int i) {
|
||||||
|
while (i < size*20){
|
||||||
|
setSlot(i%20, i/20, darkGray, "", 1000);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Team getTeam(ProxiedPlayer p) {
|
||||||
|
Team team = Team.get(SteamwarUser.get(p).getTeam());
|
||||||
|
return team.getTeamId() <= 0 ? null : team;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getTablistName(ProxiedPlayer p) {
|
||||||
Subserver server = Subserver.getSubserver(p);
|
Subserver server = Subserver.getSubserver(p);
|
||||||
if(server != null){
|
if(server != null){
|
||||||
String tablistName = server.getTablistNames().get(p);
|
String tablistName = server.getTablistNames().get(p);
|
||||||
@ -202,13 +262,14 @@ public class TablistManager extends BasicListener {
|
|||||||
StringBuilder st = new StringBuilder();
|
StringBuilder st = new StringBuilder();
|
||||||
UserGroup group = SteamwarUser.get(p).getUserGroup();
|
UserGroup group = SteamwarUser.get(p).getUserGroup();
|
||||||
|
|
||||||
//else st.append("§7");
|
if (group == UserGroup.Member) {
|
||||||
if(group == UserGroup.Member && sameServer)
|
Team team = getTeam(player);
|
||||||
st.append("§f");
|
if (team != null && team == getTeam(p)) st.append("§f");
|
||||||
else
|
else st.append("§7");
|
||||||
|
} else {
|
||||||
st.append(group.getColorCode());
|
st.append(group.getColorCode());
|
||||||
|
}
|
||||||
|
|
||||||
// if (!sameServer) st.append("§o");
|
|
||||||
return st.append(p.getName()).toString();
|
return st.append(p.getName()).toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,18 +19,18 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore.sql;
|
package de.steamwar.bungeecore.sql;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class BannedUserIPs {
|
public class BannedUserIPs {
|
||||||
|
|
||||||
private int userID;
|
private static final Statement getByID = new Statement("SELECT * FROM BannedUserIPs WHERE UserID = ? ORDER BY Timestamp ASC");
|
||||||
private Timestamp timestamp;
|
private static final Statement getByIP = new Statement("SELECT * FROM BannedUserIPs WHERE IP = ? ORDER BY Timestamp DESC");
|
||||||
|
private static final Statement banIP = new Statement("INSERT INTO BannedUserIPs (UserID, Timestamp, IP) VALUES (?, NOW(), ?) ON DUPLICATE KEY UPDATE Timestamp=NOW()");
|
||||||
|
|
||||||
|
private final int userID;
|
||||||
|
private final Timestamp timestamp;
|
||||||
|
|
||||||
private BannedUserIPs(int userID, Timestamp timestamp){
|
private BannedUserIPs(int userID, Timestamp timestamp){
|
||||||
this.userID = userID;
|
this.userID = userID;
|
||||||
@ -38,37 +38,31 @@ public class BannedUserIPs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<BannedUserIPs> get(int userID){
|
public static List<BannedUserIPs> get(int userID){
|
||||||
|
return getByID.select(rs -> {
|
||||||
List<BannedUserIPs> userIPs = new ArrayList<>();
|
List<BannedUserIPs> userIPs = new ArrayList<>();
|
||||||
ResultSet dbentry = SQL.select("SELECT * FROM BannedUserIPs WHERE UserID = ? ORDER BY Timestamp ASC", userID);
|
while(rs.next()) {
|
||||||
try {
|
|
||||||
while(dbentry.next()){
|
|
||||||
userIPs.add(new BannedUserIPs(
|
userIPs.add(new BannedUserIPs(
|
||||||
userID,
|
userID,
|
||||||
dbentry.getTimestamp("Timestamp")));
|
rs.getTimestamp("Timestamp")));
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
BungeeCore.log("Get BannedUserIPs failed", e);
|
|
||||||
}
|
}
|
||||||
return userIPs;
|
return userIPs;
|
||||||
|
}, userID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<BannedUserIPs> get(String ip){
|
public static List<BannedUserIPs> get(String ip){
|
||||||
|
return getByIP.select(rs -> {
|
||||||
List<BannedUserIPs> userIDs = new ArrayList<>();
|
List<BannedUserIPs> userIDs = new ArrayList<>();
|
||||||
ResultSet dbentry = SQL.select("SELECT * FROM BannedUserIPs WHERE IP = ? ORDER BY Timestamp DESC", ip);
|
while(rs.next()) {
|
||||||
try {
|
|
||||||
while(dbentry.next()){
|
|
||||||
userIDs.add(new BannedUserIPs(
|
userIDs.add(new BannedUserIPs(
|
||||||
dbentry.getInt("UserID"),
|
rs.getInt("UserID"),
|
||||||
dbentry.getTimestamp("Timestamp")));
|
rs.getTimestamp("Timestamp")));
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
BungeeCore.log("Get BannedUserIPs failed", e);
|
|
||||||
}
|
}
|
||||||
return userIDs;
|
return userIDs;
|
||||||
|
}, ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void banIP(SteamwarUser user, String ip){
|
static void banIP(SteamwarUser user, String ip){
|
||||||
SQL.update("INSERT INTO BannedUserIPs (UserID, Timestamp, IP) VALUES (?, NOW(), ?) ON DUPLICATE KEY UPDATE Timestamp=NOW()", user.getId(), ip);
|
banIP.update(user.getId(), ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUserID() {
|
public int getUserID() {
|
||||||
|
@ -19,15 +19,17 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore.sql;
|
package de.steamwar.bungeecore.sql;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class BauweltMember{
|
public class BauweltMember{
|
||||||
|
|
||||||
|
private static final Statement delete = new Statement("DELETE FROM BauweltMember WHERE BauweltID = ? AND MemberID = ?");
|
||||||
|
private static final Statement update = new Statement("INSERT INTO BauweltMember (BauweltID, MemberID, WorldEdit, World) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE WorldEdit = VALUES(WorldEdit), World = VALUES(World)");
|
||||||
|
private static final Statement getMember = new Statement("SELECT * FROM BauweltMember WHERE BauweltID = ? AND MemberID = ?");
|
||||||
|
private static final Statement getMembers = new Statement("SELECT * FROM BauweltMember WHERE BauweltID = ?");
|
||||||
|
|
||||||
private final int bauweltID;
|
private final int bauweltID;
|
||||||
private final int memberID;
|
private final int memberID;
|
||||||
private boolean worldEdit;
|
private boolean worldEdit;
|
||||||
@ -52,12 +54,11 @@ public class BauweltMember{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void remove(){
|
public void remove(){
|
||||||
SQL.update("DELETE FROM BauweltMember WHERE BauweltID = " + bauweltID + " AND MemberID = " + memberID);
|
delete.update(bauweltID, memberID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDB(){
|
private void updateDB(){
|
||||||
SQL.update("INSERT INTO BauweltMember (BauweltID, MemberID, WorldEdit, World) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE WorldEdit = VALUES(WorldEdit), World = VALUES(World)",
|
update.update(bauweltID, memberID, worldEdit, world);
|
||||||
bauweltID, memberID, worldEdit, world);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BauweltMember getBauMember(UUID ownerID, UUID memberID){
|
public static BauweltMember getBauMember(UUID ownerID, UUID memberID){
|
||||||
@ -65,18 +66,12 @@ public class BauweltMember{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static BauweltMember getBauMember(int ownerID, int memberID){
|
public static BauweltMember getBauMember(int ownerID, int memberID){
|
||||||
ResultSet member = SQL.select("SELECT * FROM BauweltMember WHERE BauweltID = ? AND MemberID = ?", ownerID, memberID);
|
return getMember.select(rs -> {
|
||||||
try {
|
if(!rs.next())
|
||||||
if(member == null || !member.next()){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
boolean worldEdit = member.getBoolean("WorldEdit");
|
|
||||||
boolean world = member.getBoolean("World");
|
|
||||||
return new BauweltMember(ownerID, memberID, worldEdit, world, false);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
BungeeCore.log("Could not load BauweltMember", e);
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
return new BauweltMember(ownerID, memberID, rs.getBoolean("WorldEdit"), rs.getBoolean("World"), false);
|
||||||
|
}, ownerID, memberID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<BauweltMember> getMembers(UUID bauweltID){
|
public static List<BauweltMember> getMembers(UUID bauweltID){
|
||||||
@ -84,20 +79,13 @@ public class BauweltMember{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<BauweltMember> getMembers(int bauweltID){
|
public static List<BauweltMember> getMembers(int bauweltID){
|
||||||
try{
|
return getMembers.select(rs -> {
|
||||||
ResultSet memberlist = SQL.select("SELECT * FROM BauweltMember WHERE BauweltID = ?", bauweltID);
|
|
||||||
List<BauweltMember> members = new ArrayList<>();
|
List<BauweltMember> members = new ArrayList<>();
|
||||||
while(memberlist.next()){
|
while(rs.next()){
|
||||||
int memberID = memberlist.getInt("MemberID");
|
members.add(new BauweltMember(bauweltID, rs.getInt("MemberID"), rs.getBoolean("WorldEdit"), rs.getBoolean("World"), false));
|
||||||
boolean worldEdit = memberlist.getBoolean("WorldEdit");
|
|
||||||
boolean world = memberlist.getBoolean("World");
|
|
||||||
members.add(new BauweltMember(bauweltID, memberID, worldEdit, world, false));
|
|
||||||
}
|
}
|
||||||
return members;
|
return members;
|
||||||
}catch(SQLException e){
|
}, bauweltID);
|
||||||
BungeeCore.log("Could not load BauweltMembers", e);
|
|
||||||
}
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBauweltID() {
|
public int getBauweltID() {
|
||||||
|
@ -27,6 +27,9 @@ import java.util.List;
|
|||||||
|
|
||||||
public class CheckedSchematic {
|
public class CheckedSchematic {
|
||||||
|
|
||||||
|
private static final Statement create = new Statement("INSERT INTO CheckedSchematic (SchemName, SchemOwner, Validator, StartTime, EndTime, DeclineReason) VALUES (?, ?, ?, ?, ?, ?)");
|
||||||
|
private static final Statement previous = new Statement("SELECT * FROM CheckedSchematic WHERE SchemName = ? AND SchemOwner = ? ORDER BY EndTime ASC");
|
||||||
|
|
||||||
private final String schemName;
|
private final String schemName;
|
||||||
private final int schemOwner;
|
private final int schemOwner;
|
||||||
|
|
||||||
@ -45,20 +48,16 @@ public class CheckedSchematic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void create(String schemName, int schemOwner, int validator, Timestamp startTime, Timestamp endTime, String reason){
|
public static void create(String schemName, int schemOwner, int validator, Timestamp startTime, Timestamp endTime, String reason){
|
||||||
SQL.update("INSERT INTO CheckedSchematic (SchemName, SchemOwner, Validator, StartTime, EndTime, DeclineReason) VALUES (?, ?, ?, ?, ?, ?)",
|
create.update(schemName, schemOwner, validator, startTime, endTime, reason);
|
||||||
schemName, schemOwner, validator, startTime, endTime, reason);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<CheckedSchematic> previousChecks(String schemName, int schemOwner){
|
public static List<CheckedSchematic> previousChecks(String schemName, int schemOwner){
|
||||||
ResultSet rs = SQL.select("SELECT * FROM CheckedSchematic WHERE SchemName = ? AND SchemOwner = ? ORDER BY EndTime ASC", schemName, schemOwner);
|
return previous.select(rs -> {
|
||||||
List<CheckedSchematic> schematics = new ArrayList<>();
|
List<CheckedSchematic> schematics = new ArrayList<>();
|
||||||
try {
|
|
||||||
while(rs.next())
|
while(rs.next())
|
||||||
schematics.add(new CheckedSchematic(rs));
|
schematics.add(new CheckedSchematic(rs));
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new SecurityException("Could not load previous checks", e);
|
|
||||||
}
|
|
||||||
return schematics;
|
return schematics;
|
||||||
|
}, schemName, schemOwner);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getValidator() {
|
public int getValidator() {
|
||||||
|
@ -19,33 +19,26 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore.sql;
|
package de.steamwar.bungeecore.sql;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
public class Elo {
|
public class Elo {
|
||||||
|
|
||||||
|
private static final Statement elo = new Statement("SELECT Elo FROM Elo WHERE UserID = ? AND GameMode = ?");
|
||||||
|
private static final Statement place = new Statement("SELECT COUNT(*) AS Place FROM Elo WHERE GameMode = ? AND Elo > ?");
|
||||||
|
|
||||||
private Elo(){}
|
private Elo(){}
|
||||||
|
|
||||||
public static int getElo(int userID, String gameMode){
|
public static int getElo(int userID, String gameMode){
|
||||||
ResultSet rs = SQL.select("SELECT Elo FROM Elo WHERE UserID = ? AND GameMode = ?", userID, gameMode);
|
return elo.select(rs -> {
|
||||||
int elo = 1000;
|
|
||||||
try {
|
|
||||||
if(rs.next())
|
if(rs.next())
|
||||||
elo = rs.getInt("Elo");
|
return rs.getInt("Elo");
|
||||||
} catch (SQLException e) {
|
return 1000;
|
||||||
throw new SecurityException("Could not get Elo", e);
|
}, userID, gameMode);
|
||||||
}
|
|
||||||
return elo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getPlacement(int elo, String gameMode){
|
public static int getPlacement(int elo, String gameMode){
|
||||||
ResultSet rs = SQL.select("SELECT COUNT(*) AS Place FROM Elo WHERE GameMode = ? AND Elo > ?", gameMode, elo);
|
return place.select(rs -> {
|
||||||
try{
|
if(rs.next())
|
||||||
if(!rs.next())
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return rs.getInt("Place");
|
return rs.getInt("Place");
|
||||||
}catch(SQLException e){
|
return -1;
|
||||||
throw new SecurityException("Could not get place", e);
|
}, gameMode, elo);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,17 +19,20 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore.sql;
|
package de.steamwar.bungeecore.sql;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.LinkedList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Event {
|
public class Event {
|
||||||
|
|
||||||
|
private static final Statement byCurrent = new Statement("SELECT * FROM Event WHERE Start < now() AND End > now()");
|
||||||
|
private static final Statement byId = new Statement("SELECT * FROM Event WHERE EventID = ?");
|
||||||
|
private static final Statement byName = new Statement("SELECT * FROM Event WHERE lower(EventName) = ?");
|
||||||
|
private static final Statement byComing = new Statement("SELECT * FROM Event WHERE Start > now()");
|
||||||
|
|
||||||
private final int eventID;
|
private final int eventID;
|
||||||
private final String eventName;
|
private final String eventName;
|
||||||
private final Timestamp start;
|
private final Timestamp start;
|
||||||
@ -56,57 +59,39 @@ public class Event {
|
|||||||
if(current != null && current.now())
|
if(current != null && current.now())
|
||||||
return current;
|
return current;
|
||||||
|
|
||||||
ResultSet rs = SQL.select("SELECT * FROM Event WHERE Start < now() AND End > now()");
|
return byCurrent.select(rs -> {
|
||||||
try{
|
if(rs.next())
|
||||||
if(!rs.next()){
|
|
||||||
current = null;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
current = new Event(rs);
|
current = new Event(rs);
|
||||||
|
else
|
||||||
|
current = null;
|
||||||
return current;
|
return current;
|
||||||
}catch (SQLException e){
|
});
|
||||||
BungeeCore.log("Failed to load current Event", e);
|
|
||||||
throw new SecurityException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Event get(int eventID){
|
public static Event get(int eventID){
|
||||||
ResultSet rs = SQL.select("SELECT * FROM Event WHERE EventID = " + eventID);
|
return byId.select(rs -> {
|
||||||
try{
|
|
||||||
if(!rs.next())
|
if(!rs.next())
|
||||||
throw new IllegalArgumentException();
|
throw new SQLException("Couldn't find event " + eventID);
|
||||||
|
|
||||||
return new Event(rs);
|
return new Event(rs);
|
||||||
}catch (SQLException e){
|
}, eventID);
|
||||||
BungeeCore.log("Failed to load Event", e);
|
|
||||||
throw new SecurityException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Event get(String eventName){
|
public static Event get(String eventName){
|
||||||
ResultSet rs = SQL.select("SELECT * FROM Event WHERE lower(EventName) = ?", eventName.toLowerCase());
|
return byName.select(rs -> {
|
||||||
try{
|
|
||||||
if(!rs.next())
|
if(!rs.next())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return new Event(rs);
|
return new Event(rs);
|
||||||
}catch (SQLException e){
|
}, eventName.toLowerCase());
|
||||||
BungeeCore.log("Failed to load Event by name", e);
|
|
||||||
throw new SecurityException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Event> getComing(){
|
public static List<Event> getComing(){
|
||||||
List<Event> events = new LinkedList<>();
|
return byComing.select(rs -> {
|
||||||
ResultSet rs = SQL.select("SELECT * FROM Event WHERE Start > now()");
|
List<Event> events = new ArrayList<>();
|
||||||
try{
|
|
||||||
while(rs.next())
|
while(rs.next())
|
||||||
events.add(new Event(rs));
|
events.add(new Event(rs));
|
||||||
}catch (SQLException e){
|
|
||||||
BungeeCore.log("Failed to load Events", e);
|
|
||||||
}
|
|
||||||
return events;
|
return events;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean now(){
|
private boolean now(){
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
package de.steamwar.bungeecore.sql;
|
package de.steamwar.bungeecore.sql;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.ArenaMode;
|
import de.steamwar.bungeecore.ArenaMode;
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -31,7 +30,11 @@ import static java.time.temporal.ChronoUnit.SECONDS;
|
|||||||
|
|
||||||
public class EventFight implements Comparable<EventFight> {
|
public class EventFight implements Comparable<EventFight> {
|
||||||
|
|
||||||
private static Queue<EventFight> fights = new PriorityQueue<>();
|
private static final Statement reschedule = new Statement("UPDATE EventFight SET StartTime = ? WHERE EventID = ? AND FightID = ?");
|
||||||
|
private static final Statement allComing = new Statement("SELECT * FROM EventFight WHERE StartTime > now() ORDER BY `StartTime` ASC");
|
||||||
|
private static final Statement event = new Statement("SELECT * FROM EventFight WHERE EventID = ? ORDER BY `StartTime` ASC");
|
||||||
|
|
||||||
|
private static final Queue<EventFight> fights = new PriorityQueue<>();
|
||||||
|
|
||||||
private final int eventID;
|
private final int eventID;
|
||||||
private final int fightID;
|
private final int fightID;
|
||||||
@ -57,31 +60,26 @@ public class EventFight implements Comparable<EventFight> {
|
|||||||
|
|
||||||
public void reschedule(){
|
public void reschedule(){
|
||||||
startTime = Timestamp.from(new Date().toInstant().plus(30, SECONDS));
|
startTime = Timestamp.from(new Date().toInstant().plus(30, SECONDS));
|
||||||
SQL.update("UPDATE EventFight SET StartTime = ? WHERE EventID = ? AND FightID = ?", startTime, eventID, fightID);
|
reschedule.update(startTime, eventID, fightID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void loadAllComingFights(){
|
public static void loadAllComingFights(){
|
||||||
ResultSet rs = SQL.select("SELECT * FROM EventFight WHERE StartTime > now() ORDER BY `StartTime` ASC");
|
allComing.select(rs -> {
|
||||||
fights.clear();
|
fights.clear();
|
||||||
try{
|
|
||||||
while(rs.next()){
|
while(rs.next()){
|
||||||
fights.add(new EventFight(rs));
|
fights.add(new EventFight(rs));
|
||||||
}
|
}
|
||||||
}catch (SQLException e){
|
return null;
|
||||||
BungeeCore.log("Failed to load EventFights", e);
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<EventFight> getEvent(int eventID){
|
public static List<EventFight> getEvent(int eventID){
|
||||||
ResultSet rs = SQL.select("SELECT * FROM EventFight WHERE EventID = ? ORDER BY `StartTime` ASC", eventID);
|
return event.select(rs -> {
|
||||||
List<EventFight> fights = new LinkedList<>();
|
List<EventFight> fights = new LinkedList<>();
|
||||||
try{
|
|
||||||
while(rs.next())
|
while(rs.next())
|
||||||
fights.add(new EventFight(rs));
|
fights.add(new EventFight(rs));
|
||||||
}catch (SQLException e){
|
|
||||||
BungeeCore.log("Failed to load EventFights", e);
|
|
||||||
}
|
|
||||||
return fights;
|
return fights;
|
||||||
|
}, eventID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Queue<EventFight> getFights() {
|
public static Queue<EventFight> getFights() {
|
||||||
|
@ -22,9 +22,13 @@ package de.steamwar.bungeecore.sql;
|
|||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
public class IgnoreSystem{
|
public class IgnoreSystem{
|
||||||
|
|
||||||
|
private static final Statement select = new Statement("SELECT * FROM IgnoredPlayers WHERE Ignorer = ? AND Ignored = ?");
|
||||||
|
private static final Statement insert = new Statement("INSERT INTO IgnoredPlayers (Ignorer, Ignored) VALUES (?, ?)");
|
||||||
|
private static final Statement delete = new Statement("DELETE FROM IgnoredPlayers WHERE Ignorer = ? AND Ignored = ?");
|
||||||
|
|
||||||
private IgnoreSystem(){}
|
private IgnoreSystem(){}
|
||||||
|
|
||||||
public static boolean isIgnored(ProxiedPlayer ignorer, ProxiedPlayer ignored){
|
public static boolean isIgnored(ProxiedPlayer ignorer, ProxiedPlayer ignored){
|
||||||
@ -34,22 +38,14 @@ public class IgnoreSystem{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isIgnored(SteamwarUser ignorer, SteamwarUser ignored) {
|
public static boolean isIgnored(SteamwarUser ignorer, SteamwarUser ignored) {
|
||||||
try {
|
return select.select(ResultSet::next, ignorer.getId(), ignored.getId());
|
||||||
ResultSet rs = SQL.select("SELECT COUNT(*) AS blocked FROM IgnoredPlayers WHERE Ignorer = ? AND Ignored = ?", ignorer.getId(), ignored.getId());
|
|
||||||
if(!rs.next())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return rs.getInt("blocked") > 0;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new SecurityException("Could not check if ignored", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ignore(SteamwarUser ignorer, SteamwarUser ignored) {
|
public static void ignore(SteamwarUser ignorer, SteamwarUser ignored) {
|
||||||
SQL.update("INSERT INTO IgnoredPlayers (Ignorer, Ignored) VALUES (?, ?)", ignorer.getId(), ignored.getId());
|
insert.update(ignorer.getId(), ignored.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void unIgnore(SteamwarUser ignorer, SteamwarUser ignored) {
|
public static void unIgnore(SteamwarUser ignorer, SteamwarUser ignored) {
|
||||||
SQL.update("DELETE FROM IgnoredPlayers WHERE Ignorer = ? AND Ignored = ?", ignorer.getId(), ignored.getId());
|
delete.update(ignorer.getId(), ignored.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,11 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore.sql;
|
package de.steamwar.bungeecore.sql;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
public class Mod {
|
public class Mod {
|
||||||
|
|
||||||
|
private static final Statement get = new Statement("SELECT * FROM Mods WHERE ModName = ? AND Platform = ?");
|
||||||
|
private static final Statement insert = new Statement("INSERT INTO Mods (ModName, Platform) VALUES (?, ?)");
|
||||||
|
|
||||||
private final String modName;
|
private final String modName;
|
||||||
private final Platform platform;
|
private final Platform platform;
|
||||||
private final ModType modType;
|
private final ModType modType;
|
||||||
@ -36,15 +35,15 @@ public class Mod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Mod get(String modName, Platform platform){
|
public static Mod get(String modName, Platform platform){
|
||||||
ResultSet rs = SQL.select("SELECT * FROM Mods WHERE ModName = ? AND Platform = ?", modName, platform.value);
|
Mod mod = get.select(rs -> {
|
||||||
try{
|
|
||||||
if(rs.next())
|
if(rs.next())
|
||||||
return new Mod(modName, platform, ModType.valueOf(rs.getInt("ModType")));
|
return new Mod(modName, platform, ModType.valueOf(rs.getInt("ModType")));
|
||||||
}catch (SQLException e){
|
return null;
|
||||||
BungeeCore.log("Failed to load Mod", e);
|
}, modName, platform.value);
|
||||||
throw new SecurityException();
|
if(mod != null)
|
||||||
}
|
return mod;
|
||||||
SQL.update("INSERT INTO Mods (ModName, Platform) VALUES (?, ?)", modName, platform.value);
|
|
||||||
|
insert.update(modName, platform.value);
|
||||||
return new Mod(modName, platform, ModType.UNKLASSIFIED);
|
return new Mod(modName, platform, ModType.UNKLASSIFIED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore.sql;
|
package de.steamwar.bungeecore.sql;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
|
||||||
import de.steamwar.bungeecore.listeners.PollSystem;
|
import de.steamwar.bungeecore.listeners.PollSystem;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -29,6 +28,10 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class PollAnswer {
|
public class PollAnswer {
|
||||||
|
|
||||||
|
private static final Statement get = new Statement("SELECT * FROM PollAnswer WHERE UserID = ? AND Question = ?");
|
||||||
|
private static final Statement getResults = new Statement("SELECT Count(UserID) AS Times, Answer FROM PollAnswer WHERE Question = ? GROUP BY Answer ORDER BY `Times` ASC");
|
||||||
|
private static final Statement insert = new Statement("INSERT INTO PollAnswer (UserID, Question, Answer) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Answer = VALUES(Answer)");
|
||||||
|
|
||||||
private final int userID;
|
private final int userID;
|
||||||
private final String question;
|
private final String question;
|
||||||
private int answer;
|
private int answer;
|
||||||
@ -44,38 +47,20 @@ public class PollAnswer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static PollAnswer get(int userID){
|
public static PollAnswer get(int userID){
|
||||||
ResultSet rs = SQL.select("SELECT * FROM PollAnswer WHERE UserID = ? AND Question = ?", userID, PollSystem.getQuestion());
|
return get.select(rs -> {
|
||||||
try {
|
if(rs.next())
|
||||||
if(!rs.next())
|
|
||||||
return new PollAnswer(userID, PollSystem.getQuestion());
|
|
||||||
return new PollAnswer(rs);
|
return new PollAnswer(rs);
|
||||||
} catch (SQLException e) {
|
return new PollAnswer(userID, PollSystem.getQuestion());
|
||||||
throw new SecurityException("Unable to get PollAnswer", e);
|
}, userID, PollSystem.getQuestion());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, Integer> getCurrentResults() {
|
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());
|
return getResults.select(rs -> {
|
||||||
try {
|
|
||||||
Map<String, Integer> retMap = new HashMap<>();
|
Map<String, Integer> retMap = new HashMap<>();
|
||||||
while (set.next()) {
|
while (rs.next())
|
||||||
retMap.put(PollSystem.getAnswer(set.getInt("Answer")), set.getInt("Times"));
|
retMap.put(PollSystem.getAnswer(rs.getInt("Answer")), rs.getInt("Times"));
|
||||||
}
|
|
||||||
return retMap;
|
return retMap;
|
||||||
}catch (SQLException e) {
|
}, PollSystem.getQuestion());
|
||||||
throw new SecurityException("Unable to get PollAnswer", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Integer getAllAnswered() {
|
|
||||||
ResultSet set = SQL.select("SELECT Count(UserID) AS Times FROM PollAnswer WHERE Question = ?", PollSystem.getQuestion());
|
|
||||||
try {
|
|
||||||
if(!set.next())
|
|
||||||
throw new SecurityException("Could not get PollAnswers");
|
|
||||||
return set.getInt("Times");
|
|
||||||
}catch (SQLException e) {
|
|
||||||
throw new SecurityException("Unable to get PollAnswer", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasAnswered(){
|
public boolean hasAnswered(){
|
||||||
@ -84,6 +69,6 @@ public class PollAnswer {
|
|||||||
|
|
||||||
public void setAnswer(int answer){
|
public void setAnswer(int answer){
|
||||||
this.answer = answer;
|
this.answer = answer;
|
||||||
SQL.update("INSERT INTO PollAnswer (UserID, Question, Answer) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Answer = VALUES(Answer)", userID, question, answer);
|
insert.update(userID, question, answer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,45 +31,40 @@ import java.util.*;
|
|||||||
|
|
||||||
public class Punishment {
|
public class Punishment {
|
||||||
|
|
||||||
|
private static final Statement getPunishment = new Statement("SELECT * FROM Punishments WHERE UserId = ? AND Type = ? ORDER BY PunishmentId DESC LIMIT 1");
|
||||||
|
private static final Statement getPunishments = new Statement("SELECT * FROM Punishments WHERE PunishmentId IN (SELECT MAX(PunishmentId) FROM Punishments WHERE UserId = ? GROUP BY Type)");
|
||||||
|
private static final Statement getAllPunishments = new Statement("SELECT * FROM Punishments WHERE UserId = ? ORDER BY `PunishmentId` DESC");
|
||||||
|
private static final Statement insert = new Statement("INSERT INTO Punishments (UserId, Punisher, Type, Reason, EndTime, Perma) VALUES (?, ?, ?, ?, ?, ?)");
|
||||||
|
private static final Statement update = new Statement("UPDATE Punishments SET EndTime = ?, Reason = ?, Perma = ? WHERE PunishmentId = ?");
|
||||||
|
|
||||||
public static Punishment getPunishmentOfPlayer(int user, PunishmentType type) {
|
public static Punishment getPunishmentOfPlayer(int user, PunishmentType type) {
|
||||||
ResultSet set = SQL.select("SELECT * FROM Punishments WHERE UserId = ? AND Type = ? ORDER BY PunishmentId DESC LIMIT 1", user, type.name());
|
return getPunishment.select(rs -> {
|
||||||
try {
|
if(rs.next())
|
||||||
if(!set.next())
|
return new Punishment(rs);
|
||||||
return null;
|
return null;
|
||||||
return new Punishment(set);
|
}, user, type.name());
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new SecurityException("Could not Load Punishments", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<PunishmentType, Punishment> getPunishmentsOfPlayer(int user) {
|
public static Map<PunishmentType, Punishment> getPunishmentsOfPlayer(int user) {
|
||||||
ResultSet set = SQL.select("SELECT * FROM Punishments WHERE PunishmentId IN (SELECT MAX(PunishmentId) FROM Punishments WHERE UserId = ? GROUP BY Type)", user);
|
return getPunishments.select(rs -> {
|
||||||
try {
|
|
||||||
Map<PunishmentType, Punishment> punishments = new HashMap<>();
|
Map<PunishmentType, Punishment> punishments = new HashMap<>();
|
||||||
while (set.next())
|
while (rs.next())
|
||||||
punishments.put(PunishmentType.valueOf(set.getString("Type")), new Punishment(set));
|
punishments.put(PunishmentType.valueOf(rs.getString("Type")), new Punishment(rs));
|
||||||
return punishments;
|
return punishments;
|
||||||
} catch (SQLException e) {
|
}, user);
|
||||||
throw new SecurityException("Could not Load Punishments", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Punishment> getAllPunishmentsOfPlayer(int user) {
|
public static List<Punishment> getAllPunishmentsOfPlayer(int user) {
|
||||||
ResultSet set = SQL.select("SELECT * FROM Punishments WHERE UserId = ? ORDER BY `PunishmentId` DESC", user);
|
return getAllPunishments.select(rs -> {
|
||||||
try {
|
|
||||||
List<Punishment> punishments = new ArrayList<>();
|
List<Punishment> punishments = new ArrayList<>();
|
||||||
while (set.next()) {
|
while (rs.next())
|
||||||
punishments.add(new Punishment(set));
|
punishments.add(new Punishment(rs));
|
||||||
}
|
|
||||||
return punishments;
|
return punishments;
|
||||||
} catch (SQLException e) {
|
}, user);
|
||||||
throw new SecurityException("Could not Load all Punishments", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Punishment createPunishment(int user, int executor, PunishmentType type, String reason, Timestamp endTime, boolean perma) {
|
public static Punishment createPunishment(int user, int executor, PunishmentType type, String reason, Timestamp endTime, boolean perma) {
|
||||||
SQL.update("INSERT INTO Punishments (UserId, Punisher, Type, Reason, EndTime, Perma) VALUES (?, ?, ?, ?, ?, ?)",
|
insert.update(user, executor, type.name(), reason, endTime, perma);
|
||||||
user, executor, type.name(), reason, endTime, perma);
|
|
||||||
return getPunishmentOfPlayer(user, type);
|
return getPunishmentOfPlayer(user, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +117,7 @@ public class Punishment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateEndTime(int from, String newreason, Timestamp newUpdate, boolean perma) {
|
public void updateEndTime(int from, String newreason, Timestamp newUpdate, boolean perma) {
|
||||||
if(newreason.equals(reason) && newUpdate.equals(endTime) && perma == perma)
|
if(newreason.equals(reason) && newUpdate.equals(endTime) && this.perma == perma)
|
||||||
return;
|
return;
|
||||||
ProxiedPlayer player = BungeeCore.get().getProxy().getPlayer(SteamwarUser.get(from).getUuid());
|
ProxiedPlayer player = BungeeCore.get().getProxy().getPlayer(SteamwarUser.get(from).getUuid());
|
||||||
String newReason = Message.parse("BAN_CHANGED", player, reason,
|
String newReason = Message.parse("BAN_CHANGED", player, reason,
|
||||||
@ -131,7 +126,7 @@ public class Punishment {
|
|||||||
getBantime(newUpdate, perma),
|
getBantime(newUpdate, perma),
|
||||||
newreason);
|
newreason);
|
||||||
|
|
||||||
SQL.update("UPDATE Punishments SET EndTime = ?, Reason = ?, Perma = ? WHERE PunishmentId = ?", newUpdate, newReason, perma, id);
|
update.update(newUpdate, newReason, perma, id);
|
||||||
this.reason = newReason;
|
this.reason = newReason;
|
||||||
this.perma = perma;
|
this.perma = perma;
|
||||||
this.endTime = newUpdate;
|
this.endTime = newUpdate;
|
||||||
|
@ -1,95 +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.bungeecore.BungeeCore;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
|
|
||||||
import java.sql.*;
|
|
||||||
|
|
||||||
|
|
||||||
public class SQL {
|
|
||||||
private SQL(){}
|
|
||||||
|
|
||||||
private static Connection con;
|
|
||||||
private static String url;
|
|
||||||
private static String user;
|
|
||||||
private static String password;
|
|
||||||
|
|
||||||
public static void connect(String url, String user, String password) {
|
|
||||||
SQL.url = url;
|
|
||||||
SQL.user = user;
|
|
||||||
SQL.password = password;
|
|
||||||
try {
|
|
||||||
con = DriverManager.getConnection(url + "?autoreconnect=true", user, password);
|
|
||||||
}catch (SQLException e) {
|
|
||||||
ProxyServer.getInstance().stop();
|
|
||||||
throw new SecurityException("Could not start SQL-Exception", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void close() {
|
|
||||||
try {
|
|
||||||
if(con != null)
|
|
||||||
con.close();
|
|
||||||
}catch (SQLException e) {
|
|
||||||
BungeeCore.log("Could not close SQL-Connection", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void update(String qry, Object... objects) {
|
|
||||||
try {
|
|
||||||
prepare(con, qry, objects).executeUpdate();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
sqlException();
|
|
||||||
try (PreparedStatement st = con.prepareStatement(qry)) {
|
|
||||||
st.executeUpdate();
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
throw new SecurityException("Could not execute update statement", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static ResultSet select(String qry, Object... objects){
|
|
||||||
try{
|
|
||||||
return prepare(con, qry, objects).executeQuery();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
sqlException();
|
|
||||||
try {
|
|
||||||
return prepare(con, qry, objects).executeQuery();
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
throw new SecurityException("Could not run Select-Statement", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static PreparedStatement prepare(Connection connection, String qry, Object... objects) throws SQLException{
|
|
||||||
PreparedStatement st = connection.prepareStatement(qry);
|
|
||||||
for(int i = 0; i < objects.length; i++){
|
|
||||||
st.setObject(i+1, objects[i]);
|
|
||||||
}
|
|
||||||
return st;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void sqlException(){
|
|
||||||
close();
|
|
||||||
connect(url, user, password);
|
|
||||||
}
|
|
||||||
}
|
|
@ -22,7 +22,9 @@ package de.steamwar.bungeecore.sql;
|
|||||||
public class SWException {
|
public class SWException {
|
||||||
private SWException(){}
|
private SWException(){}
|
||||||
|
|
||||||
|
private static final Statement insert = new Statement("INSERT INTO Exception (server, message, stacktrace) VALUES (?, ?, ?)");
|
||||||
|
|
||||||
public static void log(String server, String message, String stacktrace){
|
public static void log(String server, String message, String stacktrace){
|
||||||
SQL.update("INSERT INTO Exception (server, message, stacktrace) VALUES (?, ?, ?)", server, message, stacktrace);
|
insert.update(server, message, stacktrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,14 +23,22 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class Schematic {
|
public class Schematic {
|
||||||
|
|
||||||
|
private static final Statement schemByName = new Statement("SELECT SchemID, SchemName, SchemOwner, SchemType, Item FROM Schematic WHERE SchemName = ? AND SchemOwner = ?");
|
||||||
|
private static final Statement schemById = new Statement("SELECT SchemID, SchemName, SchemOwner, SchemType, Item FROM Schematic WHERE SchemID = ?");
|
||||||
|
private static final Statement schemsByType = new Statement("SELECT SchemID, SchemName, SchemOwner, SchemType, Item FROM Schematic WHERE SchemType = ?");
|
||||||
|
private static final Statement schemsByUserType = new Statement("SELECT SchemID, SchemName, SchemOwner, SchemType, Item FROM Schematic WHERE SchemType = ? AND SchemOwner = ?");
|
||||||
|
private static final Statement schemsOfUser = new Statement("SELECT SchemID, SchemName, SchemOwner, Item, SchemType, Rank, SchemFormat, Item FROM Schematic WHERE SchemOwner = ? ORDER BY SchemName");
|
||||||
|
private static final Statement updateType = new Statement("UPDATE Schematic SET SchemType = ? WHERE SchemID = ?");
|
||||||
|
private static final Statement updateRank = new Statement("UPDATE Schematic SET Rank = ? WHERE SchemID = ?");
|
||||||
|
|
||||||
private final int schemID;
|
private final int schemID;
|
||||||
private final String schemName;
|
private final String schemName;
|
||||||
private final int schemOwner;
|
private final int schemOwner;
|
||||||
private SchematicType schemType;
|
private SchematicType schemType;
|
||||||
private String schemItem;
|
private final String schemItem;
|
||||||
|
|
||||||
private Schematic(ResultSet rs) throws SQLException {
|
private Schematic(ResultSet rs) throws SQLException {
|
||||||
this.schemID = rs.getInt("SchemID");
|
this.schemID = rs.getInt("SchemID");
|
||||||
@ -40,74 +48,52 @@ public class Schematic {
|
|||||||
this.schemItem = rs.getString("Item");
|
this.schemItem = rs.getString("Item");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Schematic getSchemFromDB(String schemName, UUID schemOwner){
|
|
||||||
return getSchemFromDB(schemName, SteamwarUser.get(schemOwner).getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Schematic getSchemFromDB(String schemName, int schemOwner){
|
public static Schematic getSchemFromDB(String schemName, int schemOwner){
|
||||||
ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, SchemType, Item FROM Schematic WHERE SchemName = ? AND SchemOwner = ?", schemName, schemOwner);
|
return schemByName.select(rs -> {
|
||||||
try {
|
if(!rs.next())
|
||||||
if(schematic == null || !schematic.next()){
|
return new Schematic(rs);
|
||||||
return null;
|
return null;
|
||||||
}
|
}, schemName, schemOwner);
|
||||||
return new Schematic(schematic);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new SecurityException("Failed loading schematic", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Schematic getSchemFromDB(int schemID){
|
public static Schematic getSchemFromDB(int schemID){
|
||||||
ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, SchemType, Item FROM Schematic WHERE SchemID = ?", schemID);
|
return schemById.select(rs -> {
|
||||||
try {
|
if(!rs.next())
|
||||||
if(!schematic.next())
|
|
||||||
throw new SecurityException("Failed loading schematic " + schemID);
|
throw new SecurityException("Failed loading schematic " + schemID);
|
||||||
return new Schematic(schematic);
|
return new Schematic(rs);
|
||||||
} catch (SQLException e) {
|
}, schemID);
|
||||||
throw new SecurityException("Failed loading schematic", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Schematic> getAllSchemsOfType(SchematicType schemType){
|
public static List<Schematic> getAllSchemsOfType(SchematicType schemType){
|
||||||
try{
|
return schemsByType.select(rs -> {
|
||||||
ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, SchemType, Item FROM Schematic WHERE SchemType = ?", schemType.toDB());
|
|
||||||
List<Schematic> schematics = new ArrayList<>();
|
List<Schematic> schematics = new ArrayList<>();
|
||||||
while(schematic.next()){
|
while(rs.next())
|
||||||
schematics.add(new Schematic(schematic));
|
schematics.add(new Schematic(rs));
|
||||||
}
|
|
||||||
return schematics;
|
return schematics;
|
||||||
}catch(SQLException e){
|
}, schemType.toDB());
|
||||||
throw new SecurityException("Failed loading all schems of type", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Schematic> getSchemsOfType(int userId, SchematicType schemType){
|
public static List<Schematic> getSchemsOfType(int userId, SchematicType schemType){
|
||||||
try{
|
return schemsByUserType.select(rs -> {
|
||||||
ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, SchemType, Item FROM Schematic WHERE SchemType = ? AND SchemOwner = ?", schemType.toDB(), userId);
|
|
||||||
List<Schematic> schematics = new ArrayList<>();
|
List<Schematic> schematics = new ArrayList<>();
|
||||||
while(schematic.next()){
|
while(rs.next())
|
||||||
schematics.add(new Schematic(schematic));
|
schematics.add(new Schematic(rs));
|
||||||
}
|
|
||||||
return schematics;
|
return schematics;
|
||||||
}catch(SQLException e){
|
}, schemType.toDB(), userId);
|
||||||
throw new SecurityException("Failed loading schems of type", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Schematic> getSchemsAccessibleByUser(int schemOwner){
|
public static List<Schematic> getSchemsAccessibleByUser(int schemOwner){
|
||||||
try{
|
return schemsOfUser.select(rs -> {
|
||||||
ResultSet schematic = SQL.select("SELECT SchemID, SchemName, SchemOwner, Item, SchemType, Rank, SchemFormat, Item FROM Schematic WHERE SchemOwner = ? ORDER BY SchemName", schemOwner);
|
|
||||||
List<Schematic> schematics = new ArrayList<>();
|
List<Schematic> schematics = new ArrayList<>();
|
||||||
while(schematic.next()){
|
while(rs.next()){
|
||||||
schematics.add(new Schematic(schematic));
|
schematics.add(new Schematic(rs));
|
||||||
}
|
}
|
||||||
List<SchematicMember> addedSchems = SchematicMember.getAccessibleSchems(schemOwner);
|
List<SchematicMember> addedSchems = SchematicMember.getAccessibleSchems(schemOwner);
|
||||||
for(SchematicMember schem : addedSchems){
|
for(SchematicMember schem : addedSchems){
|
||||||
schematics.add(getSchemFromDB(schem.getSchemName(), schem.getSchemOwner()));
|
schematics.add(getSchemFromDB(schem.getSchemName(), schem.getSchemOwner()));
|
||||||
}
|
}
|
||||||
return schematics;
|
return schematics;
|
||||||
}catch(SQLException e){
|
}, schemOwner);
|
||||||
throw new SecurityException("Failed listing schematics", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSchemID() {
|
public int getSchemID() {
|
||||||
@ -132,10 +118,10 @@ public class Schematic {
|
|||||||
|
|
||||||
public void setSchemType(SchematicType schemType) {
|
public void setSchemType(SchematicType schemType) {
|
||||||
this.schemType = schemType;
|
this.schemType = schemType;
|
||||||
SQL.update("UPDATE Schematic SET SchemType = ? WHERE SchemID = ?", schemType.toDB(), schemID);
|
updateType.update(schemType.toDB(), schemID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRank(int rank) {
|
public void setRank(int rank) {
|
||||||
SQL.update("UPDATE Schematic SET Rank = ? WHERE SchemID = ?", rank, schemID);
|
updateRank.update(rank, schemID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,13 +19,15 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore.sql;
|
package de.steamwar.bungeecore.sql;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class SchematicMember {
|
public class SchematicMember {
|
||||||
|
|
||||||
|
private static final Statement insert = new Statement("INSERT INTO SchemMember (SchemName, SchemOwner, Member) VALUES (?, ?, ?)");
|
||||||
|
private static final Statement selectSchems = new Statement("SELECT * FROM SchemMember WHERE Member = ?");
|
||||||
|
private static final Statement delete = new Statement("DELETE FROM SchemMember WHERE SchemOwner = ? AND SchemName = ? AND Member = ?");
|
||||||
|
|
||||||
private final int schemOwner;
|
private final int schemOwner;
|
||||||
private final String schemName;
|
private final String schemName;
|
||||||
private final int member;
|
private final int member;
|
||||||
@ -38,82 +40,17 @@ public class SchematicMember {
|
|||||||
updateDB();
|
updateDB();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SchematicMember(String schemName, int schemOwner, int schemMember){
|
|
||||||
this(schemName, schemOwner, schemMember, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SchematicMember(String schemName, UUID schemOwner, UUID schemMember){
|
|
||||||
this(schemName, SteamwarUser.get(schemOwner).getId(), SteamwarUser.get(schemMember).getId(), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateDB(){
|
private void updateDB(){
|
||||||
SQL.update("INSERT INTO SchemMember (SchemName, SchemOwner, Member) VALUES (?, ?, ?)", schemName, schemOwner, member);
|
insert.update(schemName, schemOwner, member);
|
||||||
}
|
|
||||||
|
|
||||||
public static SchematicMember getSchemMemberFromDB(String schemName, UUID schemOwner, UUID schemMember){
|
|
||||||
return getSchemMemberFromDB(schemName, SteamwarUser.get(schemOwner).getId(), SteamwarUser.get(schemMember).getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SchematicMember getSchemMemberFromDB(String schemName, int schemOwner, int schemMember){
|
|
||||||
ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE SchemName = ? AND SchemOwner = ? AND Member = ?", schemName, schemOwner, schemMember);
|
|
||||||
try {
|
|
||||||
if(schematicMember == null || !schematicMember.next()){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new SchematicMember(schemName, schemOwner, schemMember, false);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new SecurityException("Could not get schemmember", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SchematicMember getMemberBySchematic(String schemName, int schemMember){
|
|
||||||
ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE SchemName = ? AND Member = ?", schemName, schemMember);
|
|
||||||
try {
|
|
||||||
if(schematicMember == null || !schematicMember.next()){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
int schemOwner = schematicMember.getInt("SchemOwner");
|
|
||||||
return new SchematicMember(schemName, schemOwner, schemMember, false);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new SecurityException("Could not get member", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<SchematicMember> getSchemMembers(String schemName, UUID schemOwner){
|
|
||||||
return getSchemMembers(schemName, SteamwarUser.get(schemOwner).getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<SchematicMember> getSchemMembers(String schemName, int schemOwner){
|
|
||||||
ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE SchemName = ? AND SchemOwner = ?", schemName, schemOwner);
|
|
||||||
try {
|
|
||||||
List<SchematicMember> schematicMembers = new ArrayList<>();
|
|
||||||
while(schematicMember.next()){
|
|
||||||
int schemMember = schematicMember.getInt("Member");
|
|
||||||
schematicMembers.add(new SchematicMember(schemName, schemOwner, schemMember, false));
|
|
||||||
}
|
|
||||||
return schematicMembers;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new SecurityException("Could not get schemmembers", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<SchematicMember> getAccessibleSchems(UUID schemMember){
|
|
||||||
return getAccessibleSchems(SteamwarUser.get(schemMember).getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicMember> getAccessibleSchems(int schemMember){
|
public static List<SchematicMember> getAccessibleSchems(int schemMember){
|
||||||
ResultSet schematicMember = SQL.select("SELECT * FROM SchemMember WHERE Member = ?", schemMember);
|
return selectSchems.select(rs -> {
|
||||||
try {
|
|
||||||
List<SchematicMember> schematicMembers = new ArrayList<>();
|
List<SchematicMember> schematicMembers = new ArrayList<>();
|
||||||
while(schematicMember.next()){
|
while(rs.next())
|
||||||
String schemName = schematicMember.getString("SchemName");
|
schematicMembers.add(new SchematicMember(rs.getString("SchemName"), rs.getInt("SchemOwner"), schemMember, false));
|
||||||
int schemOwner = schematicMember.getInt("SchemOwner");
|
|
||||||
schematicMembers.add(new SchematicMember(schemName, schemOwner, schemMember, false));
|
|
||||||
}
|
|
||||||
return schematicMembers;
|
return schematicMembers;
|
||||||
} catch (SQLException e) {
|
}, schemMember);
|
||||||
throw new SecurityException("Could not get accessible schems", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSchemOwner() {
|
public int getSchemOwner() {
|
||||||
@ -129,6 +66,6 @@ public class SchematicMember {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void remove(){
|
public void remove(){
|
||||||
SQL.update("DELETE FROM SchemMember WHERE SchemOwner = ? AND SchemName = ? AND Member = ?", schemOwner, schemName, member);
|
delete.update(schemOwner, schemName, member);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,12 @@ package de.steamwar.bungeecore.sql;
|
|||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
public class Session {
|
public class Session {
|
||||||
|
|
||||||
|
private static final Statement insert = new Statement("INSERT INTO Session (UserID, StartTime, EndTime) VALUES (?, ?, NOW())");
|
||||||
|
|
||||||
private Session(){}
|
private Session(){}
|
||||||
|
|
||||||
public static void insertSession(int userID, Timestamp startTime){
|
public static void insertSession(int userID, Timestamp startTime){
|
||||||
SQL.update("INSERT INTO Session (UserID, StartTime, EndTime) VALUES (?, ?, NOW())", userID, startTime);
|
insert.update(userID, startTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
137
src/de/steamwar/bungeecore/sql/Statement.java
Normale Datei
137
src/de/steamwar/bungeecore/sql/Statement.java
Normale Datei
@ -0,0 +1,137 @@
|
|||||||
|
/*
|
||||||
|
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.bungeecore.BungeeCore;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class Statement {
|
||||||
|
private static final List<Statement> statements = new ArrayList<>();
|
||||||
|
|
||||||
|
private static Connection con;
|
||||||
|
private static String url;
|
||||||
|
private static String user;
|
||||||
|
private static String password;
|
||||||
|
|
||||||
|
public static void connect(String url, String user, String password) {
|
||||||
|
Statement.url = url;
|
||||||
|
Statement.user = user;
|
||||||
|
Statement.password = password;
|
||||||
|
try {
|
||||||
|
con = DriverManager.getConnection(url + "?autoreconnect=true", user, password);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
ProxyServer.getInstance().stop();
|
||||||
|
throw new SecurityException("Could not start SQL-Connection", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void reset(SQLException e) {
|
||||||
|
BungeeCore.get().getLogger().log(Level.WARNING, "SQL Exception thrown", e);
|
||||||
|
close();
|
||||||
|
connect(url, user, password);
|
||||||
|
try {
|
||||||
|
for (Statement statement : statements) {
|
||||||
|
statement.init();
|
||||||
|
}
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
throw new SecurityException("Could not reprepare SQL Statements", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void close() {
|
||||||
|
for (Statement statement : statements) {
|
||||||
|
try {
|
||||||
|
statement.st.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
BungeeCore.get().getLogger().log(Level.INFO, "Could not close statement", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
con.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
BungeeCore.log("Could not close SQL-Connection", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String sql;
|
||||||
|
private PreparedStatement st;
|
||||||
|
|
||||||
|
Statement(String sql) {
|
||||||
|
this.sql = sql;
|
||||||
|
statements.add(this);
|
||||||
|
try {
|
||||||
|
init();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
reset(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void init() throws SQLException {
|
||||||
|
st = con.prepareStatement(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
<T> T select(ResultSetUser<T> user, Object... objects) {
|
||||||
|
return prepare(() -> {
|
||||||
|
ResultSet rs = st.executeQuery();
|
||||||
|
T result = user.use(rs);
|
||||||
|
rs.close();
|
||||||
|
return result;
|
||||||
|
}, objects);
|
||||||
|
}
|
||||||
|
|
||||||
|
void update(Object... objects) {
|
||||||
|
prepare(st::executeUpdate, objects);
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized <T> T prepare(SQLRunnable<T> runnable, Object... objects) {
|
||||||
|
try {
|
||||||
|
setObjects(objects);
|
||||||
|
return runnable.run();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
reset(e);
|
||||||
|
try {
|
||||||
|
setObjects(objects);
|
||||||
|
return runnable.run();
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
throw new SecurityException("Could not execute SQL statement", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setObjects(Object... objects) throws SQLException {
|
||||||
|
for (int i = 0; i < objects.length; i++) {
|
||||||
|
st.setObject(i + 1, objects[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ResultSetUser<T> {
|
||||||
|
T use(ResultSet rs) throws SQLException;
|
||||||
|
}
|
||||||
|
|
||||||
|
private interface SQLRunnable<T> {
|
||||||
|
T run() throws SQLException;
|
||||||
|
}
|
||||||
|
}
|
@ -24,16 +24,14 @@ import de.steamwar.bungeecore.BungeeCore;
|
|||||||
import de.steamwar.bungeecore.Message;
|
import de.steamwar.bungeecore.Message;
|
||||||
import de.steamwar.bungeecore.commands.WebregisterCommand;
|
import de.steamwar.bungeecore.commands.WebregisterCommand;
|
||||||
import de.steamwar.bungeecore.listeners.ConnectionListener;
|
import de.steamwar.bungeecore.listeners.ConnectionListener;
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Scanner;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import net.md_5.bungee.api.connection.PendingConnection;
|
import net.md_5.bungee.api.connection.PendingConnection;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import java.net.URL;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -41,25 +39,44 @@ import java.sql.Timestamp;
|
|||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Scanner;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
|
||||||
public class SteamwarUser {
|
public class SteamwarUser {
|
||||||
private final int id;
|
|
||||||
private final UUID uuid;
|
private static final Statement updateName = new Statement("UPDATE UserData SET UserName = ? WHERE id = ?");
|
||||||
private String userName;
|
private static final Statement updateBedrock = new Statement("UPDATE UserData SET Bedrock = ? WHERE id = ?");
|
||||||
private UserGroup userGroup;
|
private static final Statement insert = new Statement("INSERT INTO UserData (UUID, UserName, UserGroup) VALUES (?, ?, 'Member')");
|
||||||
private int team;
|
private static final Statement byUUID = new Statement("SELECT * FROM UserData WHERE UUID = ?");
|
||||||
private boolean leader;
|
private static final Statement byName = new Statement("SELECT * FROM UserData WHERE lower(UserName) = ?");
|
||||||
private Map<Punishment.PunishmentType, Punishment> punishments;
|
private static final Statement byID = new Statement("SELECT * FROM UserData WHERE id = ?");
|
||||||
|
private static final Statement byDiscord = new Statement("SELECT * FROM UserData WHERE DiscordId = ?");
|
||||||
|
private static final Statement updateTeam = new Statement("Update UserData SET Team = ? WHERE id = ?");
|
||||||
|
private static final Statement updateDiscord = new Statement("Update UserData SET DiscordId = ? WHERE id = ?");
|
||||||
|
private static final Statement deleteIPs = new Statement("DELETE FROM BannedUserIPs WHERE UserID = ?");
|
||||||
|
private static final Statement updateLeader = new Statement("Update UserData SET Leader = ? WHERE id = ?");
|
||||||
|
private static final Statement getPlaytime = new Statement("SELECT SUM(UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime)) as Playtime FROM Session WHERE UserID = ?");
|
||||||
|
private static final Statement getFirstjoin = new Statement("SELECT MIN(StartTime) AS FirstJoin FROM Session WHERE UserID = ?");
|
||||||
|
|
||||||
private static final Map<String, SteamwarUser> usersByName = new HashMap<>();
|
private static final Map<String, SteamwarUser> usersByName = new HashMap<>();
|
||||||
private static final Map<UUID, SteamwarUser> usersByUUID = new HashMap<>();
|
private static final Map<UUID, SteamwarUser> usersByUUID = new HashMap<>();
|
||||||
private static final Map<Integer, SteamwarUser> usersById = new HashMap<>();
|
private static final Map<Integer, SteamwarUser> usersById = new HashMap<>();
|
||||||
|
private static final Map<String, SteamwarUser> usersByDiscord = new HashMap<>();
|
||||||
private static final InetAddress LIXFEL_DE;
|
private static final InetAddress LIXFEL_DE;
|
||||||
private static final String API_URL = "https://api.mojang.com/users/profiles/minecraft/";
|
private static final String API_URL = "https://api.mojang.com/users/profiles/minecraft/";
|
||||||
private static final JsonParser jsonParser = new JsonParser();
|
private static final JsonParser jsonParser = new JsonParser();
|
||||||
|
|
||||||
|
private final int id;
|
||||||
|
private final UUID uuid;
|
||||||
|
private String userName;
|
||||||
|
private final UserGroup userGroup;
|
||||||
|
private int team;
|
||||||
|
private boolean leader;
|
||||||
|
private final Map<Punishment.PunishmentType, Punishment> punishments;
|
||||||
|
private String discordId;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
LIXFEL_DE = InetAddress.getByAddress(new byte[]{(byte) 195, (byte) 201, (byte) 242, 43});
|
LIXFEL_DE = InetAddress.getByAddress(new byte[]{(byte) 195, (byte) 201, (byte) 242, 43});
|
||||||
@ -76,9 +93,12 @@ public class SteamwarUser {
|
|||||||
userGroup = UserGroup.getUsergroup(rs.getString("UserGroup"));
|
userGroup = UserGroup.getUsergroup(rs.getString("UserGroup"));
|
||||||
team = rs.getInt("Team");
|
team = rs.getInt("Team");
|
||||||
leader = rs.getBoolean("Leader");
|
leader = rs.getBoolean("Leader");
|
||||||
|
discordId = rs.getString("DiscordId");
|
||||||
usersById.put(id, this);
|
usersById.put(id, this);
|
||||||
usersByName.put(userName.toLowerCase(), this);
|
usersByName.put(userName.toLowerCase(), this);
|
||||||
usersByUUID.put(uuid, this);
|
usersByUUID.put(uuid, this);
|
||||||
|
if(discordId != null)
|
||||||
|
usersByDiscord.put(discordId, this);
|
||||||
punishments = Punishment.getPunishmentsOfPlayer(id);
|
punishments = Punishment.getPunishmentsOfPlayer(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +108,7 @@ public class SteamwarUser {
|
|||||||
if(user != null){
|
if(user != null){
|
||||||
String userName = connection.getName();
|
String userName = connection.getName();
|
||||||
if(!user.userName.equals(userName)){
|
if(!user.userName.equals(userName)){
|
||||||
SQL.update("UPDATE UserData SET UserName = ? WHERE id = ?", userName, user.id);
|
updateName.update(userName, user.id);
|
||||||
WebregisterCommand.changeUsername(user.userName, userName);
|
WebregisterCommand.changeUsername(user.userName, userName);
|
||||||
user.userName = userName;
|
user.userName = userName;
|
||||||
}
|
}
|
||||||
@ -100,7 +120,7 @@ public class SteamwarUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean bedrock = connection.getAddress().getAddress().equals(LIXFEL_DE);
|
boolean bedrock = connection.getAddress().getAddress().equals(LIXFEL_DE);
|
||||||
SQL.update("UPDATE UserData SET Bedrock = ? WHERE id = ?", bedrock, user.id);
|
updateBedrock.update(bedrock, user.id);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +130,7 @@ public class SteamwarUser {
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID uuid = SteamwarUser.loadUUID(name);
|
UUID uuid = SteamwarUser.getUUIDofOfflinePlayer(name);
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -119,21 +139,29 @@ public class SteamwarUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static SteamwarUser createUserInDatabase(UUID uuid, String name) {
|
private static SteamwarUser createUserInDatabase(UUID uuid, String name) {
|
||||||
SQL.update("INSERT INTO UserData (UUID, UserName, UserGroup) VALUES (?, ?, 'Member')", uuid.toString(), name);
|
insert.update(uuid.toString(), name);
|
||||||
return dbInit(SQL.select("SELECT * FROM UserData WHERE UUID = ?", uuid.toString()));
|
return get(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SteamwarUser get(String userName){
|
public static SteamwarUser get(String userName){
|
||||||
userName = userName.toLowerCase();
|
userName = userName.toLowerCase();
|
||||||
if(usersByName.containsKey(userName))
|
if(usersByName.containsKey(userName))
|
||||||
return usersByName.get(userName);
|
return usersByName.get(userName);
|
||||||
return dbInit(SQL.select("SELECT * FROM UserData WHERE lower(UserName) = ?", userName));
|
return byName.select(rs -> {
|
||||||
|
if(rs.next())
|
||||||
|
return new SteamwarUser(rs);
|
||||||
|
return null;
|
||||||
|
}, userName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SteamwarUser get(UUID uuid){
|
public static SteamwarUser get(UUID uuid){
|
||||||
if(usersByUUID.containsKey(uuid))
|
if(usersByUUID.containsKey(uuid))
|
||||||
return usersByUUID.get(uuid);
|
return usersByUUID.get(uuid);
|
||||||
return dbInit(SQL.select("SELECT * FROM UserData WHERE UUID = ?", uuid.toString()));
|
return byUUID.select(rs -> {
|
||||||
|
if(rs.next())
|
||||||
|
return new SteamwarUser(rs);
|
||||||
|
return null;
|
||||||
|
}, uuid.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SteamwarUser get(ProxiedPlayer player){
|
public static SteamwarUser get(ProxiedPlayer player){
|
||||||
@ -143,34 +171,43 @@ public class SteamwarUser {
|
|||||||
public static SteamwarUser get(int id){
|
public static SteamwarUser get(int id){
|
||||||
if(usersById.containsKey(id))
|
if(usersById.containsKey(id))
|
||||||
return usersById.get(id);
|
return usersById.get(id);
|
||||||
return dbInit(SQL.select("SELECT * FROM UserData WHERE id = ?", id));
|
return byID.select(rs -> {
|
||||||
|
rs.next();
|
||||||
|
return new SteamwarUser(rs);
|
||||||
|
}, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SteamwarUser get(Long discordId) {
|
||||||
|
if(usersByDiscord.containsKey(discordId.toString()))
|
||||||
|
return usersByDiscord.get(discordId.toString());
|
||||||
|
return byDiscord.select(rs -> {
|
||||||
|
if(rs.next())
|
||||||
|
return new SteamwarUser(rs);
|
||||||
|
return null;
|
||||||
|
}, discordId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clearCache(){
|
public static void clearCache(){
|
||||||
usersById.clear();
|
usersById.clear();
|
||||||
usersByName.clear();
|
usersByName.clear();
|
||||||
usersByUUID.clear();
|
usersByUUID.clear();
|
||||||
|
usersByDiscord.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UUID loadUUID(String playerName) {
|
private static UUID getUUIDofOfflinePlayer(String playerName) {
|
||||||
try {
|
try {
|
||||||
final URL url = new URL(API_URL + playerName);
|
final URL url = new URL(API_URL + playerName);
|
||||||
return getUniqueIdFromString(jsonParser.parse(new Scanner(url.openConnection().getInputStream()).nextLine()).getAsJsonObject().get("id").getAsString());
|
String uuid = jsonParser.parse(new Scanner(url.openConnection().getInputStream()).nextLine()).getAsJsonObject().get("id").getAsString();
|
||||||
} catch (MalformedURLException e) {
|
return UUID.fromString(uuid.replaceFirst("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5"));
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
BungeeCore.get().getLogger().log(Level.SEVERE, "Could not get offline player UUID", e);
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static UUID getUniqueIdFromString(String uuid) {
|
|
||||||
return UUID.fromString(uuid.replaceFirst("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTeam(int team){
|
public void setTeam(int team){
|
||||||
this.team = team;
|
this.team = team;
|
||||||
SQL.update("Update UserData SET Team = ? WHERE id = ?", team, id);
|
updateTeam.update(team, id);
|
||||||
setLeader(false);
|
setLeader(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,11 +235,24 @@ public class SteamwarUser {
|
|||||||
return punishments.getOrDefault(type, null);
|
return punishments.getOrDefault(type, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDiscordId() {
|
||||||
|
return discordId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDiscordId(String discordId) {
|
||||||
|
usersByDiscord.remove(this.discordId);
|
||||||
|
this.discordId = discordId;
|
||||||
|
updateDiscord.update(discordId, id);
|
||||||
|
if(discordId != null) {
|
||||||
|
usersByDiscord.put(discordId, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isBanned() {
|
public boolean isBanned() {
|
||||||
if(!punishments.containsKey(Punishment.PunishmentType.Ban))
|
if(!punishments.containsKey(Punishment.PunishmentType.Ban))
|
||||||
return false;
|
return false;
|
||||||
if(!punishments.get(Punishment.PunishmentType.Ban).isCurrent()) {
|
if(!punishments.get(Punishment.PunishmentType.Ban).isCurrent()) {
|
||||||
SQL.update("DELETE FROM BannedUserIPs WHERE UserID = ?", id);
|
deleteIPs.update(id);
|
||||||
punishments.remove(Punishment.PunishmentType.Ban);
|
punishments.remove(Punishment.PunishmentType.Ban);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -273,38 +323,20 @@ public class SteamwarUser {
|
|||||||
punishments.put(Punishment.PunishmentType.Mute, Punishment.createPunishment(id, from, Punishment.PunishmentType.Mute, muteReason, time, perma));
|
punishments.put(Punishment.PunishmentType.Mute, Punishment.createPunishment(id, from, Punishment.PunishmentType.Mute, muteReason, time, perma));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SteamwarUser dbInit(ResultSet rs){
|
|
||||||
try {
|
|
||||||
if(!rs.next())
|
|
||||||
return null;
|
|
||||||
return new SteamwarUser(rs);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new SecurityException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getOnlinetime() {
|
public double getOnlinetime() {
|
||||||
ResultSet set = SQL.select("SELECT SUM(UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime)) as Playtime FROM Session WHERE UserID = ?", id);
|
return getPlaytime.select(rs -> {
|
||||||
try {
|
if(rs.next())
|
||||||
if(!set.next())
|
return rs.getBigDecimal("Playtime").doubleValue();
|
||||||
return 0;
|
return 0.0;
|
||||||
return set.getBigDecimal("Playtime").doubleValue();
|
}, id);
|
||||||
} catch (SQLException throwables) {
|
|
||||||
throw new SecurityException("Could not load Online Time", throwables);
|
|
||||||
} catch (NullPointerException e) { //When no Sessions are recorded
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Timestamp getFirstjoin() {
|
public Timestamp getFirstjoin() {
|
||||||
ResultSet set = SQL.select("SELECT MIN(StartTime) AS FirstJoin FROM Session WHERE UserID = ?", id);
|
return getFirstjoin.select(rs -> {
|
||||||
try {
|
if(rs.next())
|
||||||
if(!set.next())
|
return rs.getTimestamp("FirstJoin");
|
||||||
return null;
|
return null;
|
||||||
return set.getTimestamp("FirstJoin");
|
}, id);
|
||||||
} catch (SQLException throwables) {
|
|
||||||
throw new SecurityException("Could not load First Join");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLeader() {
|
public boolean isLeader() {
|
||||||
@ -313,6 +345,6 @@ public class SteamwarUser {
|
|||||||
|
|
||||||
public void setLeader(boolean leader) {
|
public void setLeader(boolean leader) {
|
||||||
this.leader = leader;
|
this.leader = leader;
|
||||||
SQL.update("Update UserData SET Leader = ? WHERE id = ?", leader, id);
|
updateLeader.update(leader, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,25 +19,31 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore.sql;
|
package de.steamwar.bungeecore.sql;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static de.steamwar.bungeecore.sql.SQL.select;
|
|
||||||
|
|
||||||
public class Team {
|
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) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE TeamName = VALUES(TeamName), TeamKuerzel = VALUES(TeamKuerzel), TeamColor = VALUES(TeamColor)");
|
||||||
|
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");
|
||||||
|
|
||||||
private final int teamId;
|
private final int teamId;
|
||||||
private String teamKuerzel;
|
private String teamKuerzel;
|
||||||
private String teamName;
|
private String teamName;
|
||||||
private String teamColor;
|
private String teamColor;
|
||||||
|
|
||||||
private static final List<Team> teamCache = new LinkedList<>();
|
|
||||||
private static final Team pub = new Team(0, "PUB", "Öffentlich", "8");
|
|
||||||
|
|
||||||
private Team(int id, String kuerzel, String name, String color){
|
private Team(int id, String kuerzel, String name, String color){
|
||||||
teamId = id;
|
teamId = id;
|
||||||
teamKuerzel = kuerzel;
|
teamKuerzel = kuerzel;
|
||||||
@ -52,8 +58,8 @@ public class Team {
|
|||||||
this(rs.getInt("TeamID"), rs.getString("TeamKuerzel"), rs.getString("TeamName"), rs.getString("TeamColor"));
|
this(rs.getInt("TeamID"), rs.getString("TeamKuerzel"), rs.getString("TeamName"), rs.getString("TeamColor"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void create(String kuerzel, String name, SteamwarUser user){
|
public static void create(String kuerzel, String name){
|
||||||
SQL.update("INSERT INTO Team (TeamKuerzel, TeamName) VALUES (?, ?)", kuerzel, name);
|
insert.update(kuerzel, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Team get(int id){
|
public static Team get(int id){
|
||||||
@ -64,51 +70,38 @@ public class Team {
|
|||||||
for(Team team : teamCache)
|
for(Team team : teamCache)
|
||||||
if(team.teamId == id)
|
if(team.teamId == id)
|
||||||
return team;
|
return team;
|
||||||
return load(select("SELECT * FROM Team WHERE TeamID = ?", id));
|
return byId.select(rs -> {
|
||||||
|
rs.next();
|
||||||
|
return new Team(rs);
|
||||||
|
}, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Team get(String name){
|
public static Team get(String name){
|
||||||
for(Team team : teamCache)
|
for(Team team : teamCache)
|
||||||
if(team.teamName.equalsIgnoreCase(name))
|
if(team.teamName.equalsIgnoreCase(name) || team.teamKuerzel.equalsIgnoreCase(name))
|
||||||
return team;
|
return team;
|
||||||
for(Team team : teamCache)
|
return byName.select(rs -> {
|
||||||
if(team.teamKuerzel.equalsIgnoreCase(name))
|
if(rs.next())
|
||||||
return team;
|
return new Team(rs);
|
||||||
return load(select("SELECT * FROM Team WHERE (lower(TeamName) = ? OR lower(TeamKuerzel) = ?) AND NOT TeamDeleted", name.toLowerCase(), name.toLowerCase()));
|
return null;
|
||||||
|
}, name.toLowerCase(), name.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Team> getAll(){
|
public static List<Team> getAll(){
|
||||||
clearCache();
|
clearCache();
|
||||||
try{
|
return all.select(rs -> {
|
||||||
ResultSet rs = select("SELECT * FROM Team WHERE NOT TeamDeleted");
|
|
||||||
if(rs == null)
|
|
||||||
return teamCache;
|
|
||||||
|
|
||||||
while(rs.next())
|
while(rs.next())
|
||||||
new Team(rs);
|
new Team(rs);
|
||||||
} catch (SQLException e) {
|
|
||||||
BungeeCore.log("Could not get all Teams", e);
|
|
||||||
}
|
|
||||||
return teamCache;
|
return teamCache;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clearCache(){
|
public static void clearCache(){
|
||||||
teamCache.clear();
|
teamCache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Team load(ResultSet dbteam){
|
|
||||||
try {
|
|
||||||
if(!dbteam.next())
|
|
||||||
return null;
|
|
||||||
return new Team(dbteam);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
BungeeCore.log("Could not load Team", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateDB(){
|
private void updateDB(){
|
||||||
SQL.update("INSERT INTO Team (TeamID, TeamKuerzel, TeamName, TeamColor) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE TeamName = VALUES(TeamName), TeamKuerzel = VALUES(TeamKuerzel), TeamColor = VALUES(TeamColor)", teamId, teamKuerzel, teamName, teamColor);
|
update.update(teamId, teamKuerzel, teamName, teamColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTeamId() {
|
public int getTeamId() {
|
||||||
@ -143,33 +136,24 @@ public class Team {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int size(){
|
public int size(){
|
||||||
ResultSet rs = select("SELECT COUNT(id) FROM UserData WHERE Team = ?", teamId);
|
return getSize.select(rs -> {
|
||||||
try {
|
|
||||||
rs.next();
|
rs.next();
|
||||||
return rs.getInt("COUNT(id)");
|
return rs.getInt("COUNT(id)");
|
||||||
}catch (SQLException e) {
|
}, teamId);
|
||||||
BungeeCore.log("Could not get Teamsize", e);
|
|
||||||
return 1000;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disband(SteamwarUser user){
|
public void disband(SteamwarUser user){
|
||||||
user.setLeader(false);
|
user.setLeader(false);
|
||||||
SQL.update("UPDATE Team SET TeamDeleted = 1 WHERE TeamID = ?", teamId);
|
delete.update(teamId);
|
||||||
teamCache.remove(this);
|
teamCache.remove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Integer> getMembers(){
|
public List<Integer> getMembers(){
|
||||||
try{
|
return getMembers.select(rs -> {
|
||||||
ResultSet memberlist = select("SELECT id FROM UserData WHERE Team = ?", teamId);
|
|
||||||
List<Integer> members = new ArrayList<>();
|
List<Integer> members = new ArrayList<>();
|
||||||
while(memberlist.next()){
|
while(rs.next())
|
||||||
members.add(memberlist.getInt("id"));
|
members.add(rs.getInt("id"));
|
||||||
}
|
|
||||||
return members;
|
return members;
|
||||||
}catch(SQLException e){
|
}, teamId);
|
||||||
BungeeCore.log("Could not get Teammembers", e);
|
|
||||||
}
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,55 +19,46 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore.sql;
|
package de.steamwar.bungeecore.sql;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class TeamTeilnahme {
|
public class TeamTeilnahme {
|
||||||
private TeamTeilnahme(){}
|
private TeamTeilnahme(){}
|
||||||
|
|
||||||
|
private static final Statement insert = new Statement("INSERT INTO TeamTeilnahme (TeamID, EventID) VALUES (?, ?)");
|
||||||
|
private static final Statement delete = new Statement("DELETE FROM TeamTeilnahme WHERE TeamID = ? AND EventID = ?");
|
||||||
|
private static final Statement byEventTeam = new Statement("SELECT * FROM TeamTeilnahme WHERE TeamID = ? AND EventID = ?");
|
||||||
|
private static final Statement byEvent = new Statement("SELECT * FROM TeamTeilnahme WHERE EventID = ?");
|
||||||
|
private static final Statement byTeam = new Statement("SELECT * FROM TeamTeilnahme WHERE TeamID = ?");
|
||||||
|
|
||||||
public static void teilnehmen(int teamID, int eventID){
|
public static void teilnehmen(int teamID, int eventID){
|
||||||
SQL.update("INSERT INTO TeamTeilnahme (TeamID, EventID) VALUES (?, ?)", teamID, eventID);
|
insert.update(teamID, eventID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void notTeilnehmen(int teamID, int eventID){
|
public static void notTeilnehmen(int teamID, int eventID){
|
||||||
SQL.update("DELETE FROM TeamTeilnahme WHERE TeamID = ? AND EventID = ?", teamID, eventID);
|
delete.update(teamID, eventID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean nimmtTeil(int teamID, int eventID){
|
public static boolean nimmtTeil(int teamID, int eventID){
|
||||||
ResultSet rs = SQL.select("SELECT * FROM TeamTeilnahme WHERE TeamID = ? AND EventID = ?", teamID, eventID);
|
return byEventTeam.select(ResultSet::next, teamID, eventID);
|
||||||
try{
|
|
||||||
return rs.next();
|
|
||||||
}catch (SQLException e){
|
|
||||||
BungeeCore.log("Failed to load TeamTeilnahme", e);
|
|
||||||
throw new SecurityException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<Team> getTeams(int eventID){
|
public static Set<Team> getTeams(int eventID){
|
||||||
|
return byEvent.select(rs -> {
|
||||||
Set<Team> teams = new HashSet<>();
|
Set<Team> teams = new HashSet<>();
|
||||||
ResultSet rs = SQL.select("SELECT * FROM TeamTeilnahme WHERE EventID = ?", eventID);
|
|
||||||
try{
|
|
||||||
while(rs.next())
|
while(rs.next())
|
||||||
teams.add(Team.get(rs.getInt("TeamID")));
|
teams.add(Team.get(rs.getInt("TeamID")));
|
||||||
}catch (SQLException e){
|
|
||||||
BungeeCore.log("Failed to load TeamTeilnahmen", e);
|
|
||||||
}
|
|
||||||
return teams;
|
return teams;
|
||||||
|
}, eventID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<Event> getEvents(int teamID){
|
public static Set<Event> getEvents(int teamID){
|
||||||
|
return byTeam.select(rs -> {
|
||||||
Set<Event> events = new HashSet<>();
|
Set<Event> events = new HashSet<>();
|
||||||
ResultSet rs = SQL.select("SELECT * FROM TeamTeilnahme WHERE TeamID = ?", teamID);
|
|
||||||
try{
|
|
||||||
while(rs.next())
|
while(rs.next())
|
||||||
events.add(Event.get(rs.getInt("EventID")));
|
events.add(Event.get(rs.getInt("EventID")));
|
||||||
}catch (SQLException e){
|
|
||||||
BungeeCore.log("Failed to load TeamTeilnahmen", e);
|
|
||||||
}
|
|
||||||
return events;
|
return events;
|
||||||
|
}, teamID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,9 @@ INVALID_TIME=§cUngültige Zeitangabe.
|
|||||||
|
|
||||||
STEAMWAR_BRAND=§eSteam§8War.de §7({0}) §r<- §e{1} §7({2})§r
|
STEAMWAR_BRAND=§eSteam§8War.de §7({0}) §r<- §e{1} §7({2})§r
|
||||||
|
|
||||||
|
DEV_NO_SERVER=§cDer Server ist derzeit nicht erreichbar.
|
||||||
|
DEV_UNKNOWN_SERVER=§cBitte gib einen DevServer an.
|
||||||
|
|
||||||
#ModLoader blocker
|
#ModLoader blocker
|
||||||
MODLOADER_INSTALLED=§7Du hast §e{0} §7installiert. Daher kannst du keinen Arenen beitreten.
|
MODLOADER_INSTALLED=§7Du hast §e{0} §7installiert. Daher kannst du keinen Arenen beitreten.
|
||||||
MODLOADER_DENIED=§cMit Fabric, Forge und LiteLoader kannst du keinen Arenen beitreten.
|
MODLOADER_DENIED=§cMit Fabric, Forge und LiteLoader kannst du keinen Arenen beitreten.
|
||||||
@ -104,6 +107,8 @@ MOD_YELLOW_PLUR=§7Deaktiviere die Mods\n§e{0}\n§7um weiter auf §eSteam§8War
|
|||||||
|
|
||||||
#Various commands
|
#Various commands
|
||||||
ALERT=§f{0}
|
ALERT=§f{0}
|
||||||
|
STAT_SERVER=§7Server §f{0} - §7Ram §f{1} §7CPU §f{2} §7Server Count §f{3}
|
||||||
|
NO_STATS=§7Kein Bau oder Fight Server gestartet
|
||||||
|
|
||||||
#Ban&Mute-Command
|
#Ban&Mute-Command
|
||||||
BAN_TEAM_BANNED={0} §c{1} wurde von {2} {3} gebannt. §f§lGrund: §f{4}
|
BAN_TEAM_BANNED={0} §c{1} wurde von {2} {3} gebannt. §f§lGrund: §f{4}
|
||||||
@ -480,6 +485,7 @@ TABLIST_PHASE_1=§8Teamspeak: §eSteam§8War.de
|
|||||||
TABLIST_PHASE_2=§8Discord: §8https://§eSteam§8War.de/discord
|
TABLIST_PHASE_2=§8Discord: §8https://§eSteam§8War.de/discord
|
||||||
TABLIST_PHASE_DEFAULT=§8Website: https://§eSteam§8War.de
|
TABLIST_PHASE_DEFAULT=§8Website: https://§eSteam§8War.de
|
||||||
TABLIST_BAU=Bau
|
TABLIST_BAU=Bau
|
||||||
|
LIST_COMMAND=§e{0}§8: §7{1}
|
||||||
|
|
||||||
#EventStarter
|
#EventStarter
|
||||||
EVENT_FIGHT_BROADCAST=§7Hier §eklicken §7für den Kampf §{0}{1} §8vs §{2}{3}
|
EVENT_FIGHT_BROADCAST=§7Hier §eklicken §7für den Kampf §{0}{1} §8vs §{2}{3}
|
||||||
@ -499,6 +505,7 @@ WHOIS_USERNAME=§7Username§8: §e{0}
|
|||||||
WHOIS_UUID=§7UUID§8: §e{0}
|
WHOIS_UUID=§7UUID§8: §e{0}
|
||||||
WHOIS_UUID_HOVER=§eUUID Kopieren
|
WHOIS_UUID_HOVER=§eUUID Kopieren
|
||||||
WHOIS_ID=§7ID§8: §e{0}
|
WHOIS_ID=§7ID§8: §e{0}
|
||||||
|
WHOIS_DISCORD_ID=§7Discord-ID§8: §e{0}
|
||||||
WHOIS_JOINED_FIRST=§7Beigetreten am§8: §e{0}
|
WHOIS_JOINED_FIRST=§7Beigetreten am§8: §e{0}
|
||||||
WHOIS_HOURS_PLAYED=§7Online Time§8: §e{0}h
|
WHOIS_HOURS_PLAYED=§7Online Time§8: §e{0}h
|
||||||
WHOIS_TEAM=§7Team§8: §e[§{0}{1}§e] {2}
|
WHOIS_TEAM=§7Team§8: §e[§{0}{1}§e] {2}
|
||||||
@ -506,3 +513,13 @@ WHOIS_TEAM_HOVER=§e{0} anzeigen
|
|||||||
WHOIS_PUNISHMENTS=§7Strafen:
|
WHOIS_PUNISHMENTS=§7Strafen:
|
||||||
WHOIS_PUNISHMENT=§7{0}§8» §f§l{1}: §e{2} - {3} §f{4}
|
WHOIS_PUNISHMENT=§7{0}§8» §f§l{1}: §e{2} - {3} §f{4}
|
||||||
WHOIS_NO_PUNISHMENT=§a✓ §7Der Spieler hat noch nichts getan.
|
WHOIS_NO_PUNISHMENT=§a✓ §7Der Spieler hat noch nichts getan.
|
||||||
|
|
||||||
|
#VerifyCommand
|
||||||
|
VERIFY_USAGE=§c/verify [Code]
|
||||||
|
VERIFY_INVALID=§cInvalider Code
|
||||||
|
VERIFY_SUCCESS=§7Erfolgreich mit dem Discord Account §e{0} §7verknüpft
|
||||||
|
|
||||||
|
#Discord
|
||||||
|
DISCORD_TICKET_MESSAGE=§7Ticket §e{0}§7» §f§l{1}: §7{2}
|
||||||
|
DISCORD_TICKET_NEW=§7Ticket §e{0}§7» §aTicket wurde geöffnet!
|
||||||
|
DISCORD_TICKET_CLOSED=§7Ticket §e{0}§7» §cTicket wurde geschlossen!
|
In neuem Issue referenzieren
Einen Benutzer sperren