geforkt von SteamWar/BungeeCore
Commits vergleichen
246 Commits
Autor | SHA1 | Datum | |
---|---|---|---|
![]() |
995f38fa3c | ||
![]() |
3ebd240741 | ||
![]() |
bdfb1b7772 | ||
![]() |
67a57c9c8c | ||
![]() |
c15dd16cd5 | ||
![]() |
f5306a8ba0 | ||
![]() |
c90de5c455 | ||
![]() |
209214a773 | ||
![]() |
5465111de8 | ||
![]() |
79eb2ae5a4 | ||
d8c10bba9b | |||
![]() |
883c9131b5 | ||
![]() |
8538a09a86 | ||
![]() |
a5e4646e0a | ||
![]() |
83e1a33af5 | ||
![]() |
980c09d433 | ||
![]() |
dd07603fe3 | ||
![]() |
e2024a481b | ||
![]() |
7224428345 | ||
![]() |
d09f8edfa2 | ||
![]() |
bacf366643 | ||
![]() |
48f11d3285 | ||
![]() |
9c8ce57986 | ||
![]() |
e7f0e57e9d | ||
![]() |
ff6fe9eeb5 | ||
![]() |
dbe27e92d2 | ||
![]() |
6350a99392 | ||
![]() |
276587b07f | ||
![]() |
5554b28894 | ||
![]() |
e1eb392ffd | ||
![]() |
6232da87b5 | ||
![]() |
8c098841ba | ||
![]() |
0ef4fc147c | ||
![]() |
5d9d5de237 | ||
![]() |
ba75129d57 | ||
![]() |
581f3be791 | ||
![]() |
c803fe2796 | ||
![]() |
6a42b802e7 | ||
![]() |
42dea17ff0 | ||
![]() |
47f29e8bc7 | ||
![]() |
c473182e7f | ||
![]() |
d58c461a65 | ||
213bc3d319 | |||
![]() |
755ca15cca | ||
![]() |
a15bd4aa83 | ||
![]() |
b3a987f9a5 | ||
![]() |
7deaed4961 | ||
![]() |
9d3b0ea0cd | ||
![]() |
2ef06f61e4 | ||
286f06f866 | |||
101a8ed1e4 | |||
fd1d556fa3 | |||
07c7635ab4 | |||
39571b897d | |||
![]() |
73b89256f0 | ||
![]() |
2f4290e2fe | ||
![]() |
c87ec5214a | ||
5e858cf506 | |||
9b0d7bd856 | |||
![]() |
61d42c7cca | ||
![]() |
f6f568ee40 | ||
a1d8ec806f | |||
![]() |
ef71323b05 | ||
![]() |
c39e2a0566 | ||
a188ce2c6f | |||
3b5be809dd | |||
e1e1d66177 | |||
d7798b3275 | |||
de51db2667 | |||
59b2e397ba | |||
a6feb68bf3 | |||
457b787179 | |||
9572347419 | |||
a0a2d70c46 | |||
f214751d0b | |||
8f3422dce6 | |||
![]() |
2c6de937b3 | ||
49238463a5 | |||
0fd86300ac | |||
c74178abe1 | |||
a3a65b0f53 | |||
1c99a9fb4b | |||
628e7b093c | |||
dd90ee1ced | |||
8029dd09e9 | |||
1e40decc9e | |||
437d1c055c | |||
1436069cb5 | |||
![]() |
b852423442 | ||
![]() |
6f5bb3eb97 | ||
55d08ce0db | |||
b3efb223af | |||
74291bc143 | |||
dabd880209 | |||
3b7fa8054d | |||
54b15ddd95 | |||
70662386a7 | |||
d7e9bb23fc | |||
![]() |
04ebed15d3 | ||
![]() |
9688c38954 | ||
![]() |
760cf4b3b1 | ||
![]() |
443a1b29c9 | ||
c7c541676c | |||
d7a5b72f72 | |||
510fed73d3 | |||
f0e85c21ce | |||
9567bd4c3f | |||
![]() |
3752f3f145 | ||
![]() |
2cdbe68665 | ||
ed5f84dc20 | |||
![]() |
c72a042bbb | ||
![]() |
334afbac63 | ||
779d5f57dc | |||
5162c5b05b | |||
1b3ed278c6 | |||
![]() |
e1a0c4802f | ||
![]() |
23291a7732 | ||
d22766fedd | |||
![]() |
5a0cf47878 | ||
![]() |
99f3ad5f03 | ||
3d67919f0a | |||
![]() |
c017fd23a1 | ||
a05ec1d6d9 | |||
![]() |
28f09e54b9 | ||
7411d9d875 | |||
![]() |
bdbe615790 | ||
![]() |
bfefd5a197 | ||
![]() |
56a9bd077c | ||
6dd35a265b | |||
f270d4197b | |||
2d85746d9f | |||
9de6b8602d | |||
57b220f77c | |||
74cf9d4657 | |||
3ea910501a | |||
4979889468 | |||
8e51002e6c | |||
dad5c6029e | |||
![]() |
a571832d67 | ||
![]() |
6f31058d61 | ||
e36d18ae9d | |||
![]() |
bb8b46c437 | ||
0df03a7dfb | |||
792bbd610d | |||
45cacced9d | |||
d8d519765a | |||
20481029c7 | |||
c3a011d98e | |||
![]() |
183d43dadb | ||
19903e9548 | |||
04a2a31d80 | |||
![]() |
ec6cb89bdb | ||
3d64ee3b6f | |||
![]() |
9be6ec94dc | ||
69720bfbd8 | |||
![]() |
d46c89101d | ||
![]() |
c4fcbdcb43 | ||
24d909a4da | |||
6aeeff235a | |||
65fcb5329f | |||
e981cf5c02 | |||
![]() |
5b627a7819 | ||
![]() |
157aea068e | ||
38eb8d9c06 | |||
ffc2cefcfe | |||
0fc0954d82 | |||
43bd25c13e | |||
b892450e2d | |||
6fe4dbe13a | |||
dbc9ed8b57 | |||
ecf17dd347 | |||
244f922091 | |||
ee05b42a07 | |||
fbbfc1bd03 | |||
1e9b5ead35 | |||
19b12c0055 | |||
e443235e34 | |||
cd044adc55 | |||
a308f9b940 | |||
af357cb554 | |||
356afc9bff | |||
2f928349d7 | |||
7f05d0f9ca | |||
00e08b5943 | |||
4db2ba6a5d | |||
b35d5e214a | |||
3980961b76 | |||
e5cc016652 | |||
3db61577b0 | |||
c0e1d3eff7 | |||
6284cd8e7b | |||
443ce0377f | |||
0c3f200a91 | |||
8c03d2a348 | |||
5aa402d6e8 | |||
59168c3447 | |||
137ef647fb | |||
1128a43010 | |||
5da9d55cb8 | |||
![]() |
df3e082774 | ||
![]() |
6192d0d458 | ||
![]() |
3254755e61 | ||
![]() |
e99f24b01b | ||
01c90dc4ae | |||
![]() |
4dad89ec34 | ||
4385cd3589 | |||
eacf7fd6cf | |||
feeca8f523 | |||
![]() |
e5d48024cb | ||
![]() |
8ed0847bcc | ||
![]() |
e43a724550 | ||
![]() |
9385f57612 | ||
![]() |
6002af7f6a | ||
![]() |
60d5a04d0c | ||
![]() |
9e1653740d | ||
![]() |
618c4d24a2 | ||
![]() |
fbcb043d1c | ||
![]() |
fcd686a9ba | ||
![]() |
4422fbdc8b | ||
![]() |
9af07f821d | ||
![]() |
7cd4a5bac8 | ||
![]() |
6c540c3bac | ||
![]() |
9e6c6ace27 | ||
![]() |
aaadb0e5e2 | ||
![]() |
6ed534bcb3 | ||
![]() |
6848bac447 | ||
![]() |
6a3c47994a | ||
ab207b2234 | |||
![]() |
5e09d018ba | ||
![]() |
0c0cf594c4 | ||
![]() |
9039928eb4 | ||
44e9c084c7 | |||
3fa5e51f30 | |||
98e80442b2 | |||
![]() |
65950a939b | ||
![]() |
4b38ed7c54 | ||
3df1e556ae | |||
5ac85f4e9d | |||
![]() |
ff75a43c11 | ||
![]() |
95a9e8d2a6 | ||
![]() |
ab24041d44 | ||
4052e342fb | |||
![]() |
efc7a3fe48 | ||
4f42c0eca4 | |||
![]() |
481d4a7892 | ||
![]() |
265c841920 |
@ -1 +1 @@
|
|||||||
Subproject commit 595df40e1e9078c310cbbb4bbded07744c361f15
|
Subproject commit d000b8687d93eb43520bbf6685281099055eab9f
|
55
Persistent/build.gradle
Normale Datei
55
Persistent/build.gradle
Normale Datei
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2024 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
}
|
||||||
|
|
||||||
|
group 'de.steamwar'
|
||||||
|
version ''
|
||||||
|
|
||||||
|
compileJava.options.encoding = 'UTF-8'
|
||||||
|
|
||||||
|
java {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
main {
|
||||||
|
java {
|
||||||
|
srcDirs = ['src/']
|
||||||
|
include '**/*.java', '**/*.kt'
|
||||||
|
}
|
||||||
|
resources {
|
||||||
|
srcDirs = ['src/']
|
||||||
|
exclude '**/*.java', '**/*.kt'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly 'org.projectlombok:lombok:1.18.32'
|
||||||
|
testCompileOnly 'org.projectlombok:lombok:1.18.32'
|
||||||
|
annotationProcessor 'org.projectlombok:lombok:1.18.32'
|
||||||
|
testAnnotationProcessor 'org.projectlombok:lombok:1.18.32'
|
||||||
|
|
||||||
|
compileOnly 'de.steamwar:velocity:RELEASE'
|
||||||
|
annotationProcessor 'com.velocitypowered:velocity-api:3.3.0-SNAPSHOT'
|
||||||
|
}
|
37
Persistent/src/de/steamwar/persistent/Arenaserver.java
Normale Datei
37
Persistent/src/de/steamwar/persistent/Arenaserver.java
Normale Datei
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2024 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.persistent;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class Arenaserver extends Subserver {
|
||||||
|
|
||||||
|
private final String mode;
|
||||||
|
private final String map;
|
||||||
|
private final boolean allowMerge;
|
||||||
|
|
||||||
|
public Arenaserver(String serverName, String mode, String map, boolean allowMerge, int port, ProcessBuilder processBuilder, Runnable shutdownCallback) {
|
||||||
|
super(Servertype.ARENA, serverName, port, processBuilder, shutdownCallback, null);
|
||||||
|
this.mode = mode;
|
||||||
|
this.map = map;
|
||||||
|
this.allowMerge = allowMerge;
|
||||||
|
}
|
||||||
|
}
|
60
Persistent/src/de/steamwar/persistent/Bauserver.java
Normale Datei
60
Persistent/src/de/steamwar/persistent/Bauserver.java
Normale Datei
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2024 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.persistent;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class Bauserver extends Subserver {
|
||||||
|
private static final Map<UUID, Bauserver> servers = new HashMap<>();
|
||||||
|
public static Bauserver get(UUID owner) {
|
||||||
|
synchronized (servers) {
|
||||||
|
return servers.get(owner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final UUID owner;
|
||||||
|
|
||||||
|
public Bauserver(String serverName, UUID owner, int port, ProcessBuilder processBuilder, Runnable shutdownCallback){
|
||||||
|
this(serverName, owner, port, processBuilder, shutdownCallback, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bauserver(String serverName, UUID owner, int port, ProcessBuilder processBuilder, Runnable shutdownCallback, Consumer<Exception> failureCallback){
|
||||||
|
super(Servertype.BAUSERVER, serverName, port, processBuilder, shutdownCallback, failureCallback);
|
||||||
|
this.owner = owner;
|
||||||
|
|
||||||
|
synchronized (servers) {
|
||||||
|
servers.put(owner, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void unregister() {
|
||||||
|
synchronized (servers) {
|
||||||
|
servers.remove(owner);
|
||||||
|
}
|
||||||
|
super.unregister();
|
||||||
|
}
|
||||||
|
}
|
59
Persistent/src/de/steamwar/persistent/Builderserver.java
Normale Datei
59
Persistent/src/de/steamwar/persistent/Builderserver.java
Normale Datei
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2024 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.persistent;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class Builderserver extends Subserver {
|
||||||
|
|
||||||
|
private static final Map<String, Builderserver> servers = new HashMap<>();
|
||||||
|
public static Builderserver get(String map) {
|
||||||
|
synchronized (servers) {
|
||||||
|
return servers.get(map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String map;
|
||||||
|
public Builderserver(String serverName, String map, int port, ProcessBuilder processBuilder, Runnable shutdownCallback){
|
||||||
|
this(serverName, map, port, processBuilder, shutdownCallback, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builderserver(String serverName, String map, int port, ProcessBuilder processBuilder, Runnable shutdownCallback, Consumer<Exception> failureCallback){
|
||||||
|
super(Servertype.BUILDER, serverName, port, processBuilder, shutdownCallback, failureCallback);
|
||||||
|
this.map = map;
|
||||||
|
|
||||||
|
synchronized (servers) {
|
||||||
|
servers.put(map, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void unregister() {
|
||||||
|
synchronized (servers) {
|
||||||
|
servers.remove(map);
|
||||||
|
}
|
||||||
|
super.unregister();
|
||||||
|
}
|
||||||
|
}
|
203
Persistent/src/de/steamwar/persistent/Persistent.java
Normale Datei
203
Persistent/src/de/steamwar/persistent/Persistent.java
Normale Datei
@ -0,0 +1,203 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2024 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.persistent;
|
||||||
|
|
||||||
|
import com.google.inject.AbstractModule;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Module;
|
||||||
|
import com.google.inject.name.Names;
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import com.velocitypowered.api.command.BrigadierCommand;
|
||||||
|
import com.velocitypowered.api.command.CommandManager;
|
||||||
|
import com.velocitypowered.api.command.CommandMeta;
|
||||||
|
import com.velocitypowered.api.event.EventManager;
|
||||||
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
|
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||||
|
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
||||||
|
import com.velocitypowered.api.plugin.Plugin;
|
||||||
|
import com.velocitypowered.api.plugin.PluginContainer;
|
||||||
|
import com.velocitypowered.api.plugin.PluginDescription;
|
||||||
|
import com.velocitypowered.api.plugin.PluginManager;
|
||||||
|
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||||
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
import com.velocitypowered.api.scheduler.ScheduledTask;
|
||||||
|
import com.velocitypowered.proxy.plugin.PluginClassLoader;
|
||||||
|
import com.velocitypowered.proxy.plugin.VelocityPluginManager;
|
||||||
|
import com.velocitypowered.proxy.plugin.loader.VelocityPluginContainer;
|
||||||
|
import com.velocitypowered.proxy.plugin.loader.java.JavaPluginLoader;
|
||||||
|
import lombok.Getter;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
@Plugin(
|
||||||
|
id = "persistentvelocitycore",
|
||||||
|
name = "PersistentVelocityCore"
|
||||||
|
)
|
||||||
|
public class Persistent {
|
||||||
|
|
||||||
|
private static final Reflection.Method<VelocityPluginManager> registerPlugin = new Reflection.Method<>(VelocityPluginManager.class, "registerPlugin", PluginContainer.class);
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private static Persistent instance;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final ProxyServer proxy;
|
||||||
|
@Getter
|
||||||
|
private final Logger logger;
|
||||||
|
private final Path directory;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public Persistent(ProxyServer proxy, Logger logger, @DataDirectory Path dataDirectory) {
|
||||||
|
instance = this;
|
||||||
|
this.proxy = proxy;
|
||||||
|
this.logger = logger;
|
||||||
|
this.directory = dataDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onEnable(ProxyInitializeEvent event) {
|
||||||
|
proxy.getCommandManager().register(
|
||||||
|
new BrigadierCommand(
|
||||||
|
BrigadierCommand.literalArgumentBuilder("softreload")
|
||||||
|
.requires(commandSource -> commandSource.hasPermission("bungeecore.softreload"))
|
||||||
|
.executes(commandContext -> softreload())
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onDisable(ProxyShutdownEvent event) {
|
||||||
|
Subserver.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int softreload() {
|
||||||
|
PluginContainer container = null;
|
||||||
|
ReloadablePlugin plugin = null;
|
||||||
|
try {
|
||||||
|
container = proxy.getPluginManager().getPlugin("velocitycore").orElseThrow();
|
||||||
|
plugin = (ReloadablePlugin) container.getInstance().orElseThrow();
|
||||||
|
} catch (NoSuchElementException e) {
|
||||||
|
logger.log(Level.WARNING, "Could not find loaded VelocityCore, continuing without unloading.");
|
||||||
|
}
|
||||||
|
|
||||||
|
PluginContainer newContainer;
|
||||||
|
try {
|
||||||
|
newContainer = prepareLoad();
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.log(Level.SEVERE, "Could not instantiate new VelocityCore, aborting softreload.", e);
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
broadcast("§eNetwork update is starting§8.");
|
||||||
|
try {
|
||||||
|
if(container != null && plugin != null) {
|
||||||
|
plugin.onProxyShutdown(new ProxyShutdownEvent());
|
||||||
|
unload(container, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
registerPlugin.invoke((VelocityPluginManager) proxy.getPluginManager(), newContainer);
|
||||||
|
((ReloadablePlugin) newContainer.getInstance().orElseThrow()).onProxyInitialization(new ProxyInitializeEvent());
|
||||||
|
} catch (Throwable t) {
|
||||||
|
logger.log(Level.SEVERE, "Error during softreload", t);
|
||||||
|
broadcast("§cNetwork update failed§8, §cexpect network restart soon§8.");
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
broadcast("§eNetwork update complete§8.");
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void broadcast(String message) {
|
||||||
|
Component component = LegacyComponentSerializer.legacySection().deserialize("§eSteam§8War» " + message);
|
||||||
|
proxy.getAllPlayers().forEach(player -> player.sendMessage(component));
|
||||||
|
proxy.getConsoleCommandSource().sendMessage(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PluginContainer prepareLoad() throws Exception {
|
||||||
|
Path plugins = directory.getParent();
|
||||||
|
JavaPluginLoader loader = new JavaPluginLoader(proxy, plugins);
|
||||||
|
PluginDescription description = loader.createPluginFromCandidate(loader.loadCandidate(plugins.resolve("VelocityCore.jar")));
|
||||||
|
PluginContainer container = new VelocityPluginContainer(description);
|
||||||
|
|
||||||
|
AbstractModule commonModule = new AbstractModule() {
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
this.bind(ProxyServer.class).toInstance(proxy);
|
||||||
|
this.bind(PluginManager.class).toInstance(proxy.getPluginManager());
|
||||||
|
this.bind(EventManager.class).toInstance(proxy.getEventManager());
|
||||||
|
this.bind(CommandManager.class).toInstance(proxy.getCommandManager());
|
||||||
|
this.bind(PluginContainer.class).annotatedWith(Names.named(container.getDescription().getId())).toInstance(container);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Module module = loader.createModule(container);
|
||||||
|
loader.createPlugin(container, module, commonModule);
|
||||||
|
|
||||||
|
return container;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void unload(PluginContainer container, Object plugin) throws InterruptedException, IOException {
|
||||||
|
PluginClassLoader classLoader = ((PluginClassLoader) plugin.getClass().getClassLoader());
|
||||||
|
|
||||||
|
CommandManager commandManager = proxy.getCommandManager();
|
||||||
|
for(String alias : commandManager.getAliases()) {
|
||||||
|
CommandMeta meta = commandManager.getCommandMeta(alias);
|
||||||
|
if(meta != null && meta.getPlugin() == plugin)
|
||||||
|
commandManager.unregister(meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
proxy.getEventManager().unregisterListeners(plugin);
|
||||||
|
proxy.getScheduler().tasksByPlugin(plugin).forEach(ScheduledTask::cancel);
|
||||||
|
|
||||||
|
container.getExecutorService().shutdown();
|
||||||
|
if(!container.getExecutorService().awaitTermination(100, TimeUnit.MILLISECONDS))
|
||||||
|
logger.log(Level.WARNING, "ExecutorService termination took longer than 100ms, continuing.");
|
||||||
|
|
||||||
|
for(Thread thread : Thread.getAllStackTraces().keySet()) {
|
||||||
|
if(thread.getClass().getClassLoader() != classLoader)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
thread.interrupt();
|
||||||
|
thread.join(100);
|
||||||
|
|
||||||
|
if (thread.isAlive())
|
||||||
|
logger.log(Level.WARNING, "Could not stop thread %s of plugin %s. Still running".formatted(thread.getName(), container.getDescription().getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO close all log handlers
|
||||||
|
/*for (Handler handler : plugin.getLogger().getHandlers()) {
|
||||||
|
handler.close();
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
//Clear resource bundle cache
|
||||||
|
ResourceBundle.clearCache(classLoader);
|
||||||
|
classLoader.close();
|
||||||
|
}
|
||||||
|
}
|
75
Persistent/src/de/steamwar/persistent/Reflection.java
Normale Datei
75
Persistent/src/de/steamwar/persistent/Reflection.java
Normale Datei
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2024 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.persistent;
|
||||||
|
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class Reflection {
|
||||||
|
public static class Field<C, T> {
|
||||||
|
private final java.lang.reflect.Field f;
|
||||||
|
|
||||||
|
public Field(Class<C> target, String name) {
|
||||||
|
try {
|
||||||
|
f = target.getDeclaredField(name);
|
||||||
|
f.setAccessible(true);
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
throw new IllegalArgumentException("Cannot find field with name " + name, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public T get(C target) {
|
||||||
|
try {
|
||||||
|
return (T) f.get(target);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
throw new IllegalArgumentException("Cannot access reflection.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(C target, T value) {
|
||||||
|
try {
|
||||||
|
f.set(target, value);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
throw new IllegalArgumentException("Cannot access reflection.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Method<C> {
|
||||||
|
private final java.lang.reflect.Method m;
|
||||||
|
|
||||||
|
public Method(Class<C> clazz, String methodName, Class<?>... params) {
|
||||||
|
try {
|
||||||
|
m = clazz.getDeclaredMethod(methodName, params);
|
||||||
|
m.setAccessible(true);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
throw new IllegalArgumentException("Cannot find method with name " + methodName, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object invoke(C target, Object... arguments) {
|
||||||
|
try {
|
||||||
|
return m.invoke(target, arguments);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new IllegalArgumentException("Cannot invoke method " + m, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
28
Persistent/src/de/steamwar/persistent/ReloadablePlugin.java
Normale Datei
28
Persistent/src/de/steamwar/persistent/ReloadablePlugin.java
Normale Datei
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2024 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.persistent;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||||
|
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
||||||
|
|
||||||
|
public interface ReloadablePlugin {
|
||||||
|
void onProxyInitialization(ProxyInitializeEvent event);
|
||||||
|
default void onProxyShutdown(ProxyShutdownEvent event) {}
|
||||||
|
}
|
26
Persistent/src/de/steamwar/persistent/Servertype.java
Normale Datei
26
Persistent/src/de/steamwar/persistent/Servertype.java
Normale Datei
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2024 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.persistent;
|
||||||
|
|
||||||
|
public enum Servertype {
|
||||||
|
BAUSERVER,
|
||||||
|
ARENA,
|
||||||
|
BUILDER
|
||||||
|
}
|
52
Persistent/src/de/steamwar/persistent/Storage.java
Normale Datei
52
Persistent/src/de/steamwar/persistent/Storage.java
Normale Datei
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2024 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.persistent;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||||
|
import com.velocitypowered.proxy.protocol.packet.UpsertPlayerInfoPacket;
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class Storage {
|
||||||
|
public static final Map<Player, List<Player>> challenges = new HashMap<>();
|
||||||
|
|
||||||
|
public static final Map<Player, Player> lastChats = new HashMap<>();
|
||||||
|
|
||||||
|
public static final Map<Integer, List<Integer>> teamInvitations = new HashMap<>(); // UserID -> List<TeamIDs>
|
||||||
|
|
||||||
|
public static final Map<Player, Timestamp> sessions = new HashMap<>(); // Contains session start timestamp
|
||||||
|
|
||||||
|
public static final Map<Integer, Subserver> eventServer = new HashMap<>(); // TeamID -> Subserver map
|
||||||
|
|
||||||
|
public static final Map<Player, Integer> fabricCheckedPlayers = new HashMap<>();
|
||||||
|
|
||||||
|
public static final Map<Player, Long> fabricExpectPluginMessage = new HashMap<>();
|
||||||
|
|
||||||
|
public static final Map<Integer, ServerInfo> teamServers = new HashMap<>(); // TeamID -> ServerInfo map
|
||||||
|
|
||||||
|
public static final Map<Player, Map<UUID, UpsertPlayerInfoPacket.Entry>> directTabItems = new HashMap<>();
|
||||||
|
}
|
263
Persistent/src/de/steamwar/persistent/Subserver.java
Normale Datei
263
Persistent/src/de/steamwar/persistent/Subserver.java
Normale Datei
@ -0,0 +1,263 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2024 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.persistent;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
|
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||||
|
import lombok.Getter;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public class Subserver {
|
||||||
|
|
||||||
|
private static final Component PREFIX = Component
|
||||||
|
.text("Steam").color(NamedTextColor.YELLOW)
|
||||||
|
.append(Component.text("War» ").color(NamedTextColor.DARK_GRAY));
|
||||||
|
|
||||||
|
private static final Logger logger = Persistent.getInstance().getLogger();
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private static final List<Subserver> serverList = new LinkedList<>();
|
||||||
|
private static final Map<ServerInfo, Subserver> infoToServer = new HashMap<>();
|
||||||
|
|
||||||
|
public static Subserver getSubserver(Player p) {
|
||||||
|
synchronized (serverList) {
|
||||||
|
for (int i = serverList.size() - 1; i >= 0; i--) {
|
||||||
|
if (serverList.get(i).onServer(p))
|
||||||
|
return serverList.get(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Subserver getSubserver(ServerInfo server) {
|
||||||
|
synchronized (serverList) {
|
||||||
|
return infoToServer.get(server);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void shutdown() {
|
||||||
|
while (!serverList.isEmpty()) {
|
||||||
|
Subserver server = serverList.get(0);
|
||||||
|
server.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String serverName;
|
||||||
|
private final boolean checkpoint;
|
||||||
|
private final Runnable shutdownCallback;
|
||||||
|
private final Consumer<Exception> failureCallback;
|
||||||
|
private final Process process;
|
||||||
|
private final PrintWriter writer;
|
||||||
|
@Getter
|
||||||
|
private final ServerInfo server;
|
||||||
|
@Getter
|
||||||
|
private RegisteredServer registeredServer;
|
||||||
|
@Getter
|
||||||
|
private final Servertype type;
|
||||||
|
private final Thread thread;
|
||||||
|
@Getter
|
||||||
|
private boolean started;
|
||||||
|
|
||||||
|
private final List<Player> cachedPlayers = new LinkedList<>();
|
||||||
|
@Getter
|
||||||
|
private final Map<Player, String> tablistNames = new HashMap<>();
|
||||||
|
|
||||||
|
protected Subserver(Servertype type, String serverName, int port, ProcessBuilder processBuilder, Runnable shutdownCallback, Consumer<Exception> failureCallback) {
|
||||||
|
this.started = false;
|
||||||
|
this.serverName = serverName;
|
||||||
|
this.type = type;
|
||||||
|
this.shutdownCallback = shutdownCallback;
|
||||||
|
this.failureCallback = failureCallback == null ? this::fatalError : failureCallback;
|
||||||
|
this.checkpoint = processBuilder.command().contains("criu");
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.process = processBuilder.start();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new SecurityException("Server could not be started", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
InetSocketAddress address = new InetSocketAddress("127.0.0.1", port);
|
||||||
|
this.server = new ServerInfo(serverName, address);
|
||||||
|
this.writer = new PrintWriter(process.getOutputStream(), true);
|
||||||
|
|
||||||
|
this.thread = new Thread(this::run, "Subserver " + serverName);
|
||||||
|
this.thread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendPlayer(Player p) {
|
||||||
|
if (!started) {
|
||||||
|
p.sendActionBar(generateBar(0));
|
||||||
|
cachedPlayers.add(p);
|
||||||
|
} else {
|
||||||
|
p.createConnectionRequest(registeredServer).connect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(String command) {
|
||||||
|
writer.println(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
try {
|
||||||
|
long pid = process.pid();
|
||||||
|
if (checkpoint)
|
||||||
|
pid = process.children().findAny().map(ProcessHandle::pid).orElse(pid);
|
||||||
|
|
||||||
|
Runtime.getRuntime().exec(new String[]{"kill", "-SIGUSR1", Long.toString(pid)});
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.log(Level.SEVERE, "Failed to send SIGUSR1 to subserver.", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!process.waitFor(1, TimeUnit.MINUTES)) {
|
||||||
|
logger.log(Level.SEVERE, () -> serverName + " did not stop correctly, forcibly stopping!");
|
||||||
|
process.destroyForcibly();
|
||||||
|
}
|
||||||
|
|
||||||
|
thread.join();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
logger.log(Level.SEVERE, "Subserver stop interrupted!", e);
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean onServer(Player p) {
|
||||||
|
return cachedPlayers.contains(p) || (registeredServer != null && registeredServer.getPlayersConnected().contains(p));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fatalError(Exception e) {
|
||||||
|
logger.log(Level.SEVERE, e, () -> serverName + " did not run correctly!");
|
||||||
|
|
||||||
|
for (Player cached : cachedPlayers)
|
||||||
|
cached.sendMessage(PREFIX.append(Component.text("Unexpected error during server startup.").color(NamedTextColor.RED)));
|
||||||
|
if (registeredServer != null) {
|
||||||
|
for (Player player : registeredServer.getPlayersConnected())
|
||||||
|
player.sendMessage(PREFIX.append(Component.text("Lost connection to server.").color(NamedTextColor.RED)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void start(InputStream stream, Predicate<String> test) throws IOException {
|
||||||
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) {
|
||||||
|
String line = "";
|
||||||
|
while (!started && (line = reader.readLine()) != null) {
|
||||||
|
started = test.test(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line == null)
|
||||||
|
throw new IOException(serverName + " did not start correctly!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void register() {
|
||||||
|
if (Persistent.getInstance().getProxy().getServer(serverName).isPresent()) {
|
||||||
|
SecurityException e = new SecurityException("Server already registered: " + serverName);
|
||||||
|
stop();
|
||||||
|
failureCallback.accept(e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized (serverList) {
|
||||||
|
registeredServer = Persistent.getInstance().getProxy().registerServer(server);
|
||||||
|
serverList.add(this);
|
||||||
|
infoToServer.put(server, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void unregister() {
|
||||||
|
synchronized (serverList) {
|
||||||
|
infoToServer.remove(server);
|
||||||
|
serverList.remove(this);
|
||||||
|
Persistent.getInstance().getProxy().unregisterServer(server);
|
||||||
|
registeredServer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void run() {
|
||||||
|
register();
|
||||||
|
|
||||||
|
Exception ex = null;
|
||||||
|
try {
|
||||||
|
if (checkpoint) {
|
||||||
|
start(process.getErrorStream(), line -> line.contains("Restore finished successfully."));
|
||||||
|
} else {
|
||||||
|
start(process.getInputStream(), line -> {
|
||||||
|
if (line.contains("Loading libraries, please wait"))
|
||||||
|
sendProgress(2);
|
||||||
|
else if (line.contains("Starting Minecraft server on"))
|
||||||
|
sendProgress(4);
|
||||||
|
else if (line.contains("Preparing start region"))
|
||||||
|
sendProgress(6);
|
||||||
|
return line.contains("Finished mapping loading");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!started)
|
||||||
|
return;
|
||||||
|
|
||||||
|
sendProgress(8);
|
||||||
|
|
||||||
|
Thread.sleep(300);
|
||||||
|
|
||||||
|
sendProgress(10);
|
||||||
|
for (Player cachedPlayer : cachedPlayers) {
|
||||||
|
sendPlayer(cachedPlayer);
|
||||||
|
}
|
||||||
|
cachedPlayers.clear();
|
||||||
|
|
||||||
|
process.waitFor();
|
||||||
|
} catch (IOException e) {
|
||||||
|
ex = e;
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
ex = e;
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
} finally {
|
||||||
|
unregister();
|
||||||
|
shutdownCallback.run();
|
||||||
|
if (ex != null)
|
||||||
|
failureCallback.accept(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Component generateBar(int progress) {
|
||||||
|
return Component.text("⬛".repeat(Math.max(0, progress))).color(NamedTextColor.YELLOW)
|
||||||
|
.append(Component.text("⬛".repeat(Math.max(0, 10 - progress))).color(NamedTextColor.DARK_GRAY));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendProgress(int progress) {
|
||||||
|
Component tc = generateBar(progress);
|
||||||
|
for (Player cached : cachedPlayers)
|
||||||
|
cached.sendActionBar(tc);
|
||||||
|
}
|
||||||
|
}
|
248
build.gradle
248
build.gradle
@ -17,52 +17,24 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import org.apache.tools.ant.taskdefs.condition.Os
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
// Adding the base plugin fixes the following gradle warnings in IntelliJ:
|
|
||||||
//
|
|
||||||
// Warning: root project 'module-work-multi': Unable to resolve all content root directories
|
|
||||||
// Details: java.lang.IllegalStateException: No value has been specified for this provider.
|
|
||||||
//
|
|
||||||
// Warning: root project 'module-work-multi': Unable to resolve additional project configuration.
|
|
||||||
// Details: java.lang.IllegalStateException: No value has been specified for this provider.
|
|
||||||
id 'base'
|
id 'base'
|
||||||
id 'java'
|
id 'java'
|
||||||
id 'application'
|
id 'application'
|
||||||
|
|
||||||
id 'com.github.johnrengelman.shadow' version '5.0.0'
|
id 'com.github.johnrengelman.shadow' version '8.1.1'
|
||||||
|
id 'de.steamwar.gradle' version 'RELEASE'
|
||||||
}
|
}
|
||||||
|
|
||||||
group 'de.steamwar'
|
group 'de.steamwar'
|
||||||
version ''
|
version ''
|
||||||
|
|
||||||
Properties steamwarProperties = new Properties()
|
|
||||||
if (file("steamwar.properties").exists()) {
|
|
||||||
steamwarProperties.load(file("steamwar.properties").newDataInputStream())
|
|
||||||
}
|
|
||||||
|
|
||||||
ext {
|
|
||||||
buildName = 'BungeeCore'
|
|
||||||
artifactName = 'bungeecore'
|
|
||||||
|
|
||||||
uberJarName = "${buildName}-all.jar"
|
|
||||||
jarName = "${artifactName}.jar"
|
|
||||||
libs = "${buildDir}/libs"
|
|
||||||
|
|
||||||
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
||||||
operatingSystem = "windows"
|
|
||||||
} else {
|
|
||||||
operatingSystem = "unix"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
compileJava.options.encoding = 'UTF-8'
|
compileJava.options.encoding = 'UTF-8'
|
||||||
|
|
||||||
sourceCompatibility = 1.8
|
java {
|
||||||
targetCompatibility = 1.8
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
|
}
|
||||||
|
|
||||||
mainClassName = ''
|
mainClassName = ''
|
||||||
|
|
||||||
@ -78,176 +50,64 @@ sourceSets {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
allprojects {
|
||||||
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven {
|
maven {
|
||||||
url 'https://m2.dv8tion.net/releases'
|
url 'https://repo.papermc.io/repository/maven-public/'
|
||||||
|
content {
|
||||||
|
includeGroup 'com.velocitypowered'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
maven {
|
maven {
|
||||||
url = uri('https://steamwar.de/maven')
|
url 'https://m2.dv8tion.net/releases'
|
||||||
|
content {
|
||||||
|
includeGroup 'net.dv8tion'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
maven {
|
||||||
|
url 'https://repo.lunarclient.dev'
|
||||||
|
content {
|
||||||
|
includeGroup 'com.lunarclient'
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
shadowJar {
|
||||||
compileOnly 'org.projectlombok:lombok:1.18.22'
|
exclude 'META-INF/*'
|
||||||
testCompileOnly 'org.projectlombok:lombok:1.18.22'
|
exclude 'org/sqlite/native/FreeBSD/**', 'org/sqlite/native/Mac/**', 'org/sqlite/native/Windows/**', 'org/sqlite/native/Linux-Android/**', 'org/sqlite/native/Linux-Musl/**'
|
||||||
annotationProcessor 'org.projectlombok:lombok:1.18.22'
|
exclude 'org/sqlite/native/Linux/aarch64/**', 'org/sqlite/native/Linux/arm/**', 'org/sqlite/native/Linux/armv6/**', 'org/sqlite/native/Linux/armv7/**', 'org/sqlite/native/Linux/ppc64/**', 'org/sqlite/native/Linux/x86/**'
|
||||||
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
|
exclude 'org/slf4j/**'
|
||||||
|
//https://imperceptiblethoughts.com/shadow/configuration/minimizing/
|
||||||
|
minimize {
|
||||||
|
exclude project(':')
|
||||||
|
exclude dependency('mysql:mysql-connector-java:.*')
|
||||||
|
}
|
||||||
|
duplicatesStrategy DuplicatesStrategy.INCLUDE
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly 'org.projectlombok:lombok:1.18.32'
|
||||||
|
testCompileOnly 'org.projectlombok:lombok:1.18.32'
|
||||||
|
annotationProcessor 'org.projectlombok:lombok:1.18.32'
|
||||||
|
testAnnotationProcessor 'org.projectlombok:lombok:1.18.32'
|
||||||
|
|
||||||
|
annotationProcessor 'com.velocitypowered:velocity-api:3.3.0-SNAPSHOT'
|
||||||
|
compileOnly 'de.steamwar:velocity:RELEASE'
|
||||||
|
|
||||||
|
compileOnly project(":Persistent")
|
||||||
|
implementation project(":CommonCore")
|
||||||
|
|
||||||
|
implementation 'org.xerial:sqlite-jdbc:3.46.0.0'
|
||||||
|
implementation 'mysql:mysql-connector-java:8.0.33'
|
||||||
|
|
||||||
compileOnly 'de.steamwar:waterfall:RELEASE'
|
|
||||||
compileOnly 'de.steamwar:persistentbungeecore:RELEASE'
|
|
||||||
implementation("net.dv8tion:JDA:4.4.0_352") {
|
implementation("net.dv8tion:JDA:4.4.0_352") {
|
||||||
exclude module: 'opus-java'
|
exclude module: 'opus-java'
|
||||||
}
|
}
|
||||||
|
|
||||||
implementation project(":CommonCore")
|
implementation 'org.msgpack:msgpack-core:0.9.8' //AlpineClient
|
||||||
}
|
|
||||||
|
implementation 'com.lunarclient:apollo-api:1.1.0'
|
||||||
task buildProject {
|
implementation 'com.lunarclient:apollo-common:1.1.0'
|
||||||
description 'Build this project'
|
|
||||||
group "Steamwar"
|
|
||||||
|
|
||||||
dependsOn build
|
|
||||||
}
|
|
||||||
|
|
||||||
task finalizeProject {
|
|
||||||
description 'Finalize this project'
|
|
||||||
group "Steamwar"
|
|
||||||
|
|
||||||
doLast {
|
|
||||||
if ("${buildDir}" == null) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
delete fileTree("${libs}").matching {
|
|
||||||
exclude("${uberJarName}")
|
|
||||||
}
|
|
||||||
file(libs + "/" + uberJarName).renameTo(file(libs + "/" + jarName))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
build.finalizedBy(finalizeProject)
|
|
||||||
|
|
||||||
if (steamwarProperties.containsKey("hostname")) {
|
|
||||||
String hostname = steamwarProperties.get("hostname")
|
|
||||||
String uploadPath = steamwarProperties.getOrDefault("uploadPath", "~")
|
|
||||||
|
|
||||||
String server = steamwarProperties.getOrDefault("server", "DevBungee")
|
|
||||||
String serverStartFlags = steamwarProperties.getOrDefault("serverStartFlags", "")
|
|
||||||
|
|
||||||
task uploadProject {
|
|
||||||
description 'Upload this project'
|
|
||||||
group "Steamwar"
|
|
||||||
|
|
||||||
doLast {
|
|
||||||
await(shell("scp ${libs}/${jarName} ${hostname}:${uploadPath}/${server}/plugins"))
|
|
||||||
if (steamwarProperties.getOrDefault("directStart", "false") == "false" && !answer("Start ${server} server?")) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
serverStart(server, serverStartFlags, hostname)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
uploadProject.dependsOn(buildProject)
|
|
||||||
|
|
||||||
task startDevServer {
|
|
||||||
description 'Start the DevBungee'
|
|
||||||
group "Steamwar"
|
|
||||||
|
|
||||||
doLast {
|
|
||||||
serverStart(server, serverStartFlags, hostname)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private def await(Process proc) {
|
|
||||||
def out = new StringBuilder()
|
|
||||||
def err = new StringBuilder()
|
|
||||||
proc.waitForProcessOutput(out, err)
|
|
||||||
return [out, err, proc.exitValue()]
|
|
||||||
}
|
|
||||||
|
|
||||||
private def shell(String command) {
|
|
||||||
if (operatingSystem == "unix") {
|
|
||||||
return ['bash', '-c', command].execute()
|
|
||||||
} else {
|
|
||||||
return ["cmd", "/c", command].execute()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private def serverStart(String serverName, String serverFlags, String hostname) {
|
|
||||||
def proc = shell("ssh -t ${hostname} \"./mc ${serverFlags} ${serverName}\"")
|
|
||||||
|
|
||||||
Set<String> strings = new HashSet<>()
|
|
||||||
File file = new File("${projectDir}/ignoredlog");
|
|
||||||
if (file.exists()) {
|
|
||||||
new BufferedReader(new InputStreamReader(new FileInputStream(file))).readLines().forEach({ s ->
|
|
||||||
strings.add(s)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
Thread outputThread = new Thread({
|
|
||||||
Reader reader = proc.getInputStream().newReader();
|
|
||||||
Writer writer = System.out.newWriter();
|
|
||||||
try {
|
|
||||||
while (proc.alive) {
|
|
||||||
String s = reader.readLine()
|
|
||||||
if (s == null) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (strings.stream().anyMatch({check -> s.contains(check)})) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
writer.write(s + "\n")
|
|
||||||
writer.flush()
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
// Ignored
|
|
||||||
}
|
|
||||||
})
|
|
||||||
outputThread.setName("${serverName} - OutputThread")
|
|
||||||
outputThread.start()
|
|
||||||
|
|
||||||
Writer writer
|
|
||||||
Thread inputThread = new Thread({
|
|
||||||
Reader reader = System.in.newReader()
|
|
||||||
writer = proc.getOutputStream().newWriter()
|
|
||||||
try {
|
|
||||||
while (proc.alive) {
|
|
||||||
String s = reader.readLine()
|
|
||||||
writer.write(s + "\n")
|
|
||||||
writer.flush()
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
// Ignored
|
|
||||||
}
|
|
||||||
})
|
|
||||||
inputThread.setName("${serverName} - InputThread")
|
|
||||||
inputThread.start()
|
|
||||||
|
|
||||||
gradle.buildFinished { buildResult ->
|
|
||||||
if (!proc.alive) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
writer = proc.getOutputStream().newWriter()
|
|
||||||
writer.write("stop\n")
|
|
||||||
writer.flush()
|
|
||||||
awaitClose(proc, outputThread, inputThread)
|
|
||||||
}
|
|
||||||
awaitClose(proc, outputThread, inputThread)
|
|
||||||
};
|
|
||||||
|
|
||||||
private static def awaitClose(Process proc, Thread outputThread, Thread inputThread) {
|
|
||||||
while (proc.alive) {
|
|
||||||
Thread.sleep(10)
|
|
||||||
}
|
|
||||||
proc.closeStreams()
|
|
||||||
outputThread.interrupt()
|
|
||||||
inputThread.interrupt()
|
|
||||||
}
|
|
||||||
|
|
||||||
private def answer(String question) {
|
|
||||||
while (System.in.available() > 0) System.in.read()
|
|
||||||
println(question)
|
|
||||||
boolean valid = "Yy".contains(((char) System.in.read()).toString())
|
|
||||||
while (System.in.available() > 0) System.in.read()
|
|
||||||
return valid
|
|
||||||
}
|
}
|
86
deployarena.py
Ausführbare Datei
86
deployarena.py
Ausführbare Datei
@ -0,0 +1,86 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import datetime
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import sys
|
||||||
|
import tarfile
|
||||||
|
from os import path
|
||||||
|
|
||||||
|
# Non stdlib
|
||||||
|
from nbt import nbt
|
||||||
|
from ruamel.yaml import YAML
|
||||||
|
yaml = YAML()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
configfile = f'/configs/GameModes/{sys.argv[1]}'
|
||||||
|
version = int(sys.argv[2])
|
||||||
|
worldname = sys.argv[3]
|
||||||
|
|
||||||
|
with open(configfile, 'r') as file:
|
||||||
|
gamemode = yaml.load(file)
|
||||||
|
|
||||||
|
builderworld = path.expanduser(f'~/builder{version}/{worldname}')
|
||||||
|
arenaworld = f'/servers/{gamemode["Server"]["Folder"]}/arenas/{worldname}'
|
||||||
|
|
||||||
|
if path.exists(arenaworld):
|
||||||
|
backupworld = path.expanduser(f'~/backup/arenas/{datetime.datetime.now()}-{worldname}-{version}.tar.xz')
|
||||||
|
with tarfile.open(backupworld, 'w:xz') as tar:
|
||||||
|
tar.add(arenaworld, arcname=worldname)
|
||||||
|
|
||||||
|
shutil.rmtree(arenaworld)
|
||||||
|
else:
|
||||||
|
gamemode['Server']['Maps'].append(worldname)
|
||||||
|
|
||||||
|
with open(configfile, 'w') as file:
|
||||||
|
yaml.dump(gamemode, file)
|
||||||
|
|
||||||
|
|
||||||
|
level = nbt.NBTFile(f'{builderworld}/level.dat')
|
||||||
|
level['Data']['Difficulty'] = nbt.TAG_Byte(2)
|
||||||
|
gameRules = level['Data']['GameRules']
|
||||||
|
gameRules['announceAdvancements'] = nbt.TAG_String('false')
|
||||||
|
gameRules['disableRaids'] = nbt.TAG_String('true')
|
||||||
|
gameRules['doDaylightCycle'] = nbt.TAG_String('false')
|
||||||
|
gameRules['doEntityDrops'] = nbt.TAG_String('false')
|
||||||
|
gameRules['doFireTick'] = nbt.TAG_String('true')
|
||||||
|
gameRules['doImmediateRespawn'] = nbt.TAG_String('true')
|
||||||
|
gameRules['doInsomnia'] = nbt.TAG_String('false')
|
||||||
|
gameRules['doLimitedCrafting'] = nbt.TAG_String('false')
|
||||||
|
gameRules['doMobLoot'] = nbt.TAG_String('false')
|
||||||
|
gameRules['doMobSpawning'] = nbt.TAG_String('false')
|
||||||
|
gameRules['doPatrolSpawning'] = nbt.TAG_String('false')
|
||||||
|
gameRules['doTileDrops'] = nbt.TAG_String('true')
|
||||||
|
gameRules['doTraderSpawning'] = nbt.TAG_String('false')
|
||||||
|
gameRules['doWardenSpawning'] = nbt.TAG_String('false')
|
||||||
|
gameRules['doWeatherCycle'] = nbt.TAG_String('false')
|
||||||
|
gameRules['drowningDamage'] = nbt.TAG_String('true')
|
||||||
|
gameRules['fallDamage'] = nbt.TAG_String('true')
|
||||||
|
gameRules['fireDamage'] = nbt.TAG_String('true')
|
||||||
|
gameRules['freezeDamage'] = nbt.TAG_String('true')
|
||||||
|
gameRules['keepInventory'] = nbt.TAG_String('true')
|
||||||
|
gameRules['lavaSourceConversion'] = nbt.TAG_String('false')
|
||||||
|
gameRules['maxEntityCramming'] = nbt.TAG_String('24')
|
||||||
|
gameRules['mobGriefing'] = nbt.TAG_String('false')
|
||||||
|
gameRules['naturalRegeneration'] = nbt.TAG_String('false')
|
||||||
|
gameRules['randomTickSpeed'] = nbt.TAG_String('3')
|
||||||
|
gameRules['reducedDebugInfo'] = nbt.TAG_String('true')
|
||||||
|
gameRules['snowAccumulationHeight'] = nbt.TAG_String('1')
|
||||||
|
gameRules['spawnRadius'] = nbt.TAG_String('0')
|
||||||
|
gameRules['spectatorsGenerateChunks'] = nbt.TAG_String('true')
|
||||||
|
gameRules['waterSourceConversion'] = nbt.TAG_String('true')
|
||||||
|
level.write_file()
|
||||||
|
|
||||||
|
if path.exists(arenaworld):
|
||||||
|
shutil.rmtree(arenaworld)
|
||||||
|
|
||||||
|
os.makedirs(f'{arenaworld}/backup')
|
||||||
|
shutil.copy2(f'{builderworld}/level.dat', f'{arenaworld}/backup/level.dat')
|
||||||
|
shutil.copytree(f'{builderworld}/region', f'{arenaworld}/backup/region')
|
||||||
|
|
||||||
|
shutil.copy2(f'{builderworld}/level.dat', f'{arenaworld}/level.dat')
|
||||||
|
shutil.copytree(f'{builderworld}/region', f'{arenaworld}/region')
|
||||||
|
shutil.copy2(f'{builderworld}/config.yml', f'{arenaworld}/config.yml')
|
||||||
|
|
||||||
|
if path.exists(f'{builderworld}/paper-world.yml'):
|
||||||
|
shutil.copy2(f'{builderworld}/paper-world.yml', f'{arenaworld}/backup/paper-world.yml')
|
||||||
|
shutil.copy2(f'{builderworld}/paper-world.yml', f'{arenaworld}/paper-world.yml')
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
|||||||
#Sat Apr 10 23:34:12 CEST 2021
|
#Sat Apr 10 23:34:12 CEST 2021
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-all.zip
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
@ -17,6 +17,16 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
rootProject.name = 'BungeeCore'
|
pluginManagement {
|
||||||
|
repositories {
|
||||||
|
gradlePluginPortal()
|
||||||
|
maven {
|
||||||
|
url = uri("https://steamwar.de/maven/")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rootProject.name = 'VelocityCore'
|
||||||
|
|
||||||
include 'CommonCore'
|
include 'CommonCore'
|
||||||
|
include 'Persistent'
|
||||||
|
@ -1,187 +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;
|
|
||||||
|
|
||||||
import de.steamwar.sql.SchematicType;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.config.Configuration;
|
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class ArenaMode {
|
|
||||||
|
|
||||||
private static final Map<String, ArenaMode> byChat = new HashMap<>();
|
|
||||||
private static final Map<String, ArenaMode> byInternal = new HashMap<>();
|
|
||||||
private static final Map<SchematicType, ArenaMode> bySchemType = new HashMap<>();
|
|
||||||
private static final List<ArenaMode> allModes = new LinkedList<>();
|
|
||||||
private static final Random random = new Random();
|
|
||||||
|
|
||||||
static {
|
|
||||||
File folder = new File(ProxyServer.getInstance().getPluginsFolder(), "FightSystem");
|
|
||||||
|
|
||||||
for(File configFile : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().collect(Collectors.toList())) {
|
|
||||||
Configuration config;
|
|
||||||
try {
|
|
||||||
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new SecurityException("Could not load SchematicTypes", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(config.contains("Server"))
|
|
||||||
new ArenaMode(configFile.getName().replace(".yml", ""), config);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ArenaMode getByChat(String name){
|
|
||||||
return byChat.get(name.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ArenaMode getByInternal(String name){
|
|
||||||
return byInternal.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> getAllChatNames(boolean historic) {
|
|
||||||
List<String> chatNames = new LinkedList<>();
|
|
||||||
for(ArenaMode mode : byInternal.values()){
|
|
||||||
if(historic == mode.historic)
|
|
||||||
chatNames.addAll(mode.chatNames);
|
|
||||||
}
|
|
||||||
return chatNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> getAllRankedChatNames(){
|
|
||||||
List<String> chatNames = new LinkedList<>();
|
|
||||||
for(ArenaMode mode : byInternal.values()){
|
|
||||||
if(mode.isRanked())
|
|
||||||
chatNames.addAll(mode.chatNames);
|
|
||||||
}
|
|
||||||
return chatNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ArenaMode getBySchemType(SchematicType schemType){
|
|
||||||
return bySchemType.get(schemType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<ArenaMode> getAllModes(){
|
|
||||||
return allModes;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final String displayName;
|
|
||||||
private final String folder;
|
|
||||||
private final List<String> chatNames;
|
|
||||||
private final String serverJar;
|
|
||||||
private final String config;
|
|
||||||
private final List<String> maps;
|
|
||||||
private final Map<String, String> lowerToRealMapNames = new HashMap<>();
|
|
||||||
private final boolean historic;
|
|
||||||
private final String internalName;
|
|
||||||
|
|
||||||
private final boolean ranked;
|
|
||||||
private final String schemType;
|
|
||||||
|
|
||||||
private ArenaMode(String internalName, Configuration config){
|
|
||||||
this.internalName = internalName;
|
|
||||||
this.folder = config.getString("Server.Folder");
|
|
||||||
this.serverJar = config.getString("Server.ServerJar");
|
|
||||||
this.config = internalName + ".yml";
|
|
||||||
this.maps = config.getStringList("Server.Maps");
|
|
||||||
maps.forEach(map -> lowerToRealMapNames.put(map.toLowerCase(), map));
|
|
||||||
this.displayName = config.getString("GameName", internalName);
|
|
||||||
this.chatNames = config.getStringList("Server.ChatNames");
|
|
||||||
this.schemType = config.getString("Schematic.Type", "").toLowerCase();
|
|
||||||
|
|
||||||
this.ranked = config.getBoolean("Server.Ranked", false);
|
|
||||||
this.historic = config.getBoolean("Server.Historic", false);
|
|
||||||
|
|
||||||
allModes.add(this);
|
|
||||||
byInternal.put(internalName, this);
|
|
||||||
for(String name : chatNames){
|
|
||||||
byChat.put(name.toLowerCase(), this);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!this.schemType.equals(""))
|
|
||||||
bySchemType.put(SchematicType.fromDB(this.schemType), this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDisplayName() {
|
|
||||||
return displayName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String serverJar() {
|
|
||||||
return serverJar;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getConfig(){
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String hasMap(String map){
|
|
||||||
for(String m : maps){
|
|
||||||
if(m.equalsIgnoreCase(map))
|
|
||||||
return m;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFolder() {
|
|
||||||
return folder;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRandomMap(){
|
|
||||||
return maps.get(random.nextInt(maps.size()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getMaps() {
|
|
||||||
return maps;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String convertToRealMapName(String map){
|
|
||||||
return lowerToRealMapNames.get(map.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getChatName(){
|
|
||||||
return chatNames.get(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean withoutChatName(){
|
|
||||||
return chatNames.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isHistoric(){
|
|
||||||
return historic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRanked() {
|
|
||||||
return ranked;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSchemType() {
|
|
||||||
return schemType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getInternalName() {
|
|
||||||
return internalName;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,355 +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;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
|
||||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
|
||||||
import de.steamwar.bungeecore.commands.*;
|
|
||||||
import de.steamwar.bungeecore.listeners.*;
|
|
||||||
import de.steamwar.bungeecore.listeners.mods.*;
|
|
||||||
import de.steamwar.bungeecore.listeners.ping.PingListener;
|
|
||||||
import de.steamwar.bungeecore.network.BungeeNetworkHandler;
|
|
||||||
import de.steamwar.bungeecore.network.NetworkReceiver;
|
|
||||||
import de.steamwar.bungeecore.network.SWScriptSyntaxForwarder;
|
|
||||||
import de.steamwar.sql.Punishment;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.sql.UserElo;
|
|
||||||
import de.steamwar.bungeecore.tablist.TablistManager;
|
|
||||||
import de.steamwar.command.SWCommandUtils;
|
|
||||||
import de.steamwar.command.SWTypeMapperCreator;
|
|
||||||
import de.steamwar.command.TabCompletionCache;
|
|
||||||
import de.steamwar.command.TypeMapper;
|
|
||||||
import de.steamwar.sql.Team;
|
|
||||||
import de.steamwar.sql.internal.Statement;
|
|
||||||
import net.md_5.bungee.BungeeCord;
|
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
|
||||||
import net.md_5.bungee.api.chat.HoverEvent;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
|
||||||
import net.md_5.bungee.config.Configuration;
|
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
public class BungeeCore extends Plugin {
|
|
||||||
|
|
||||||
public static boolean MAIN_SERVER;
|
|
||||||
|
|
||||||
public static String CHAT_PREFIX;
|
|
||||||
public static String LOBBY_SERVER;
|
|
||||||
public static boolean EVENT_MODE;
|
|
||||||
|
|
||||||
private static BungeeCore instance;
|
|
||||||
|
|
||||||
public static final Map<String, String> serverPermissions = new HashMap<>();
|
|
||||||
public static final Map<String, String> commands = new HashMap<>();
|
|
||||||
|
|
||||||
public static Node local;
|
|
||||||
private ErrorLogger errorLogger;
|
|
||||||
private TablistManager tablistManager;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEnable(){
|
|
||||||
getProxy().registerChannel("sw:bridge");
|
|
||||||
getProxy().registerChannel("fabricmodsender:mods");
|
|
||||||
getProxy().registerChannel("nochatreports:sync");
|
|
||||||
getProxy().registerChannel("sw:script_syntax");
|
|
||||||
|
|
||||||
setInstance(this);
|
|
||||||
MAIN_SERVER = ProxyServer.getInstance().getConfig().getListeners().stream().anyMatch(info -> ((InetSocketAddress) info.getSocketAddress()).getPort() == 25565);
|
|
||||||
loadConfig();
|
|
||||||
|
|
||||||
errorLogger = new ErrorLogger();
|
|
||||||
|
|
||||||
SWCommandUtils.init((SWTypeMapperCreator<TypeMapper<Object>, CommandSender, Object>) (mapper, tabCompleter) -> new TypeMapper<Object>() {
|
|
||||||
@Override
|
|
||||||
public Object map(CommandSender commandSender, String[] previousArguments, String s) {
|
|
||||||
return mapper.apply(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) {
|
|
||||||
return tabCompleter.apply(sender, s);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
BungeeCord.getInstance().getScheduler().schedule(this, TabCompletionCache::invalidateOldEntries, 1, 1, TimeUnit.SECONDS);
|
|
||||||
|
|
||||||
new NonFabricFabricCheck();
|
|
||||||
|
|
||||||
new SWScriptSyntaxForwarder();
|
|
||||||
new ConnectionListener();
|
|
||||||
new Forge();
|
|
||||||
new Forge12();
|
|
||||||
new LabyMod();
|
|
||||||
new Badlion();
|
|
||||||
new ChatListener();
|
|
||||||
new BanListener();
|
|
||||||
new CheckListener();
|
|
||||||
new ModLoaderBlocker();
|
|
||||||
new WorldDownloader();
|
|
||||||
new BrandListener();
|
|
||||||
new Fabric();
|
|
||||||
new SubserverProtocolFixer();
|
|
||||||
new PingListener();
|
|
||||||
|
|
||||||
local = new Node.LocalNode();
|
|
||||||
if(MAIN_SERVER) {
|
|
||||||
//new Node.RemoteNode("lx");
|
|
||||||
}
|
|
||||||
|
|
||||||
commands.put("/tp", null);
|
|
||||||
commands.put("/bc", null);
|
|
||||||
commands.put("/bauchat", null);
|
|
||||||
commands.put("/local", null);
|
|
||||||
|
|
||||||
new TeamchatCommand();
|
|
||||||
new MsgCommand();
|
|
||||||
new RCommand();
|
|
||||||
new PingCommand();
|
|
||||||
new AlertCommand();
|
|
||||||
new KickCommand();
|
|
||||||
new JoinmeCommand();
|
|
||||||
new TpCommand();
|
|
||||||
HelpCommand helpCommand = new HelpCommand();
|
|
||||||
new TeamCommand();
|
|
||||||
new ServerTeamchatCommand();
|
|
||||||
new DevCommand();
|
|
||||||
new EventCommand();
|
|
||||||
new EventreloadCommand();
|
|
||||||
new EventRescheduleCommand();
|
|
||||||
new PollCommand();
|
|
||||||
new BugCommand();
|
|
||||||
new WhoisCommand();
|
|
||||||
new RegelnCommand();
|
|
||||||
new IgnoreCommand();
|
|
||||||
new UnIgnoreCommand();
|
|
||||||
new PollresultCommand();
|
|
||||||
new ListCommand();
|
|
||||||
new StatCommand();
|
|
||||||
new VerifyCommand();
|
|
||||||
new GDPRQuery();
|
|
||||||
new PlaytimeCommand();
|
|
||||||
new ArenaCommand();
|
|
||||||
new RankCommand();
|
|
||||||
new LocalCommand();
|
|
||||||
new SetLocaleCommand();
|
|
||||||
new BuilderCloudCommand();
|
|
||||||
|
|
||||||
new CalendarCommand();
|
|
||||||
new CalendarListener();
|
|
||||||
|
|
||||||
new ModCommand();
|
|
||||||
|
|
||||||
// Punishment Commands:
|
|
||||||
new PunishmentCommand("ban", Punishment.PunishmentType.Ban);
|
|
||||||
new PunishmentCommand("mute", Punishment.PunishmentType.Mute);
|
|
||||||
new PunishmentCommand("noschemreceiving", Punishment.PunishmentType.NoSchemReceiving);
|
|
||||||
new PunishmentCommand("noschemsharing", Punishment.PunishmentType.NoSchemSharing);
|
|
||||||
new PunishmentCommand("noschemsubmitting", Punishment.PunishmentType.NoSchemSubmitting);
|
|
||||||
new PunishmentCommand("nodev", Punishment.PunishmentType.NoDevServer);
|
|
||||||
new PunishmentCommand("nofight", Punishment.PunishmentType.NoFightServer);
|
|
||||||
new PunishmentCommand("noteamserver", Punishment.PunishmentType.NoTeamServer);
|
|
||||||
new PunishmentCommand("note", Punishment.PunishmentType.Note);
|
|
||||||
|
|
||||||
if(!EVENT_MODE){
|
|
||||||
new BauCommand(helpCommand);
|
|
||||||
new WebpasswordCommand();
|
|
||||||
new FightCommand();
|
|
||||||
new ChallengeCommand();
|
|
||||||
new HistoricCommand();
|
|
||||||
new CheckCommand();
|
|
||||||
new ReplayCommand();
|
|
||||||
new TutorialCommand();
|
|
||||||
|
|
||||||
new Broadcaster();
|
|
||||||
}else{
|
|
||||||
new EventModeListener();
|
|
||||||
}
|
|
||||||
|
|
||||||
new EventStarter();
|
|
||||||
new SessionManager();
|
|
||||||
new NetworkReceiver();
|
|
||||||
BungeeNetworkHandler.register();
|
|
||||||
tablistManager = new TablistManager();
|
|
||||||
new SettingsChangedListener();
|
|
||||||
|
|
||||||
getProxy().getScheduler().schedule(this, () -> {
|
|
||||||
SteamwarUser.clear();
|
|
||||||
UserElo.clear();
|
|
||||||
Team.clear();
|
|
||||||
}, 1, 1, TimeUnit.HOURS);
|
|
||||||
|
|
||||||
if (SteamwarDiscordBotConfig.loaded) {
|
|
||||||
try {
|
|
||||||
new SteamwarDiscordBot();
|
|
||||||
} catch (Throwable e) {
|
|
||||||
getLogger().log(Level.SEVERE, "Could not initialize discord bot", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDisable(){
|
|
||||||
if (SteamwarDiscordBotConfig.loaded) {
|
|
||||||
try {
|
|
||||||
SteamwarDiscordBot.instance().getJda().shutdown();
|
|
||||||
} catch (Throwable e) {
|
|
||||||
getLogger().log(Level.SEVERE, "Could not shutdown discord bot", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(tablistManager != null)
|
|
||||||
tablistManager.disable();
|
|
||||||
errorLogger.unregister();
|
|
||||||
Statement.closeAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BungeeCore get() {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TextComponent stringToText(String msg){
|
|
||||||
return new TextComponent(TextComponent.fromLegacyText(msg));
|
|
||||||
}
|
|
||||||
public static void send(ProxiedPlayer player, String msg){
|
|
||||||
send(player, msg, null, null);
|
|
||||||
}
|
|
||||||
public static void send(CommandSender sender, String msg){
|
|
||||||
sender.sendMessage(stringToText(msg));
|
|
||||||
}
|
|
||||||
public static void send(ProxiedPlayer player, ChatMessageType type, String msg){
|
|
||||||
send(player, type, msg, null, null);
|
|
||||||
}
|
|
||||||
public static void send(ProxiedPlayer player, String msg, String onHover, ClickEvent onClick){
|
|
||||||
send(player, ChatMessageType.SYSTEM, msg, onHover, onClick);
|
|
||||||
}
|
|
||||||
public static void send(ProxiedPlayer player, ChatMessageType type, String msg, String onHover, ClickEvent onClick){
|
|
||||||
if(type == ChatMessageType.CHAT && player.getChatMode() != ProxiedPlayer.ChatMode.SHOWN)
|
|
||||||
return;
|
|
||||||
TextComponent message = stringToText(msg);
|
|
||||||
if(onHover != null)
|
|
||||||
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(onHover)));
|
|
||||||
if(onClick != null)
|
|
||||||
message.setClickEvent(onClick);
|
|
||||||
player.sendMessage(type, message);
|
|
||||||
}
|
|
||||||
public static void broadcast(String msg){
|
|
||||||
ProxyServer.getInstance().broadcast(stringToText(msg));
|
|
||||||
}
|
|
||||||
public static void broadcast(String msg, String onHover, ClickEvent onClick){
|
|
||||||
TextComponent message = stringToText(msg);
|
|
||||||
if(onHover != null)
|
|
||||||
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(onHover)));
|
|
||||||
if(onClick != null)
|
|
||||||
message.setClickEvent(onClick);
|
|
||||||
ProxyServer.getInstance().broadcast(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void log(final ServerInfo server, final String msg){
|
|
||||||
log(server.getName() + ": " + msg);
|
|
||||||
}
|
|
||||||
public static void log(final ProxiedPlayer player, final String msg){
|
|
||||||
log(player.getName() + ": " + msg);
|
|
||||||
}
|
|
||||||
public static void log(final String msg){
|
|
||||||
log(Level.INFO, msg);
|
|
||||||
}
|
|
||||||
public static void log(final Level logLevel, final String msg){
|
|
||||||
get().getLogger().log(logLevel, msg);
|
|
||||||
}
|
|
||||||
public static void log(final String msg, final Throwable e){
|
|
||||||
get().getLogger().log(Level.SEVERE, msg, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static void loadConfig(){
|
|
||||||
Configuration config;
|
|
||||||
try{
|
|
||||||
if(!get().getDataFolder().exists() && !get().getDataFolder().mkdir())
|
|
||||||
throw new IOException();
|
|
||||||
File configFile = new File(get().getDataFolder().getPath(), "config.yml");
|
|
||||||
if(!configFile.exists()){
|
|
||||||
boolean created = configFile.createNewFile();
|
|
||||||
if(created)
|
|
||||||
ProxyServer.getInstance().stop("Config file not initialized");
|
|
||||||
else
|
|
||||||
ProxyServer.getInstance().stop("Could not save conig file");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
|
|
||||||
}catch(Exception e){
|
|
||||||
log("Could not save/load config.yml", e);
|
|
||||||
ProxyServer.getInstance().stop();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
CHAT_PREFIX = config.getString("prefix");
|
|
||||||
LOBBY_SERVER = config.getString("lobbyserver");
|
|
||||||
EVENT_MODE = config.getBoolean("eventmode");
|
|
||||||
Broadcaster.setBroadCastMsgs(config.getStringList("broadcasts").toArray(new String[1]));
|
|
||||||
PollSystem.init(config.getString("poll.question"), config.getStringList("poll.answers"));
|
|
||||||
Persistent.setChatPrefix(CHAT_PREFIX);
|
|
||||||
Persistent.setLobbyServer(LOBBY_SERVER);
|
|
||||||
|
|
||||||
final Configuration servers = config.getSection("servers");
|
|
||||||
for(final String serverName : servers.getKeys()){
|
|
||||||
final Configuration server = servers.getSection(serverName);
|
|
||||||
List<String> cmds = server.getStringList("commands");
|
|
||||||
serverPermissions.put(serverName, "bungeecore.server." + server.getString("permission"));
|
|
||||||
String cmd = cmds.remove(0);
|
|
||||||
new ServerSwitchCommand(
|
|
||||||
cmd,
|
|
||||||
serverName,
|
|
||||||
serverPermissions.get(serverName),
|
|
||||||
cmds.toArray(new String[0])
|
|
||||||
);
|
|
||||||
if(server.getBoolean("modchecked", false)) {
|
|
||||||
ModLoaderBlocker.addServer(serverName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
File discordFile = new File(System.getProperty("user.home"), "discord.yml");
|
|
||||||
if(discordFile.exists() && !EVENT_MODE) {
|
|
||||||
try {
|
|
||||||
SteamwarDiscordBotConfig.loadConfig(ConfigurationProvider.getProvider(YamlConfiguration.class).load(discordFile));
|
|
||||||
} catch (IOException e) {
|
|
||||||
get().getLogger().log(Level.SEVERE, "Could not load discord bot configuration", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void setInstance(BungeeCore core){
|
|
||||||
instance = core;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,92 +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;
|
|
||||||
|
|
||||||
import de.steamwar.sql.SWException;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.logging.Handler;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.LogRecord;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
public class ErrorLogger extends Handler {
|
|
||||||
|
|
||||||
ErrorLogger(){
|
|
||||||
Logger.getLogger("").addHandler(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void unregister(){
|
|
||||||
Logger.getLogger("").removeHandler(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void publish(LogRecord logRecord) {
|
|
||||||
if(logRecord.getLevel().intValue() < Level.WARNING.intValue())
|
|
||||||
return;
|
|
||||||
|
|
||||||
String message = MessageFormat.format(logRecord.getMessage(), logRecord.getParameters());
|
|
||||||
for(String reason : ignoreContains)
|
|
||||||
if(message.contains(reason))
|
|
||||||
return;
|
|
||||||
|
|
||||||
ByteArrayOutputStream stacktraceOutput = new ByteArrayOutputStream();
|
|
||||||
if(logRecord.getThrown() != null)
|
|
||||||
logRecord.getThrown().printStackTrace(new PrintStream(stacktraceOutput));
|
|
||||||
String stacktrace = stacktraceOutput.toString();
|
|
||||||
if (stacktrace.contains("ErrorLogger")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SWException.log(message, stacktrace);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void flush() {
|
|
||||||
//ignored
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() {
|
|
||||||
//ignored
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final List<String> ignoreContains;
|
|
||||||
|
|
||||||
static {
|
|
||||||
List<String> contains = new ArrayList<>();
|
|
||||||
contains.add("Error authenticating ");
|
|
||||||
contains.add("read timed out");
|
|
||||||
contains.add("could not decode packet");
|
|
||||||
contains.add("Connection reset by peer");
|
|
||||||
contains.add("No client connected for pending server");
|
|
||||||
contains.add("Error occurred processing connection for");
|
|
||||||
contains.add("Server is online mode!");
|
|
||||||
contains.add(" took ");
|
|
||||||
contains.add("Could not translate packet ");
|
|
||||||
ignoreContains = Collections.unmodifiableList(contains);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,145 +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;
|
|
||||||
|
|
||||||
import de.steamwar.messages.ChatSender;
|
|
||||||
import de.steamwar.messages.SteamwarResourceBundle;
|
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.ResourceBundle;
|
|
||||||
|
|
||||||
public class Message {
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static TextComponent parseToComponent(String message, boolean prefixed, CommandSender sender, Object... params){
|
|
||||||
return new TextComponent(TextComponent.fromLegacyText(parse(message, prefixed, locale(sender), params)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static String parsePrefixed(String message, CommandSender sender, Object... params){
|
|
||||||
return parse(message, true, locale(sender), params);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static String parse(String message, CommandSender sender, Object... params){
|
|
||||||
return parse(message, false, locale(sender), params);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static String parse(String message, Locale locale, Object... params){
|
|
||||||
return parse(message, false, locale, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
private static Locale locale(CommandSender sender) {
|
|
||||||
return ChatSender.of(sender).getLocale();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
private static String parse(String message, boolean prefixed, Locale locale, Object... params){
|
|
||||||
if(locale == null)
|
|
||||||
locale = Locale.getDefault();
|
|
||||||
ResourceBundle resourceBundle = SteamwarResourceBundle.getResourceBundle(locale);
|
|
||||||
String pattern = "";
|
|
||||||
if(prefixed)
|
|
||||||
pattern = resourceBundle.getObject("PREFIX") + " ";
|
|
||||||
pattern += (String)resourceBundle.getObject(message);
|
|
||||||
|
|
||||||
MessageFormat format = new MessageFormat(pattern, locale);
|
|
||||||
for (int i = 0; i < params.length; i++) {
|
|
||||||
if(params[i] instanceof Message) {
|
|
||||||
Message msg = (Message) params[i];
|
|
||||||
params[i] = parse(msg.getFormat(), false, locale, msg.getParams());
|
|
||||||
} else if(params[i] instanceof Date) {
|
|
||||||
params[i] = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale).format((Date) params[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return format.format(params);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static void send(String message, CommandSender sender, Object... params){
|
|
||||||
send(message, true, sender, ChatMessageType.SYSTEM, null, null, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static void sendPrefixless(String message, CommandSender sender, Object... params){
|
|
||||||
send(message, false, sender, ChatMessageType.SYSTEM, null, null, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static void send(String message, CommandSender sender, String onHover, ClickEvent onClick, Object... params){
|
|
||||||
send(message, true, sender, ChatMessageType.SYSTEM, onHover, onClick, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static void sendPrefixless(String message, CommandSender sender, String onHover, ClickEvent onClick, Object... params){
|
|
||||||
send(message, false, sender, ChatMessageType.SYSTEM, onHover, onClick, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
private static void send(String message, boolean prefixed, CommandSender s, ChatMessageType type, String onHover, ClickEvent onClick, Object... params){
|
|
||||||
ChatSender sender = ChatSender.of(s);
|
|
||||||
if(type == ChatMessageType.CHAT && !sender.chatShown())
|
|
||||||
return;
|
|
||||||
|
|
||||||
sender.send(prefixed, type, onHover != null ? new Message("PLAIN_STRING", onHover) : null, onClick, new Message(message, params));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void broadcast(String message, Object... params) {
|
|
||||||
broadcast(message, null, null, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void broadcast(String message, String onHover, ClickEvent onClick, Object... params) {
|
|
||||||
ChatSender.allReceivers().forEach(player -> player.system(message, onHover != null ? new Message(onHover, params) : null, onClick, params));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void team(String message, Object... params) {
|
|
||||||
team(message, null, null, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void team(String message, String onHover, ClickEvent onClick, Object... params) {
|
|
||||||
ChatSender.serverteamReceivers().filter(player -> player.user().getUserGroup().isTeamGroup()).forEach(player -> player.prefixless(message, onHover != null ? new Message(onHover, params) : null, onClick, params));
|
|
||||||
}
|
|
||||||
|
|
||||||
private final String format;
|
|
||||||
private final Object[] params;
|
|
||||||
|
|
||||||
public Message(String format, Object... params) {
|
|
||||||
this.format = format;
|
|
||||||
this.params = params;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFormat() {
|
|
||||||
return format;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object[] getParams() {
|
|
||||||
return params;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,81 +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.bot;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
|
||||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
|
||||||
import de.steamwar.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 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());
|
|
||||||
BungeeCore.get().getProxy().getScheduler().schedule(BungeeCore.get(), () -> TOKENS.remove(code), 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.getIdLong());
|
|
||||||
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().queue(privateChannel -> privateChannel.sendMessage(builder.build()).queue());
|
|
||||||
if (member.getNickname() == null) {
|
|
||||||
try {
|
|
||||||
member.getGuild().modifyNickname(member, user.getUserName()).queue();
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Ignored
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TOKENS.remove(code);
|
|
||||||
return member;
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,166 +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.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.messages.ChatSender;
|
|
||||||
import de.steamwar.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.exceptions.ErrorResponseException;
|
|
||||||
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;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
public class SteamwarDiscordBot {
|
|
||||||
|
|
||||||
private static SteamwarDiscordBot INSTANCE;
|
|
||||||
|
|
||||||
public static SteamwarDiscordBot instance() {
|
|
||||||
return INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
private volatile AnnouncementListener announcementListener;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
private volatile DiscordChatListener ingameChatListener;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
private volatile DiscordChatListener 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);
|
|
||||||
}
|
|
||||||
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
|
|
||||||
try {
|
|
||||||
jda.awaitReady();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
activity();
|
|
||||||
} catch (Exception e) {
|
|
||||||
BungeeCore.get().getLogger().log(Level.SEVERE, "Could not set initial activity to discord", e);
|
|
||||||
}
|
|
||||||
EventManager.update();
|
|
||||||
SchematicsManager.update();
|
|
||||||
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
|
|
||||||
try {
|
|
||||||
activity();
|
|
||||||
EventManager.update();
|
|
||||||
SchematicsManager.update();
|
|
||||||
} catch (ErrorResponseException e) {
|
|
||||||
//ignored
|
|
||||||
}
|
|
||||||
}, 30, 30, TimeUnit.SECONDS);
|
|
||||||
DiscordRolesMessage.sendMessage();
|
|
||||||
DiscordRulesMessage.sendMessage();
|
|
||||||
DiscordTicketMessage.sendMessage();
|
|
||||||
new RolesInteractionButtonListener();
|
|
||||||
new DiscordTicketListener();
|
|
||||||
new DiscordAuthListener();
|
|
||||||
new DiscordEventListener();
|
|
||||||
new PrivateMessageListener();
|
|
||||||
announcementListener = new AnnouncementListener();
|
|
||||||
ingameChatListener = new DiscordChatListener(SteamwarDiscordBotConfig.INGAME_CHANNEL, "CHAT_DISCORD_GLOBAL", ChatSender::globalReceivers);
|
|
||||||
serverTeamChatListener = new DiscordChatListener(SteamwarDiscordBotConfig.SERVER_TEAM_CHANNEL, "CHAT_SERVERTEAM", ChatSender::serverteamReceivers);
|
|
||||||
new SlashCommandListener();
|
|
||||||
jda.retrieveCommands().complete().forEach(command -> jda.deleteCommandById(command.getId()).queue());
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,66 +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.bot.commands;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.Message;
|
|
||||||
import de.steamwar.bungeecore.commands.PunishmentCommand;
|
|
||||||
import de.steamwar.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 = PunishmentCommand.getOrCreateOfflinePlayer(event.getOption("user").getAsString());
|
|
||||||
if (target == null) {
|
|
||||||
event.reply("Angegebener User invalide").setEphemeral(true).queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Timestamp time = PunishmentCommand.parseTime(null, event.getOption("time").getAsString());
|
|
||||||
if (time == null) {
|
|
||||||
event.reply("Angegebene Zeit invalide").setEphemeral(true).queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String msg = event.getOption("reason").getAsString();
|
|
||||||
boolean isPerma = event.getOption("time").getAsString().equals("perma");
|
|
||||||
|
|
||||||
PunishmentCommand.ban(target, time, msg, sender, isPerma);
|
|
||||||
Message.team("BAN_TEAM", 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).queue();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,54 +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.bot.commands;
|
|
||||||
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.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).queue();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,43 +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.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.getCustomTablist();
|
|
||||||
EmbedBuilder embedBuilder = new EmbedBuilder();
|
|
||||||
embedBuilder.setTitle("List");
|
|
||||||
de.steamwar.bungeecore.commands.ListCommand.getCustomTablist().forEach((s, proxiedPlayers) -> {
|
|
||||||
embedBuilder.addField(s, proxiedPlayers.stream().map(player -> "`" + player.getName() + "`").collect(Collectors.joining(", ")), true);
|
|
||||||
});
|
|
||||||
event.replyEmbeds(embedBuilder.build()).setEphemeral(true).queue();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,67 +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.bot.commands;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.Message;
|
|
||||||
import de.steamwar.bungeecore.commands.PunishmentCommand;
|
|
||||||
import de.steamwar.sql.Punishment;
|
|
||||||
import de.steamwar.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 = PunishmentCommand.getOrCreateOfflinePlayer(event.getOption("user").getAsString());
|
|
||||||
if (target == null) {
|
|
||||||
event.reply("Angegebener User invalide").setEphemeral(true).complete();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Timestamp time = PunishmentCommand.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.punish(Punishment.PunishmentType.Mute, time, msg, sender.getId(), isPerma);
|
|
||||||
Message.team("MUTE_TEAM", 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).queue();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,96 +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.bot.commands;
|
|
||||||
|
|
||||||
import de.steamwar.sql.Event;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.sql.Team;
|
|
||||||
import de.steamwar.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).queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (steamwarUser.getTeam() == 0) {
|
|
||||||
event.reply("Du bist in keinem Team").setEphemeral(true).queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
team = Team.get(steamwarUser.getTeam());
|
|
||||||
} else {
|
|
||||||
team = Team.get(optionMapping.getAsString());
|
|
||||||
}
|
|
||||||
if (team == null) {
|
|
||||||
event.reply("Unbekanntes Team").setEphemeral(true).queue();
|
|
||||||
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).queue();
|
|
||||||
return;
|
|
||||||
default:
|
|
||||||
event.reply("Unbekannter Befehl").setEphemeral(true).queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isOnline(SteamwarUser user) {
|
|
||||||
return ProxyServer.getInstance().getPlayer(user.getUUID()) != null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,62 +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.bot.commands;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.commands.PunishmentCommand;
|
|
||||||
import de.steamwar.sql.BannedUserIPs;
|
|
||||||
import de.steamwar.sql.Punishment;
|
|
||||||
import de.steamwar.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 = PunishmentCommand.getOrCreateOfflinePlayer(event.getOption("user").getAsString());
|
|
||||||
if (target == null) {
|
|
||||||
event.reply("Angegebener User invalide").setEphemeral(true).queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!target.isPunished(Punishment.PunishmentType.Ban)) {
|
|
||||||
event.reply("Angegebener User ist nicht gebannt").setEphemeral(true).queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
target.punish(Punishment.PunishmentType.Ban, Timestamp.from(new Date().toInstant()), "Unban", sender.getId(), false);
|
|
||||||
BannedUserIPs.unbanIPs(target.getId());
|
|
||||||
event.reply("Erfolgreich " + target.getUserName() + " entbannt").setEphemeral(true).queue();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,94 +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.bot.commands;
|
|
||||||
|
|
||||||
import de.steamwar.sql.Punishment;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.sql.Team;
|
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
|
||||||
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
|
||||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
|
||||||
|
|
||||||
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).queue();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,39 +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.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));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,36 +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.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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,41 +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.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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,116 +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.bot.config;
|
|
||||||
|
|
||||||
import de.steamwar.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 boolean loaded = false;
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
loaded = true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,73 +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.bot.events;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
|
||||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
|
||||||
import de.steamwar.bungeecore.commands.CheckCommand;
|
|
||||||
import de.steamwar.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.getOwner()).getUserName());
|
|
||||||
String checker = CheckCommand.getChecker(schematic);
|
|
||||||
if (checker != null) {
|
|
||||||
st.append("\nWird Geprüft von: ").append(checker);
|
|
||||||
}
|
|
||||||
embedBuilder.addField(schematic.getName(), st.toString(), true);
|
|
||||||
});
|
|
||||||
|
|
||||||
MessageBuilder messageBuilder = new MessageBuilder();
|
|
||||||
messageBuilder.setEmbeds(embedBuilder.build());
|
|
||||||
if (message == null) {
|
|
||||||
textChannel.sendMessage(messageBuilder.build()).queue(message1 -> message = message1);
|
|
||||||
} else {
|
|
||||||
message.editMessage(messageBuilder.build()).queue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,50 +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.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()).queue();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,59 +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.bot.listeners;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.bot.AuthManager;
|
|
||||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
|
||||||
import de.steamwar.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).queue();
|
|
||||||
} else {
|
|
||||||
event.reply("Du hast bereits einen Code am laufen").setEphemeral(true).queue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(event.getComponentId().equals("tada") && event.getChannelType() == ChannelType.PRIVATE) {
|
|
||||||
event.reply(":tada:").setEphemeral(false).queue();
|
|
||||||
}
|
|
||||||
|
|
||||||
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).queue();
|
|
||||||
} else {
|
|
||||||
user.setDiscordId(null);
|
|
||||||
event.reply(":x: Die Verknüpfung wurde beendet").setEphemeral(false).queue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,71 +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.bot.listeners;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
|
||||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
|
||||||
import de.steamwar.bungeecore.listeners.ChatListener;
|
|
||||||
import de.steamwar.sql.Punishment;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.messages.ChatSender;
|
|
||||||
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;
|
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
public class DiscordChatListener extends BasicDiscordListener {
|
|
||||||
|
|
||||||
private final String channel;
|
|
||||||
private final String format;
|
|
||||||
|
|
||||||
private final Supplier<Stream<ChatSender>> targets;
|
|
||||||
|
|
||||||
public DiscordChatListener(String channel, String format, Supplier<Stream<ChatSender>> targets) {
|
|
||||||
this.channel = channel;
|
|
||||||
this.format = format;
|
|
||||||
this.targets = targets;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
|
|
||||||
if (!event.getChannel().getId().equals(channel) || event.getAuthor().isBot())
|
|
||||||
return;
|
|
||||||
|
|
||||||
Member member = event.getMember();
|
|
||||||
SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong());
|
|
||||||
if (steamwarUser == null || event.getMessage().getContentRaw().length() > 250 || steamwarUser.isPunished(Punishment.PunishmentType.Ban)) {
|
|
||||||
event.getMessage().delete().queue();
|
|
||||||
} else {
|
|
||||||
ChatListener.sendChat(ChatSender.of(event.getMessage(), steamwarUser), targets.get(), format, null, event.getMessage().getContentDisplay().replace('§', '&').replace('\n', ' '));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void send(String message) {
|
|
||||||
TextChannel textChannel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(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();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,93 +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.bot.listeners;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
|
||||||
import de.steamwar.bungeecore.bot.events.EventManager;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.sql.Team;
|
|
||||||
import de.steamwar.sql.TeamTeilnahme;
|
|
||||||
import de.steamwar.sql.Event;
|
|
||||||
import net.dv8tion.jda.api.events.interaction.SelectionMenuEvent;
|
|
||||||
import net.dv8tion.jda.api.interactions.components.Component;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
|
|
||||||
public class DiscordEventListener extends BasicDiscordListener {
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSelectionMenu(@NotNull SelectionMenuEvent event) {
|
|
||||||
if(event.getChannel().getId().equals(SteamwarDiscordBotConfig.EVENTS_CHANNEL) && event.getComponentType() == Component.Type.SELECTION_MENU) {
|
|
||||||
if(event.getSelectedOptions().isEmpty()) {
|
|
||||||
event.deferReply(true).queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(event.getSelectedOptions().get(0).getValue().matches("([0-9]+)")) {
|
|
||||||
SteamwarUser user = SteamwarUser.get(event.getUser().getIdLong());
|
|
||||||
if(user == null) {
|
|
||||||
event.reply("Du hast dein Minecraft nicht verknüpft").setEphemeral(true).queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(user.getTeam() == 0) {
|
|
||||||
event.reply("Du bist in keinem Team").setEphemeral(true).queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!user.isLeader()) {
|
|
||||||
event.reply("Du bist kein Leader in deinem Team").setEphemeral(true).queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Event.get() != null) {
|
|
||||||
event.reply("Du kannst dich nicht während einem Event an einem Event anmelden").setEphemeral(true).queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Event swEvent = Event.get(Integer.decode(event.getSelectedOptions().get(0).getValue()));
|
|
||||||
if(swEvent == null){
|
|
||||||
event.reply("Das Event gibt es nicht").setEphemeral(true).queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Instant.now().isAfter(swEvent.getDeadline().toInstant())){
|
|
||||||
event.reply("Du kannst dich nicht mehr an diesen Event anmelden").setEphemeral(true).queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Team team = Team.get(user.getTeam());
|
|
||||||
|
|
||||||
if(TeamTeilnahme.nimmtTeil(team.getTeamId(), swEvent.getEventID())){
|
|
||||||
TeamTeilnahme.notTeilnehmen(team.getTeamId(), swEvent.getEventID());
|
|
||||||
event.reply("Dein Team **" + team.getTeamName() + "** nimmt nun nicht mehr an **" + swEvent.getEventName() + "** teil!").setEphemeral(true).queue();
|
|
||||||
}else{
|
|
||||||
TeamTeilnahme.teilnehmen(team.getTeamId(), swEvent.getEventID());
|
|
||||||
event.reply("Dein Team **" + team.getTeamName() + "** nimmt nun an **" + swEvent.getEventName() + "** teil!").setEphemeral(true).queue();
|
|
||||||
}
|
|
||||||
|
|
||||||
EventManager.update();
|
|
||||||
} else {
|
|
||||||
event.reply("Lefuq?").setEphemeral(true).queue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,156 +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.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.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);
|
|
||||||
|
|
||||||
LinkedList<StringBuilder> stringBuilders = new LinkedList<>();
|
|
||||||
stringBuilders.add(new StringBuilder());
|
|
||||||
|
|
||||||
new LinkedList<>(event.getTextChannel().getIterableHistory().complete()).descendingIterator().forEachRemaining(message -> {
|
|
||||||
if(message.getAuthor().isSystem() || message.getAuthor().isBot()) return;
|
|
||||||
StringBuilder currentBuilder = new StringBuilder();
|
|
||||||
currentBuilder.append("<t:").append(message.getTimeCreated().toInstant().getEpochSecond()).append("> ")
|
|
||||||
.append("**")
|
|
||||||
.append(message.getAuthor().getName())
|
|
||||||
.append("**: ")
|
|
||||||
.append(message.getContentRaw());
|
|
||||||
if(!message.getAttachments().isEmpty()) {
|
|
||||||
currentBuilder.append("\n")
|
|
||||||
.append("Files: ").append("\n");
|
|
||||||
message.getAttachments().forEach(attachment -> currentBuilder.append(attachment.getUrl()).append("\n"));
|
|
||||||
}
|
|
||||||
|
|
||||||
currentBuilder.append("\n");
|
|
||||||
if(currentBuilder.length() >= 4096) {
|
|
||||||
stringBuilders.getLast().append(currentBuilder.substring(0, 4090));
|
|
||||||
stringBuilders.add(new StringBuilder(currentBuilder.substring(4090, currentBuilder.length() - 1)));
|
|
||||||
} else if (currentBuilder.length() + stringBuilders.getLast().length() >= 4096) {
|
|
||||||
stringBuilders.add(new StringBuilder(currentBuilder.toString()));
|
|
||||||
} else {
|
|
||||||
stringBuilders.getLast().append(currentBuilder);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
String footer = "<t:" + Instant.now().getEpochSecond() + "> **" + event.getUser().getName() + "**: Ticket geschlossen";
|
|
||||||
if(stringBuilders.getLast().length() + footer.length() > 4090) {
|
|
||||||
stringBuilders.add(new StringBuilder(footer));
|
|
||||||
} else {
|
|
||||||
stringBuilders.getLast().append(footer);
|
|
||||||
}
|
|
||||||
|
|
||||||
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());
|
|
||||||
stringBuilders.forEach(stringBuilder -> {
|
|
||||||
embedBuilder.setDescription(stringBuilder.toString());
|
|
||||||
MessageBuilder builder = new MessageBuilder();
|
|
||||||
builder.setEmbeds(embedBuilder.build());
|
|
||||||
|
|
||||||
logChannel.sendMessage(builder.build()).queue();
|
|
||||||
});
|
|
||||||
|
|
||||||
Message.team("DISCORD_TICKET_CLOSED", event.getTextChannel().getName());
|
|
||||||
event.getTextChannel().delete().reason("Closed").queue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@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.getUniqueId());
|
|
||||||
boolean sendMessage;
|
|
||||||
if(user.getDiscordId() == null) {
|
|
||||||
sendMessage = user.getUserGroup().isCheckSchematics();
|
|
||||||
} else {
|
|
||||||
if(event.getAuthor().getId().equals(user.getDiscordId())) return;
|
|
||||||
sendMessage = user.getDiscordId().equals(event.getChannel().getTopic()) || user.getUserGroup().isCheckSchematics();
|
|
||||||
}
|
|
||||||
if(sendMessage) {
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,80 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
* <p>
|
|
||||||
* 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.
|
|
||||||
* <p>
|
|
||||||
* 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.
|
|
||||||
* <p>
|
|
||||||
* 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.sql.NodeData;
|
|
||||||
import de.steamwar.sql.Punishment;
|
|
||||||
import de.steamwar.sql.SchematicNode;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
|
||||||
import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
public class PrivateMessageListener extends BasicDiscordListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPrivateMessageReceived(PrivateMessageReceivedEvent event) {
|
|
||||||
if(!event.getMessage().getAttachments().isEmpty()) {
|
|
||||||
SteamwarUser user = SteamwarUser.get(event.getAuthor().getIdLong());
|
|
||||||
if (user == null) {
|
|
||||||
event.getMessage().reply("Du must dein Minecraft Account mit dem Bot verbinden, gehe dazu auf dem SteamWar Discord in den `regeln-infos` Channel und Klicke auf `Minecraft Verknüpfen`").complete();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(user.isPunished(Punishment.PunishmentType.NoSchemReceiving)) {
|
|
||||||
event.getMessage().reply("Du darfst keine Schematics hochladen").complete();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Message.Attachment attachment : event.getMessage().getAttachments()) {
|
|
||||||
if(attachment.getFileExtension() == null ||
|
|
||||||
(!attachment.getFileExtension().equalsIgnoreCase("schem") &&
|
|
||||||
!attachment.getFileExtension().equalsIgnoreCase("schematic"))) {
|
|
||||||
event.getMessage().reply("`" + attachment.getFileName() + "` wird ignoriert, da die Datei keine Schematic ist").queue();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean newFormat = attachment.getFileExtension().equalsIgnoreCase("schem");
|
|
||||||
int dot = attachment.getFileName().lastIndexOf(".");
|
|
||||||
String name = attachment.getFileName().substring(0, dot);
|
|
||||||
if(SchematicNode.invalidSchemName(new String[] {name})) {
|
|
||||||
event.getMessage().reply("`" + name + "` hat nicht zugelassene Zeichen im Namen").queue();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
SchematicNode node = SchematicNode.getSchematicNode(user.getId(), name, (Integer) null);
|
|
||||||
if(node == null) {
|
|
||||||
node = SchematicNode.createSchematic(user.getId(), name, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
InputStream in = attachment.retrieveInputStream().get();
|
|
||||||
NodeData.get(node).saveFromStream(in, newFormat);
|
|
||||||
in.close();
|
|
||||||
event.getMessage().reply("`" + name + "` wurde erfolgreich hochgeladen").queue();
|
|
||||||
} catch (Exception e) {
|
|
||||||
event.getMessage().reply("`" + name + "` konnte nicht hochgeladen werden, bitte versuche es später nochmal oder wende dich an einen Developer").queue();
|
|
||||||
BungeeCore.log("Could not Upload Schem \"" + name + "\" from User \"" + user.getUserName() + "\"", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,42 +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.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).queue();
|
|
||||||
} 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).queue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +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.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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,69 +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.bot.util;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
|
||||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
import net.dv8tion.jda.api.entities.Guild;
|
|
||||||
import net.dv8tion.jda.api.entities.Role;
|
|
||||||
import net.dv8tion.jda.api.exceptions.ErrorResponseException;
|
|
||||||
|
|
||||||
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);
|
|
||||||
guild.retrieveMemberById(steamwarUser.getDiscordId()).queue(member -> {
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}, throwable -> {
|
|
||||||
if(throwable instanceof ErrorResponseException) {
|
|
||||||
ErrorResponseException e = (ErrorResponseException) throwable;
|
|
||||||
if(e.getErrorCode() == 10007) {
|
|
||||||
steamwarUser.setDiscordId(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,61 +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.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;
|
|
||||||
|
|
||||||
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(channel.hasLatestMessage()) {
|
|
||||||
channel.getIterableHistory().queue(messages -> {
|
|
||||||
Message message = messages.stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null);
|
|
||||||
if (message != null) {
|
|
||||||
message.editMessage(builder.build()).queue();
|
|
||||||
} else {
|
|
||||||
channel.sendMessage(builder.build()).queue();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
channel.sendMessage(builder.build()).queue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,68 +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.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()).queue();
|
|
||||||
} else {
|
|
||||||
channel.sendMessage(messageBuilder.build()).queue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,79 +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.bot.util;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
|
||||||
import de.steamwar.sql.SchematicNode;
|
|
||||||
import de.steamwar.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(SchematicNode 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.getName() + "** 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(SchematicNode 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.getName() + "** 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,76 +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.bot.util;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
|
||||||
import de.steamwar.bungeecore.bot.config.DiscordTicketType;
|
|
||||||
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;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@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<List<Button>> buttons = new ArrayList<>();
|
|
||||||
chunked(new ArrayList<>(SteamwarDiscordBotConfig.TICKET_TYPES.values()), 5).forEach(discordTicketTypes -> {
|
|
||||||
buttons.add(discordTicketTypes.stream().map(DiscordTicketType::toButton).collect(Collectors.toList()));
|
|
||||||
});
|
|
||||||
|
|
||||||
MessageBuilder messageBuilder = new MessageBuilder();
|
|
||||||
messageBuilder.setEmbeds(builder.build());
|
|
||||||
messageBuilder.setActionRows(buttons.stream().map(ActionRow::of).collect(Collectors.toList()));
|
|
||||||
if (message != null) {
|
|
||||||
message.editMessage(messageBuilder.build()).queue();
|
|
||||||
} else {
|
|
||||||
channel.sendMessage(messageBuilder.build()).queue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <T> List<List<T>> chunked(List<T> list, int chunkSize) {
|
|
||||||
List<List<T>> chunks = new ArrayList<>();
|
|
||||||
for (int i = 0; i < list.size(); i += chunkSize) {
|
|
||||||
chunks.add(list.subList(i, Math.min(i + chunkSize, list.size())));
|
|
||||||
}
|
|
||||||
return chunks;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,336 +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.commands;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.*;
|
|
||||||
import de.steamwar.bungeecore.inventory.SWInventory;
|
|
||||||
import de.steamwar.bungeecore.inventory.SWItem;
|
|
||||||
import de.steamwar.bungeecore.network.NetworkSender;
|
|
||||||
import de.steamwar.bungeecore.util.BauLock;
|
|
||||||
import de.steamwar.bungeecore.util.Chat19;
|
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
import de.steamwar.command.TypeMapper;
|
|
||||||
import de.steamwar.command.TypeValidator;
|
|
||||||
import de.steamwar.messages.ChatSender;
|
|
||||||
import de.steamwar.network.packets.server.BaumemberUpdatePacket;
|
|
||||||
import de.steamwar.bungeecore.util.BauLockState;
|
|
||||||
import de.steamwar.sql.BauweltMember;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
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.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class BauCommand extends SWCommand {
|
|
||||||
|
|
||||||
private final HelpCommand command;
|
|
||||||
|
|
||||||
public BauCommand(HelpCommand command){
|
|
||||||
super("bau", null, "b", "build", "gs");
|
|
||||||
this.command = command;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(noTabComplete = true)
|
|
||||||
public void genericHelp(ProxiedPlayer p, String... args) {
|
|
||||||
this.command.sendBauHelp(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register
|
|
||||||
public void toBau(ProxiedPlayer p, @Mapper("version") @OptionalValue(value = "", onlyUINIG = true) int version) {
|
|
||||||
versionSelector(version,
|
|
||||||
() -> new ServerStarter().build12(p.getUniqueId()).send(p).start(),
|
|
||||||
() -> new ServerStarter().build15(p.getUniqueId()).send(p).start(),
|
|
||||||
() -> new ServerStarter().build19(p.getUniqueId()).send(p).start()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void versionSelector(int version, Runnable r12, Runnable r15, Runnable r19) {
|
|
||||||
switch (version) {
|
|
||||||
case 12:
|
|
||||||
r12.run();
|
|
||||||
break;
|
|
||||||
case 15:
|
|
||||||
r15.run();
|
|
||||||
break;
|
|
||||||
case 19:
|
|
||||||
r19.run();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Mapper(value = "version", local = true)
|
|
||||||
public TypeMapper<Integer> versionMapper() {
|
|
||||||
Map<String, Integer> versionMap = new HashMap<>();
|
|
||||||
versionMap.put("19", 19);
|
|
||||||
versionMap.put("1.19", 19);
|
|
||||||
versionMap.put("mwg", 19);
|
|
||||||
versionMap.put("miniwargear", 19);
|
|
||||||
versionMap.put("wg", 19);
|
|
||||||
versionMap.put("wargear", 19);
|
|
||||||
versionMap.put("ws", 15);
|
|
||||||
|
|
||||||
versionMap.put("15", 15);
|
|
||||||
versionMap.put("1.15", 15);
|
|
||||||
versionMap.put("warship", 15);
|
|
||||||
versionMap.put("as", 15);
|
|
||||||
versionMap.put("airship", 15);
|
|
||||||
|
|
||||||
versionMap.put("12", 12);
|
|
||||||
versionMap.put("1.12", 12);
|
|
||||||
|
|
||||||
return new TypeMapper<Integer>() {
|
|
||||||
@Override
|
|
||||||
public Integer map(CommandSender commandSender, String[] previousArguments, String s) {
|
|
||||||
if (commandSender == null) return null;
|
|
||||||
ProxiedPlayer player = (ProxiedPlayer) commandSender;
|
|
||||||
if (s.isEmpty()) {
|
|
||||||
int version = player.getPendingConnection().getVersion();
|
|
||||||
if (version > 578) { // Version > 1.15.2
|
|
||||||
return 19;
|
|
||||||
} else if (version > 340) { // Version > 1.12.2
|
|
||||||
return 15;
|
|
||||||
} else {
|
|
||||||
return 12;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return versionMap.get(s.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) {
|
|
||||||
return versionMap.keySet();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = "addmember", description = "BAU_ADDMEMBER_USAGE")
|
|
||||||
public void addmember(ProxiedPlayer p, @Validator("addMemberTarget") SteamwarUser target) {
|
|
||||||
BauweltMember.addMember(p.getUniqueId(), target.getUUID());
|
|
||||||
Message.send("BAU_ADDMEMBER_ADDED", p);
|
|
||||||
|
|
||||||
ProxiedPlayer z = ProxyServer.getInstance().getPlayer(target.getUUID());
|
|
||||||
if(z != null)
|
|
||||||
Message.send("BAU_ADDMEMBER_ADDED_TARGET", z, p.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Validator(value = "addMemberTarget", local = true)
|
|
||||||
public TypeValidator<SteamwarUser> addMemberTargetValidator() {
|
|
||||||
return (sender, value, messageSender) -> {
|
|
||||||
if (value == null) {
|
|
||||||
messageSender.send("UNKNOWN_PLAYER");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (((ProxiedPlayer) sender).getUniqueId().equals(value.getUUID())) {
|
|
||||||
messageSender.send("BAU_ADDMEMBER_SELFADD");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (BauweltMember.getBauMember(((ProxiedPlayer) sender).getUniqueId(), value.getUUID()) != null) {
|
|
||||||
messageSender.send("BAU_ADDMEMBER_ISADDED");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = "tp", description = "BAU_TP_USAGE")
|
|
||||||
@Register("teleport")
|
|
||||||
public void teleport(ProxiedPlayer p, @Validator("teleportTarget") SteamwarUser worldOwner, @Mapper("version") @OptionalValue(value = "", onlyUINIG = true) int version) {
|
|
||||||
versionSelector(version,
|
|
||||||
() -> new ServerStarter().build12(worldOwner.getUUID()).send(p).start(),
|
|
||||||
() -> new ServerStarter().build15(worldOwner.getUUID()).send(p).start(),
|
|
||||||
() -> new ServerStarter().build19(worldOwner.getUUID()).send(p).start()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Validator(value = "teleportTarget", local = true)
|
|
||||||
public TypeValidator<SteamwarUser> teleportTargetValidator() {
|
|
||||||
return (sender, value, messageSender) -> {
|
|
||||||
if (value == null) {
|
|
||||||
messageSender.send("UNKNOWN_PLAYER");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
ProxiedPlayer p = (ProxiedPlayer) sender;
|
|
||||||
if (!p.getUniqueId().equals(value.getUUID()) && BauweltMember.getBauMember(value.getUUID(), p.getUniqueId()) == null) {
|
|
||||||
SubserverSystem.sendDeniedMessage(p, value.getUUID());
|
|
||||||
messageSender.send("BAU_TP_NOALLOWED");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(BauLock.isLocked(value, SteamwarUser.get(p.getUniqueId()))) {
|
|
||||||
messageSender.send("BAU_LOCKED_NOALLOWED");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register("info")
|
|
||||||
public void info(ProxiedPlayer p) {
|
|
||||||
Chat19.chat(p, "/bauinfo");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register("togglewe")
|
|
||||||
public void togglewe(ProxiedPlayer p, @AllowNull @OptionalValue("") SteamwarUser user) {
|
|
||||||
if (user == null) {
|
|
||||||
Message.send("BAU_MEMBER_TOGGLE_USAGE", p, "togglewe");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
BauweltMember target = member(p, user);
|
|
||||||
if (target == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
target.setWorldEdit(!target.isWorldEdit());
|
|
||||||
clearMembercache(p);
|
|
||||||
isAllowedTo(target.isWorldEdit(), p, target, "BAU_MEMBER_TOGGLE_WORLD_EDIT");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register("toggleworld")
|
|
||||||
public void toggleworld(ProxiedPlayer p, @AllowNull @OptionalValue("") SteamwarUser user) {
|
|
||||||
if (user == null) {
|
|
||||||
Message.send("BAU_MEMBER_TOGGLE_USAGE", p, "toggleworld");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
BauweltMember target = member(p, user);
|
|
||||||
if (target == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
target.setWorld(!target.isWorld());
|
|
||||||
clearMembercache(p);
|
|
||||||
isAllowedTo(target.isWorld(), p, target, "BAU_MEMBER_TOGGLE_WORLD");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void clearMembercache(ProxiedPlayer p){
|
|
||||||
for(ServerInfo info : ProxyServer.getInstance().getServers().values()){
|
|
||||||
Subserver server = Subserver.getSubserver(info);
|
|
||||||
if(server != null && server.getType() == Servertype.BAUSERVER && ((Bauserver)server).getOwner().equals(p.getUniqueId())){
|
|
||||||
info.getPlayers().stream().findAny().ifPresent(player -> NetworkSender.send(player, new BaumemberUpdatePacket()));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = "delmember", description = "BAU_DELMEMBER_USAGE")
|
|
||||||
public void delmember(ProxiedPlayer p, SteamwarUser user) {
|
|
||||||
BauweltMember target = member(p, user);
|
|
||||||
if (target == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(SteamwarUser.get(target.getMemberID()).getUUID().equals(p.getUniqueId())) {
|
|
||||||
Message.send("BAU_DELMEMBER_SELFDEL", p);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
target.remove();
|
|
||||||
ProxiedPlayer toRemove = ProxyServer.getInstance().getPlayer(SteamwarUser.get(target.getMemberID()).getUUID());
|
|
||||||
if(toRemove != null){
|
|
||||||
Message.send("BAU_DELMEMBER_DELETED_TARGET", toRemove, p.getName());
|
|
||||||
Subserver currentServer = Subserver.getSubserver(toRemove.getServer().getInfo());
|
|
||||||
if (currentServer != null && currentServer.getType() == Servertype.BAUSERVER && ((Bauserver) currentServer).getOwner().equals(p.getUniqueId())) {
|
|
||||||
toRemove.connect(ProxyServer.getInstance().getServerInfo(BungeeCore.LOBBY_SERVER));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Message.send("BAU_DELMEMBER_DELETED", p);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register("resetall")
|
|
||||||
@Register("delete")
|
|
||||||
public void delete(ProxiedPlayer p, @Mapper("version") @OptionalValue(value = "", onlyUINIG = true) int version) {
|
|
||||||
SteamwarUser user = SteamwarUser.get(p.getUniqueId());
|
|
||||||
versionSelector(version,
|
|
||||||
() -> deleteConfirmation(p, () -> deleteWorld(p, ServerStarter.WORLDS12_PATH + p.getUniqueId().toString())),
|
|
||||||
() -> deleteConfirmation(p, () -> deleteWorld(p, ServerStarter.WORLDS15_PATH + user.getId())),
|
|
||||||
() -> deleteConfirmation(p, () -> deleteWorld(p, ServerStarter.WORLDS19_PATH + user.getId()))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void deleteConfirmation(ProxiedPlayer p, Runnable worldDeletion) {
|
|
||||||
SWInventory inventory = new SWInventory(p, 9, Message.parse("BAU_DELETE_GUI_NAME", p));
|
|
||||||
inventory.addItem(8, new SWItem(Message.parse("BAU_DELETE_GUI_CANCEL", p), 1), click ->
|
|
||||||
inventory.close()
|
|
||||||
);
|
|
||||||
inventory.addItem(0, new SWItem(Message.parse("BAU_DELETE_GUI_DELETE", p), 10), click -> {
|
|
||||||
worldDeletion.run();
|
|
||||||
inventory.close();
|
|
||||||
});
|
|
||||||
inventory.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void deleteWorld(ProxiedPlayer player, String world) {
|
|
||||||
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
|
|
||||||
for (Subserver subserver : Subserver.getServerList()) {
|
|
||||||
if (subserver.getType() == Servertype.BAUSERVER && ((Bauserver) subserver).getOwner().equals(player.getUniqueId())) {
|
|
||||||
subserver.stop();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SubserverSystem.deleteFolder(BungeeCore.local, world);
|
|
||||||
Message.send("BAU_DELETE_DELETED", player);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register("test")
|
|
||||||
@Register("testarena")
|
|
||||||
public void testarena(ProxiedPlayer p, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) {
|
|
||||||
FightCommand.createArena(p, "/bau testarena ", false, arenaMode, map, false, (player, mode, m) -> {
|
|
||||||
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> new ServerStarter().test(mode, m, p).start());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = "lock", description = "BAU_LOCKED_OPTIONS")
|
|
||||||
public void lock(ProxiedPlayer p, BauLockState bauLockState) {
|
|
||||||
BauLock.setLocked(p, bauLockState);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register("unlock")
|
|
||||||
public void unlock(ProxiedPlayer p) {
|
|
||||||
BauLock.setLocked(p, BauLockState.OPEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static BauweltMember member(ProxiedPlayer p, SteamwarUser member){
|
|
||||||
if (member == null) {
|
|
||||||
Message.send("UNKNOWN_PLAYER", p);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
BauweltMember target = BauweltMember.getBauMember(p.getUniqueId(), member.getUUID());
|
|
||||||
if (target == null) {
|
|
||||||
Message.send("BAU_MEMBER_NOMEMBER", p);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void isAllowedTo(boolean permission, ProxiedPlayer p, BauweltMember target, String what){
|
|
||||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(target.getMemberID()).getUUID());
|
|
||||||
|
|
||||||
if(permission){
|
|
||||||
if(player != null)
|
|
||||||
Message.send("BAU_MEMBER_TOGGLE_TARGET", player, p.getName(), Message.parse(what, player));
|
|
||||||
Message.send("BAU_MEMBER_TOGGLE", p, Message.parse(what, p));
|
|
||||||
}else{
|
|
||||||
if(player != null)
|
|
||||||
Message.send("BAU_MEMBER_TOGGLE_TARGET_OFF", player, p.getName(), Message.parse(what, player));
|
|
||||||
Message.send("BAU_MEMBER_TOGGLE_OFF", p, Message.parse(what, p));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,121 +0,0 @@
|
|||||||
package de.steamwar.bungeecore.commands;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.ServerStarter;
|
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
import de.steamwar.command.TypeMapper;
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class BuilderCloudCommand extends SWCommand {
|
|
||||||
|
|
||||||
private final Map<String, ServerStarter.Version> versionMap = new HashMap<>();
|
|
||||||
|
|
||||||
public BuilderCloudCommand() {
|
|
||||||
super("buildercloud", "bungeecore.server.team");
|
|
||||||
|
|
||||||
versionMap.put("15", ServerStarter.Version.SPIGOT_15);
|
|
||||||
versionMap.put("1.15", ServerStarter.Version.SPIGOT_15);
|
|
||||||
versionMap.put("1.15.2", ServerStarter.Version.SPIGOT_15);
|
|
||||||
versionMap.put("19", ServerStarter.Version.PAPER_19);
|
|
||||||
versionMap.put("1.19", ServerStarter.Version.PAPER_19);
|
|
||||||
versionMap.put("1.19.2", ServerStarter.Version.PAPER_19);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(description = "BUILDERCLOUD_USAGE")
|
|
||||||
public void genericCommand(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String map, @OptionalValue("") @Mapper("generator") @AllowNull File generator) {
|
|
||||||
new ServerStarter().builder(version, map, generator).send(player).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
@ClassMapper(value = ServerStarter.Version.class, local = true)
|
|
||||||
private TypeMapper<ServerStarter.Version> versionTypeMapper() {
|
|
||||||
return new TypeMapper<ServerStarter.Version>() {
|
|
||||||
@Override
|
|
||||||
public ServerStarter.Version map(CommandSender commandSender, String[] previousArguments, String s) {
|
|
||||||
return versionMap.get(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) {
|
|
||||||
return versionMap.keySet();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Cached(global = true)
|
|
||||||
@Mapper(value = "map", local = true)
|
|
||||||
private TypeMapper<String> mapTypeMapper() {
|
|
||||||
|
|
||||||
return new TypeMapper<String>() {
|
|
||||||
@Override
|
|
||||||
public String map(CommandSender commandSender, String[] previousArguments, String s) {
|
|
||||||
File folder = getWorldFolder(previousArguments, 1);
|
|
||||||
|
|
||||||
if(folder == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
File map = new File(folder, s);
|
|
||||||
if(!map.exists() && !map.mkdir())
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return map.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) {
|
|
||||||
File folder = getWorldFolder(previousArguments, 1);
|
|
||||||
|
|
||||||
String[] files;
|
|
||||||
if(folder == null || (files = folder.list()) == null)
|
|
||||||
return Collections.emptyList();
|
|
||||||
|
|
||||||
return Arrays.stream(files).filter(file -> new File(folder, file).isDirectory()).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Cached(global = true)
|
|
||||||
@Mapper(value = "generator", local = true)
|
|
||||||
private TypeMapper<File> generatorTypeMapper() {
|
|
||||||
|
|
||||||
return new TypeMapper<File>() {
|
|
||||||
@Override
|
|
||||||
public File map(CommandSender commandSender, String[] previousArguments, String s) {
|
|
||||||
if(s.equals(""))
|
|
||||||
return null;
|
|
||||||
|
|
||||||
File folder = getWorldFolder(previousArguments, 2);
|
|
||||||
|
|
||||||
if(folder == null)
|
|
||||||
throw new SecurityException();
|
|
||||||
|
|
||||||
File generator = new File(folder, s + ".dat");
|
|
||||||
if(!generator.exists() || !generator.isFile())
|
|
||||||
throw new SecurityException();
|
|
||||||
|
|
||||||
return generator;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) {
|
|
||||||
File folder = getWorldFolder(previousArguments, 2);
|
|
||||||
|
|
||||||
String[] files;
|
|
||||||
if(folder == null || (files = folder.list()) == null)
|
|
||||||
return Collections.emptyList();
|
|
||||||
|
|
||||||
return Arrays.stream(files).filter(file -> new File(folder, file).isFile()).filter(file -> file.endsWith(".dat")).map(file -> file.substring(0, file.length() - 4)).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private File getWorldFolder(String[] previousArguments, int offset) {
|
|
||||||
ServerStarter.Version v = versionMap.get(previousArguments[previousArguments.length - offset]);
|
|
||||||
if(v == null)
|
|
||||||
return null;
|
|
||||||
return new File(v.getWorldFolder(ServerStarter.BUILDER_BASE_PATH));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,113 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 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.inventory.SWInventory;
|
|
||||||
import de.steamwar.bungeecore.inventory.SWItem;
|
|
||||||
import de.steamwar.sql.NodeMember;
|
|
||||||
import de.steamwar.sql.SchematicNode;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.Month;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class CalendarCommand extends SWCommand {
|
|
||||||
|
|
||||||
private static Map<Integer, Integer> dayToSchematicId = new HashMap<>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
dayToSchematicId.put(1, 105386);
|
|
||||||
dayToSchematicId.put(2, 105463);
|
|
||||||
dayToSchematicId.put(3, 105438);
|
|
||||||
dayToSchematicId.put(4, 105383);
|
|
||||||
dayToSchematicId.put(5, 105381);
|
|
||||||
dayToSchematicId.put(6, 105396);
|
|
||||||
dayToSchematicId.put(7, 105462);
|
|
||||||
dayToSchematicId.put(8, 105457);
|
|
||||||
dayToSchematicId.put(9, 105388);
|
|
||||||
dayToSchematicId.put(10, 105390);
|
|
||||||
dayToSchematicId.put(11, 105385);
|
|
||||||
dayToSchematicId.put(12, 105397);
|
|
||||||
dayToSchematicId.put(13, 105455);
|
|
||||||
dayToSchematicId.put(14, 105389);
|
|
||||||
dayToSchematicId.put(15, 105454);
|
|
||||||
dayToSchematicId.put(16, 105394);
|
|
||||||
dayToSchematicId.put(17, 105459);
|
|
||||||
dayToSchematicId.put(18, 105384);
|
|
||||||
dayToSchematicId.put(19, 105392);
|
|
||||||
dayToSchematicId.put(20, 105465);
|
|
||||||
dayToSchematicId.put(21, 105393);
|
|
||||||
dayToSchematicId.put(22, 105464);
|
|
||||||
dayToSchematicId.put(23, 105380);
|
|
||||||
dayToSchematicId.put(24, 105505);
|
|
||||||
dayToSchematicId.put(25, 107355);
|
|
||||||
dayToSchematicId.put(26, 107355);
|
|
||||||
dayToSchematicId.put(31, 105507);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CalendarCommand() {
|
|
||||||
super("calendar", null, "cal");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register
|
|
||||||
public void genericCommand(ProxiedPlayer player) {
|
|
||||||
LocalDate localDate = LocalDate.now();
|
|
||||||
int day = localDate.getDayOfMonth();
|
|
||||||
Month month = localDate.getMonth();
|
|
||||||
Random random = new Random(localDate.getYear());
|
|
||||||
|
|
||||||
if (month != Month.NOVEMBER && month != Month.DECEMBER && month != Month.JANUARY) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
|
||||||
List<SWItem> items = new ArrayList<>();
|
|
||||||
for (Map.Entry<Integer, Integer> present : dayToSchematicId.entrySet()) {
|
|
||||||
boolean b = NodeMember.getNodeMember(present.getValue(), user.getId()) != null;
|
|
||||||
SWItem randomPresent = random.nextDouble() > 0.5 ? SWItem.getSkull("MHF_Present1") : SWItem.getSkull("MHF_Present2");
|
|
||||||
SWItem swItem = b ? SWItem.getSkull("MHF_Chest") : randomPresent;
|
|
||||||
swItem.setName(Message.parse("ADVENT_CALENDAR_DAY", player, present.getKey()));
|
|
||||||
swItem.setCallback(click -> {
|
|
||||||
if (b) return;
|
|
||||||
if (month != Month.DECEMBER) return;
|
|
||||||
if (present.getKey() != day) return;
|
|
||||||
if (NodeMember.getNodeMember(present.getValue(), user.getId()) != null) return;
|
|
||||||
NodeMember.createNodeMember(present.getValue(), user.getId());
|
|
||||||
Message.send("ADVENT_CALENDAR_OPEN", player, SchematicNode.getSchematicNode(present.getValue()).getName());
|
|
||||||
});
|
|
||||||
items.add(swItem);
|
|
||||||
}
|
|
||||||
Collections.shuffle(items, random);
|
|
||||||
|
|
||||||
SWInventory inventory = new SWInventory(player, 27, Message.parse("ADVENT_CALENDAR_TITLE", player));
|
|
||||||
for (int i = 0; i < items.size(); i++) {
|
|
||||||
inventory.addItem(i, items.get(i));
|
|
||||||
}
|
|
||||||
inventory.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean hasDay(int day) {
|
|
||||||
return dayToSchematicId.containsKey(day);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,340 +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.commands;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.*;
|
|
||||||
import de.steamwar.bungeecore.bot.util.DiscordSchemAlert;
|
|
||||||
import de.steamwar.bungeecore.listeners.ConnectionListener;
|
|
||||||
import de.steamwar.sql.CheckedSchematic;
|
|
||||||
import de.steamwar.sql.SchematicNode;
|
|
||||||
import de.steamwar.sql.SchematicType;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.config.Configuration;
|
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
public class CheckCommand extends SWCommand {
|
|
||||||
private static final Map<SchematicType, SchematicType> fightTypes = new HashMap<>();
|
|
||||||
private static Map<SchematicType, List<String>> checkQuestions = new HashMap<>();
|
|
||||||
private static Map<SchematicType, List<String>> ranks = new HashMap<>();
|
|
||||||
|
|
||||||
private static Map<UUID, CheckSession> currentCheckers = new HashMap<>();
|
|
||||||
private static Map<Integer, CheckSession> currentSchems = new HashMap<>();
|
|
||||||
|
|
||||||
public static void setCheckQuestions(SchematicType checkType, Configuration config) {
|
|
||||||
checkQuestions.put(checkType, config.getStringList("CheckQuestions"));
|
|
||||||
if(!config.getStringList("Ranks").isEmpty())
|
|
||||||
ranks.put(checkType, config.getStringList("Ranks"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addFightType(SchematicType checkType, SchematicType fightType) {
|
|
||||||
fightTypes.put(checkType, fightType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isChecking(ProxiedPlayer player){
|
|
||||||
return currentCheckers.containsKey(player.getUniqueId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SchematicNode getCheckingSchem(ProxiedPlayer player) {
|
|
||||||
return currentCheckers.get(player.getUniqueId()).schematic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CheckCommand() {
|
|
||||||
super("check", ConnectionListener.CHECK_PERMISSION);
|
|
||||||
|
|
||||||
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
|
|
||||||
List<SchematicNode> schematics = getSchemsToCheck();
|
|
||||||
if(schematics.size() != currentCheckers.size())
|
|
||||||
Message.team("CHECK_REMINDER", "CHECK_REMINDER_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check list"), schematics.size() - currentCheckers.size());
|
|
||||||
}, 10, 10, TimeUnit.MINUTES);
|
|
||||||
}
|
|
||||||
public static void sendReminder(ProxiedPlayer player) {
|
|
||||||
List<SchematicNode> schematics = getSchemsToCheck();
|
|
||||||
if(schematics.size() != currentCheckers.size())
|
|
||||||
Message.send("CHECK_REMINDER", player, Message.parse("CHECK_REMINDER_HOVER", player), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check list"), schematics.size() - currentCheckers.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = "list", description = "CHECK_HELP_LIST")
|
|
||||||
public void list(ProxiedPlayer player) {
|
|
||||||
List<SchematicNode> schematicList = getSchemsToCheck();
|
|
||||||
|
|
||||||
Message.sendPrefixless("CHECK_LIST_HEADER", player, schematicList.size());
|
|
||||||
|
|
||||||
for (SchematicNode schematic : schematicList) {
|
|
||||||
CheckSession current = currentSchems.get(schematic.getId());
|
|
||||||
long waitedMillis = Timestamp.from(Instant.now()).getTime() - schematic.getLastUpdate().getTime();
|
|
||||||
String color = waitedMillis > 14400000 ? (waitedMillis > 86400000 ? "§c" : "§e") : "§a";
|
|
||||||
long hours = waitedMillis / 3600000;
|
|
||||||
long minutes = (waitedMillis - hours * 3600000) / 60000;
|
|
||||||
String waitTime = color + Message.parse("CHECK_LIST_WAIT", player, hours, (minutes < 10) ? "0" + minutes : minutes);
|
|
||||||
if (current == null) {
|
|
||||||
Message.sendPrefixless("CHECK_LIST_TO_CHECK", player,
|
|
||||||
Message.parse("CHECK_LIST_TO_CHECK_HOVER", player),
|
|
||||||
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check schematic " + schematic.getId()),
|
|
||||||
waitTime,
|
|
||||||
schematic.getSchemtype().getKuerzel(), SteamwarUser.get(schematic.getOwner()).getUserName(), schematic.getName());
|
|
||||||
} else {
|
|
||||||
Message.sendPrefixless("CHECK_LIST_CHECKING", player,
|
|
||||||
Message.parse("CHECK_LIST_CHECKING_HOVER", player),
|
|
||||||
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + current.checker.getName()),
|
|
||||||
waitTime,
|
|
||||||
schematic.getSchemtype().getKuerzel(), SteamwarUser.get(schematic.getOwner()).getUserName(), schematic.getName(), current.checker.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = "schematic", noTabComplete = true)
|
|
||||||
public void schematic(ProxiedPlayer player, String schemID) {
|
|
||||||
if(isChecking(player)){
|
|
||||||
Message.send("CHECK_SCHEMATIC_ALREADY_CHECKING", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SchematicNode schem = SchematicNode.getSchematicNode(Integer.parseInt(schemID));
|
|
||||||
if(!schem.getSchemtype().check()){
|
|
||||||
ProxyServer.getInstance().getLogger().log(Level.SEVERE, player.getName() + " tried to check an uncheckable schematic!");
|
|
||||||
return;
|
|
||||||
}else if(schem.getOwner() == SteamwarUser.get(player.getUniqueId()).getId()) {
|
|
||||||
Message.send("CHECK_SCHEMATIC_OWN", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
new CheckSession(player, schem);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = "cancel", description = "CHECK_HELP_CANCEL")
|
|
||||||
@Register("abort")
|
|
||||||
public void abortCommand(ProxiedPlayer player) {
|
|
||||||
abort(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void abort(ProxiedPlayer player) {
|
|
||||||
if(notChecking(player))
|
|
||||||
return;
|
|
||||||
|
|
||||||
Message.send("CHECK_ABORT", player);
|
|
||||||
currentCheckers.get(player.getUniqueId()).abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = "next", description = "CHECK_HELP_NEXT")
|
|
||||||
public void next(ProxiedPlayer player) {
|
|
||||||
next(player, new String[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = "accept")
|
|
||||||
public void accept(ProxiedPlayer player, @OptionalValue("") String rank) {
|
|
||||||
if (rank.equals("")) {
|
|
||||||
next(player, new String[0]);
|
|
||||||
} else {
|
|
||||||
next(player, new String[]{rank});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = "decline", description = "CHECK_HELP_DECLINE")
|
|
||||||
public void decline(ProxiedPlayer player, String... message) {
|
|
||||||
if(notChecking(player))
|
|
||||||
return;
|
|
||||||
|
|
||||||
currentCheckers.get(player.getUniqueId()).decline(String.join(" ", message));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<SchematicNode> getSchemsToCheck(){
|
|
||||||
List<SchematicNode> schematicList = new LinkedList<>();
|
|
||||||
|
|
||||||
for (SchematicType type : SchematicType.values()) {
|
|
||||||
if (type.check())
|
|
||||||
schematicList.addAll(SchematicNode.getAllSchematicsOfType(type.toDB()));
|
|
||||||
}
|
|
||||||
return schematicList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getChecker(SchematicNode schematic) {
|
|
||||||
if (currentSchems.get(schematic.getId()) == null) return null;
|
|
||||||
return currentSchems.get(schematic.getId()).checker.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean notChecking(ProxiedPlayer player){
|
|
||||||
if(!isChecking(player)){
|
|
||||||
Message.send("CHECK_NOT_CHECKING", player);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void next(ProxiedPlayer player, String[] args){
|
|
||||||
if(notChecking(player))
|
|
||||||
return;
|
|
||||||
|
|
||||||
int rank = 0;
|
|
||||||
if(args.length > 0){
|
|
||||||
try{
|
|
||||||
rank = Integer.parseInt(args[0]);
|
|
||||||
}catch(NumberFormatException e){
|
|
||||||
Message.send("CHECK_INVALID_RANK", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
currentCheckers.get(player.getUniqueId()).next(rank);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class CheckSession{
|
|
||||||
private final ProxiedPlayer checker;
|
|
||||||
private final SchematicNode schematic;
|
|
||||||
private final Timestamp startTime;
|
|
||||||
private final ListIterator<String> checkList;
|
|
||||||
|
|
||||||
private CheckSession(ProxiedPlayer checker, SchematicNode schematic){
|
|
||||||
this.checker = checker;
|
|
||||||
this.schematic = schematic;
|
|
||||||
this.startTime = Timestamp.from(Instant.now());
|
|
||||||
this.checkList = checkQuestions.get(schematic.getSchemtype()).listIterator();
|
|
||||||
|
|
||||||
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
|
|
||||||
ArenaMode mode = ArenaMode.getBySchemType(fightTypes.get(schematic.getSchemtype()));
|
|
||||||
if(new ServerStarter().test(mode, mode.getRandomMap(), checker).check(schematic.getId()).start() == null) {
|
|
||||||
remove();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentCheckers.put(checker.getUniqueId(), this);
|
|
||||||
currentSchems.put(schematic.getId(), this);
|
|
||||||
for(CheckedSchematic previous : CheckedSchematic.previousChecks(schematic))
|
|
||||||
Message.sendPrefixless("CHECK_SCHEMATIC_PREVIOUS", checker, previous.getEndTime(), SteamwarUser.get(previous.getValidator()).getUserName(), previous.getDeclineReason());
|
|
||||||
next(0);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void next(int rank) {
|
|
||||||
if(!checkList.hasNext()){
|
|
||||||
accept(rank);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
checker.sendMessage(TextComponent.fromLegacyText(checkList.next()));
|
|
||||||
|
|
||||||
TextComponent next = new TextComponent();
|
|
||||||
next.setColor(ChatColor.GREEN);
|
|
||||||
if(checkList.hasNext()){
|
|
||||||
next.setText(Message.parse("CHECK_NEXT", checker));
|
|
||||||
next.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check next"));
|
|
||||||
}else if(ranks.containsKey(schematic.getSchemtype())){
|
|
||||||
List<String> r = ranks.get(schematic.getSchemtype());
|
|
||||||
for(int i = 0; i < r.size(); i++){
|
|
||||||
Message.sendPrefixless("CHECK_RANK", checker,
|
|
||||||
Message.parse("CHECK_RANK_HOVER", checker),
|
|
||||||
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check accept " + (i+1)),
|
|
||||||
i+1, r.get(i));
|
|
||||||
Message.sendPrefixless("SPACER", checker);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
next.setText(Message.parse("CHECK_ACCEPT", checker));
|
|
||||||
next.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check accept"));
|
|
||||||
}
|
|
||||||
|
|
||||||
TextComponent decline = new TextComponent(" " + Message.parse("CHECK_DECLINE", checker));
|
|
||||||
decline.setColor(ChatColor.RED);
|
|
||||||
decline.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/check decline "));
|
|
||||||
|
|
||||||
next.addExtra(decline);
|
|
||||||
checker.sendMessage(next);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void accept(int rank){
|
|
||||||
if(createLog("freigegeben")) {
|
|
||||||
if(ranks.containsKey(schematic.getSchemtype())){
|
|
||||||
if(rank <= 0 || ranks.get(schematic.getSchemtype()).size() < rank){
|
|
||||||
Message.send("CHECK_INVALID_RANK", checker);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
schematic.setRank(rank);
|
|
||||||
}
|
|
||||||
|
|
||||||
schematic.setType(fightTypes.get(schematic.getSchemtype()).toDB());
|
|
||||||
SteamwarUser user = SteamwarUser.get(schematic.getOwner());
|
|
||||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUUID());
|
|
||||||
if(player != null) {
|
|
||||||
Message.send("CHECK_ACCEPTED", player, schematic.getSchemtype().name(), schematic.getName());
|
|
||||||
} else {
|
|
||||||
DiscordSchemAlert.sendAccept(schematic, user);
|
|
||||||
}
|
|
||||||
Message.team("CHECK_ACCEPTED_TEAM", schematic.getName(), user.getUserName());
|
|
||||||
}
|
|
||||||
stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void decline(String reason){
|
|
||||||
if(createLog(reason)) {
|
|
||||||
SteamwarUser user = SteamwarUser.get(schematic.getOwner());
|
|
||||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUUID());
|
|
||||||
if(player != null) {
|
|
||||||
Message.send("CHECK_DECLINED", player, schematic.getSchemtype().name(), schematic.getName(), reason);
|
|
||||||
} else {
|
|
||||||
DiscordSchemAlert.sendDecline(schematic, user, reason);
|
|
||||||
}
|
|
||||||
Message.team("CHECK_DECLINED_TEAM", schematic.getName(), user.getUserName(), reason);
|
|
||||||
schematic.setType(SchematicType.Normal.toDB());
|
|
||||||
}
|
|
||||||
|
|
||||||
stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void abort(){
|
|
||||||
createLog("Prüfvorgang abgebrochen");
|
|
||||||
stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void stop(){
|
|
||||||
currentCheckers.remove(checker.getUniqueId());
|
|
||||||
currentSchems.remove(schematic.getId());
|
|
||||||
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
|
|
||||||
for (Subserver subserver : Subserver.getServerList()) {
|
|
||||||
if (subserver.getType() == Servertype.BAUSERVER && ((Bauserver) subserver).getOwner().equals(checker.getUniqueId())) {
|
|
||||||
subserver.stop();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void remove() {
|
|
||||||
currentCheckers.remove(checker.getUniqueId());
|
|
||||||
currentSchems.remove(schematic.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean createLog(String reason) {
|
|
||||||
if(SchematicNode.getSchematicNode(schematic.getId()) == null) // Schematic was deleted
|
|
||||||
return false;
|
|
||||||
|
|
||||||
CheckedSchematic.create(schematic, SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), reason);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,138 +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.commands;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.*;
|
|
||||||
import de.steamwar.messages.ChatSender;
|
|
||||||
import de.steamwar.sql.*;
|
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
import de.steamwar.command.SWCommandUtils;
|
|
||||||
import de.steamwar.command.TypeMapper;
|
|
||||||
import de.steamwar.command.TypeValidator;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class EventCommand extends SWCommand {
|
|
||||||
|
|
||||||
public EventCommand() {
|
|
||||||
super("event");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Validator("noEvent")
|
|
||||||
public TypeValidator<ProxiedPlayer> noEventValidator() {
|
|
||||||
return (sender, value, messageSender) -> Event.get() == null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register
|
|
||||||
public void noCurrentEvent(@Validator("noEvent") ProxiedPlayer player){
|
|
||||||
Message.send("EVENT_NO_CURRENT", player);
|
|
||||||
List<Event> coming = Event.getComing();
|
|
||||||
Instant now = Instant.now();
|
|
||||||
if(!coming.isEmpty()){
|
|
||||||
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern(Message.parse("EVENT_DATE_FORMAT", player));
|
|
||||||
Message.send("EVENT_COMING", player);
|
|
||||||
for(Event e : coming){
|
|
||||||
Message.send("EVENT_COMING_EVENT", player, e.getStart().toLocalDateTime().format(dateFormat), e.getEnd().toLocalDateTime().format(dateFormat), e.getEventName());
|
|
||||||
Set<Team> teams = TeamTeilnahme.getTeams(e.getEventID());
|
|
||||||
if(now.isBefore(e.getDeadline().toInstant())) {
|
|
||||||
Message.send("EVENT_COMING_DEADLINE", player, e.getDeadline());
|
|
||||||
}
|
|
||||||
SchematicType schemType = e.getSchematicType();
|
|
||||||
if (schemType != null) {
|
|
||||||
if (schemType.getDeadline() != null && now.isBefore(schemType.getDeadline().toInstant())) {
|
|
||||||
Message.send("EVENT_COMING_SCHEM_DEADLINE", player, e.getDeadline());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!teams.isEmpty()){
|
|
||||||
StringBuilder tline = new StringBuilder();
|
|
||||||
for(Team t : teams){
|
|
||||||
tline.append(' ').append(Message.parse("EVENT_COMING_TEAM", player, t.getTeamColor(), t.getTeamKuerzel()));
|
|
||||||
}
|
|
||||||
Message.send("EVENT_COMING_TEAMS", player, tline.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register
|
|
||||||
public void eventOverview(@Validator(value = "noEvent", invert = true) ProxiedPlayer player) {
|
|
||||||
Event currentEvent = Event.get();
|
|
||||||
Message.send("EVENT_USAGE", player);
|
|
||||||
|
|
||||||
List<EventFight> fights = EventFight.getEvent(currentEvent.getEventID());
|
|
||||||
|
|
||||||
Message.send("EVENT_CURRENT_EVENT", player, currentEvent.getEventName());
|
|
||||||
|
|
||||||
DateTimeFormatter timeFormat = DateTimeFormatter.ofPattern(Message.parse("EVENT_TIME_FORMAT", player));
|
|
||||||
for(EventFight fight : fights){
|
|
||||||
Team blue = Team.get(fight.getTeamBlue());
|
|
||||||
Team red = Team.get(fight.getTeamRed());
|
|
||||||
StringBuilder fline = new StringBuilder(Message.parse("EVENT_CURRENT_FIGHT", player, fight.getStartTime().toLocalDateTime().format(timeFormat), blue.getTeamColor(), blue.getTeamKuerzel(),
|
|
||||||
red.getTeamColor(), red.getTeamKuerzel()));
|
|
||||||
|
|
||||||
if(fight.hasFinished()){
|
|
||||||
switch(fight.getErgebnis()){
|
|
||||||
case 1:
|
|
||||||
fline.append(Message.parse("EVENT_CURRENT_FIGHT_WIN", player, blue.getTeamColor(), blue.getTeamKuerzel()));
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
fline.append(Message.parse("EVENT_CURRENT_FIGHT_WIN", player, red.getTeamColor(), red.getTeamKuerzel()));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
fline.append(Message.parse("EVENT_CURRENT_FIGHT_DRAW", player));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BungeeCore.send(player, fline.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register
|
|
||||||
public void eventWithTeam(@Validator(value = "noEvent", invert = true) ProxiedPlayer player, @ErrorMessage("EVENT_NO_TEAM") Team team) {
|
|
||||||
Subserver eventArena = EventStarter.getEventServer().get(team.getTeamId());
|
|
||||||
if(eventArena == null || !Subserver.getServerList().contains(eventArena)){
|
|
||||||
Message.send("EVENT_NO_FIGHT_TEAM", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ChatSender sender = ChatSender.of(player);
|
|
||||||
if (!PunishmentCommand.isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer)) {
|
|
||||||
SubserverSystem.sendPlayer(eventArena, player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ClassMapper(Team.class)
|
|
||||||
@Cached(cacheDuration = 10, global = true)
|
|
||||||
public TypeMapper<Team> teamMapper() {
|
|
||||||
return SWCommandUtils.createMapper(Team::get, s -> EventStarter.getEventServer()
|
|
||||||
.keySet()
|
|
||||||
.stream()
|
|
||||||
.map(Team::get)
|
|
||||||
.map(t -> Arrays.asList(t.getTeamKuerzel(), t.getTeamColor()))
|
|
||||||
.flatMap(Collection::stream)
|
|
||||||
.collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,213 +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.commands;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.*;
|
|
||||||
import de.steamwar.bungeecore.inventory.SWInventory;
|
|
||||||
import de.steamwar.bungeecore.inventory.SWItem;
|
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
import de.steamwar.messages.ChatSender;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
|
||||||
import net.md_5.bungee.api.chat.HoverEvent;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import net.md_5.bungee.api.chat.hover.content.Text;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Jeder Fightcommand (auch bau testarena und challenge) haben folgende Optionskette:
|
|
||||||
*
|
|
||||||
* [ArenaMode] [Map]
|
|
||||||
*
|
|
||||||
* Sollte der ArenaMode fehlen, kann er mit getMode() bestimmt werden.
|
|
||||||
* Sollte die Map fehlen, kann sie mit getMap() bestimmt werden.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class FightCommand extends SWCommand {
|
|
||||||
|
|
||||||
public FightCommand() {
|
|
||||||
super("fight", "", "f");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ArenaMode getMode(ChatSender sender, String arg){
|
|
||||||
ArenaMode mode = ArenaMode.getByChat(arg);
|
|
||||||
if(mode != null)
|
|
||||||
return mode;
|
|
||||||
|
|
||||||
sender.system("FIGHT_UNKNOWN_GAMEMODE", arg);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getMap(ChatSender sender, ArenaMode mode, String arg){
|
|
||||||
String realMap = mode.hasMap(arg.toLowerCase());
|
|
||||||
if(realMap != null)
|
|
||||||
return realMap;
|
|
||||||
if(arg.equalsIgnoreCase("Random"))
|
|
||||||
return mode.getRandomMap();
|
|
||||||
|
|
||||||
sender.system("FIGHT_UNKNOWN_ARENA");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void getModes(ChatSender sender, String precommand, boolean historic){
|
|
||||||
TextComponent start = new TextComponent();
|
|
||||||
TextComponent current = start;
|
|
||||||
for(ArenaMode mode : ArenaMode.getAllModes()){
|
|
||||||
if(mode.withoutChatName() || mode.isHistoric() != historic)
|
|
||||||
continue;
|
|
||||||
String command = precommand + mode.getChatName();
|
|
||||||
current.setBold(true);
|
|
||||||
current.setColor(ChatColor.GRAY);
|
|
||||||
current.setText(mode.getChatName() + " ");
|
|
||||||
current.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("§e" + command)));
|
|
||||||
current.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
|
|
||||||
if(current != start)
|
|
||||||
start.addExtra(current);
|
|
||||||
current = new TextComponent();
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.sendMessage(ChatMessageType.SYSTEM, start);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void getMaps(ChatSender sender, String precommand, ArenaMode mode){
|
|
||||||
TextComponent start = new TextComponent();
|
|
||||||
TextComponent current = start;
|
|
||||||
if(mode.getMaps().size() > 1){
|
|
||||||
String command = precommand + mode.getChatName() + " Random";
|
|
||||||
start.setBold(true);
|
|
||||||
start.setColor(ChatColor.GRAY);
|
|
||||||
start.setText(sender.parseToPlain("FIGHT_ARENA_RANDOM") + " ");
|
|
||||||
start.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("§e" + command)));
|
|
||||||
start.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
|
|
||||||
current = new TextComponent();
|
|
||||||
}
|
|
||||||
|
|
||||||
for(String map : mode.getMaps()){
|
|
||||||
String command = precommand + mode.getChatName() + " " + map;
|
|
||||||
current.setBold(true);
|
|
||||||
current.setColor(ChatColor.GRAY);
|
|
||||||
current.setText(map + " ");
|
|
||||||
current.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("§e" + command)));
|
|
||||||
current.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
|
|
||||||
if(current != start)
|
|
||||||
start.addExtra(current);
|
|
||||||
current = new TextComponent();
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.sendMessage(ChatMessageType.SYSTEM, start);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean alreadyInArena(ProxiedPlayer player){
|
|
||||||
Subserver subserver = Subserver.getSubserver(player);
|
|
||||||
if(subserver != null && subserver.getType() == Servertype.ARENA){
|
|
||||||
Message.send("FIGHT_IN_ARENA", player);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void createArena(ProxiedPlayer player, String precommand, boolean allowMerging, ArenaMode arenaMode, String map, boolean historic, FightCallback callback) {
|
|
||||||
ChatSender sender = ChatSender.of(player);
|
|
||||||
|
|
||||||
if(alreadyInArena(player))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (arenaMode == null) {
|
|
||||||
getModes(sender, precommand, historic);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (map == null) {
|
|
||||||
if (arenaMode.getMaps().size() == 1) {
|
|
||||||
map = arenaMode.getRandomMap();
|
|
||||||
} else {
|
|
||||||
getMaps(sender, precommand, arenaMode);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else if (map.equalsIgnoreCase("random")) {
|
|
||||||
map = arenaMode.getRandomMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!allowMerging) {
|
|
||||||
callback.run(player, arenaMode, map);
|
|
||||||
} else {
|
|
||||||
suggestMerging(player, arenaMode, map, callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void suggestMerging(ProxiedPlayer player, ArenaMode mode, String map, FightCallback declineMerge) {
|
|
||||||
Arenaserver mergable = null;
|
|
||||||
synchronized (Subserver.getServerList()) {
|
|
||||||
for (Subserver subserver : Subserver.getServerList()) {
|
|
||||||
if(subserver instanceof Arenaserver) {
|
|
||||||
Arenaserver arenaserver = (Arenaserver) subserver;
|
|
||||||
if(mode.getInternalName().equals(arenaserver.getMode()) && map.equals(arenaserver.getMap()) && arenaserver.isAllowMerge() && arenaserver.getServer().getPlayers().size() == 1) {
|
|
||||||
mergable = arenaserver;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(mergable == null) {
|
|
||||||
declineMerge.run(player, mode, map);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SWInventory inventory = new SWInventory(player, 9, Message.parse("FIGHT_MERGE_TITLE", player));
|
|
||||||
inventory.addItem(0, new SWItem(Message.parse("FIGHT_MERGE_DECLINE", player), 1), click -> {
|
|
||||||
inventory.close();
|
|
||||||
declineMerge.run(player, mode, map);
|
|
||||||
});
|
|
||||||
Arenaserver finalMergable = mergable;
|
|
||||||
SWItem item = new SWItem(Message.parse("FIGHT_MERGE_INFO", player, mode.getDisplayName(), finalMergable.getMap()), 11);
|
|
||||||
item.addLore(Message.parse("FIGHT_MERGE_INFO_LORE_1", player, finalMergable.getServer().getPlayers().toArray(new ProxiedPlayer[1])[0].getName()));
|
|
||||||
inventory.addItem(4, item, click -> {});
|
|
||||||
inventory.addItem(8, new SWItem(Message.parse("FIGHT_MERGE_ACCEPT", player), 10), click -> {
|
|
||||||
if(Subserver.getServerList().contains(finalMergable)) {
|
|
||||||
finalMergable.sendPlayer(player);
|
|
||||||
} else {
|
|
||||||
Message.send("FIGHT_MERGE_OFFLINE", player);
|
|
||||||
declineMerge.run(player, mode, map);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
inventory.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register
|
|
||||||
public void fight(@Validator("arenaPlayer") ProxiedPlayer player, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) {
|
|
||||||
createArena(player, "/fight ", true, arenaMode, map, false, (p, mode, m) -> {
|
|
||||||
Subserver arena = new ServerStarter().arena(mode, m).blueLeader(p).start();
|
|
||||||
if(arena != null) {
|
|
||||||
Message.broadcast("FIGHT_BROADCAST", "FIGHT_BROADCAST_HOVER"
|
|
||||||
, new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is called when arena parameters are clear.
|
|
||||||
*/
|
|
||||||
interface FightCallback {
|
|
||||||
void run(ProxiedPlayer player, ArenaMode mode, String map);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,94 +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.commands;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.*;
|
|
||||||
import de.steamwar.sql.BauweltMember;
|
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
import de.steamwar.command.TypeValidator;
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
public class JoinmeCommand extends SWCommand {
|
|
||||||
|
|
||||||
public JoinmeCommand() {
|
|
||||||
super("joinme");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(description = "JOINME_USAGE")
|
|
||||||
public void genericCommand(ProxiedPlayer player) {
|
|
||||||
if (!player.hasPermission("bungeecore.joinme")) {
|
|
||||||
Message.send("JOINME_USAGE", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Message.broadcast("JOINME_BROADCAST", "JOINME_BROADCAST_HOVER",
|
|
||||||
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()), player.getName(), player.getServer().getInfo().getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register
|
|
||||||
public void genericCommand(ProxiedPlayer player, @Validator ProxiedPlayer target) {
|
|
||||||
if (target.equals(player)){
|
|
||||||
Message.send("JOINME_PLAYER_SELF", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ServerInfo server = target.getServer().getInfo();
|
|
||||||
String serverPerm = BungeeCore.serverPermissions.get(server.getName());
|
|
||||||
Subserver subserver = Subserver.getSubserver(target);
|
|
||||||
|
|
||||||
if(subserver != null) {
|
|
||||||
Servertype type = subserver.getType();
|
|
||||||
if (type == Servertype.ARENA) {
|
|
||||||
SubserverSystem.sendPlayer(subserver, player);
|
|
||||||
} else if (type == Servertype.BAUSERVER) {
|
|
||||||
Bauserver bauserver = (Bauserver) subserver;
|
|
||||||
if (bauserver.getOwner().equals(player.getUniqueId()) ||
|
|
||||||
BauweltMember.getBauMember(bauserver.getOwner(), player.getUniqueId()) != null) {
|
|
||||||
SubserverSystem.sendPlayer(subserver, player);
|
|
||||||
} else {
|
|
||||||
SubserverSystem.sendDeniedMessage(player, bauserver.getOwner());
|
|
||||||
Message.send("JOIN_PLAYER_BLOCK", player);
|
|
||||||
}
|
|
||||||
} else if(type == Servertype.BUILDER && !player.hasPermission("bungeecore.server.team")) {
|
|
||||||
Message.send("JOIN_PLAYER_BLOCK", player);
|
|
||||||
} else {
|
|
||||||
SubserverSystem.sendPlayer(subserver, player);
|
|
||||||
}
|
|
||||||
}else if(serverPerm != null && !player.hasPermission(serverPerm)){
|
|
||||||
Message.send("JOIN_PLAYER_BLOCK", player);
|
|
||||||
}else if(serverPerm == null && !player.getGroups().contains("team")) {
|
|
||||||
Message.send("JOIN_PLAYER_BLOCK", player);
|
|
||||||
}else{
|
|
||||||
player.connect(server);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ClassValidator(ProxiedPlayer.class)
|
|
||||||
public TypeValidator<ProxiedPlayer> playerMapper() {
|
|
||||||
return (sender, value, messageSender) -> {
|
|
||||||
if (value == null || !value.isConnected()) {
|
|
||||||
messageSender.send("JOINME_PLAYER_OFFLINE", sender);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,60 +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.commands;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
|
||||||
import de.steamwar.bungeecore.Message;
|
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
import de.steamwar.command.SWCommandUtils;
|
|
||||||
import de.steamwar.command.TypeMapper;
|
|
||||||
import net.md_5.bungee.BungeeCord;
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class KickCommand extends SWCommand {
|
|
||||||
|
|
||||||
public KickCommand() {
|
|
||||||
super("kick", "bungeecore.kick");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(description = "KICK_USAGE")
|
|
||||||
public void genericCommand(CommandSender sender, @Mapper("player") String player, String... message) {
|
|
||||||
ProxiedPlayer target = ProxyServer.getInstance().getPlayer(player);
|
|
||||||
if(target == null){
|
|
||||||
Message.send("KICK_OFFLINE", sender);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (message.length == 0) {
|
|
||||||
target.disconnect(Message.parseToComponent("KICK_NORMAL", true, target));
|
|
||||||
} else {
|
|
||||||
target.disconnect(BungeeCore.stringToText(BungeeCore.CHAT_PREFIX + "§c" + String.join(" ", message)));
|
|
||||||
}
|
|
||||||
Message.send("KICK_CONFIRM", sender, target.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Mapper(value = "player", local = true)
|
|
||||||
public TypeMapper<String> playerTypeMapper() {
|
|
||||||
return SWCommandUtils.createMapper(s -> s, s -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,75 +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.commands;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.Message;
|
|
||||||
import de.steamwar.bungeecore.Servertype;
|
|
||||||
import de.steamwar.bungeecore.Subserver;
|
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
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 SWCommand {
|
|
||||||
|
|
||||||
public ListCommand() {
|
|
||||||
super("list", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static synchronized TreeMap<String, List<ProxiedPlayer>> getCustomTablist(){
|
|
||||||
TreeMap<String, List<ProxiedPlayer>> playerMap = new TreeMap<>();
|
|
||||||
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())));
|
|
||||||
return playerMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register
|
|
||||||
public void genericCommand(CommandSender commandSender) {
|
|
||||||
TreeMap<String, List<ProxiedPlayer>> playerMap = getCustomTablist();
|
|
||||||
for (String server : playerMap.navigableKeySet()) {
|
|
||||||
String serverName = server;
|
|
||||||
if (server.equals("Bau")) {
|
|
||||||
serverName = Message.parse("TABLIST_BAU", commandSender);
|
|
||||||
}
|
|
||||||
Message.send("LIST_COMMAND", commandSender, serverName, playerMap.get(server).stream().map(CommandSender::getName).collect(Collectors.joining(", ")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,147 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is a part of the SteamWar software.
|
|
||||||
|
|
||||||
Copyright (C) 2023 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.inventory.SWInventory;
|
|
||||||
import de.steamwar.bungeecore.inventory.SWItem;
|
|
||||||
import de.steamwar.bungeecore.inventory.SWListInv;
|
|
||||||
import de.steamwar.bungeecore.inventory.SWStreamInv;
|
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
import de.steamwar.sql.Mod;
|
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class ModCommand extends SWCommand {
|
|
||||||
|
|
||||||
public ModCommand() {
|
|
||||||
super("mod", "bungeecore.softreload", "mods");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final Map<ProxiedPlayer, Mod.ModType> playerFilterType = new HashMap<>();
|
|
||||||
|
|
||||||
@Register
|
|
||||||
public void genericCommand(ProxiedPlayer p) {
|
|
||||||
playerFilterType.putIfAbsent(p,Mod.ModType.UNKLASSIFIED);
|
|
||||||
openGui(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void openGui(ProxiedPlayer p) {
|
|
||||||
SWStreamInv<Mod> swStreamInv = new SWStreamInv<>(p,Message.parse("MOD_COMMAND_GUI_TITLE",p), (click, element) -> {
|
|
||||||
openClassificationGui(p,element);
|
|
||||||
},page -> {
|
|
||||||
Mod.ModType filtertype = playerFilterType.get(p);
|
|
||||||
return Mod.getAllModsFiltered(page,45, filtertype).stream().map(mod -> new SWListInv.SWListEntry<>(getModItem(mod),mod)).collect(Collectors.toList());
|
|
||||||
});
|
|
||||||
|
|
||||||
swStreamInv.addItem(52,new SWItem("NAME_TAG","Filter"), click -> {
|
|
||||||
swStreamInv.close();
|
|
||||||
openFilterGui(p);
|
|
||||||
});
|
|
||||||
|
|
||||||
swStreamInv.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateAndCloseGui(Mod.ModType modType, Mod mod, SWInventory toClose, ProxiedPlayer p) {
|
|
||||||
mod.setModType(modType);
|
|
||||||
toClose.close();
|
|
||||||
openGui(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void openFilterGui(ProxiedPlayer p) {
|
|
||||||
SWInventory inv = new SWInventory(p, 9, "Filter");
|
|
||||||
|
|
||||||
inv.addItem(1, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), click -> playerFilterType.replace(p, Mod.ModType.UNKLASSIFIED));
|
|
||||||
inv.addItem(2, new SWItem(Message.parse("MOD_ALLOWED",p),2), click -> playerFilterType.replace(p, Mod.ModType.GREEN));
|
|
||||||
inv.addItem(3, new SWItem(Message.parse("MOD_FORBIDDEN",p), 11), click -> playerFilterType.replace(p, Mod.ModType.YELLOW));
|
|
||||||
inv.addItem(4, new SWItem(Message.parse("MOD_AUTOBAN",p),1), click -> playerFilterType.replace(p, Mod.ModType.RED));
|
|
||||||
inv.addItem(5, new SWItem(Message.parse("MOD_YT",p),13), click -> playerFilterType.replace(p, Mod.ModType.YOUTUBER_ONLY));
|
|
||||||
|
|
||||||
inv.addItem(8, new SWItem("ARROW", Message.parse("MOD_ITEM_BACK",p)), click -> {
|
|
||||||
inv.close();
|
|
||||||
openGui(p);
|
|
||||||
});
|
|
||||||
|
|
||||||
inv.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void openClassificationGui(ProxiedPlayer p,Mod element) {
|
|
||||||
SWInventory swInventory = new SWInventory(p,9,Message.parse("MOD_COMMAND_CLASSICIATION_GUI",p));
|
|
||||||
|
|
||||||
swInventory.addItem(2, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), (click1 -> updateAndCloseGui(Mod.ModType.UNKLASSIFIED,element,swInventory,p)));
|
|
||||||
swInventory.addItem(3, new SWItem(Message.parse("MOD_ALLOWED",p), 2), (click1 -> updateAndCloseGui(Mod.ModType.GREEN,element,swInventory,p)));
|
|
||||||
swInventory.addItem(4, new SWItem(Message.parse("MOD_FORBIDDEN",p), 11), (click1 -> updateAndCloseGui(Mod.ModType.YELLOW,element,swInventory,p)));
|
|
||||||
swInventory.addItem(5, new SWItem(Message.parse("MOD_AUTOBAN",p),1), (click1 -> updateAndCloseGui(Mod.ModType.RED,element,swInventory,p)));
|
|
||||||
swInventory.addItem(6, new SWItem(Message.parse("MOD_YT",p), 13), (click1 -> updateAndCloseGui(Mod.ModType.YOUTUBER_ONLY,element,swInventory,p)));
|
|
||||||
|
|
||||||
swInventory.addItem(8,new SWItem("ARROW",Message.parse("MOD_ITEM_BACK",p)), click1 -> {
|
|
||||||
swInventory.close();
|
|
||||||
openGui(p);
|
|
||||||
});
|
|
||||||
|
|
||||||
swInventory.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
private SWItem getModItem(Mod modEntry) {
|
|
||||||
SWItem item = new SWItem("NAME_TAG", modEntry.getModName());
|
|
||||||
|
|
||||||
item.addLore(modEntry.getPlatform().name());
|
|
||||||
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = {"set"},description = "MOD_COMMAND_SET_USAGE")
|
|
||||||
public void set(ProxiedPlayer p,String modName,Mod.Platform platform,Mod.ModType newModType) {
|
|
||||||
Mod mod = Mod.get(modName, platform);
|
|
||||||
if(mod == null) {
|
|
||||||
Message.send("MOD_COMMAND_NOT_FOUND_IN_DATABASE",p,modName, platform.name());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mod.setModType(newModType);
|
|
||||||
Message.send("MOD_CHANGED_TYPE",p,modName,platform.name(),newModType.name());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = {"get"},description = "MOD_COMMAND_GET_USAGE")
|
|
||||||
public void get(ProxiedPlayer p,String modName,Mod.Platform platform) {
|
|
||||||
Mod mod = Mod.get(modName, platform);
|
|
||||||
if(mod == null) {
|
|
||||||
Message.send("MOD_COMMAND_NOT_FOUND_IN_DATABASE", p, modName, platform.name());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Message.send("MOD_COMMAND_INFO", p, modName, platform.name(), mod.getModType().name());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = {"next"})
|
|
||||||
public void next(ProxiedPlayer p) {
|
|
||||||
Mod mod = Mod.findFirstMod();
|
|
||||||
if(mod == null) {
|
|
||||||
Message.send("MOD_NO_MORE_UNCLASSIFIED_MODS",p);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Message.send("MOD_FOUND_NEXT_MOD",p,"MOD_OPEN_GUI",new ClickEvent(ClickEvent.Action.RUN_COMMAND,""),mod.getModName(),mod.getPlatform().name());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,86 +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.commands;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.ArenaMode;
|
|
||||||
import de.steamwar.bungeecore.Message;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.sql.UserElo;
|
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
import de.steamwar.command.SWCommandUtils;
|
|
||||||
import de.steamwar.command.TypeMapper;
|
|
||||||
import net.md_5.bungee.BungeeCord;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class RankCommand extends SWCommand {
|
|
||||||
|
|
||||||
public RankCommand() {
|
|
||||||
super("rank");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register
|
|
||||||
public void ownRank(ProxiedPlayer player) {
|
|
||||||
rank(player, player.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register
|
|
||||||
public void rank(ProxiedPlayer player, @Mapper("player") String s) {
|
|
||||||
SteamwarUser user = SteamwarUser.get(s);
|
|
||||||
if (user == null) {
|
|
||||||
Message.send("RANK_PLAYER_NOT_FOUND", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!player.getName().equals(s)) {
|
|
||||||
Message.send("RANK_PLAYER_FOUND", player, user.getUserName());
|
|
||||||
}
|
|
||||||
for(ArenaMode mode : ArenaMode.getAllModes()) {
|
|
||||||
if (!mode.isRanked())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
Message.send("RANK_HEADER", player, mode.getChatName());
|
|
||||||
|
|
||||||
Optional<Integer> elo = UserElo.getElo(user.getId(), mode.getSchemType());
|
|
||||||
|
|
||||||
if (elo.isPresent()) {
|
|
||||||
int placement = UserElo.getPlacement(elo.get(), mode.getSchemType());
|
|
||||||
Message.send("RANK_PLACED", player, placement, elo.get());
|
|
||||||
} else {
|
|
||||||
Message.send("RANK_UNPLACED", player);
|
|
||||||
}
|
|
||||||
Message.send("RANK_EMBLEM", player, getEmblemProgression(player, mode.getChatName(), user.getId()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getEmblemProgression(ProxiedPlayer player, String gameMode, int userId) {
|
|
||||||
int fightsOfSeason = UserElo.getFightsOfSeason(userId, gameMode);
|
|
||||||
if (fightsOfSeason < 10)
|
|
||||||
return Message.parse("RANK_NEEDED_FIGHTS_LEFT", player, "§8✧ ✦ ✶ ✷ ✸ ✹ ❂", 10 - fightsOfSeason);
|
|
||||||
|
|
||||||
return UserElo.getEmblemProgression(gameMode, userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Mapper(value = "player", local = true)
|
|
||||||
public TypeMapper<String> playerTypeMapper() {
|
|
||||||
return SWCommandUtils.createMapper(s -> s, s -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,40 +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.commands;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.Message;
|
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
public class RegelnCommand extends SWCommand {
|
|
||||||
public RegelnCommand() {
|
|
||||||
super("regeln", null, "rules");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register
|
|
||||||
public void genericCommand(ProxiedPlayer player) {
|
|
||||||
Message.send("REGELN_RULES", player);
|
|
||||||
Message.sendPrefixless("REGELN_AS", player, Message.parse("REGELN_AS_HOVER", player), new ClickEvent(ClickEvent.Action.OPEN_URL, Message.parse("REGELN_AS_URL", player)));
|
|
||||||
Message.sendPrefixless("REGELN_MWG", player, Message.parse("REGELN_MWG_HOVER", player), new ClickEvent(ClickEvent.Action.OPEN_URL, Message.parse("REGELN_MWG_URL", player)));
|
|
||||||
Message.sendPrefixless("REGELN_WG", player, Message.parse("REGELN_WG_HOVER", player), new ClickEvent(ClickEvent.Action.OPEN_URL, Message.parse("REGELN_WG_URL", player)));
|
|
||||||
Message.sendPrefixless("REGELN_WS", player, Message.parse("REGELN_WS_HOVER", player), new ClickEvent(ClickEvent.Action.OPEN_URL, Message.parse("REGELN_WS_URL", player)));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,684 +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.commands;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.Message;
|
|
||||||
import de.steamwar.bungeecore.Storage;
|
|
||||||
import de.steamwar.bungeecore.inventory.SWItem;
|
|
||||||
import de.steamwar.bungeecore.inventory.SWListInv;
|
|
||||||
import de.steamwar.sql.Punishment;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.sql.Team;
|
|
||||||
import de.steamwar.sql.TeamTeilnahme;
|
|
||||||
import de.steamwar.command.PreviousArguments;
|
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
import de.steamwar.command.TypeMapper;
|
|
||||||
import de.steamwar.messages.ChatSender;
|
|
||||||
import de.steamwar.sql.Event;
|
|
||||||
import net.md_5.bungee.BungeeCord;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.ServerConnectRequest;
|
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
|
||||||
import net.md_5.bungee.api.chat.HoverEvent;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.event.ServerConnectEvent;
|
|
||||||
|
|
||||||
import java.net.*;
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static de.steamwar.bungeecore.Storage.teamInvitations;
|
|
||||||
|
|
||||||
public class TeamCommand extends SWCommand {
|
|
||||||
|
|
||||||
private static final List<SWListInv.SWListEntry<String>> COLOR_CODES = new ArrayList<>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
addColor("4", 1);
|
|
||||||
addColor("c", 15);
|
|
||||||
addColor("6", 14);
|
|
||||||
addColor("e", 11);
|
|
||||||
addColor("2", 2);
|
|
||||||
addColor("a", 10);
|
|
||||||
addColor("b", 12);
|
|
||||||
addColor("3", 6);
|
|
||||||
addColor("1", 4);
|
|
||||||
addColor("9", 6);
|
|
||||||
addColor("d", 9);
|
|
||||||
addColor("5", 5);
|
|
||||||
addColor("f", 15);
|
|
||||||
addColor("7", 7);
|
|
||||||
addColor("8", 8);
|
|
||||||
addColor("0", 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void addColor(String color, int colorCode) {
|
|
||||||
COLOR_CODES.add(new SWListInv.SWListEntry(new SWItem("§" + color, colorCode), color));
|
|
||||||
}
|
|
||||||
|
|
||||||
public TeamCommand() {
|
|
||||||
super("team");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(noTabComplete = true)
|
|
||||||
public void help(CommandSender sender, String... args){
|
|
||||||
Message.send("TEAM_HELP_HEADER", sender);
|
|
||||||
Message.send("TEAM_HELP_LIST", sender);
|
|
||||||
Message.send("TEAM_HELP_INFO", sender);
|
|
||||||
if(!(sender instanceof ProxiedPlayer))
|
|
||||||
return;
|
|
||||||
Message.send("TEAM_HELP_TP", sender);
|
|
||||||
|
|
||||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
|
||||||
if(user.getTeam() == 0) {
|
|
||||||
Message.send("TEAM_HELP_CREATE", sender);
|
|
||||||
Message.send("TEAM_HELP_JOIN", sender);
|
|
||||||
}else{
|
|
||||||
Message.send("TEAM_HELP_CHAT", sender);
|
|
||||||
Message.send("TEAM_HELP_EVENT", sender);
|
|
||||||
Message.send("TEAM_HELP_LEAVE", sender);
|
|
||||||
|
|
||||||
if(user.isLeader()){
|
|
||||||
Message.send("TEAM_HELP_INVITE", sender);
|
|
||||||
Message.send("TEAM_HELP_REMOVE", sender);
|
|
||||||
Message.send("TEAM_HELP_KUERZEL", sender);
|
|
||||||
Message.send("TEAM_HELP_NAME", sender);
|
|
||||||
Message.send("TEAM_HELP_COLOR", sender);
|
|
||||||
Message.send("TEAM_HELP_LEADER", sender);
|
|
||||||
Message.send("TEAM_HELP_STEP_BACK", sender);
|
|
||||||
Message.send("TEAM_HELP_SERVER", sender);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = "create", description = "TEAM_CREATE_USAGE")
|
|
||||||
public void create(ProxiedPlayer player, @Length(min = 2, max = 4) @ErrorMessage("TEAM_KUERZEL_LENGTH") String kuerzel, @Length(min = 4, max = 15) @ErrorMessage("TEAM_NAME_LENGTH") String name){
|
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
|
||||||
Team team = Team.get(user.getTeam());
|
|
||||||
if(unwantedInTeam(player, user))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(checkTeamKuerzel(player, team, kuerzel))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(checkTeamName(player, team, name))
|
|
||||||
return;
|
|
||||||
|
|
||||||
Team.create(kuerzel, name);
|
|
||||||
user.setTeam(Team.get(kuerzel).getTeamId());
|
|
||||||
user.setLeader(true);
|
|
||||||
Message.send("TEAM_CREATE_CREATED", player, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register("join")
|
|
||||||
public void join(ProxiedPlayer player, String... args){
|
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
|
||||||
if(unwantedInTeam(player, user))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(notDuringEvent(player))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(!teamInvitations.containsKey(user.getId())){
|
|
||||||
Message.send("TEAM_JOIN_NO_INVITE", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Integer> invs = teamInvitations.get(user.getId());
|
|
||||||
Integer t = null;
|
|
||||||
|
|
||||||
if(invs.size() == 1){
|
|
||||||
t = invs.get(0);
|
|
||||||
}else{
|
|
||||||
if(args.length != 1){
|
|
||||||
Message.send("TEAM_JOIN_USAGE", player);
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for(int inv : invs){
|
|
||||||
Team team = Team.get(inv);
|
|
||||||
sb.append(team.getTeamName()).append(" ");
|
|
||||||
}
|
|
||||||
Message.send("TEAM_JOIN_INVITED", player, sb.toString());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int inv : invs){
|
|
||||||
Team team = Team.get(inv);
|
|
||||||
if(team.getTeamName().equals(args[0])){
|
|
||||||
t = inv;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(t == null){
|
|
||||||
Message.send("TEAM_JOIN_NOT_BY_TEAM", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
user.setTeam(t);
|
|
||||||
teamInvitations.remove(user.getId());
|
|
||||||
Message.send("TEAM_JOIN_JOINED", player, Team.get(t).getTeamName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register("stepback")
|
|
||||||
public void stepBack(ProxiedPlayer player) {
|
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
|
||||||
Team team = Team.get(user.getTeam());
|
|
||||||
if(notLeader(player, user))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(team.size() > 1 && team.getMembers().stream().map(SteamwarUser::get).filter(member -> user != member).noneMatch(SteamwarUser::isLeader)){
|
|
||||||
Message.send("TEAM_OTHER_LEADER_REQUIRED", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
user.setLeader(false);
|
|
||||||
Message.send("TEAM_STEP_BACK", player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register("leave")
|
|
||||||
public void leave(ProxiedPlayer player){
|
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
|
||||||
Team team = Team.get(user.getTeam());
|
|
||||||
if(notInTeam(player, user))
|
|
||||||
return;
|
|
||||||
|
|
||||||
int teamSize = team.size();
|
|
||||||
if(teamSize > 1 && user.isLeader() && team.getMembers().stream().map(SteamwarUser::get).filter(member -> user != member).noneMatch(SteamwarUser::isLeader)){
|
|
||||||
Message.send("TEAM_OTHER_LEADER_REQUIRED", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
user.setTeam(0);
|
|
||||||
|
|
||||||
if(teamSize == 1){
|
|
||||||
team.disband(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
Message.send("TEAM_LEAVE_LEFT", player);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Register(value = "invite", description = "TEAM_INVITE_USAGE")
|
|
||||||
public void invite(ProxiedPlayer player, String toInvite){
|
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
|
||||||
Team team = Team.get(user.getTeam());
|
|
||||||
if(notLeader(player, user))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(notDuringEvent(player))
|
|
||||||
return;
|
|
||||||
|
|
||||||
SteamwarUser target = SteamwarUser.get(toInvite);
|
|
||||||
if(target == null){
|
|
||||||
Message.send("TEAM_INVITE_NO_PLAYER", player);
|
|
||||||
return;
|
|
||||||
}else if(target.getTeam() != 0){
|
|
||||||
Message.send("TEAM_INVITE_IN_TEAM", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!teamInvitations.containsKey(target.getId()))
|
|
||||||
teamInvitations.put(target.getId(), new LinkedList<>());
|
|
||||||
|
|
||||||
if(teamInvitations.get(target.getId()).contains(team.getTeamId())){
|
|
||||||
Message.send("TEAM_INVITE_ALREADY_INVITED", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
teamInvitations.get(target.getId()).add(team.getTeamId());
|
|
||||||
|
|
||||||
Message.send("TEAM_INVITE_INVITED", player, toInvite);
|
|
||||||
ProxiedPlayer p = ProxyServer.getInstance().getPlayer(target.getUUID());
|
|
||||||
if(p != null)
|
|
||||||
Message.send("TEAM_INVITE_INVITED_TARGET", p, team.getTeamColor(), team.getTeamName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = "remove", description = "TEAM_REMOVE_USAGE")
|
|
||||||
public void remove(ProxiedPlayer player, String toRemove){
|
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
|
||||||
Team team = Team.get(user.getTeam());
|
|
||||||
if(notLeader(player, user))
|
|
||||||
return;
|
|
||||||
|
|
||||||
SteamwarUser target = SteamwarUser.get(toRemove);
|
|
||||||
if(target == null){
|
|
||||||
Message.send("TEAM_REMOVE_NOT_PLAYER", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (target.isLeader()) {
|
|
||||||
Message.send("TEAM_REMOVE_NOT_LEADER", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(teamInvitations.containsKey(target.getId())){
|
|
||||||
if(teamInvitations.get(target.getId()).remove((Integer) team.getTeamId())){
|
|
||||||
Message.send("TEAM_REMOVE_INVITE", player);
|
|
||||||
if(teamInvitations.get(target.getId()).isEmpty())
|
|
||||||
teamInvitations.remove(target.getId());
|
|
||||||
}else{
|
|
||||||
Message.send("TEAM_REMOVE_NO_INVITE", player);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(target.getTeam() != user.getTeam()){
|
|
||||||
Message.send("TEAM_REMOVE_NOT_IN_TEAM", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
target.setTeam(0);
|
|
||||||
|
|
||||||
Message.send("TEAM_REMOVE_REMOVED", player);
|
|
||||||
ProxiedPlayer p = ProxyServer.getInstance().getPlayer(target.getUUID());
|
|
||||||
if(p != null)
|
|
||||||
Message.send("TEAM_REMOVE_REMOVED_TARGET", player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = "changekurzel", description = "TEAM_KUERZEL_USAGE")
|
|
||||||
public void changekuerzel(ProxiedPlayer player, @Length(min = 2, max = 4) @ErrorMessage("TEAM_KUERZEL_LENGTH") String kuerzel){
|
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
|
||||||
Team team = Team.get(user.getTeam());
|
|
||||||
if(notLeader(player, user))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(notDuringEvent(player))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(checkTeamKuerzel(player, team, kuerzel))
|
|
||||||
return;
|
|
||||||
|
|
||||||
team.setTeamKuerzel(kuerzel);
|
|
||||||
Message.send("TEAM_KUERZEL_CHANGED", player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = "changename", description = "TEAM_NAME_USAGE")
|
|
||||||
public void changename(ProxiedPlayer player, @Length(min = 4, max = 15) @ErrorMessage("TEAM_NAME_LENGTH") String name){
|
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
|
||||||
Team team = Team.get(user.getTeam());
|
|
||||||
if(notLeader(player, user))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(notDuringEvent(player))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(checkTeamName(player, team, name))
|
|
||||||
return;
|
|
||||||
|
|
||||||
team.setTeamName(name);
|
|
||||||
Message.send("TEAM_NAME_CHANGED", player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = "promote", description = "TEAM_LEADER_USAGE")
|
|
||||||
public void promote(ProxiedPlayer player, String toPromote){
|
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
|
||||||
if(notLeader(player, user))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(notDuringEvent(player))
|
|
||||||
return;
|
|
||||||
|
|
||||||
SteamwarUser target = SteamwarUser.get(toPromote);
|
|
||||||
if(target == null){
|
|
||||||
Message.send("TEAM_LEADER_NOT_USER", player, toPromote);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(target.getTeam() != user.getTeam()){
|
|
||||||
Message.send("TEAM_LEADER_NOT_MEMBER", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
target.setLeader(true);
|
|
||||||
Message.send("TEAM_LEADER_PROMOTED", player, toPromote);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String playerName(SteamwarUser user){
|
|
||||||
return ProxyServer.getInstance().getPlayer(user.getUUID()) != null ? "§a" + user.getUserName() : "§e" + user.getUserName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register("info")
|
|
||||||
public void info(ProxiedPlayer player, String... args){
|
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
|
||||||
Team team = Team.get(user.getTeam());
|
|
||||||
if(args.length == 0 && user.getTeam() == 0){
|
|
||||||
Message.send("TEAM_INFO_USAGE", player);
|
|
||||||
return;
|
|
||||||
}else if(user.getTeam() == 0 || args.length == 1){
|
|
||||||
team = Team.get(args[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(team == null){
|
|
||||||
Message.send("UNKNOWN_TEAM", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Message.sendPrefixless("TEAM_INFO_TEAM", player, team.getTeamName(), team.getTeamColor(), team.getTeamKuerzel());
|
|
||||||
|
|
||||||
List<SteamwarUser> users = team.getMembers().stream().map(SteamwarUser::get).collect(Collectors.toList());
|
|
||||||
|
|
||||||
Message.sendPrefixless("TEAM_INFO_LEADER", player, getMemberList(users, true));
|
|
||||||
|
|
||||||
String members = getMemberList(users, false);
|
|
||||||
|
|
||||||
if(members.length() > 0) {
|
|
||||||
Message.sendPrefixless("TEAM_INFO_MEMBER", player, members);
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<Event> events = TeamTeilnahme.getEvents(team.getTeamId());
|
|
||||||
if(!events.isEmpty()){
|
|
||||||
Message.sendPrefixless("TEAM_INFO_EVENTS", player, events.stream().map(Event::getEventName).collect(Collectors.joining(", ")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getMemberList(List<SteamwarUser> users, boolean leaders) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for(SteamwarUser user : users) {
|
|
||||||
if(user.isLeader() == leaders) {
|
|
||||||
sb.append(playerName(user)).append(" ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register("list")
|
|
||||||
public void list(ProxiedPlayer player, @Min(intValue = 1) @OptionalValue("1") @ErrorMessage("TEAM_LIST_NOT_PAGE") int page){
|
|
||||||
final int TEAMS_PER_PAGE = 10;
|
|
||||||
|
|
||||||
List<Team> all = Team.getAll();
|
|
||||||
final int lastPage = ((all.size() - 1) / 10) + 1;
|
|
||||||
if(page < 1 || page > lastPage){
|
|
||||||
Message.send("TEAM_LIST_UNKNOWN_PAGE", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Message.sendPrefixless("TEAM_LIST_HEADER", player, page, lastPage);
|
|
||||||
|
|
||||||
for(int i = (page-1) * TEAMS_PER_PAGE; i < (page-1) * TEAMS_PER_PAGE + TEAMS_PER_PAGE && i < all.size(); i++){
|
|
||||||
Team tm = all.get(i);
|
|
||||||
|
|
||||||
Message.sendPrefixless("TEAM_LIST_TEAM", player, Message.parse("TEAM_LIST_TEAM_HOVER", player),
|
|
||||||
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team info " + tm.getTeamKuerzel()), tm.getTeamColor(), tm.getTeamKuerzel(), tm.getTeamName());
|
|
||||||
}
|
|
||||||
|
|
||||||
TextComponent beforePage = new TextComponent("««");
|
|
||||||
if(page > 1){
|
|
||||||
beforePage.setColor(ChatColor.YELLOW);
|
|
||||||
beforePage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(Message.parse("TEAM_LIST_PREV", player)).create()));
|
|
||||||
beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team list " + (page - 1)));
|
|
||||||
}else
|
|
||||||
beforePage.setColor(ChatColor.DARK_GRAY);
|
|
||||||
|
|
||||||
TextComponent nextPage = new TextComponent(" " + Message.parse("TEAM_LIST_PAGE", player) +" »»");
|
|
||||||
if(page < lastPage){
|
|
||||||
nextPage.setColor(ChatColor.YELLOW);
|
|
||||||
nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(Message.parse("TEAM_LIST_NEXT", player)).create()));
|
|
||||||
nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team list " + (page + 1)));
|
|
||||||
}else
|
|
||||||
nextPage.setColor(ChatColor.DARK_GRAY);
|
|
||||||
|
|
||||||
beforePage.addExtra(nextPage);
|
|
||||||
player.sendMessage(beforePage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register("event")
|
|
||||||
public void event(ProxiedPlayer player) {
|
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
|
||||||
Team team = Team.get(user.getTeam());
|
|
||||||
if(notInTeam(player, user))
|
|
||||||
return;
|
|
||||||
|
|
||||||
Message.send("TEAM_EVENT_USAGE", player);
|
|
||||||
Set<Event> events = TeamTeilnahme.getEvents(team.getTeamId());
|
|
||||||
if(!events.isEmpty()){
|
|
||||||
Message.send("TEAM_EVENT_HEADER", player);
|
|
||||||
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern(Message.parse("EVENT_DATE_FORMAT", player));
|
|
||||||
for(Event e : events)
|
|
||||||
Message.sendPrefixless("TEAM_EVENT_EVENT", player, e.getStart().toLocalDateTime().format(dateFormat), e.getEventName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register("event")
|
|
||||||
public void event(ProxiedPlayer player, Event event){
|
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
|
||||||
Team team = Team.get(user.getTeam());
|
|
||||||
if(notInTeam(player, user))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(notLeader(player, user))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(notDuringEvent(player))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(Instant.now().isAfter(event.getDeadline().toInstant())){
|
|
||||||
Message.send("TEAM_EVENT_OVER", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(TeamTeilnahme.nimmtTeil(team.getTeamId(), event.getEventID())){
|
|
||||||
TeamTeilnahme.notTeilnehmen(team.getTeamId(), event.getEventID());
|
|
||||||
Message.send("TEAM_EVENT_LEFT", player);
|
|
||||||
}else{
|
|
||||||
TeamTeilnahme.teilnehmen(team.getTeamId(), event.getEventID());
|
|
||||||
Message.send("TEAM_EVENT_JOINED", player, event.getEventName());
|
|
||||||
Message.sendPrefixless("TEAM_EVENT_HOW_TO_LEAVE", player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register("tp")
|
|
||||||
public void tp(ProxiedPlayer player, String... args){
|
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
|
||||||
Team team = Team.get(user.getTeam());
|
|
||||||
if(args.length == 0){
|
|
||||||
if(notInTeam(player, user))
|
|
||||||
return;
|
|
||||||
tp(player, team);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Team targetTeam = Team.get(args[0]);
|
|
||||||
if(targetTeam == null){
|
|
||||||
Message.send("TEAM_TP_NO_TEAM", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
tp(player, targetTeam);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void tp(ProxiedPlayer player, Team targetTeam) {
|
|
||||||
if (targetTeam.getAddress() == null) {
|
|
||||||
Message.send("TEAM_NO_ADDRESS", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ServerInfo serverInfo = Storage.teamServers.computeIfAbsent(targetTeam.getTeamId(), integer -> {
|
|
||||||
InetSocketAddress address = new InetSocketAddress(targetTeam.getAddress(), targetTeam.getPort());
|
|
||||||
ServerInfo info = ProxyServer.getInstance().constructServerInfo("Team " + targetTeam.getTeamKuerzel(), address, "SteamWar.de - Teamserver", false);
|
|
||||||
ProxyServer.getInstance().getServers().put(info.getName(), info);
|
|
||||||
return info;
|
|
||||||
});
|
|
||||||
player.connect(ServerConnectRequest.builder()
|
|
||||||
.target(serverInfo)
|
|
||||||
.connectTimeout(BungeeCord.getInstance().getConfig().getServerConnectTimeout())
|
|
||||||
.retry(false)
|
|
||||||
.reason(ServerConnectEvent.Reason.PLUGIN)
|
|
||||||
.callback((success, error) -> {
|
|
||||||
if (error != null) {
|
|
||||||
Message.send("TEAM_OFFLINE", player);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.build());
|
|
||||||
/*
|
|
||||||
((UserConnection) player).connect(serverInfo, (success, error) -> {
|
|
||||||
if (error != null) {
|
|
||||||
Message.send("TEAM_OFFLINE", player);
|
|
||||||
}
|
|
||||||
}, false, ServerConnectEvent.Reason.PLUGIN, BungeeCord.getInstance().getConfig().getServerConnectTimeout(), false);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = "server", description = "TEAM_SERVER_USAGE")
|
|
||||||
public void server(ProxiedPlayer player, String server, @Min(intValue = 1) @Max(intValue = 65535) @ErrorMessage("TEAM_SERVER_PORT_INVALID") int port){
|
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
|
||||||
Team team = Team.get(user.getTeam());
|
|
||||||
if(notLeader(player, user))
|
|
||||||
return;
|
|
||||||
if (PunishmentCommand.isPunishedWithMessage(ChatSender.of(player), Punishment.PunishmentType.NoTeamServer)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (isLocalhost(InetAddress.getByName(server))) {
|
|
||||||
Message.send("TEAM_SERVER_ADDRESS_INVALID", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (UnknownHostException e) {
|
|
||||||
Message.send("TEAM_SERVER_ADDRESS_INVALID", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
team.setAddress(server);
|
|
||||||
team.setPort(port);
|
|
||||||
Storage.teamServers.remove(team.getTeamId());
|
|
||||||
Message.send("TEAM_SERVER_SET", player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isLocalhost(InetAddress addr) {
|
|
||||||
// Check if the address is a valid special local or loop back
|
|
||||||
if (addr.isAnyLocalAddress() || addr.isLoopbackAddress())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// Check if the address is defined on any interface
|
|
||||||
try {
|
|
||||||
return NetworkInterface.getByInetAddress(addr) != null;
|
|
||||||
} catch (SocketException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register("color")
|
|
||||||
public void changeColor(ProxiedPlayer player) {
|
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
|
||||||
Team team = Team.get(user.getTeam());
|
|
||||||
if(notLeader(player, user))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(notDuringEvent(player))
|
|
||||||
return;
|
|
||||||
|
|
||||||
List<SWListInv.SWListEntry<String>> colors = new ArrayList<>();
|
|
||||||
COLOR_CODES.forEach(stringSWListEntry -> {
|
|
||||||
SWItem item = stringSWListEntry.getItem().clone();
|
|
||||||
item.setName(stringSWListEntry.getItem().getTitle() + Team.get(user.getTeam()).getTeamKuerzel());
|
|
||||||
colors.add(new SWListInv.SWListEntry<>(item, stringSWListEntry.getObject()));
|
|
||||||
});
|
|
||||||
|
|
||||||
SWListInv<String> inv = new SWListInv<>(player, Message.parse("TEAM_COLOR_TITLE", player), colors, (click, element) -> {});
|
|
||||||
inv.setCallback((click, element) -> {
|
|
||||||
inv.close();
|
|
||||||
team.setTeamColor(element);
|
|
||||||
});
|
|
||||||
inv.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
@ClassMapper(Event.class)
|
|
||||||
public TypeMapper<Event> eventTypeMapper() {
|
|
||||||
return new TypeMapper<Event>() {
|
|
||||||
@Override
|
|
||||||
public Event map(CommandSender commandSender, String[] previousArguments, String s) {
|
|
||||||
return Event.get(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean validate(CommandSender sender, Event value, MessageSender messageSender) {
|
|
||||||
if (value == null) {
|
|
||||||
messageSender.send("TEAM_EVENT_NO_EVENT", sender);
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
|
|
||||||
return Event.getComing().stream().map(Event::getEventName).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checkTeamName(ProxiedPlayer player, Team team, String arg){
|
|
||||||
Team t = Team.get(arg);
|
|
||||||
if(t != null && t.getTeamId() != team.getTeamId()){
|
|
||||||
Message.send("TEAM_NAME_TAKEN", player);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checkTeamKuerzel(ProxiedPlayer player, Team team, String arg){
|
|
||||||
Team t = Team.get(arg);
|
|
||||||
if(t != null && (team == null || t.getTeamId() != team.getTeamId())){
|
|
||||||
Message.send("TEAM_KUERZEL_TAKEN", player);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean unwantedInTeam(ProxiedPlayer player, SteamwarUser user){
|
|
||||||
if(user.getTeam() != 0){
|
|
||||||
Message.send("TEAM_IN_TEAM", player);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean notInTeam(ProxiedPlayer player, SteamwarUser user){
|
|
||||||
if(user.getTeam() == 0){
|
|
||||||
Message.send("TEAM_NOT_IN_TEAM", player);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean notLeader(ProxiedPlayer player, SteamwarUser user){
|
|
||||||
if(notInTeam(player, user))
|
|
||||||
return true;
|
|
||||||
if(!user.isLeader()){
|
|
||||||
Message.send("TEAM_NOT_LEADER", player);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean notDuringEvent(ProxiedPlayer player){
|
|
||||||
if(Event.get() != null){
|
|
||||||
Message.send("TEAM_NOT_IN_EVENT", player);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,162 +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.commands;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.*;
|
|
||||||
import de.steamwar.sql.BauweltMember;
|
|
||||||
import de.steamwar.sql.Punishment;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.sql.Team;
|
|
||||||
import de.steamwar.bungeecore.util.BauLock;
|
|
||||||
import de.steamwar.bungeecore.util.Chat19;
|
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
import de.steamwar.command.TypeMapper;
|
|
||||||
import de.steamwar.messages.ChatSender;
|
|
||||||
import de.steamwar.sql.Event;
|
|
||||||
import net.md_5.bungee.BungeeCord;
|
|
||||||
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.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class TpCommand extends SWCommand {
|
|
||||||
|
|
||||||
public TpCommand(){
|
|
||||||
super("join", null, "tp", "teleport");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register
|
|
||||||
public void genericCommand(ProxiedPlayer p) {
|
|
||||||
ChatSender.of(p).system(Event.get() == null ? "TP_USAGE" : "TP_USAGE_EVENT");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register
|
|
||||||
public void teleportCommand(ProxiedPlayer p, @Mapper("to") String to, String... rest) {
|
|
||||||
ServerInfo server = getTarget(to);
|
|
||||||
|
|
||||||
//Give control of teleport command to server
|
|
||||||
if (server == p.getServer().getInfo() || server == null) {
|
|
||||||
if (rest.length == 0) {
|
|
||||||
Chat19.chat(p, "/tp " + to);
|
|
||||||
} else {
|
|
||||||
Chat19.chat(p, "/tp " + to + " " + String.join(" ", rest));
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
teleport(p, server);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Mapper("to")
|
|
||||||
@Cached(cacheDuration = 10, global = true)
|
|
||||||
public TypeMapper<String> tabCompleter() {
|
|
||||||
return new TypeMapper<String>() {
|
|
||||||
@Override
|
|
||||||
public String map(CommandSender commandSender, String[] previousArguments, String s) {
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) {
|
|
||||||
List<String> list = new ArrayList<>();
|
|
||||||
for (ProxiedPlayer player : BungeeCord.getInstance().getPlayers()) {
|
|
||||||
list.add(player.getName());
|
|
||||||
}
|
|
||||||
if (Event.get() != null) {
|
|
||||||
EventStarter.getEventServer().keySet().forEach(teamId -> {
|
|
||||||
Team team = Team.get(teamId);
|
|
||||||
list.add(team.getTeamName());
|
|
||||||
list.add(team.getTeamKuerzel());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void teleport(ProxiedPlayer player, ServerInfo server){
|
|
||||||
ChatSender sender = ChatSender.of(player);
|
|
||||||
if(CheckCommand.isChecking(player)){
|
|
||||||
sender.system("CHECK_CHECKING");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String serverPerm = BungeeCore.serverPermissions.get(server.getName());
|
|
||||||
Subserver subserver = Subserver.getSubserver(server);
|
|
||||||
|
|
||||||
if (subserver != null && subserver.getType() == Servertype.ARENA) {
|
|
||||||
if (!PunishmentCommand.isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer))
|
|
||||||
SubserverSystem.sendPlayer(subserver, player);
|
|
||||||
|
|
||||||
} else if(subserver instanceof Bauserver) {
|
|
||||||
Bauserver bauserver = (Bauserver) subserver;
|
|
||||||
ProxiedPlayer checker = BungeeCord.getInstance().getPlayer(bauserver.getOwner());
|
|
||||||
if (checker != null && CheckCommand.isChecking(checker)) {
|
|
||||||
SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId());
|
|
||||||
if (steamwarUser.getUserGroup().isCheckSchematics() || CheckCommand.getCheckingSchem(checker).getOwner() == steamwarUser.getId()) {
|
|
||||||
SubserverSystem.sendPlayer(subserver, player);
|
|
||||||
} else {
|
|
||||||
sender.system("JOIN_PLAYER_BLOCK");
|
|
||||||
}
|
|
||||||
}else if (BauLock.isLocked(SteamwarUser.get(bauserver.getOwner()), sender.user())) {
|
|
||||||
Message.send("BAU_LOCKED_NOALLOWED", player);
|
|
||||||
}else if (bauserver.getOwner().equals(player.getUniqueId()) || BauweltMember.getBauMember(bauserver.getOwner(), player.getUniqueId()) != null) {
|
|
||||||
SubserverSystem.sendPlayer(subserver, player);
|
|
||||||
} else {
|
|
||||||
SubserverSystem.sendDeniedMessage(player, bauserver.getOwner());
|
|
||||||
sender.system("JOIN_PLAYER_BLOCK");
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if(subserver instanceof Builderserver && !player.hasPermission("bungeecore.server.team")) {
|
|
||||||
sender.system("JOIN_PLAYER_BLOCK");
|
|
||||||
} else if (serverPerm != null && !player.hasPermission(serverPerm)) {
|
|
||||||
sender.system("JOIN_PLAYER_BLOCK");
|
|
||||||
} else if (serverPerm == null && !player.getGroups().contains("team")) {
|
|
||||||
sender.system("JOIN_PLAYER_BLOCK");
|
|
||||||
} else {
|
|
||||||
player.connect(server);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ServerInfo getTarget(String arg) {
|
|
||||||
ServerInfo server = null;
|
|
||||||
|
|
||||||
//Get target player server
|
|
||||||
ProxiedPlayer target = ProxyServer.getInstance().getPlayer(arg);
|
|
||||||
if(target != null)
|
|
||||||
server = target.getServer().getInfo();
|
|
||||||
|
|
||||||
//Get target team event arena
|
|
||||||
if(server == null){
|
|
||||||
Team team = Team.get(arg);
|
|
||||||
if(team != null){
|
|
||||||
Subserver eventArena = EventStarter.getEventServer().get(team.getTeamId());
|
|
||||||
if(eventArena != null && Subserver.getServerList().contains(eventArena))
|
|
||||||
server = eventArena.getServer();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return server;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,169 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 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.*;
|
|
||||||
import de.steamwar.bungeecore.inventory.SWInventory;
|
|
||||||
import de.steamwar.bungeecore.inventory.SWItem;
|
|
||||||
import de.steamwar.bungeecore.inventory.SWListInv;
|
|
||||||
import de.steamwar.bungeecore.inventory.SWStreamInv;
|
|
||||||
import de.steamwar.bungeecore.util.Chat19;
|
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
import de.steamwar.command.TypeValidator;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.sql.Tutorial;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class TutorialCommand extends SWCommand {
|
|
||||||
|
|
||||||
public TutorialCommand() {
|
|
||||||
super("tutorial", null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register
|
|
||||||
public void genericCommand(ProxiedPlayer player) {
|
|
||||||
openInventory(player, true, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register("rate")
|
|
||||||
public void rate(ProxiedPlayer player) {
|
|
||||||
Chat19.chat(player, "/tutorial rate");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register("rate")
|
|
||||||
public void rate(ProxiedPlayer player, int id) {
|
|
||||||
Tutorial tutorial = Tutorial.get(id);
|
|
||||||
if(tutorial == null) {
|
|
||||||
Chat19.chat(player, "/tutorial rate"); // Catch players manually entering numbers
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
rate(player, tutorial);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = "create", description = "TUTORIAL_CREATE_HELP")
|
|
||||||
public void create(ProxiedPlayer player, String material, String... name) {
|
|
||||||
create(player, String.join(" ", name), material.toUpperCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register("own")
|
|
||||||
public void own(ProxiedPlayer player) {
|
|
||||||
openInventory(player, false, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register("unreleased")
|
|
||||||
public void unreleased(@Validator("unreleased") ProxiedPlayer player) {
|
|
||||||
openInventory(player, false, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Validator("unreleased")
|
|
||||||
public TypeValidator<ProxiedPlayer> unreleasedChecker() {
|
|
||||||
return (sender, value, messageSender) -> {
|
|
||||||
return (SteamwarUser.get((value).getUniqueId()).getUserGroup().isTeamGroup());
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private void openInventory(ProxiedPlayer player, boolean released, boolean own) {
|
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
|
||||||
|
|
||||||
new SWStreamInv<>(
|
|
||||||
player,
|
|
||||||
Message.parse("TUTORIAL_TITLE", player),
|
|
||||||
(click, tutorial) -> {
|
|
||||||
if(!released && click.isShiftClick() && user.getUserGroup().isTeamGroup() && user.getId() != tutorial.getCreator()) {
|
|
||||||
tutorial.release();
|
|
||||||
openInventory(player, released, own);
|
|
||||||
return;
|
|
||||||
} else if(own && click.isShiftClick() && click.isRightClick()) {
|
|
||||||
tutorial.delete();
|
|
||||||
SubserverSystem.deleteFolder(BungeeCore.local, world(tutorial).getPath());
|
|
||||||
openInventory(player, released, own);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
new ServerStarter().tutorial(player, tutorial).start();
|
|
||||||
},
|
|
||||||
page -> (own ? Tutorial.getOwn(user.getId(), page, 45) : Tutorial.getPage(page, 45, released)).stream().map(tutorial -> new SWListInv.SWListEntry<>(getTutorialItem(player, tutorial, own), tutorial)).collect(Collectors.toList())
|
|
||||||
).open();
|
|
||||||
}
|
|
||||||
|
|
||||||
private SWItem getTutorialItem(ProxiedPlayer player, Tutorial tutorial, boolean personalHighlights) {
|
|
||||||
SWItem item = new SWItem(tutorial.getItem(), Message.parse("TUTORIAL_NAME", player, tutorial.getName()));
|
|
||||||
item.setHideAttributes(true);
|
|
||||||
|
|
||||||
List<String> lore = new ArrayList<>();
|
|
||||||
lore.add(Message.parse("TUTORIAL_BY", player, SteamwarUser.get(tutorial.getCreator()).getUserName()));
|
|
||||||
lore.add(Message.parse("TUTORIAL_STARS", player, String.format("%.1f", tutorial.getStars())));
|
|
||||||
|
|
||||||
if (personalHighlights)
|
|
||||||
lore.add(Message.parse("TUTORIAL_DELETE", player));
|
|
||||||
|
|
||||||
item.setLore(lore);
|
|
||||||
|
|
||||||
if (personalHighlights && tutorial.isReleased())
|
|
||||||
item.setEnchanted(true);
|
|
||||||
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void rate(ProxiedPlayer player, Tutorial tutorial) {
|
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
|
||||||
int[] rates = new int[]{1, 2, 3, 4, 5};
|
|
||||||
|
|
||||||
new SWListInv<>(player, Message.parse("TUTORIAL_RATE_TITLE", player), Arrays.stream(rates).mapToObj(rate -> new SWListInv.SWListEntry<>(new SWItem("NETHER_STAR", Message.parse("TUTORIAL_RATE", player, rate)), rate)).collect(Collectors.toList()), (click, rate) -> {
|
|
||||||
tutorial.rate(user.getId(), rate);
|
|
||||||
SWInventory.close(player);
|
|
||||||
}).open();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void create(ProxiedPlayer player, String name, String item) {
|
|
||||||
Subserver subserver = Subserver.getSubserver(player);
|
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
|
||||||
File tempWorld = new File(ServerStarter.TEMP_WORLD_PATH, ServerStarter.serverToWorldName(ServerStarter.bauServerName(user)));
|
|
||||||
|
|
||||||
if(subserver == null || !subserver.hasStarted() || subserver.getType() != Servertype.BAUSERVER || !tempWorld.exists()) {
|
|
||||||
Message.send("TUTORIAL_CREATE_MISSING", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
subserver.execute("save-all");
|
|
||||||
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
|
|
||||||
Tutorial tutorial = Tutorial.create(user.getId(), name, item);
|
|
||||||
File tutorialWorld = world(tutorial);
|
|
||||||
|
|
||||||
if (tutorialWorld.exists())
|
|
||||||
SubserverSystem.deleteFolder(BungeeCore.local, tutorialWorld.getPath());
|
|
||||||
ServerStarter.copyWorld(BungeeCore.local, tempWorld.getPath(), tutorialWorld.getPath());
|
|
||||||
Message.send("TUTORIAL_CREATED", player);
|
|
||||||
}, 1, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
private File world(Tutorial tutorial) {
|
|
||||||
return new File(ServerStarter.TUTORIAL_PATH, String.valueOf(tutorial.getTutorialId()));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,190 +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.commands;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.Message;
|
|
||||||
import de.steamwar.bungeecore.Storage;
|
|
||||||
import de.steamwar.bungeecore.listeners.mods.Utils;
|
|
||||||
import de.steamwar.command.SWCommand;
|
|
||||||
import de.steamwar.command.SWCommandUtils;
|
|
||||||
import de.steamwar.command.TypeMapper;
|
|
||||||
import de.steamwar.sql.*;
|
|
||||||
import lombok.Getter;
|
|
||||||
import net.md_5.bungee.BungeeCord;
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.text.DecimalFormat;
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
|
|
||||||
public class WhoisCommand extends SWCommand {
|
|
||||||
public WhoisCommand() {
|
|
||||||
super("whois");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(description = "WHOIS_USAGE")
|
|
||||||
public void genericCommand(ProxiedPlayer player, @Mapper("player") String target, WhoisParameterTypes... parameters) {
|
|
||||||
SteamwarUser user = SteamwarUser.get(target);
|
|
||||||
if (user == null) {
|
|
||||||
try {
|
|
||||||
int id = Integer.parseInt(target);
|
|
||||||
user = SteamwarUser.get(id);
|
|
||||||
} catch (NumberFormatException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (user == null) {
|
|
||||||
try {
|
|
||||||
long id = Long.parseLong(target);
|
|
||||||
user = SteamwarUser.get(id);
|
|
||||||
} catch (NumberFormatException ignored) {
|
|
||||||
// Ignored
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (user == null) {
|
|
||||||
Message.send("UNKNOWN_PLAYER", player);
|
|
||||||
} else {
|
|
||||||
EnumSet<WhoisParameterTypes> set = parameters.length == 0 ? EnumSet.noneOf(WhoisParameterTypes.class) : EnumSet.copyOf(Arrays.asList(parameters));
|
|
||||||
sendUserinfo(player, user, set);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Mapper(value = "player", local = true)
|
|
||||||
public TypeMapper<String> playerTypeMapper() {
|
|
||||||
return SWCommandUtils.createMapper(s -> s, s -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void sendUserinfo(ProxiedPlayer player, SteamwarUser user, EnumSet<WhoisParameterTypes> parameterTypes) {
|
|
||||||
UserGroup userGroup = SteamwarUser.get(player.getUniqueId()).getUserGroup();
|
|
||||||
|
|
||||||
Message.send("WHOIS_USERNAME", player, user.getUserName());
|
|
||||||
Message.send("WHOIS_GROUP", player, user.getUserGroup().getColorCode(), user.getUserGroup().name());
|
|
||||||
Team team = Team.get(user.getTeam());
|
|
||||||
Message.send("WHOIS_TEAM", player, Message.parse("WHOIS_TEAM_HOVER", player, team.getTeamName()), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team info " + team.getTeamKuerzel()), team.getTeamColor(), team.getTeamKuerzel(), team.getTeamName());
|
|
||||||
if (!userGroup.isTeamGroup()) return;
|
|
||||||
|
|
||||||
if (userGroup.isAdminGroup()) {
|
|
||||||
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());
|
|
||||||
if (user.getDiscordId() != null) {
|
|
||||||
Message.send("WHOIS_DISCORD_ID", player, user.getDiscordId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Timestamp firstJoin = user.getFirstjoin();
|
|
||||||
if (firstJoin == null) {
|
|
||||||
Message.send("WHOIS_JOINED_FIRST", player, "0000-00-00 00:00:00");
|
|
||||||
} else {
|
|
||||||
Message.send("WHOIS_JOINED_FIRST", player, firstJoin.toString());
|
|
||||||
}
|
|
||||||
Message.send("WHOIS_HOURS_PLAYED", player, new DecimalFormat("###.##").format(user.getOnlinetime() / 3600d));
|
|
||||||
|
|
||||||
if(BungeeCord.getInstance().getPlayer(user.getUUID()) != null) {
|
|
||||||
ProxiedPlayer target = BungeeCord.getInstance().getPlayer(user.getUUID());
|
|
||||||
Message.send("WHOIS_CURRENT_PLAYED", player, new DecimalFormat("####.##").format((Instant.now().getEpochSecond() - Storage.sessions.get(target).toInstant().getEpochSecond()) / 60d));
|
|
||||||
Message.send("WHOIS_CURRENT_SERVER", player, target.getServer().getInfo().getName());
|
|
||||||
Message.send("WHOIS_CURRENT_PROTOCOL", player, target.getPendingConnection().getVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Utils.playerModMap.containsKey(user.getUUID())) {
|
|
||||||
Mod.Platform modPlatform = Utils.playerModMap.get(user.getUUID()).get(0).getPlatform();
|
|
||||||
Message.send("WHOIS_PLATFORM", player, modPlatform.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parameterTypes.contains(WhoisParameterTypes.MOD)) {
|
|
||||||
List<Mod> activeMods = Utils.playerModMap.get(user.getUUID());
|
|
||||||
|
|
||||||
if (activeMods != null && !activeMods.isEmpty()) {
|
|
||||||
Message.send("WHOIS_ACTIVE_MODS", player,activeMods.size());
|
|
||||||
String result = activeMods.stream().map(mod -> "§" + mod.getModType().getColorCode() + mod.getModName()).collect(Collectors.joining("§8, "));
|
|
||||||
Message.send("WHOIS_ACTIVE_MOD", player, result);
|
|
||||||
} else {
|
|
||||||
Message.send("WHOIS_NO_ACTIVE_MODS", player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Message.send("WHOIS_PUNISHMENTS", player);
|
|
||||||
List<Punishment> punishmentList = Punishment.getAllPunishmentsOfPlayer(user.getId());
|
|
||||||
Set<Punishment.PunishmentType> found = new HashSet<>();
|
|
||||||
boolean isPunished = false;
|
|
||||||
boolean all = parameterTypes.contains(WhoisParameterTypes.ALL);
|
|
||||||
for (Punishment punishment : punishmentList) {
|
|
||||||
if (!all && !punishment.getType().isMulti() && !found.add(punishment.getType())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!all && !punishment.isCurrent()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Message.sendPrefixless("WHOIS_PUNISHMENT", player, SteamwarUser.get(punishment.getPunisher()).getUserName(), punishment.getType().name(), punishment.getBantime(punishment.getStartTime(), false), punishment.getBantime(punishment.getEndTime(), punishment.isPerma()), punishment.getReason());
|
|
||||||
isPunished = true;
|
|
||||||
}
|
|
||||||
if (!isPunished) {
|
|
||||||
Message.send(all ? "WHOIS_NO_ALL_PUNISHMENT" : "WHOIS_NO_PUNISHMENT", player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ClassMapper(value = WhoisParameterTypes.class, local = true)
|
|
||||||
public TypeMapper<WhoisParameterTypes> argumentTypeMapper() {
|
|
||||||
WhoisParameterTypes[] values = WhoisParameterTypes.values();
|
|
||||||
|
|
||||||
return new TypeMapper<WhoisParameterTypes>() {
|
|
||||||
@Override
|
|
||||||
public WhoisParameterTypes map(CommandSender commandSender, String[] previousArguments, String s) {
|
|
||||||
UserGroup userGroup = SteamwarUser.get(((ProxiedPlayer) commandSender).getUniqueId()).getUserGroup();
|
|
||||||
return Stream.of(values)
|
|
||||||
.filter(p -> p.userGroupSet.contains(userGroup))
|
|
||||||
.filter(p -> p.getTabCompletes().contains(s))
|
|
||||||
.findFirst()
|
|
||||||
.orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<String> tabCompletes(CommandSender commandSender, String[] previousArguments, String s) {
|
|
||||||
UserGroup userGroup = SteamwarUser.get(((ProxiedPlayer) commandSender).getUniqueId()).getUserGroup();
|
|
||||||
return Stream.of(values)
|
|
||||||
.filter(p -> p.userGroupSet.contains(userGroup))
|
|
||||||
.flatMap(p -> p.getTabCompletes().stream())
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private enum WhoisParameterTypes {
|
|
||||||
ALL(Arrays.asList("-a", "-all"), UserGroup.Admin, UserGroup.Moderator, UserGroup.Developer, UserGroup.Supporter, UserGroup.Builder),
|
|
||||||
MOD(Arrays.asList("-m", "-mod", "-mods"), UserGroup.Admin, UserGroup.Moderator, UserGroup.Developer);
|
|
||||||
|
|
||||||
private final EnumSet<UserGroup> userGroupSet;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
private List<String> tabCompletes;
|
|
||||||
|
|
||||||
|
|
||||||
WhoisParameterTypes(List<String> tabCompletes, UserGroup... userGroups) {
|
|
||||||
this.userGroupSet = EnumSet.copyOf(Arrays.asList(userGroups));
|
|
||||||
this.tabCompletes = tabCompletes;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,158 +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.inventory;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.network.NetworkSender;
|
|
||||||
import de.steamwar.bungeecore.network.handlers.InventoryCallbackHandler;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.network.packets.server.CloseInventoryPacket;
|
|
||||||
import de.steamwar.network.packets.server.InventoryPacket;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.function.BiFunction;
|
|
||||||
|
|
||||||
public class SWInventory {
|
|
||||||
|
|
||||||
private final Map<Integer, SWItem> itemMap;
|
|
||||||
private InvCallback close;
|
|
||||||
private ProxiedPlayer player;
|
|
||||||
private int size;
|
|
||||||
private String title;
|
|
||||||
private boolean next;
|
|
||||||
|
|
||||||
private final AtomicBoolean processingClick = new AtomicBoolean();
|
|
||||||
|
|
||||||
public SWInventory(ProxiedPlayer proxiedPlayer, int size, String title) {
|
|
||||||
itemMap = new HashMap<>();
|
|
||||||
InventoryCallbackHandler.inventoryHashMap.put(SteamwarUser.get(proxiedPlayer.getUniqueId()).getId(), this);
|
|
||||||
this.player = proxiedPlayer;
|
|
||||||
this.size = size;
|
|
||||||
this.title = title;
|
|
||||||
next = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addItem(int pos, SWItem item, InvCallback callback) {
|
|
||||||
addItem(pos, item, new ArrayList<>(), callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addItem(int pos, SWItem item, List<String> lore, InvCallback callback) {
|
|
||||||
item.setCallback(callback);
|
|
||||||
item.setLore(lore);
|
|
||||||
itemMap.put(pos, item);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addItem(int pos, SWItem item) {
|
|
||||||
itemMap.put(pos, item);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addItem(int pos, SWItem item, String name, InvCallback callback) {
|
|
||||||
item.setName(name);
|
|
||||||
item.setCallback(callback);
|
|
||||||
itemMap.put(pos, item);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeItem(int position) {
|
|
||||||
itemMap.remove(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize() {
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSize(int size) {
|
|
||||||
this.size = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTitle(String title) {
|
|
||||||
this.title = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCallback(int pos, InvCallback callback) {
|
|
||||||
itemMap.get(pos).setCallback(callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNext(boolean next) {
|
|
||||||
this.next = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isNext() {
|
|
||||||
return next;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<Integer, SWItem> getItems() {
|
|
||||||
return itemMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handleCallback(InvCallback.ClickType type, int pos) {
|
|
||||||
if(processingClick.compareAndSet(false, true)) {
|
|
||||||
itemMap.get(pos).getCallback().clicked(type);
|
|
||||||
processingClick.set(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handleClose() {
|
|
||||||
if(processingClick.compareAndSet(false, true)) {
|
|
||||||
InventoryCallbackHandler.inventoryHashMap.remove(SteamwarUser.get(player.getUniqueId()).getId(), this);
|
|
||||||
if(close != null)
|
|
||||||
close.clicked(null);
|
|
||||||
processingClick.set(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void open() {
|
|
||||||
InventoryPacket inv = new InventoryPacket(title, SteamwarUser.get(player.getUniqueId()).getId(), size, map(itemMap, (integer, swItem) -> swItem.writeToString(integer).toString()));
|
|
||||||
NetworkSender.send(player, inv);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <T, K, J> Map<T, J> map(Map<T, K> map, BiFunction<T, K, J> function) {
|
|
||||||
Map<T, J> result = new HashMap<>();
|
|
||||||
map.forEach((key, value) -> result.put(key, function.apply(key, value)));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void close() {
|
|
||||||
close(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void close(ProxiedPlayer player) {
|
|
||||||
NetworkSender.send(player, new CloseInventoryPacket(SteamwarUser.get(player.getUniqueId()).getId()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setClose(InvCallback close) {
|
|
||||||
this.close = close;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProxiedPlayer getPlayer() {
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPlayer(ProxiedPlayer player) {
|
|
||||||
this.player = player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTitle() {
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,173 +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.inventory;
|
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class SWItem {
|
|
||||||
|
|
||||||
private String material, title, skullOwner;
|
|
||||||
private boolean enchanted, hideAttributes;
|
|
||||||
private List<String> lore;
|
|
||||||
private InvCallback callback;
|
|
||||||
private int color;
|
|
||||||
|
|
||||||
public SWItem(String material, String title) {
|
|
||||||
this.material = material.toUpperCase();
|
|
||||||
lore = new ArrayList<>();
|
|
||||||
this.title = title;
|
|
||||||
color = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SWItem(String title, int color) {
|
|
||||||
this.material = "DYE";
|
|
||||||
lore = new ArrayList<>();
|
|
||||||
this.title = title;
|
|
||||||
this.color = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SWItem getSkull(String skullOwner) {
|
|
||||||
SWItem item = new SWItem("SKULL", skullOwner);
|
|
||||||
item.setSkullOwner(skullOwner);
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCallback(InvCallback callback) {
|
|
||||||
this.callback = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setColor(int color) {
|
|
||||||
this.color = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InvCallback getCallback() {
|
|
||||||
return callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMaterial() {
|
|
||||||
return material;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMaterial(String material) {
|
|
||||||
this.material = material.toUpperCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSkullOwner() {
|
|
||||||
return skullOwner;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSkullOwner(String skullOwner) {
|
|
||||||
this.skullOwner = skullOwner;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEnchanted() {
|
|
||||||
return enchanted;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEnchanted(boolean enchanted) {
|
|
||||||
this.enchanted = enchanted;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isHideAttributes() {
|
|
||||||
return hideAttributes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHideAttributes(boolean hideAttributes) {
|
|
||||||
this.hideAttributes = hideAttributes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SWItem setName(String name) {
|
|
||||||
title = name;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTitle() {
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addLore(String lore) {
|
|
||||||
this.lore.add(lore);
|
|
||||||
}
|
|
||||||
|
|
||||||
public JsonObject writeToString(int position) {
|
|
||||||
JsonObject object = new JsonObject();
|
|
||||||
object.addProperty("material", material);
|
|
||||||
object.addProperty("position", position);
|
|
||||||
object.addProperty("title", title);
|
|
||||||
if(skullOwner != null)
|
|
||||||
object.addProperty("skullOwner", skullOwner);
|
|
||||||
if(enchanted)
|
|
||||||
object.addProperty("enchanted", true);
|
|
||||||
if(hideAttributes)
|
|
||||||
object.addProperty("hideAttributes", true);
|
|
||||||
if(color != 0)
|
|
||||||
object.addProperty("color", color);
|
|
||||||
if(lore != null) {
|
|
||||||
JsonArray array = new JsonArray();
|
|
||||||
for (String lores:
|
|
||||||
lore) {
|
|
||||||
array.add(lores);
|
|
||||||
}
|
|
||||||
object.add("lore", array);
|
|
||||||
}
|
|
||||||
|
|
||||||
return object;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if(!(o instanceof SWItem))
|
|
||||||
return false;
|
|
||||||
SWItem item = (SWItem) o;
|
|
||||||
if(item.enchanted != enchanted)
|
|
||||||
return false;
|
|
||||||
if(item.hideAttributes != hideAttributes)
|
|
||||||
return false;
|
|
||||||
if(!item.material.equals(material))
|
|
||||||
return false;
|
|
||||||
if(!item.lore.equals(lore))
|
|
||||||
return false;
|
|
||||||
if(!item.skullOwner.equals(skullOwner))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLore(List<String> lore) {
|
|
||||||
this.lore = lore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SWItem clone() {
|
|
||||||
SWItem item;
|
|
||||||
if(color != 0) {
|
|
||||||
item = new SWItem(title, color);
|
|
||||||
}else {
|
|
||||||
item = new SWItem(material, title);
|
|
||||||
}
|
|
||||||
item.setLore(lore);
|
|
||||||
item.setCallback(callback);
|
|
||||||
item.setEnchanted(enchanted);
|
|
||||||
item.setHideAttributes(hideAttributes);
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,121 +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.inventory;
|
|
||||||
|
|
||||||
import net.md_5.bungee.BungeeCord;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class SWListInv<T> extends SWInventory {
|
|
||||||
private ListCallback<T> callback;
|
|
||||||
private List<SWListEntry<T>> elements;
|
|
||||||
private int page;
|
|
||||||
|
|
||||||
public SWListInv(ProxiedPlayer p, String t, List<SWListEntry<T>> l, ListCallback<T> c){
|
|
||||||
super(p, (l.size()>45) ? 54 : (l.size() + 9-l.size()%9), t);
|
|
||||||
callback = c;
|
|
||||||
elements = l;
|
|
||||||
page = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void open(){
|
|
||||||
if(elements.size() > 54){
|
|
||||||
if(page != 0)
|
|
||||||
addItem(45, new SWItem("§eSeite zurück", 10), (InvCallback.ClickType click) -> {
|
|
||||||
page--;
|
|
||||||
open();
|
|
||||||
});
|
|
||||||
else
|
|
||||||
addItem(45, new SWItem("§7Seite zurück", 8), (InvCallback.ClickType click) -> {});
|
|
||||||
if(page < elements.size()/45)
|
|
||||||
addItem(53, new SWItem("§eSeite vor", 10), "§eSeite vor", (InvCallback.ClickType click) -> {
|
|
||||||
page++;
|
|
||||||
open();
|
|
||||||
});
|
|
||||||
else
|
|
||||||
addItem(53, new SWItem("§eSeite vor", 8), (InvCallback.ClickType click) -> {});
|
|
||||||
}
|
|
||||||
|
|
||||||
int ipageLimit = elements.size() - page*45;
|
|
||||||
if(ipageLimit > 45 && elements.size() > 54){
|
|
||||||
ipageLimit = 45;
|
|
||||||
}
|
|
||||||
int i = page*45;
|
|
||||||
for(int ipage=0; ipage < ipageLimit; ipage++ ){
|
|
||||||
SWItem e = elements.get(i).getItem();
|
|
||||||
|
|
||||||
final int pos = i;
|
|
||||||
addItem(ipage, e);
|
|
||||||
setCallback(ipage, (InvCallback.ClickType click) -> callback.clicked(click, elements.get(pos).getObject()));
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
super.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCallback(ListCallback<T> c){
|
|
||||||
callback = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface ListCallback<T>{
|
|
||||||
void clicked(InvCallback.ClickType click, T element);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<SWListEntry<UUID>> createPlayerList(UUID without){
|
|
||||||
List<SWListEntry<UUID>> onlinePlayers = new ArrayList<>();
|
|
||||||
for(ProxiedPlayer player : BungeeCord.getInstance().getPlayer(without).getServer().getInfo().getPlayers()){
|
|
||||||
if(without != null && player.getUniqueId().equals(without))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
onlinePlayers.add(new SWListEntry<>(SWItem.getSkull(player.getName()), player.getUniqueId()));
|
|
||||||
}
|
|
||||||
return onlinePlayers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<SWListEntry<UUID>> createGlobalPlayerList(UUID without){
|
|
||||||
List<SWListEntry<UUID>> onlinePlayers = new ArrayList<>();
|
|
||||||
for(ProxiedPlayer player : BungeeCord.getInstance().getPlayers()){
|
|
||||||
if(without != null && player.getUniqueId().equals(without))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
onlinePlayers.add(new SWListEntry<>(SWItem.getSkull(player.getName()), player.getUniqueId()));
|
|
||||||
}
|
|
||||||
return onlinePlayers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class SWListEntry<T>{
|
|
||||||
final SWItem item;
|
|
||||||
final T object;
|
|
||||||
|
|
||||||
public SWListEntry(SWItem item, T object){
|
|
||||||
this.item = item;
|
|
||||||
this.object = object;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SWItem getItem(){
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T getObject(){
|
|
||||||
return object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
package de.steamwar.bungeecore.inventory;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public class SWStreamInv<T> extends SWInventory {
|
|
||||||
private final SWListInv.ListCallback<T> callback;
|
|
||||||
private final Function<Integer, List<SWListInv.SWListEntry<T>>> constructor;
|
|
||||||
private int page;
|
|
||||||
|
|
||||||
public SWStreamInv(ProxiedPlayer proxiedPlayer, String title, SWListInv.ListCallback<T> callback, Function<Integer, List<SWListInv.SWListEntry<T>>> constructor) {
|
|
||||||
super(proxiedPlayer, 54, title);
|
|
||||||
this.callback = callback;
|
|
||||||
this.constructor = constructor;
|
|
||||||
page = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void open(){
|
|
||||||
List<SWListInv.SWListEntry<T>> entries = constructor.apply(page);
|
|
||||||
|
|
||||||
if(page != 0)
|
|
||||||
addItem(45, new SWItem("§eSeite zurück", 10), (InvCallback.ClickType click) -> {
|
|
||||||
page--;
|
|
||||||
open();
|
|
||||||
});
|
|
||||||
else
|
|
||||||
addItem(45, new SWItem("§7Seite zurück", 8), (InvCallback.ClickType click) -> {});
|
|
||||||
|
|
||||||
if(entries.size() == 45)
|
|
||||||
addItem(53, new SWItem("§eSeite vor", 10), (InvCallback.ClickType click) -> {
|
|
||||||
page++;
|
|
||||||
open();
|
|
||||||
});
|
|
||||||
else
|
|
||||||
addItem(53, new SWItem("§7Seite vor", 8), (InvCallback.ClickType click) -> {});
|
|
||||||
|
|
||||||
for(int i = 0; i < entries.size(); i++) {
|
|
||||||
SWListInv.SWListEntry<T> item = entries.get(i);
|
|
||||||
addItem(i, item.getItem());
|
|
||||||
setCallback(i, (InvCallback.ClickType click) -> {
|
|
||||||
close();
|
|
||||||
callback.clicked(click, item.getObject());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
super.open();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,106 +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.listeners;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
|
||||||
import de.steamwar.bungeecore.Message;
|
|
||||||
import de.steamwar.bungeecore.commands.PunishmentCommand;
|
|
||||||
import de.steamwar.bungeecore.commands.WebpasswordCommand;
|
|
||||||
import de.steamwar.bungeecore.listeners.mods.Forge;
|
|
||||||
import de.steamwar.sql.BannedUserIPs;
|
|
||||||
import de.steamwar.sql.Punishment;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.messages.ChatSender;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
|
||||||
import net.md_5.bungee.api.chat.HoverEvent;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import net.md_5.bungee.api.connection.PendingConnection;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.event.LoginEvent;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class BanListener extends BasicListener {
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onLogin(LoginEvent event) {
|
|
||||||
event.registerIntent(BungeeCore.get());
|
|
||||||
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
|
|
||||||
PendingConnection connection = event.getConnection();
|
|
||||||
SteamwarUser user = SteamwarUser.getOrCreate(connection.getUniqueId(), connection.getName(), ConnectionListener::newPlayer, WebpasswordCommand::changeUsername);
|
|
||||||
if (user.isPunished(Punishment.PunishmentType.Ban)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
BannedUserIPs.banIP(user.getId(), connection.getAddress().getAddress().getHostAddress());
|
|
||||||
ChatSender.of(event).system(PunishmentCommand.punishmentMessage(user, Punishment.PunishmentType.Ban));
|
|
||||||
event.completeIntent(BungeeCore.get());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<BannedUserIPs> ips = BannedUserIPs.get(connection.getAddress().getAddress().getHostAddress());
|
|
||||||
if(!ips.isEmpty()){
|
|
||||||
|
|
||||||
Timestamp highestBan = ips.get(0).getTimestamp();
|
|
||||||
boolean perma = false;
|
|
||||||
for(BannedUserIPs banned : ips) {
|
|
||||||
SteamwarUser bannedUser = SteamwarUser.get(banned.getUserID());
|
|
||||||
if (bannedUser.isPunished(Punishment.PunishmentType.Ban)) {
|
|
||||||
Punishment ban = bannedUser.getPunishment(Punishment.PunishmentType.Ban);
|
|
||||||
if(ban.isPerma()) {
|
|
||||||
perma = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(ban.getEndTime().after(highestBan))
|
|
||||||
highestBan = ban.getEndTime();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ban " + user.getUserName() + " "
|
|
||||||
+ (perma?"perma":highestBan.toLocalDateTime().format(DateTimeFormatter.ofPattern("dd.MM.yyyy_HH:mm")))
|
|
||||||
+ " Bannumgehung");
|
|
||||||
|
|
||||||
for (ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
|
|
||||||
if ((target.hasPermission("bungeecore.teamchat"))
|
|
||||||
&& (target.getChatMode() == ProxiedPlayer.ChatMode.COMMANDS_ONLY
|
|
||||||
|| target.getChatMode() == ProxiedPlayer.ChatMode.SHOWN)){
|
|
||||||
StringBuilder potentialBan = new StringBuilder();
|
|
||||||
potentialBan.append(Message.parsePrefixed("BAN_AVOIDING_ALERT", target, user.getUserName()));
|
|
||||||
|
|
||||||
for(BannedUserIPs banned : ips) {
|
|
||||||
SteamwarUser bannedUser = SteamwarUser.get(banned.getUserID());
|
|
||||||
potentialBan.append(Message.parse("BAN_AVOIDING_LIST", target, bannedUser.getUserName(),
|
|
||||||
banned.getTimestamp().toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", target)))));
|
|
||||||
}
|
|
||||||
|
|
||||||
TextComponent msg = new TextComponent(potentialBan.toString());
|
|
||||||
msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(Message.parse("BAN_AVOIDING_BAN_HOVER", target)).create()));
|
|
||||||
msg.setClickEvent(clickEvent);
|
|
||||||
target.sendMessage(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Forge.onServerConnected(event);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,31 +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.listeners;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.plugin.Listener;
|
|
||||||
|
|
||||||
public abstract class BasicListener implements Listener {
|
|
||||||
|
|
||||||
public BasicListener(){
|
|
||||||
ProxyServer.getInstance().getPluginManager().registerListener(BungeeCore.get(), this);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,71 +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.listeners;
|
|
||||||
|
|
||||||
import de.steamwar.messages.ChatSender;
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import io.netty.buffer.ByteBufAllocator;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
import net.md_5.bungee.protocol.DefinedPacket;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.NetworkInterface;
|
|
||||||
import java.net.SocketException;
|
|
||||||
|
|
||||||
public class BrandListener extends BasicListener {
|
|
||||||
|
|
||||||
private static boolean isLocalHost(InetAddress addr) {
|
|
||||||
if (addr.isAnyLocalAddress() || addr.isLoopbackAddress()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return NetworkInterface.getByInetAddress(addr) != null;
|
|
||||||
} catch (SocketException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onServerSwitch(PluginMessageEvent event) {
|
|
||||||
if(!event.getTag().equals("minecraft:brand") && !event.getTag().equals("MC|Brand")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isLocalHost(event.getReceiver().getAddress().getAddress())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(event.getReceiver() instanceof ProxiedPlayer)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
event.setCancelled(true);
|
|
||||||
|
|
||||||
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
|
|
||||||
String brandString = ChatSender.of(player).parseToLegacy("STEAMWAR_BRAND", ProxyServer.getInstance().getName(), player.getServer().getInfo().getName(), new String(event.getData(), 1, event.getData().length - 1));
|
|
||||||
|
|
||||||
ByteBuf brand = ByteBufAllocator.DEFAULT.heapBuffer();
|
|
||||||
DefinedPacket.writeString(brandString, brand);
|
|
||||||
player.sendData(event.getTag(), DefinedPacket.toArray(brand));
|
|
||||||
brand.release();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 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.listeners;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
|
||||||
import de.steamwar.bungeecore.Message;
|
|
||||||
import de.steamwar.bungeecore.commands.CalendarCommand;
|
|
||||||
import net.md_5.bungee.BungeeCord;
|
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
|
||||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.Month;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class CalendarListener extends BasicListener {
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPostLogin(PostLoginEvent event) {
|
|
||||||
LocalDate localDate = LocalDate.now();
|
|
||||||
int day = localDate.getDayOfMonth();
|
|
||||||
Month month = localDate.getMonth();
|
|
||||||
|
|
||||||
if (month != Month.DECEMBER) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!CalendarCommand.hasDay(day)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
BungeeCord.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
|
|
||||||
Message.send("ADVENT_CALENDAR_MESSAGE", event.getPlayer(), Message.parse("ADVENT_CALENDAR_MESSAGE_HOVER", event.getPlayer()), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/calendar"));
|
|
||||||
}, 2, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,268 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is a part of the SteamWar software.
|
|
||||||
|
|
||||||
Copyright (C) 2022 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.listeners;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.*;
|
|
||||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
|
||||||
import de.steamwar.bungeecore.commands.PunishmentCommand;
|
|
||||||
import de.steamwar.bungeecore.network.NetworkSender;
|
|
||||||
import de.steamwar.bungeecore.util.Chat19;
|
|
||||||
import de.steamwar.messages.ChatSender;
|
|
||||||
import de.steamwar.network.packets.server.PingPacket;
|
|
||||||
import de.steamwar.sql.*;
|
|
||||||
import net.md_5.bungee.api.*;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.event.ChatEvent;
|
|
||||||
import net.md_5.bungee.api.event.TabCompleteEvent;
|
|
||||||
import net.md_5.bungee.api.event.TabCompleteResponseEvent;
|
|
||||||
import net.md_5.bungee.api.scheduler.TaskScheduler;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
public class ChatListener extends BasicListener {
|
|
||||||
|
|
||||||
private static final List<String> rankedModes = ArenaMode.getAllModes().stream().filter(ArenaMode::isRanked).map(ArenaMode::getSchemType).collect(Collectors.toList());
|
|
||||||
|
|
||||||
private static final Set<Integer> coloredTeams = new HashSet<>();
|
|
||||||
static {
|
|
||||||
coloredTeams.add(12);
|
|
||||||
coloredTeams.add(54);
|
|
||||||
coloredTeams.add(285);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onChatEvent(ChatEvent e) {
|
|
||||||
if(!(e.getSender() instanceof ProxiedPlayer))
|
|
||||||
return;
|
|
||||||
ProxiedPlayer player = (ProxiedPlayer) e.getSender();
|
|
||||||
String message = e.getMessage();
|
|
||||||
|
|
||||||
e.setCancelled(true);
|
|
||||||
|
|
||||||
if (message.contains("jndi:ldap")) {
|
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
|
||||||
PunishmentCommand.ban(user, Punishment.PERMA_TIME, "Versuchte Exploit-Ausnutzung", SteamwarUser.get(-1), true);
|
|
||||||
BungeeCore.log(Level.SEVERE, user.getUserName() + " " + user.getId() + " wurde automatisch wegen jndi:ldap gebannt.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isCommand(player, message))
|
|
||||||
return;
|
|
||||||
|
|
||||||
Subserver subserver = Subserver.getSubserver(player);
|
|
||||||
if(subserver != null && subserver.getType() == Servertype.ARENA && subserver.getServer() == player.getServer().getInfo()) {
|
|
||||||
localChat(player, message);
|
|
||||||
} else if (message.startsWith("+")) {
|
|
||||||
localChat(player, message.substring(1));
|
|
||||||
} else {
|
|
||||||
sendChat(ChatSender.of(player), ChatSender.globalReceivers(), "CHAT_GLOBAL", null, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isCommand(ProxiedPlayer player, String message) {
|
|
||||||
String command = message.substring(1);
|
|
||||||
boolean isCommand = message.startsWith("/") || (message.startsWith("7") && command.split(" ", 2)[0].matches("[7/]?[A-Za-z]+"));
|
|
||||||
if(isCommand && !ProxyServer.getInstance().getPluginManager().dispatchCommand(player, command)) {
|
|
||||||
if(command.startsWith("7"))
|
|
||||||
command = "/" + command.substring(1);
|
|
||||||
message = "/" + command;
|
|
||||||
|
|
||||||
if(filteredCommand(player, message))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
Chat19.chat(player, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
return isCommand;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendChat(ChatSender sender, Stream<ChatSender> receivers, String format, ChatSender msgReceiver, String message) {
|
|
||||||
SteamwarUser user = sender.user();
|
|
||||||
final String coloredMessage = (user.getUserGroup() != UserGroup.Member || coloredTeams.contains(user.getTeam())) ? ChatColor.translateAlternateColorCodes('&', message) : message;
|
|
||||||
if(chatFilter(sender, coloredMessage))
|
|
||||||
return;
|
|
||||||
|
|
||||||
AtomicBoolean noReceiver = new AtomicBoolean(true);
|
|
||||||
receivers.filter(ChatSender::chatShown).forEach(player -> {
|
|
||||||
if(sender.user().getId() != player.user().getId())
|
|
||||||
noReceiver.set(false);
|
|
||||||
chatToReciever(player, msgReceiver, user, format, coloredMessage);
|
|
||||||
});
|
|
||||||
|
|
||||||
chatToReciever(ChatSender.console(), msgReceiver, user, format, coloredMessage);
|
|
||||||
|
|
||||||
if(format.equals("CHAT_GLOBAL")) {
|
|
||||||
if (SteamwarDiscordBot.instance() != null)
|
|
||||||
chatToReciever(ChatSender.discordChannel(SteamwarDiscordBot.instance().getIngameChatListener()), msgReceiver, user, format, coloredMessage);
|
|
||||||
} else if (format.equals("CHAT_SERVERTEAM")) {
|
|
||||||
if (SteamwarDiscordBot.instance() != null)
|
|
||||||
chatToReciever(ChatSender.discordChannel(SteamwarDiscordBot.instance().getServerTeamChatListener()), msgReceiver, user, format, coloredMessage);
|
|
||||||
} else if (noReceiver.get()) {
|
|
||||||
sender.system("CHAT_NO_RECEIVER");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void localChat(ProxiedPlayer player, String message) {
|
|
||||||
ChatSender sender = ChatSender.of(player);
|
|
||||||
if(message.length() == 0){
|
|
||||||
sender.system("CHAT_BC_USAGE");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ChatListener.filteredCommand(player, message))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(!message.startsWith("/") && chatFilter(sender, message))
|
|
||||||
return;
|
|
||||||
|
|
||||||
Chat19.chat(player, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean chatFilter(ChatSender sender, String message) {
|
|
||||||
if(!sender.chatShown()) {
|
|
||||||
sender.system("CHAT_RECEIVE");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(message.replace("§[a-f0-9klmno]", "").trim().isEmpty()) {
|
|
||||||
sender.system("CHAT_EMPTY");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
SteamwarUser user = sender.user();
|
|
||||||
UserGroup group = user.getUserGroup();
|
|
||||||
if(!group.isTeamGroup() && (message.contains("http:") || message.contains("https:") || message.contains("www."))){
|
|
||||||
sender.system("CHAT_NO_LINKS");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PunishmentCommand.isPunishedWithMessage(sender, Punishment.PunishmentType.Mute))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (message.contains("LIXFEL"))
|
|
||||||
specialAlert(sender, "Lixfel", "CHAT_LIXFEL_", 3, 6, 11, 12, 15);
|
|
||||||
if (message.contains("YOYONOW"))
|
|
||||||
specialAlert(sender, "YoyoNow", "CHAT_YOYONOW_", 3, 6, 11, 12);
|
|
||||||
if (message.contains("CHAOSCAOT"))
|
|
||||||
specialAlert(sender, "Chaoscaot", "CHAT_CHAOSCAOT_", 3, 6, 11, 12, 15, 17);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void chatToReciever(ChatSender receiver, ChatSender msgReceiver, SteamwarUser sender, String format, String message) {
|
|
||||||
UserGroup group = sender.getUserGroup();
|
|
||||||
receiver.chat(new Message(format,
|
|
||||||
sender,
|
|
||||||
msgReceiver == null ? receiver : msgReceiver,
|
|
||||||
highlightMentions(message, group.getChatColorCode(), receiver),
|
|
||||||
sender.getTeam() == 0 ? "" : "§" + Team.get(sender.getTeam()).getTeamColor() + Team.get(sender.getTeam()).getTeamKuerzel() + " ",
|
|
||||||
UserElo.getEmblem(sender, rankedModes),
|
|
||||||
group.getColorCode(),
|
|
||||||
group.getChatPrefix().length() == 0 ? "§f" : group.getChatPrefix() + " ",
|
|
||||||
group.getChatColorCode()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean filteredCommand(CommandSender sender, String message) {
|
|
||||||
String command = message.split(" ", 2)[0];
|
|
||||||
if(command.startsWith("/") && command.contains(":")) {
|
|
||||||
Message.send("UNKNOWN_COMMAND", sender);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void specialAlert(ChatSender sender, String name, String baseMessage, int... delay) {
|
|
||||||
sender.system("CHAT_LIXFEL_ACTION_BAR");
|
|
||||||
TaskScheduler scheduler = ProxyServer.getInstance().getScheduler();
|
|
||||||
for(int i = 0; i < delay.length; i++) {
|
|
||||||
int finalI = i;
|
|
||||||
scheduler.schedule(BungeeCore.get(), () -> sender.prefixless("CHAT_MSG", name, sender.user(), new Message(baseMessage + (finalI+1))), delay[i], TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String highlightMentions(String message, String returnColor, ChatSender player) {
|
|
||||||
if(!message.contains("@"))
|
|
||||||
return message;
|
|
||||||
|
|
||||||
String mark = "@" + player.user().getUserName();
|
|
||||||
return Arrays.stream(message.split(" ")).map(cur -> {
|
|
||||||
if(cur.equalsIgnoreCase(mark)) {
|
|
||||||
NetworkSender.send(ProxyServer.getInstance().getPlayer(player.user().getUUID()), new PingPacket(player.user().getId()));
|
|
||||||
return "§e" + cur + returnColor;
|
|
||||||
}
|
|
||||||
return cur;
|
|
||||||
}).collect(Collectors.joining(" "));
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onTabCompleteEvent(TabCompleteEvent e){
|
|
||||||
List<String> suggestions = e.getSuggestions();
|
|
||||||
String [] cursor = e.getCursor().split(" ");
|
|
||||||
String last;
|
|
||||||
if(cursor.length != 0)
|
|
||||||
last = cursor[cursor.length - 1];
|
|
||||||
else
|
|
||||||
last = "";
|
|
||||||
for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers()){
|
|
||||||
String name = player.getName();
|
|
||||||
if (last.isEmpty() || name.startsWith(last)) {
|
|
||||||
suggestions.add(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(last.startsWith("@")) {
|
|
||||||
String plrName = last.replace("@", "");
|
|
||||||
for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers()){
|
|
||||||
String name = player.getName();
|
|
||||||
if ((plrName.isEmpty() || name.startsWith(plrName)) && !plrName.equalsIgnoreCase(name)) {
|
|
||||||
suggestions.add("@" + name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(e.getSender() instanceof ProxiedPlayer && cursor.length == 1 && cursor[0].startsWith("/")){
|
|
||||||
ProxiedPlayer player = (ProxiedPlayer) e.getSender();
|
|
||||||
for(String cmd : BungeeCore.commands.keySet()){
|
|
||||||
if(cmd.startsWith(cursor[0]) && player.hasPermission(BungeeCore.commands.get(cmd))){
|
|
||||||
suggestions.add(cmd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onTabCompleteResponseEvent(TabCompleteResponseEvent e){
|
|
||||||
List<String> suggestions = e.getSuggestions();
|
|
||||||
int i = 0;
|
|
||||||
while (i < suggestions.size()) {
|
|
||||||
String suggestion = suggestions.get(i);
|
|
||||||
if(suggestion.startsWith("/") && suggestion.contains(":"))
|
|
||||||
suggestions.remove(i);
|
|
||||||
else
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,156 +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.listeners;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
|
||||||
import de.steamwar.bungeecore.Message;
|
|
||||||
import de.steamwar.bungeecore.Servertype;
|
|
||||||
import de.steamwar.bungeecore.Subserver;
|
|
||||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
|
||||||
import de.steamwar.bungeecore.bot.util.DiscordRanks;
|
|
||||||
import de.steamwar.bungeecore.commands.ChallengeCommand;
|
|
||||||
import de.steamwar.bungeecore.commands.CheckCommand;
|
|
||||||
import de.steamwar.bungeecore.commands.ModCommand;
|
|
||||||
import de.steamwar.bungeecore.commands.MsgCommand;
|
|
||||||
import de.steamwar.bungeecore.listeners.mods.Utils;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.sql.UserGroup;
|
|
||||||
import net.md_5.bungee.api.AbstractReconnectHandler;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
|
||||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
|
||||||
import net.md_5.bungee.api.event.ServerDisconnectEvent;
|
|
||||||
import net.md_5.bungee.api.event.ServerKickEvent;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class ConnectionListener extends BasicListener {
|
|
||||||
|
|
||||||
private static final String ADMIN_GROUP = "admin";
|
|
||||||
public static final String TEAM_GROUP = "team";
|
|
||||||
public static final String CHECK_PERMISSION = "bungeecore.check";
|
|
||||||
private static final String YOUTUBER_MODS = "bungeecore.youtubermods";
|
|
||||||
|
|
||||||
private static final Set<UUID> newPlayers = new HashSet<>();
|
|
||||||
|
|
||||||
public static void newPlayer(UUID player){
|
|
||||||
newPlayers.add(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPostLogin(PostLoginEvent event) {
|
|
||||||
ProxiedPlayer player = event.getPlayer();
|
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
|
||||||
|
|
||||||
player.removeGroups("Admin", "team");
|
|
||||||
|
|
||||||
if(user.getUserGroup().isAdminGroup())
|
|
||||||
player.addGroups(ADMIN_GROUP);
|
|
||||||
|
|
||||||
if(user.getUserGroup().isTeamGroup()) {
|
|
||||||
player.addGroups(TEAM_GROUP);
|
|
||||||
CheckCommand.sendReminder(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(user.getUserGroup().isCheckSchematics())
|
|
||||||
player.setPermission(CHECK_PERMISSION, true);
|
|
||||||
|
|
||||||
if(user.getUserGroup() != UserGroup.Member) {
|
|
||||||
player.setPermission(YOUTUBER_MODS, true);
|
|
||||||
player.setDisplayName(user.getUserGroup().getColorCode() + user.getUserGroup().getChatPrefix() + " " + player.getName() + "§r");
|
|
||||||
player.setPermission("bungeecore.group." + user.getUserGroup().name().toLowerCase(), true);
|
|
||||||
}else {
|
|
||||||
player.setDisplayName("§f" + player.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
for(Subserver subserver : Subserver.getServerList()){
|
|
||||||
if(subserver.getType() == Servertype.ARENA){
|
|
||||||
Iterator<ProxiedPlayer> it = subserver.getServer().getPlayers().iterator();
|
|
||||||
if(it.hasNext()){
|
|
||||||
Message.send("JOIN_ARENA", player, Message.parse("JOIN_ARENA_HOVER", player),
|
|
||||||
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + it.next().getName()), subserver.getServer().getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(newPlayers.contains(player.getUniqueId())){
|
|
||||||
Message.broadcast("JOIN_FIRST", player.getName());
|
|
||||||
newPlayers.remove(player.getUniqueId());
|
|
||||||
}
|
|
||||||
|
|
||||||
if(SteamwarDiscordBotConfig.loaded)
|
|
||||||
DiscordRanks.update(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** To redirect players to the lobby in case of server closure. */
|
|
||||||
@EventHandler
|
|
||||||
public void onServerKickEvent(ServerKickEvent ev)
|
|
||||||
{
|
|
||||||
if(!ev.getPlayer().isConnected())
|
|
||||||
return;
|
|
||||||
|
|
||||||
ServerInfo kickedFrom;
|
|
||||||
|
|
||||||
if (ev.getPlayer().getServer() != null){
|
|
||||||
kickedFrom = ev.getPlayer().getServer().getInfo();
|
|
||||||
}else if (ProxyServer.getInstance().getReconnectHandler() != null){
|
|
||||||
kickedFrom = ProxyServer.getInstance().getReconnectHandler().getServer(ev.getPlayer());
|
|
||||||
}else{
|
|
||||||
kickedFrom = AbstractReconnectHandler.getForcedHost(ev.getPlayer().getPendingConnection());
|
|
||||||
if (kickedFrom == null){
|
|
||||||
kickedFrom = ProxyServer.getInstance().getServerInfo(ev.getPlayer().getPendingConnection().getListener().getDefaultServer());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ServerInfo kickTo = ProxyServer.getInstance().getServerInfo(BungeeCore.LOBBY_SERVER);
|
|
||||||
|
|
||||||
if (kickedFrom != null && kickedFrom.equals(kickTo)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ev.setCancelled(true);
|
|
||||||
ev.setCancelServer(kickTo);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onDisconnect(PlayerDisconnectEvent e){
|
|
||||||
ChallengeCommand.remove(e.getPlayer());
|
|
||||||
MsgCommand.remove(e.getPlayer());
|
|
||||||
Utils.playerModMap.remove(e.getPlayer().getUniqueId());
|
|
||||||
ModCommand.playerFilterType.remove(e.getPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onServerDisconnect(ServerDisconnectEvent e){
|
|
||||||
ServerInfo server = e.getTarget();
|
|
||||||
Subserver subserver = Subserver.getSubserver(server);
|
|
||||||
if(subserver == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ProxiedPlayer player = e.getPlayer();
|
|
||||||
Collection<ProxiedPlayer> players = server.getPlayers();
|
|
||||||
if(players.isEmpty() || (players.size() == 1 && players.contains(player)))
|
|
||||||
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), subserver::waitForTermination);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
package de.steamwar.bungeecore.listeners;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.Message;
|
|
||||||
import de.steamwar.sql.EventFight;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.sql.TeamTeilnahme;
|
|
||||||
import de.steamwar.sql.Event;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
|
|
||||||
public class EventModeListener extends BasicListener {
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPostLogin(PostLoginEvent e) {
|
|
||||||
SteamwarUser user = SteamwarUser.get(e.getPlayer().getUniqueId());
|
|
||||||
|
|
||||||
Event event = Event.get();
|
|
||||||
if(event == null){
|
|
||||||
e.getPlayer().disconnect(TextComponent.fromLegacyText(Message.parse("EVENTMODE_KICK", e.getPlayer())));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(TeamTeilnahme.nimmtTeil(user.getTeam(), event.getEventID()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
for(EventFight eventFight : EventFight.getEvent(event.getEventID())){
|
|
||||||
if(eventFight.getKampfleiter() == user.getId())
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
e.getPlayer().disconnect(TextComponent.fromLegacyText(Message.parse("EVENTMODE_KICK", e.getPlayer())));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,97 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 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.listeners;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
|
||||||
import de.steamwar.bungeecore.Message;
|
|
||||||
import de.steamwar.bungeecore.Storage;
|
|
||||||
import net.md_5.bungee.BungeeCord;
|
|
||||||
import net.md_5.bungee.api.connection.Connection;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.event.LoginEvent;
|
|
||||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
|
||||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class NonFabricFabricCheck extends BasicListener {
|
|
||||||
|
|
||||||
private final Set<UUID> usingFabric = new HashSet<>();
|
|
||||||
|
|
||||||
private final Set<ProxiedPlayer> checking = new HashSet<>();
|
|
||||||
private final Set<ProxiedPlayer> vanilla = new HashSet<>();
|
|
||||||
|
|
||||||
{
|
|
||||||
BungeeCord.getInstance().getScheduler().schedule(BungeeCore.get(), usingFabric::clear, 0, 15, TimeUnit.MINUTES);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void pluginMessageEvent(PluginMessageEvent e) {
|
|
||||||
Connection sender = e.getSender();
|
|
||||||
if(!(sender instanceof ProxiedPlayer))
|
|
||||||
return;
|
|
||||||
|
|
||||||
ProxiedPlayer p = (ProxiedPlayer) sender;
|
|
||||||
if (e.getTag().equals("minecraft:register") && new String(e.getData()).contains("fabric-screen-handler-api-v1:open_screen")) {
|
|
||||||
BungeeCord.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
|
|
||||||
if (!sender.isConnected()) return;
|
|
||||||
if (!vanilla.remove(p)) return;
|
|
||||||
if (Storage.fabricCheckedPlayers.containsKey(p)) return;
|
|
||||||
p.disconnect(Message.parse("MOD_USE_MODSENDER", p));
|
|
||||||
}, 25, TimeUnit.SECONDS);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!e.getTag().equals("minecraft:brand"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(!new String(e.getData()).equals("vanilla"))
|
|
||||||
return;
|
|
||||||
vanilla.add(p);
|
|
||||||
|
|
||||||
BungeeCord.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
|
|
||||||
if (!p.isConnected()) return;
|
|
||||||
if (Storage.fabricCheckedPlayers.containsKey(p)) return;
|
|
||||||
checking.add(p);
|
|
||||||
p.sendData("fabric-screen-handler-api-v1:open_screen", new byte[] {0});
|
|
||||||
BungeeCord.getInstance().getScheduler().schedule(BungeeCore.get(), () -> checking.remove(p), 1, TimeUnit.SECONDS);
|
|
||||||
}, 30, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerPreLogin(LoginEvent e) {
|
|
||||||
if (usingFabric.remove(e.getConnection().getUniqueId())) {
|
|
||||||
e.getConnection().disconnect(Message.parse("MOD_USE_MODSENDER", Locale.getDefault()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerDisconnect(PlayerDisconnectEvent e) {
|
|
||||||
if (checking.remove(e.getPlayer())) {
|
|
||||||
usingFabric.add(e.getPlayer().getUniqueId());
|
|
||||||
}
|
|
||||||
vanilla.remove(e.getPlayer());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,82 +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.listeners;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.Message;
|
|
||||||
import de.steamwar.sql.PollAnswer;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class PollSystem extends BasicListener {
|
|
||||||
|
|
||||||
private static String question;
|
|
||||||
private static List<String> answers;
|
|
||||||
|
|
||||||
public static void init(String question, List<String> answers){
|
|
||||||
PollSystem.question = question;
|
|
||||||
PollSystem.answers = answers;
|
|
||||||
|
|
||||||
if(noCurrentPoll())
|
|
||||||
return;
|
|
||||||
|
|
||||||
PollAnswer.setCurrentPoll(question);
|
|
||||||
new PollSystem();
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPostLogin(PostLoginEvent event){
|
|
||||||
ProxiedPlayer player = event.getPlayer();
|
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
|
||||||
|
|
||||||
PollAnswer answer = PollAnswer.get(user.getId());
|
|
||||||
if(answer.hasAnswered())
|
|
||||||
return;
|
|
||||||
|
|
||||||
sendPoll(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendPoll(ProxiedPlayer player){
|
|
||||||
Message.send("POLL_HEADER", player);
|
|
||||||
Message.sendPrefixless("POLL_HEADER2", player);
|
|
||||||
Message.sendPrefixless("POLL_QUESTION", player, question);
|
|
||||||
|
|
||||||
for(int i = 1; i <= answers.size(); i++){
|
|
||||||
Message.send("POLL_ANWSER", player, Message.parse("POLL_ANWSER_HOVER", player, answers.get(i-1)),
|
|
||||||
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/poll " + i), answers.get(i-1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean noCurrentPoll(){
|
|
||||||
return question == null || question.equals("");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int answers(){
|
|
||||||
return answers.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getAnswer(int i) {
|
|
||||||
return answers.get(i);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,70 +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.listeners;
|
|
||||||
|
|
||||||
import net.md_5.bungee.BungeeCord;
|
|
||||||
import net.md_5.bungee.api.event.LoginEvent;
|
|
||||||
import net.md_5.bungee.connection.InitialHandler;
|
|
||||||
import net.md_5.bungee.connection.LoginResult;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
import net.md_5.bungee.protocol.Property;
|
|
||||||
import net.md_5.bungee.util.AddressUtil;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
public class SubserverProtocolFixer extends BasicListener {
|
|
||||||
|
|
||||||
private final InetSocketAddress inetSocketAddress = new InetSocketAddress("127.127.127.127", 25565);
|
|
||||||
|
|
||||||
private Field field;
|
|
||||||
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
field = InitialHandler.class.getDeclaredField("extraDataInHandshake");
|
|
||||||
field.setAccessible(true);
|
|
||||||
} catch (NoSuchFieldException e) {
|
|
||||||
BungeeCord.getInstance().getLogger().log(Level.SEVERE, e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void loginEvent(LoginEvent e) {
|
|
||||||
InitialHandler initialHandler = ((InitialHandler) e.getConnection());
|
|
||||||
|
|
||||||
String undashedUUID = initialHandler.getUniqueId().toString().replace("-", "");
|
|
||||||
String extraData = "\00" + AddressUtil.sanitizeAddress(inetSocketAddress) + "\00" + undashedUUID;
|
|
||||||
|
|
||||||
LoginResult result = initialHandler.getLoginProfile();
|
|
||||||
if (result != null) {
|
|
||||||
Property[] properties = result.getProperties();
|
|
||||||
if (properties.length > 0) {
|
|
||||||
extraData += "\00" + BungeeCord.getInstance().gson.toJson(properties);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
field.set(initialHandler, extraData);
|
|
||||||
} catch (IllegalAccessException ex) {
|
|
||||||
BungeeCord.getInstance().getLogger().log(Level.SEVERE, ex.getMessage(), ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
package de.steamwar.bungeecore.listeners.mods;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.listeners.BasicListener;
|
|
||||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
import net.md_5.bungee.protocol.packet.PluginMessage;
|
|
||||||
|
|
||||||
public class Badlion extends BasicListener {
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPostLogin(PostLoginEvent event) {
|
|
||||||
/*
|
|
||||||
{
|
|
||||||
"modsDisallowed": {
|
|
||||||
"Clear Glass":{"disabled":true},
|
|
||||||
"ClearWater":{"disabled":true},
|
|
||||||
"FOV Changer":{"disabled":true},
|
|
||||||
"Hitboxes":{"disabled":true},
|
|
||||||
"MiniMap":{"disabled":true},
|
|
||||||
"MLG Cobweb":{"disabled":true},
|
|
||||||
"Replay":{"disabled":true},
|
|
||||||
"Schematica":{"disabled":true},
|
|
||||||
"ToggleSneak":{"disabled":true},
|
|
||||||
"ToggleSprint":{"disabled":true},
|
|
||||||
"TNT Time":{"disabled":true}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
event.getPlayer().unsafe().sendPacket(new PluginMessage("badlion:mods", ("{\"Clear Glass\":{\"disabled\":true},\"ClearWater\":{\"disabled\":true},\"FOV Changer\":{\"disabled\":true},\"Hitboxes\":{\"disabled\":true},\"MiniMap\":{\"disabled\":true},\"MLG Cobweb\":{\"disabled\":true},\"Replay\":{\"disabled\":true},\"Schematica\":{\"disabled\":true},\"ToggleSneak\":{\"disabled\":true},\"ToggleSprint\":{\"disabled\":true},\"TNT Time\":{\"disabled\":true}}").getBytes(), false));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,194 +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.listeners.mods;
|
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import com.google.gson.JsonSyntaxException;
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
|
||||||
import de.steamwar.bungeecore.Message;
|
|
||||||
import de.steamwar.bungeecore.Storage;
|
|
||||||
import de.steamwar.bungeecore.listeners.BasicListener;
|
|
||||||
import de.steamwar.sql.Mod;
|
|
||||||
import de.steamwar.sql.SWException;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import net.md_5.bungee.BungeeCord;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
|
||||||
import net.md_5.bungee.api.event.ServerSwitchEvent;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.nio.charset.UnsupportedCharsetException;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class Fabric extends BasicListener {
|
|
||||||
|
|
||||||
public static void remove(ProxiedPlayer player) {
|
|
||||||
Storage.fabricCheckedPlayers.remove(player);
|
|
||||||
synchronized (Storage.fabricExpectPluginMessage) {
|
|
||||||
Storage.fabricExpectPluginMessage.remove(player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final HashSet<String> ppCircumventerList = new HashSet<>();
|
|
||||||
static {
|
|
||||||
ppCircumventerList.add("java");
|
|
||||||
ppCircumventerList.add("minecraft");
|
|
||||||
ppCircumventerList.add("org_joml_joml");
|
|
||||||
ppCircumventerList.add("steamwarmodsender");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final Set<String> neededMods = new HashSet<>();
|
|
||||||
static {
|
|
||||||
neededMods.add("java");
|
|
||||||
neededMods.add("minecraft");
|
|
||||||
neededMods.add("fabricloader");
|
|
||||||
neededMods.add("steamwarmodsender");
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
BungeeCord.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
|
|
||||||
synchronized (Storage.fabricExpectPluginMessage) {
|
|
||||||
for (Map.Entry<ProxiedPlayer, Long> entry : Storage.fabricExpectPluginMessage.entrySet()) {
|
|
||||||
if (!Storage.fabricCheckedPlayers.containsKey(entry.getKey())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (System.currentTimeMillis() - entry.getValue() > TimeUnit.SECONDS.toMillis(20)) {
|
|
||||||
logMessage(SteamwarUser.get(entry.getKey().getUniqueId()), "Expected message not received", String.valueOf(entry.getValue()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 0, 1, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPluginMessageEvent(PluginMessageEvent e){
|
|
||||||
if(!e.getTag().equals("fabricmodsender:mods"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!(e.getSender() instanceof ProxiedPlayer)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ProxiedPlayer player = (ProxiedPlayer) e.getSender();
|
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
|
||||||
byte[] data = e.getData();
|
|
||||||
|
|
||||||
if (!Storage.fabricCheckedPlayers.containsKey(player)) {
|
|
||||||
synchronized (Storage.fabricExpectPluginMessage) {
|
|
||||||
if (Storage.fabricExpectPluginMessage.containsKey(player)) {
|
|
||||||
logMessage(user, "Was not fabric checked but send message nonetheless", Arrays.toString(data));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Storage.fabricExpectPluginMessage.remove(player);
|
|
||||||
|
|
||||||
List<Mod> mods = new ArrayList<>();
|
|
||||||
|
|
||||||
Utils.VarInt varInt = Utils.readVarInt(data,0);
|
|
||||||
|
|
||||||
if(data.length != varInt.length + varInt.value) {
|
|
||||||
logMessage(user, "Invalid message length", Arrays.toString(data));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
data = Arrays.copyOfRange(data,varInt.length, data.length);
|
|
||||||
|
|
||||||
String dataString;
|
|
||||||
|
|
||||||
try{
|
|
||||||
dataString = new String(data, StandardCharsets.UTF_8);
|
|
||||||
}catch (UnsupportedCharsetException exception) {
|
|
||||||
logMessage(user, "Unsupported charset", Arrays.toString(data));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonArray array;
|
|
||||||
|
|
||||||
try {
|
|
||||||
array = JsonParser.parseString(dataString).getAsJsonArray();
|
|
||||||
}catch (JsonSyntaxException exception) {
|
|
||||||
logMessage(user, "Invalid json", dataString);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(JsonElement mod : array) {
|
|
||||||
mods.add(Mod.getOrCreate(mod.getAsString(), Mod.Platform.FABRIC));
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean neededMods = neededModsContained(mods);
|
|
||||||
if(!neededMods) {
|
|
||||||
logMessage(user, "Needed mods are not contained", dataString);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ppCircumventerCheck(mods))
|
|
||||||
logMessage(user, "PP circumventer suspicion", dataString);
|
|
||||||
|
|
||||||
if(!Utils.handleMods(player,mods))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (Storage.fabricCheckedPlayers.containsKey(player)) {
|
|
||||||
long current = Storage.fabricCheckedPlayers.get(player);
|
|
||||||
if (current != dataString.hashCode()) {
|
|
||||||
logMessage(user, "Mods changed during runtime", dataString);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Message.send("MODIFICATION_CHECK_SUCCESS", player);
|
|
||||||
Storage.fabricCheckedPlayers.put(player, dataString.hashCode());
|
|
||||||
}
|
|
||||||
Storage.fabricPlayers.remove(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onServerSwitchEvent(ServerSwitchEvent e) {
|
|
||||||
if (e.getFrom() == null) return;
|
|
||||||
synchronized (Storage.fabricExpectPluginMessage) {
|
|
||||||
Storage.fabricExpectPluginMessage.put(e.getPlayer(), System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean neededModsContained(List<Mod> mods) {
|
|
||||||
return mods.stream()
|
|
||||||
.map(Mod::getModName)
|
|
||||||
.filter(neededMods::contains)
|
|
||||||
.count() == neededMods.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void logMessage(SteamwarUser user, String reason, String data) {
|
|
||||||
SWException.log("FabricModSender " + user.getUserName() + ": " + reason, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean ppCircumventerCheck(List<Mod> mods) {
|
|
||||||
for(Mod mod : mods) {
|
|
||||||
String name = mod.getModName();
|
|
||||||
if(!name.startsWith("fabric") && !ppCircumventerList.contains(name))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,147 +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.listeners.mods;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
|
||||||
import de.steamwar.bungeecore.listeners.BasicListener;
|
|
||||||
import de.steamwar.sql.Mod;
|
|
||||||
import io.netty.channel.ChannelPipeline;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import net.md_5.bungee.api.connection.PendingConnection;
|
|
||||||
import net.md_5.bungee.api.event.LoginEvent;
|
|
||||||
import net.md_5.bungee.connection.InitialHandler;
|
|
||||||
import net.md_5.bungee.netty.ChannelWrapper;
|
|
||||||
import net.md_5.bungee.netty.HandlerBoss;
|
|
||||||
import net.md_5.bungee.netty.PacketHandler;
|
|
||||||
import net.md_5.bungee.protocol.packet.LoginPayloadRequest;
|
|
||||||
import net.md_5.bungee.protocol.packet.LoginPayloadResponse;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
public class Forge extends BasicListener {
|
|
||||||
|
|
||||||
private static final String WRAPPER = "fml:loginwrapper";
|
|
||||||
|
|
||||||
private static final Field initialHandlerCh;
|
|
||||||
static{
|
|
||||||
try {
|
|
||||||
initialHandlerCh = InitialHandler.class.getDeclaredField("ch");
|
|
||||||
} catch (NoSuchFieldException e) {
|
|
||||||
throw new SecurityException("Could not initialize Reflection", e);
|
|
||||||
}
|
|
||||||
initialHandlerCh.setAccessible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void onServerConnected(LoginEvent event) {
|
|
||||||
if(event.getConnection().getVersion() < 341) { //1.13+
|
|
||||||
event.completeIntent(BungeeCore.get());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//fml:handshake without mods, channels and registries
|
|
||||||
//for more information see https://wiki.vg/Minecraft_Forge_Handshake#FML2_protocol_.281.13_-_Current.29
|
|
||||||
event.getConnection().unsafe().sendPacket(new LoginPayloadRequest(1, WRAPPER, new byte[]{13,102,109,108,58,104,97,110,100,115,104,97,107,101,4,1,0,0,0}));
|
|
||||||
|
|
||||||
InitialHandler handler = (InitialHandler) event.getConnection();
|
|
||||||
|
|
||||||
ChannelWrapper wrapper;
|
|
||||||
try{
|
|
||||||
wrapper = (ChannelWrapper) initialHandlerCh.get(handler);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
BungeeCore.get().getLogger().log(Level.SEVERE, "Could not get Channel", e);
|
|
||||||
event.completeIntent(BungeeCore.get());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ChannelPipeline pipeline = wrapper.getHandle().pipeline();
|
|
||||||
if(pipeline != null) {
|
|
||||||
HandlerBoss handlerBoss = pipeline.get(HandlerBoss.class);
|
|
||||||
if(handlerBoss != null)
|
|
||||||
handlerBoss.setHandler(new CustomPacketHandler(event));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class CustomPacketHandler extends PacketHandler {
|
|
||||||
private final LoginEvent event;
|
|
||||||
|
|
||||||
public CustomPacketHandler(LoginEvent event) {
|
|
||||||
this.event = event;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "SteamWar Forge Handler";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(LoginPayloadResponse response){
|
|
||||||
byte[] data = response.getData();
|
|
||||||
if(data == null) {
|
|
||||||
event.completeIntent(BungeeCore.get());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//for more information see https://wiki.vg/Minecraft_Forge_Handshake#FML2_protocol_.281.13_-_Current.29
|
|
||||||
Utils.VarInt channelLength = Utils.readVarInt(data, 0);
|
|
||||||
int pos = channelLength.length;
|
|
||||||
if(!new String(data, pos, channelLength.value).equals("fml:handshake")) {
|
|
||||||
event.getConnection().disconnect(TextComponent.fromLegacyText("Invalid forge registry response (0x00)"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
pos += channelLength.value;
|
|
||||||
|
|
||||||
Utils.VarInt length = Utils.readVarInt(data, pos);
|
|
||||||
pos += length.length;
|
|
||||||
if(channelLength.length + channelLength.value + length.length + length.value != data.length) {
|
|
||||||
event.getConnection().disconnect(TextComponent.fromLegacyText("Invalid forge registry response (0x01)"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Utils.VarInt packetId = Utils.readVarInt(data, pos);
|
|
||||||
pos += packetId.length;
|
|
||||||
if(packetId.value != 2) {
|
|
||||||
event.getConnection().disconnect(TextComponent.fromLegacyText("Invalid forge registry response (0x02)"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Utils.VarInt modCount = Utils.readVarInt(data, pos);
|
|
||||||
pos += modCount.length;
|
|
||||||
|
|
||||||
List<Mod> mods = new ArrayList<>();
|
|
||||||
for(int i = 0; i < modCount.value; i++) {
|
|
||||||
Utils.VarInt nameLength = Utils.readVarInt(data, pos);
|
|
||||||
pos += nameLength.length;
|
|
||||||
|
|
||||||
mods.add(Mod.getOrCreate(new String(data, pos, nameLength.value), Mod.Platform.FORGE));
|
|
||||||
pos += nameLength.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
PendingConnection connection = event.getConnection();
|
|
||||||
if(!Utils.handleMods(connection.getUniqueId(), Locale.getDefault(), event::setCancelReason, mods)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
event.completeIntent(BungeeCore.get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,113 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is a part of the SteamWar software.
|
|
||||||
|
|
||||||
Copyright (C) 2022 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.listeners.mods;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
|
||||||
import de.steamwar.bungeecore.listeners.BasicListener;
|
|
||||||
import de.steamwar.sql.Mod;
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import io.netty.buffer.UnpooledByteBufAllocator;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.connection.Connection;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
|
||||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class Forge12 extends BasicListener {
|
|
||||||
private static final String FMLHS = "FML|HS";
|
|
||||||
private static final byte[] REGISTER;
|
|
||||||
private static final byte[] HELLO = new byte[]{0, 2, 0, 0, 0, 0};
|
|
||||||
|
|
||||||
private static final Set<UUID> unlocked = new HashSet<>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
ByteBuf buf = UnpooledByteBufAllocator.DEFAULT.directBuffer(7);
|
|
||||||
buf.writeByte(6);
|
|
||||||
buf.writeCharSequence(FMLHS, StandardCharsets.UTF_8);
|
|
||||||
REGISTER = new byte[buf.readableBytes()];
|
|
||||||
buf.readBytes(REGISTER);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPostLogin(PostLoginEvent event) {
|
|
||||||
ProxiedPlayer player = event.getPlayer();
|
|
||||||
|
|
||||||
synchronized (unlocked) {
|
|
||||||
if(unlocked.contains(player.getUniqueId())){
|
|
||||||
unlocked.remove(player.getUniqueId());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(player.getPendingConnection().getVersion() <= 340) {
|
|
||||||
player.sendData("REGISTER", REGISTER); //1.12-
|
|
||||||
player.sendData(FMLHS, HELLO);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPluginMessageEvent(PluginMessageEvent e){
|
|
||||||
if(!e.getTag().equals(FMLHS))
|
|
||||||
return;
|
|
||||||
|
|
||||||
e.setCancelled(true);
|
|
||||||
byte[] data = e.getData();
|
|
||||||
|
|
||||||
Connection sender = e.getSender();
|
|
||||||
if(!(sender instanceof ProxiedPlayer))
|
|
||||||
return;
|
|
||||||
ProxiedPlayer p = (ProxiedPlayer) sender;
|
|
||||||
|
|
||||||
if (data[0] == 2) {
|
|
||||||
Utils.VarInt numMods = Utils.readVarInt(data, 1);
|
|
||||||
List<Mod> mods = new LinkedList<>();
|
|
||||||
|
|
||||||
int bytePos = 1 + numMods.length;
|
|
||||||
for (int i = 0; i < numMods.value; i++) {
|
|
||||||
byte[] name = Arrays.copyOfRange(data, bytePos + 1, bytePos + data[bytePos] + 1);
|
|
||||||
bytePos += 1 + data[bytePos];
|
|
||||||
//Version information is unused
|
|
||||||
bytePos += 1 + data[bytePos];
|
|
||||||
|
|
||||||
mods.add(Mod.getOrCreate(new String(name), Mod.Platform.FORGE));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Utils.handleMods(p, mods)) {
|
|
||||||
synchronized (unlocked) {
|
|
||||||
unlocked.add(p.getUniqueId());
|
|
||||||
}
|
|
||||||
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(),
|
|
||||||
() -> p.disconnect(BungeeCore.stringToText("§7Deine installierten Mods wurden überprüft\n§aDu kannst nun §eSteam§8War §abetreten")),
|
|
||||||
2, TimeUnit.SECONDS);
|
|
||||||
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
|
|
||||||
synchronized (unlocked) {
|
|
||||||
unlocked.remove(p.getUniqueId());
|
|
||||||
}
|
|
||||||
}, 30, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,184 +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.listeners.mods;
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.stream.JsonReader;
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
|
||||||
import de.steamwar.bungeecore.listeners.BasicListener;
|
|
||||||
import de.steamwar.sql.Mod;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.connection.Connection;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class LabyMod extends BasicListener {
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPluginMessageEvent(PluginMessageEvent event){
|
|
||||||
if(!event.getTag().equals("LMC"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
Connection sender = event.getSender();
|
|
||||||
if(!(sender instanceof ProxiedPlayer))
|
|
||||||
return;
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
|
||||||
updateGameInfo((ProxiedPlayer) sender);
|
|
||||||
byte[] data = event.getData();
|
|
||||||
|
|
||||||
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> runAsync(data, (ProxiedPlayer) sender));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void runAsync(byte[] data, ProxiedPlayer player) {
|
|
||||||
VarString purpose = readString(data, 0);
|
|
||||||
if(!"INFO".equals(purpose.value))
|
|
||||||
return;
|
|
||||||
|
|
||||||
VarString value = readString(data, purpose.length);
|
|
||||||
List<Mod> mods = new LinkedList<>();
|
|
||||||
|
|
||||||
try{
|
|
||||||
InfoPacket info = new InfoPacket(value.value);
|
|
||||||
for(InfoPacket.Addon addon : info.addons) {
|
|
||||||
mods.add(Mod.getOrCreate(addon.name, Mod.Platform.LABYMOD));
|
|
||||||
}
|
|
||||||
}catch(IOException e){
|
|
||||||
BungeeCore.log("Could not read JSON", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
Utils.handleMods(player, mods);
|
|
||||||
}
|
|
||||||
|
|
||||||
private VarString readString(byte[] array, int startPos){
|
|
||||||
Utils.VarInt varInt = Utils.readVarInt(array, startPos);
|
|
||||||
startPos += varInt.length;
|
|
||||||
return new VarString(varInt.value+varInt.length, new String(Arrays.copyOfRange(array, startPos, startPos + varInt.value), StandardCharsets.UTF_8));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateGameInfo(ProxiedPlayer proxiedPlayer) {
|
|
||||||
JsonObject obj = new JsonObject();
|
|
||||||
obj.addProperty("hasGame", true);
|
|
||||||
obj.addProperty("game_mode", "steamwar.de");
|
|
||||||
obj.addProperty("game_startTime", 0);
|
|
||||||
obj.addProperty("game_endTime", 0);
|
|
||||||
String output = "{ \"hasGame\" : \"true\", \"game_mode\" : \"steamwar.de\", \"game_startTime\" : \"0\", \"game_endTime\" : \"0\" }";
|
|
||||||
|
|
||||||
proxiedPlayer.sendData("LMC", output.getBytes());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class VarString{
|
|
||||||
private final int length;
|
|
||||||
private final String value;
|
|
||||||
|
|
||||||
private VarString(int length, String value) {
|
|
||||||
this.length = length;
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class InfoPacket{
|
|
||||||
String version = null;
|
|
||||||
Feature ccp = null;
|
|
||||||
Feature shadow = null;
|
|
||||||
List<Addon> addons = new LinkedList<>();
|
|
||||||
|
|
||||||
InfoPacket(String input) throws IOException {
|
|
||||||
JsonReader reader = new JsonReader(new StringReader(input));
|
|
||||||
reader.beginObject();
|
|
||||||
while(reader.hasNext()){
|
|
||||||
String name = reader.nextName();
|
|
||||||
switch(name){
|
|
||||||
case "version":
|
|
||||||
version = reader.nextString();
|
|
||||||
break;
|
|
||||||
case "ccp":
|
|
||||||
ccp = new Feature(reader);
|
|
||||||
break;
|
|
||||||
case "shadow":
|
|
||||||
shadow = new Feature(reader);
|
|
||||||
break;
|
|
||||||
case "addons":
|
|
||||||
reader.beginArray();
|
|
||||||
while(reader.hasNext()){
|
|
||||||
addons.add(new Addon(reader));
|
|
||||||
}
|
|
||||||
reader.endArray();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
reader.skipValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
reader.endObject();
|
|
||||||
reader.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
static class Addon{
|
|
||||||
UUID uuid = null;
|
|
||||||
String name = null;
|
|
||||||
|
|
||||||
Addon(JsonReader reader) throws IOException {
|
|
||||||
reader.beginObject();
|
|
||||||
while(reader.hasNext()){
|
|
||||||
String n = reader.nextName();
|
|
||||||
if(n.equals("uuid"))
|
|
||||||
try{
|
|
||||||
uuid = UUID.fromString(reader.nextString());
|
|
||||||
}catch(IllegalArgumentException ignored){
|
|
||||||
//ignored
|
|
||||||
}
|
|
||||||
else if(n.equals("name"))
|
|
||||||
name = reader.nextString();
|
|
||||||
else
|
|
||||||
reader.skipValue();
|
|
||||||
}
|
|
||||||
reader.endObject();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class Feature{
|
|
||||||
boolean enabled;
|
|
||||||
int version;
|
|
||||||
|
|
||||||
Feature(JsonReader reader) throws IOException {
|
|
||||||
reader.beginObject();
|
|
||||||
while(reader.hasNext()){
|
|
||||||
String name = reader.nextName();
|
|
||||||
if(name.equals("version"))
|
|
||||||
version = reader.nextInt();
|
|
||||||
else if(name.equals("enabled"))
|
|
||||||
enabled = reader.nextBoolean();
|
|
||||||
else
|
|
||||||
reader.skipValue();
|
|
||||||
}
|
|
||||||
reader.endObject();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,87 +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.listeners.mods;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.*;
|
|
||||||
import de.steamwar.bungeecore.listeners.BasicListener;
|
|
||||||
import net.md_5.bungee.api.connection.Connection;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
|
||||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
|
||||||
import net.md_5.bungee.api.event.ServerSwitchEvent;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class ModLoaderBlocker extends BasicListener {
|
|
||||||
|
|
||||||
private static final Set<String> BLOCKED_SERVER = new HashSet<>();
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPluginMessageEvent(PluginMessageEvent e){
|
|
||||||
Connection sender = e.getSender();
|
|
||||||
if(!(sender instanceof ProxiedPlayer))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(!e.getTag().equals("minecraft:brand"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
String brand = new String(e.getData());
|
|
||||||
if(brand.contains("fabric") || brand.contains("quilt")){
|
|
||||||
ProxiedPlayer p = (ProxiedPlayer) sender;
|
|
||||||
if (!Storage.fabricCheckedPlayers.containsKey(p) && !Storage.fabricPlayers.contains(p)) {
|
|
||||||
Storage.fabricPlayers.add(p);
|
|
||||||
Message.send("MODLOADER_INSTALLED_FABRIC", p, "Fabric");
|
|
||||||
}
|
|
||||||
}else if(brand.contains("LiteLoader")) {
|
|
||||||
ProxiedPlayer p = (ProxiedPlayer) sender;
|
|
||||||
if (!Storage.fabricPlayers.contains(p)) {
|
|
||||||
Storage.fabricPlayers.add(p);
|
|
||||||
Message.send("MODLOADER_INSTALLED", p, "LiteLoader");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onDisconnect(PlayerDisconnectEvent e){
|
|
||||||
Fabric.remove(e.getPlayer());
|
|
||||||
Storage.fabricPlayers.remove(e.getPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onServerSwitch(ServerSwitchEvent event) {
|
|
||||||
if(((Subserver.getSubserver(event.getPlayer()) != null
|
|
||||||
&& Subserver.getSubserver(event.getPlayer()).getType() == Servertype.ARENA)
|
|
||||||
|| BLOCKED_SERVER.contains(event.getPlayer().getServer().getInfo().getName()))
|
|
||||||
&& isFabric(event.getPlayer())) {
|
|
||||||
event.getPlayer().connect(BungeeCore.get().getProxy().getServerInfo(BungeeCore.LOBBY_SERVER));
|
|
||||||
Message.send("MODLOADER_DENIED", event.getPlayer());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isFabric(ProxiedPlayer player) {
|
|
||||||
return Storage.fabricPlayers.contains(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addServer(String server) {
|
|
||||||
BLOCKED_SERVER.add(server);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,117 +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.listeners.mods;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
|
||||||
import de.steamwar.bungeecore.Message;
|
|
||||||
import de.steamwar.bungeecore.commands.PunishmentCommand;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.messages.ChatSender;
|
|
||||||
import de.steamwar.sql.Mod;
|
|
||||||
import de.steamwar.sql.Mod.ModType;
|
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class Utils {
|
|
||||||
|
|
||||||
public static final Map<UUID,List<Mod>> playerModMap = new HashMap<>();
|
|
||||||
|
|
||||||
private Utils(){}
|
|
||||||
|
|
||||||
static VarInt readVarInt(byte[] array, int startPos) {
|
|
||||||
int numRead = 0;
|
|
||||||
int result = 0;
|
|
||||||
byte read;
|
|
||||||
do {
|
|
||||||
read = array[startPos + numRead];
|
|
||||||
int value = (read & 0b01111111);
|
|
||||||
result |= (value << (7 * numRead));
|
|
||||||
|
|
||||||
numRead++;
|
|
||||||
if (numRead > 5) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while ((read & 0b10000000) != 0);
|
|
||||||
|
|
||||||
return new VarInt(numRead, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean handleMods(ProxiedPlayer player, List<Mod> mods) {
|
|
||||||
return handleMods(player.getUniqueId(), ChatSender.of(player).getLocale(), player::disconnect, mods);
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean handleMods(UUID uuid, Locale locale, Consumer<BaseComponent[]> disconnect, List<Mod> mods){
|
|
||||||
SteamwarUser user = SteamwarUser.get(uuid);
|
|
||||||
boolean privileged = user.getUserGroup().isPrivilegedMods();
|
|
||||||
playerModMap.put(uuid,new ArrayList<>(mods));
|
|
||||||
|
|
||||||
ModType max = ModType.YELLOW;
|
|
||||||
Iterator<Mod> it = mods.iterator();
|
|
||||||
while(it.hasNext()){
|
|
||||||
Mod mod = it.next();
|
|
||||||
if(mod.getModType() == ModType.UNKLASSIFIED || mod.getModType() == ModType.GREEN || (mod.getModType() == ModType.YOUTUBER_ONLY && privileged))
|
|
||||||
it.remove();
|
|
||||||
else if(mod.getModType() == ModType.RED)
|
|
||||||
max = ModType.RED;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(mods.isEmpty()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ModType finalMax = max;
|
|
||||||
String modList = mods.stream().filter(mod -> finalMax == ModType.YELLOW || mod.getModType() == ModType.RED).map(Mod::getModName).collect(Collectors.joining("\n"));
|
|
||||||
String message;
|
|
||||||
|
|
||||||
if(mods.size() == 1) {
|
|
||||||
message = Message.parse(max == ModType.RED ? "MOD_RED_SING" : "MOD_YELLOW_SING", locale, modList);
|
|
||||||
} else {
|
|
||||||
message = Message.parse(max == ModType.RED ? "MOD_RED_PLUR" : "MOD_YELLOW_PLUR", locale, modList);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(max == ModType.RED) {
|
|
||||||
PunishmentCommand.ban(user, Timestamp.from(Instant.now().plus(7, ChronoUnit.DAYS)), message, SteamwarUser.get(-1), false);
|
|
||||||
BungeeCore.log(Level.SEVERE, user.getUserName() + " " + user.getId() + " wurde automatisch wegen der Mods " + modList + " gebannt.");
|
|
||||||
}
|
|
||||||
|
|
||||||
disconnect.accept(TextComponent.fromLegacyText(message));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static class VarInt{
|
|
||||||
final int length;
|
|
||||||
final int value;
|
|
||||||
|
|
||||||
VarInt(int length, int value){
|
|
||||||
this.length = length;
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
package de.steamwar.bungeecore.listeners.mods;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
import de.steamwar.bungeecore.listeners.BasicListener;
|
|
||||||
import de.steamwar.sql.Mod;
|
|
||||||
import net.md_5.bungee.api.connection.Connection;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class WorldDownloader extends BasicListener {
|
|
||||||
|
|
||||||
private static final Set<String> wdlTags = Collections.unmodifiableSet(
|
|
||||||
Sets.newHashSet("WDL|INIT", "wdl:init", "WDL|REQUEST", "wdl:request")
|
|
||||||
);
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPluginMessageEvent(PluginMessageEvent event){
|
|
||||||
if(!wdlTags.contains(event.getTag()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
Connection sender = event.getSender();
|
|
||||||
if(!(sender instanceof ProxiedPlayer))
|
|
||||||
return;
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
|
||||||
Utils.handleMods((ProxiedPlayer) sender, Lists.newArrayList(Mod.getOrCreate("wdl", Mod.Platform.FORGE)));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is a part of the SteamWar software.
|
|
||||||
|
|
||||||
Copyright (C) 2022 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.listeners.ping;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.listeners.BasicListener;
|
|
||||||
import net.md_5.bungee.api.event.ProxyPingEvent;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
|
|
||||||
public class PingListener extends BasicListener {
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPing(ProxyPingEvent event) {
|
|
||||||
event.setResponse(new SteamWarServerPing(event.getResponse(), event.getConnection().getVersion()));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,90 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is a part of the SteamWar software.
|
|
||||||
|
|
||||||
Copyright (C) 2022 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.listeners.ping;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.ServerPing;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class SteamWarServerPing extends ServerPing {
|
|
||||||
|
|
||||||
private final boolean preventsChatReports = true;
|
|
||||||
private final ForgeData forgeData;
|
|
||||||
|
|
||||||
public SteamWarServerPing(ServerPing existing, int version) {
|
|
||||||
super(existing.getVersion(), existing.getPlayers(), existing.getDescriptionComponent(), existing.getFaviconObject());
|
|
||||||
forgeData = new ForgeData(version);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ForgeData {
|
|
||||||
private final List<ForgeChannel> channels = new ArrayList<>();
|
|
||||||
private final List<ForgeMod> mods = new ArrayList<>();
|
|
||||||
private final int fmlNetworkVersion = 2;
|
|
||||||
|
|
||||||
public ForgeData(int versionNumber) {
|
|
||||||
channels.add(new ForgeChannel("minecraft:unregister"));
|
|
||||||
channels.add(new ForgeChannel("minecraft:register"));
|
|
||||||
channels.add(new ForgeChannel("fml:handshake"));
|
|
||||||
mods.add(new ForgeMod("minecraft", ProtocolVersion.getVersion(versionNumber)));
|
|
||||||
mods.add(new ForgeMod("forge", "ANY"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public final static class ProtocolVersion {
|
|
||||||
|
|
||||||
private static final HashMap<Integer, String> versions;
|
|
||||||
|
|
||||||
static {
|
|
||||||
versions = new HashMap();
|
|
||||||
versions.put(757, "1.18");
|
|
||||||
versions.put(756, "1.17.1");
|
|
||||||
versions.put(754, "1.16.5");
|
|
||||||
versions.put(578, "1.15.2");
|
|
||||||
versions.put(498, "1.14.1");
|
|
||||||
versions.put(393, "1.13");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getVersion(int version) {
|
|
||||||
return versions.get(version);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ForgeChannel {
|
|
||||||
private final String res;
|
|
||||||
private final String version = "FML2";
|
|
||||||
private final boolean required = true;
|
|
||||||
|
|
||||||
private ForgeChannel(String res) {
|
|
||||||
this.res = res;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ForgeMod {
|
|
||||||
private final String modId;
|
|
||||||
private final String modmarker;
|
|
||||||
|
|
||||||
private ForgeMod(String modId, String modmarker) {
|
|
||||||
this.modId = modId;
|
|
||||||
this.modmarker = modmarker;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 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.network;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.network.handlers.*;
|
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
|
|
||||||
@UtilityClass
|
|
||||||
public class BungeeNetworkHandler {
|
|
||||||
public static void register() {
|
|
||||||
new ExecuteCommandHandler().register();
|
|
||||||
new FightEndsHandler().register();
|
|
||||||
new FightInfoHandler().register();
|
|
||||||
new ImALobbyHandler().register();
|
|
||||||
new InventoryCallbackHandler().register();
|
|
||||||
new PrepareSchemHandler().register();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 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.network;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
|
||||||
import de.steamwar.bungeecore.commands.TeamCommand;
|
|
||||||
import de.steamwar.bungeecore.listeners.BasicListener;
|
|
||||||
import de.steamwar.sql.SWException;
|
|
||||||
import de.steamwar.network.packets.NetworkPacket;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.connection.Server;
|
|
||||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
import net.md_5.bungee.event.EventPriority;
|
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Base64;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class NetworkReceiver extends BasicListener {
|
|
||||||
|
|
||||||
private static final List<String> blockedTags = Arrays.asList("bungeecord:main", "BungeeCord", "sw:bridge");
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onPluginMessage(PluginMessageEvent event) {
|
|
||||||
if (blockedTags.contains(event.getTag()) && !TeamCommand.isLocalhost(((InetSocketAddress) event.getSender().getSocketAddress()).getAddress())) {
|
|
||||||
SWException.log(((InetSocketAddress) event.getSender().getSocketAddress()).getHostString() + " tried to send a plugin message with tag " + event.getTag(), Base64.getEncoder().encodeToString(event.getData()));
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!event.getTag().equals("sw:bridge"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
|
||||||
if(!(event.getSender() instanceof Server))
|
|
||||||
return;
|
|
||||||
|
|
||||||
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> NetworkPacket.handle(new ServerMetaInfo(((Server) event.getSender()).getInfo()), event.getData()));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 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.network;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.commands.TeamCommand;
|
|
||||||
import de.steamwar.bungeecore.listeners.BasicListener;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.connection.Server;
|
|
||||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
|
||||||
import net.md_5.bungee.event.EventPriority;
|
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
|
|
||||||
public class SWScriptSyntaxForwarder extends BasicListener {
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onPluginMessage(PluginMessageEvent event) {
|
|
||||||
if (!event.getTag().equals("sw:script_syntax")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
event.setCancelled(true);
|
|
||||||
if (!(event.getSender() instanceof Server)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!TeamCommand.isLocalhost(((InetSocketAddress) event.getSender().getSocketAddress()).getAddress())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
((ProxiedPlayer) event.getReceiver()).sendData("sw:script_syntax", event.getData());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,155 +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.network.handlers;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.ArenaMode;
|
|
||||||
import de.steamwar.network.packets.PacketHandler;
|
|
||||||
import de.steamwar.network.packets.common.FightEndsPacket;
|
|
||||||
import de.steamwar.sql.*;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class FightEndsHandler extends PacketHandler {
|
|
||||||
|
|
||||||
private Map<String, LinkedList<Game>> gameModeGames = new HashMap<>();
|
|
||||||
|
|
||||||
private int K = 20;
|
|
||||||
|
|
||||||
private long defaultFightRange = 1000 /* Milliseconds */ * 60 /* Seconds */ * 15L /* Minutes */;
|
|
||||||
private Map<String, Long> fightRanges = new HashMap<>();
|
|
||||||
private long defaultFightCount = 1;
|
|
||||||
private Map<String, Long> fightCounts = new HashMap<>();
|
|
||||||
|
|
||||||
{
|
|
||||||
fightRanges.put("miniwargear", 1000 /* Milliseconds */ * 60 /* Seconds */ * 30L /* Minutes */);
|
|
||||||
fightCounts.put("miniwargear", 3L);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Handler
|
|
||||||
public void handle(FightEndsPacket fightEndsPacket) {
|
|
||||||
if (!ArenaMode.getBySchemType(SchematicType.fromDB(fightEndsPacket.getGameMode())).isRanked()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bluePlayerSize = fightEndsPacket.getBluePlayers().size();
|
|
||||||
int redPlayerSize = fightEndsPacket.getRedPlayers().size();
|
|
||||||
double playerRatio = bluePlayerSize > redPlayerSize ? (double) redPlayerSize / bluePlayerSize : (double) bluePlayerSize / redPlayerSize;
|
|
||||||
if (playerRatio < 0.6) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean bluePublic = SchematicNode.getSchematicNode(fightEndsPacket.getBlueSchem()).getOwner() == 0;
|
|
||||||
boolean redPublic = SchematicNode.getSchematicNode(fightEndsPacket.getRedSchem()).getOwner() == 0;
|
|
||||||
|
|
||||||
if (bluePublic ^ redPublic) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
double blueResult;
|
|
||||||
if (fightEndsPacket.getWin() == 0) {
|
|
||||||
blueResult = 0.5;
|
|
||||||
} else if (fightEndsPacket.getWin() == 1) {
|
|
||||||
blueResult = 1;
|
|
||||||
} else {
|
|
||||||
blueResult = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Die nächsten Zeilen filtern ein Fight innerhalb eines Teams nicht gewertet wird, bzw auch wenn nur Teile beider Teams im
|
|
||||||
// gleichen Team sind dieser ungewertet ist.
|
|
||||||
Set<Integer> teamsIds = fightEndsPacket.getBluePlayers().stream().map(SteamwarUser::get).map(SteamwarUser::getTeam).collect(Collectors.toSet());
|
|
||||||
for (int redPlayer : fightEndsPacket.getRedPlayers()) {
|
|
||||||
if (teamsIds.contains(SteamwarUser.get(redPlayer).getTeam())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (teamComboExistedAlready(fightEndsPacket.getBluePlayers(), fightEndsPacket.getRedPlayers(), fightEndsPacket.getGameMode())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
gameModeGames.computeIfAbsent(fightEndsPacket.getGameMode(), s -> new LinkedList<>()).add(new Game(fightEndsPacket.getBluePlayers(), fightEndsPacket.getRedPlayers()));
|
|
||||||
}
|
|
||||||
|
|
||||||
int blueSchemElo = SchemElo.getCurrentElo(fightEndsPacket.getBlueSchem());
|
|
||||||
int redSchemElo = SchemElo.getCurrentElo(fightEndsPacket.getRedSchem());
|
|
||||||
|
|
||||||
int blueTeamElo = fightEndsPacket.getBluePlayers().stream().mapToInt(player -> UserElo.getEloOrDefault(player, fightEndsPacket.getGameMode())).sum();
|
|
||||||
int redTeamElo = fightEndsPacket.getRedPlayers().stream().mapToInt(player -> UserElo.getEloOrDefault(player, fightEndsPacket.getGameMode())).sum();
|
|
||||||
|
|
||||||
calculateEloOfTeam(fightEndsPacket.getBlueSchem(), blueSchemElo, redSchemElo, blueTeamElo, redTeamElo, blueResult, fightEndsPacket.getBluePlayers(), fightEndsPacket.getGameMode(), bluePublic || redPublic);
|
|
||||||
calculateEloOfTeam(fightEndsPacket.getRedSchem(), redSchemElo, blueSchemElo, redTeamElo, blueTeamElo, 1 - blueResult, fightEndsPacket.getRedPlayers(), fightEndsPacket.getGameMode(), bluePublic || redPublic);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void calculateEloOfTeam(int schemId, int eloSchemOwn, int eloSchemEnemy, int eloTeamOwn, int eloTeamEnemy, double result, List<Integer> players, String gameMode, boolean noPlayerRank) {
|
|
||||||
double winSchemExpectation = calsWinExpectation(eloSchemOwn, eloSchemEnemy);
|
|
||||||
SchemElo.setElo(schemId, (int) Math.round(eloSchemOwn + K * (result - winSchemExpectation)));
|
|
||||||
|
|
||||||
if (noPlayerRank) return;
|
|
||||||
double winTeamExpectation = calsWinExpectation(eloTeamOwn, eloTeamEnemy);
|
|
||||||
for (int player : players) {
|
|
||||||
int playerElo = UserElo.getEloOrDefault(player, gameMode);
|
|
||||||
int fights = UserElo.getFightsOfSeason(player, gameMode);
|
|
||||||
UserElo.setElo(player, gameMode, (int) Math.round(playerElo + getK(fights) * (result - winTeamExpectation)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private double calsWinExpectation(int eloOwn, int eloEnemy) {
|
|
||||||
return 1 / (1 + Math.pow(10, (eloEnemy - eloOwn) / 600f));
|
|
||||||
}
|
|
||||||
|
|
||||||
private double getK(int fights) {
|
|
||||||
return K * Math.max(1.3 - (fights / 200.0), 0.8);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean teamComboExistedAlready(List<Integer> bluePlayers, List<Integer> redPlayers, String gameMode) {
|
|
||||||
if (!gameModeGames.containsKey(gameMode)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
LinkedList<Game> games = gameModeGames.get(gameMode);
|
|
||||||
long lifetime = fightRanges.getOrDefault(gameMode, defaultFightRange);
|
|
||||||
while (!games.isEmpty()) {
|
|
||||||
Game game = games.getFirst();
|
|
||||||
if (game.livedMillis() > lifetime) {
|
|
||||||
games.removeFirst();
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return games.stream().filter(game -> game.isSame(bluePlayers, redPlayers)).count() > fightCounts.getOrDefault(gameMode, defaultFightCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
private static class Game {
|
|
||||||
private long time = System.currentTimeMillis();
|
|
||||||
private final List<Integer> bluePlayers;
|
|
||||||
private final List<Integer> redPlayers;
|
|
||||||
|
|
||||||
public long livedMillis() {
|
|
||||||
return System.currentTimeMillis() - time;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSame(List<Integer> bluePlayers, List<Integer> redPlayers) {
|
|
||||||
return bluePlayers.containsAll(this.bluePlayers) && redPlayers.containsAll(this.redPlayers);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,66 +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.network.handlers;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.network.NetworkSender;
|
|
||||||
import de.steamwar.bungeecore.network.ServerMetaInfo;
|
|
||||||
import de.steamwar.bungeecore.tablist.TablistManager;
|
|
||||||
import de.steamwar.network.packets.PacketHandler;
|
|
||||||
import de.steamwar.network.packets.common.FightInfoPacket;
|
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class FightInfoHandler extends PacketHandler {
|
|
||||||
|
|
||||||
private static final Set<ServerInfo> lobbys = new HashSet<>();
|
|
||||||
|
|
||||||
public static void addLobby(ServerInfo lobby) {
|
|
||||||
lobbys.add(lobby);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean onLobby(ProxiedPlayer player) {
|
|
||||||
return lobbys.contains(player.getServer().getInfo());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Handler
|
|
||||||
public void handle(FightInfoPacket packet) {
|
|
||||||
ServerInfo info = ((ServerMetaInfo) packet.getMetaInfos()).getSender();
|
|
||||||
|
|
||||||
FightInfoPacket lobbyPacket = packet.withServerName(info.getName());
|
|
||||||
|
|
||||||
TablistManager.newFightInfo(info, packet);
|
|
||||||
|
|
||||||
Iterator<ServerInfo> lobbyIt = lobbys.iterator();
|
|
||||||
while(lobbyIt.hasNext()) {
|
|
||||||
ServerInfo lobby = lobbyIt.next();
|
|
||||||
Iterator<ProxiedPlayer> it = lobby.getPlayers().iterator();
|
|
||||||
if(!it.hasNext()){
|
|
||||||
lobbyIt.remove();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
NetworkSender.send(lobby, lobbyPacket);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,360 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 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.tablist;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.Storage;
|
|
||||||
import de.steamwar.messages.ChatSender;
|
|
||||||
import io.netty.channel.ChannelHandler;
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
|
||||||
import io.netty.channel.ChannelPipeline;
|
|
||||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
|
||||||
import net.md_5.bungee.ServerConnection;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.chat.ComponentSerializer;
|
|
||||||
import net.md_5.bungee.netty.PipelineUtils;
|
|
||||||
import net.md_5.bungee.protocol.DefinedPacket;
|
|
||||||
import net.md_5.bungee.protocol.PacketWrapper;
|
|
||||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
|
||||||
import net.md_5.bungee.protocol.packet.*;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.IntStream;
|
|
||||||
|
|
||||||
@ChannelHandler.Sharable
|
|
||||||
public class Tablist extends MessageToMessageDecoder<PacketWrapper> {
|
|
||||||
|
|
||||||
private static final UUID[] uuids = IntStream.range(0, 80).mapToObj(i -> UUID.randomUUID()).toArray(UUID[]::new);
|
|
||||||
private static final String[] names = IntStream.range(0, 80).mapToObj(i -> " »SW« " + String.format("%02d", i)).toArray(String[]::new);
|
|
||||||
private static final String TAB_TEAM = "»SW-Tab";
|
|
||||||
private static final Team teamPacket = new Team(TAB_TEAM, (byte) 0, ComponentSerializer.toString(TextComponent.fromLegacyText("")), ComponentSerializer.toString(TextComponent.fromLegacyText("")), ComponentSerializer.toString(TextComponent.fromLegacyText("")), "never", "always", 21, (byte)0x00, names);
|
|
||||||
|
|
||||||
private final Map<UUID, PlayerListItem.Item> directTabItems;
|
|
||||||
private final Set<UUID> npcs = new HashSet<>();
|
|
||||||
private final List<PlayerListItem.Item> current = new ArrayList<>();
|
|
||||||
|
|
||||||
private final ProxiedPlayer player;
|
|
||||||
private final ChatSender viewer;
|
|
||||||
private ServerConnection connection;
|
|
||||||
|
|
||||||
public Tablist(ProxiedPlayer player) {
|
|
||||||
this.player = player;
|
|
||||||
this.viewer = ChatSender.of(player);
|
|
||||||
this.directTabItems = Storage.directTabItems.computeIfAbsent(player, p -> new HashMap<>());
|
|
||||||
injection();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update(TablistPart global, int seconds) {
|
|
||||||
if (connection == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
player.unsafe().sendPacket(new PlayerListHeaderFooter(
|
|
||||||
ComponentSerializer.toString(header(viewer, seconds)),
|
|
||||||
ComponentSerializer.toString(viewer.parse(false, "TABLIST_FOOTER", connection.getInfo().getName(), ping(), ProxyServer.getInstance().getPlayers().size()))
|
|
||||||
));
|
|
||||||
|
|
||||||
List<TablistPart.Item> tablist = new ArrayList<>();
|
|
||||||
List<TablistPart.Item> direct = new ArrayList<>();
|
|
||||||
global.print(viewer, player, tablist, direct);
|
|
||||||
|
|
||||||
// NPC handling
|
|
||||||
List<String> addNpc = new ArrayList<>();
|
|
||||||
List<String> removeNpc = new ArrayList<>();
|
|
||||||
List<PlayerListItem.Item> update = new ArrayList<>();
|
|
||||||
Set<UUID> nonNPCs = direct.stream().map(TablistPart.Item::getUuid).collect(Collectors.toSet());
|
|
||||||
synchronized (directTabItems) {
|
|
||||||
for (TablistPart.Item item : direct) {
|
|
||||||
PlayerListItem.Item tabItem = directTabItems.get(item.getUuid());
|
|
||||||
|
|
||||||
if(npcs.remove(item.getUuid()))
|
|
||||||
removeNpc.add(tabItem.getUsername());
|
|
||||||
|
|
||||||
if(tabItem == null) {
|
|
||||||
tablist.add(0, item);
|
|
||||||
} else if(!tabItem.getDisplayName().equals(item.getDisplayName())) {
|
|
||||||
tabItem.setDisplayName(item.getDisplayName());
|
|
||||||
tabItem.setListed(true);
|
|
||||||
update.add(tabItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(PlayerListItem.Item item : directTabItems.values()) {
|
|
||||||
if(!nonNPCs.contains(item.getUuid()) && !npcs.contains(item.getUuid())) {
|
|
||||||
npcs.add(item.getUuid());
|
|
||||||
addNpc.add(item.getUsername());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sendNpcPacket(addNpc, false);
|
|
||||||
sendNpcPacket(removeNpc, true);
|
|
||||||
|
|
||||||
// Main list handling
|
|
||||||
int i = 0;
|
|
||||||
List<PlayerListItem.Item> add = new ArrayList<>();
|
|
||||||
List<PlayerListItem.Item> remove = new ArrayList<>();
|
|
||||||
for (; i < tablist.size() && i < 80; i++) {
|
|
||||||
PlayerListItem.Item tabItem;
|
|
||||||
if(current.size() > i) {
|
|
||||||
tabItem = current.get(i);
|
|
||||||
} else {
|
|
||||||
tabItem = new PlayerListItem.Item();
|
|
||||||
tabItem.setUuid(uuids[i]);
|
|
||||||
tabItem.setUsername(names[i]);
|
|
||||||
tabItem.setGamemode(1);
|
|
||||||
tabItem.setListed(true);
|
|
||||||
tabItem.setPing(1000);
|
|
||||||
current.add(tabItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
TablistPart.Item item = tablist.get(i);
|
|
||||||
if(!Arrays.equals(tabItem.getProperties(), item.getProperties())) {
|
|
||||||
tabItem.setProperties(item.getProperties());
|
|
||||||
tabItem.setDisplayName(item.getDisplayName());
|
|
||||||
add.add(tabItem);
|
|
||||||
if(current.size() > i) {
|
|
||||||
remove.add(tabItem);
|
|
||||||
}
|
|
||||||
} else if(!item.getDisplayName().equals(tabItem.getDisplayName())) {
|
|
||||||
tabItem.setDisplayName(item.getDisplayName());
|
|
||||||
update.add(tabItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Excess removal
|
|
||||||
while(i < current.size()) {
|
|
||||||
remove.add(current.remove(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
sendTabPacket(remove, PlayerListItem.Action.REMOVE_PLAYER);
|
|
||||||
sendTabPacket(update, PlayerListItem.Action.UPDATE_DISPLAY_NAME);
|
|
||||||
sendTabPacket(add, PlayerListItem.Action.ADD_PLAYER);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onServerSwitch() {
|
|
||||||
injection();
|
|
||||||
|
|
||||||
synchronized (directTabItems) {
|
|
||||||
sendNpcPacket(npcs.stream().map(npc -> directTabItems.get(npc).getUsername()).collect(Collectors.toList()), true);
|
|
||||||
directTabItems.clear();
|
|
||||||
npcs.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void injection() {
|
|
||||||
connection = (ServerConnection) player.getServer();
|
|
||||||
|
|
||||||
if(connection != null) {
|
|
||||||
ChannelPipeline pipeline = connection.getCh().getHandle().pipeline();
|
|
||||||
if(pipeline.get("steamwar-tablist") != null) //Catch unclean exit
|
|
||||||
pipeline.remove("steamwar-tablist");
|
|
||||||
|
|
||||||
pipeline.addBefore(PipelineUtils.BOSS_HANDLER, "steamwar-tablist", this);
|
|
||||||
player.unsafe().sendPacket(teamPacket);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void disable() {
|
|
||||||
sendTabPacket(current, PlayerListItem.Action.REMOVE_PLAYER);
|
|
||||||
current.clear();
|
|
||||||
synchronized (directTabItems) {
|
|
||||||
sendNpcPacket(npcs.stream().map(npc -> directTabItems.get(npc).getUsername()).collect(Collectors.toList()), true);
|
|
||||||
npcs.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(connection != null)
|
|
||||||
connection.getCh().getHandle().pipeline().remove(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void decode(ChannelHandlerContext ctx, PacketWrapper packetWrapper, List<Object> out) {
|
|
||||||
if(!connection.isObsolete()) {
|
|
||||||
DefinedPacket packet = packetWrapper.packet;
|
|
||||||
|
|
||||||
if(packet instanceof PlayerListHeaderFooter) {
|
|
||||||
packetWrapper.trySingleRelease();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(packet instanceof PlayerListItem) {
|
|
||||||
PlayerListItem list = (PlayerListItem) packet;
|
|
||||||
PlayerListItem.Action action = list.getAction();
|
|
||||||
|
|
||||||
switch(action) {
|
|
||||||
case UPDATE_LATENCY:
|
|
||||||
case UPDATE_DISPLAY_NAME:
|
|
||||||
packetWrapper.trySingleRelease();
|
|
||||||
return;
|
|
||||||
case UPDATE_GAMEMODE:
|
|
||||||
for (PlayerListItem.Item item : list.getItems()) {
|
|
||||||
ProxiedPlayer p = ProxyServer.getInstance().getPlayer(item.getUuid());
|
|
||||||
if(p != null && p != player && item.getGamemode() == 3) {
|
|
||||||
item.setGamemode(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ADD_PLAYER:
|
|
||||||
for (PlayerListItem.Item item : list.getItems()) {
|
|
||||||
item.setPing(1);
|
|
||||||
item.setDisplayName(ComponentSerializer.toString(TextComponent.fromLegacyText("")));
|
|
||||||
item.setListed(false);
|
|
||||||
item.setPublicKey(null);
|
|
||||||
if(!player.getUniqueId().equals(item.getUuid()) && item.getGamemode() == 3)
|
|
||||||
item.setGamemode(1);
|
|
||||||
|
|
||||||
synchronized (directTabItems) {
|
|
||||||
directTabItems.put(item.getUuid(), item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case REMOVE_PLAYER:
|
|
||||||
List<String> names = new ArrayList<>();
|
|
||||||
for(PlayerListItem.Item item : list.getItems()) {
|
|
||||||
synchronized (directTabItems) {
|
|
||||||
PlayerListItem.Item directItem = directTabItems.remove(item.getUuid());
|
|
||||||
if(npcs.remove(item.getUuid()))
|
|
||||||
names.add(directItem.getUsername());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sendNpcPacket(names, true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else if(packet instanceof PlayerListItemRemove) {
|
|
||||||
List<String> names = new ArrayList<>();
|
|
||||||
for(UUID uuid : ((PlayerListItemRemove) packet).getUuids()) {
|
|
||||||
synchronized (directTabItems) {
|
|
||||||
PlayerListItem.Item directItem = directTabItems.remove(uuid);
|
|
||||||
if(npcs.remove(uuid))
|
|
||||||
names.add(directItem.getUsername());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sendNpcPacket(names, true);
|
|
||||||
} else if(packet instanceof PlayerListItemUpdate) {
|
|
||||||
PlayerListItemUpdate list = (PlayerListItemUpdate) packet;
|
|
||||||
EnumSet<PlayerListItemUpdate.Action> actions = list.getActions();
|
|
||||||
actions.remove(PlayerListItemUpdate.Action.INITIALIZE_CHAT);
|
|
||||||
actions.remove(PlayerListItemUpdate.Action.UPDATE_LATENCY);
|
|
||||||
actions.remove(PlayerListItemUpdate.Action.UPDATE_DISPLAY_NAME);
|
|
||||||
actions.remove(PlayerListItemUpdate.Action.UPDATE_LISTED);
|
|
||||||
if(actions.isEmpty()) {
|
|
||||||
packetWrapper.trySingleRelease();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(PlayerListItemUpdate.Action action : actions) {
|
|
||||||
switch (action) {
|
|
||||||
case ADD_PLAYER:
|
|
||||||
for (PlayerListItem.Item item : list.getItems()) {
|
|
||||||
item.setPing(1);
|
|
||||||
item.setDisplayName(ComponentSerializer.toString(TextComponent.fromLegacyText("")));
|
|
||||||
item.setListed(false);
|
|
||||||
item.setPublicKey(null);
|
|
||||||
if(!player.getUniqueId().equals(item.getUuid()) && item.getGamemode() == 3)
|
|
||||||
item.setGamemode(1);
|
|
||||||
|
|
||||||
synchronized (directTabItems) {
|
|
||||||
directTabItems.put(item.getUuid(), item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case UPDATE_GAMEMODE:
|
|
||||||
for (PlayerListItem.Item item : list.getItems()) {
|
|
||||||
ProxiedPlayer p = ProxyServer.getInstance().getPlayer(item.getUuid());
|
|
||||||
if(p != null && p != player && item.getGamemode() == 3) {
|
|
||||||
item.setGamemode(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case UPDATE_LISTED:
|
|
||||||
case INITIALIZE_CHAT:
|
|
||||||
case UPDATE_LATENCY:
|
|
||||||
case UPDATE_DISPLAY_NAME:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(actions.contains(PlayerListItemUpdate.Action.ADD_PLAYER)) {
|
|
||||||
actions.add(PlayerListItemUpdate.Action.UPDATE_LISTED);
|
|
||||||
actions.add(PlayerListItemUpdate.Action.UPDATE_DISPLAY_NAME);
|
|
||||||
actions.add(PlayerListItemUpdate.Action.UPDATE_LATENCY);
|
|
||||||
actions.add(PlayerListItemUpdate.Action.UPDATE_GAMEMODE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
out.add(packetWrapper);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean oldTab() {
|
|
||||||
return player.getPendingConnection().getVersion() < ProtocolConstants.MINECRAFT_1_19_3;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendTabPacket(List<PlayerListItem.Item> items, PlayerListItem.Action action) { //Breaks in 1.19.3 if action != UPDATE_DISPLAY_NAME, ADD_PLAYER or REMOVE_PLAYER
|
|
||||||
if(!items.isEmpty()) {
|
|
||||||
if(oldTab()) {
|
|
||||||
PlayerListItem packet = new PlayerListItem();
|
|
||||||
packet.setAction(action);
|
|
||||||
packet.setItems(items.toArray(new PlayerListItem.Item[0]));
|
|
||||||
player.unsafe().sendPacket(packet);
|
|
||||||
} else if(action == PlayerListItem.Action.REMOVE_PLAYER) {
|
|
||||||
PlayerListItemRemove packet = new PlayerListItemRemove();
|
|
||||||
packet.setUuids(items.stream().map(PlayerListItem.Item::getUuid).toArray(UUID[]::new));
|
|
||||||
player.unsafe().sendPacket(packet);
|
|
||||||
} else {
|
|
||||||
PlayerListItemUpdate packet = new PlayerListItemUpdate();
|
|
||||||
packet.setActions(action == PlayerListItem.Action.UPDATE_DISPLAY_NAME ? EnumSet.of(PlayerListItemUpdate.Action.UPDATE_DISPLAY_NAME, PlayerListItemUpdate.Action.UPDATE_LISTED) : EnumSet.of(PlayerListItemUpdate.Action.ADD_PLAYER, PlayerListItemUpdate.Action.UPDATE_DISPLAY_NAME, PlayerListItemUpdate.Action.UPDATE_LATENCY, PlayerListItemUpdate.Action.UPDATE_LISTED, PlayerListItemUpdate.Action.UPDATE_GAMEMODE));
|
|
||||||
packet.setItems(items.toArray(new PlayerListItem.Item[0]));
|
|
||||||
player.unsafe().sendPacket(packet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendNpcPacket(List<String> names, boolean remove) {
|
|
||||||
if(!names.isEmpty()) {
|
|
||||||
Team packet = new Team(TAB_TEAM);
|
|
||||||
packet.setMode((byte) (remove ? 4 : 3));
|
|
||||||
packet.setPlayers(names.toArray(new String[0]));
|
|
||||||
player.unsafe().sendPacket(packet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private BaseComponent[] header(ChatSender p, int seconds) {
|
|
||||||
int phase = (seconds % 16) / 3;
|
|
||||||
switch (phase) {
|
|
||||||
case 0:
|
|
||||||
return p.parse(false, "TABLIST_PHASE_1");
|
|
||||||
case 1:
|
|
||||||
return p.parse(false, "TABLIST_PHASE_2");
|
|
||||||
default:
|
|
||||||
return p.parse(false, "TABLIST_PHASE_DEFAULT");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String ping() {
|
|
||||||
int ping = player.getPing();
|
|
||||||
if (ping < 50) {
|
|
||||||
return "§a" + ping;
|
|
||||||
} else if (ping < 150) {
|
|
||||||
return "§e" + ping;
|
|
||||||
} else {
|
|
||||||
return "§c" + ping;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,90 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 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.tablist;
|
|
||||||
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.sql.UserGroup;
|
|
||||||
import de.steamwar.messages.ChatSender;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.chat.ComponentSerializer;
|
|
||||||
import net.md_5.bungee.connection.InitialHandler;
|
|
||||||
import net.md_5.bungee.connection.LoginResult;
|
|
||||||
import net.md_5.bungee.protocol.Property;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
interface TablistPart {
|
|
||||||
String sortKey();
|
|
||||||
void print(ChatSender viewer, ProxiedPlayer player, List<Item> tablist, List<Item> direct);
|
|
||||||
|
|
||||||
class Item {
|
|
||||||
|
|
||||||
public static Property[] playerProperties(ProxiedPlayer player) {
|
|
||||||
LoginResult loginResult = ((InitialHandler) player.getPendingConnection()).getLoginProfile();
|
|
||||||
if(loginResult == null)
|
|
||||||
return new Property[0];
|
|
||||||
|
|
||||||
return loginResult.getProperties();
|
|
||||||
}
|
|
||||||
|
|
||||||
private final UUID uuid;
|
|
||||||
private final String displayName;
|
|
||||||
private final Property[] properties;
|
|
||||||
|
|
||||||
public Item(UUID uuid, String displayName, Property[] properties) {
|
|
||||||
this.uuid = uuid;
|
|
||||||
this.displayName = reformat(displayName);
|
|
||||||
this.properties = properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Item(ProxiedPlayer player) {
|
|
||||||
this(player, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Item(ProxiedPlayer player, boolean sameTeam) {
|
|
||||||
this.uuid = player.getUniqueId();
|
|
||||||
UserGroup userGroup = SteamwarUser.get(player.getUniqueId()).getUserGroup();
|
|
||||||
if (userGroup == UserGroup.Member && sameTeam) {
|
|
||||||
this.displayName = reformat("§f" + player.getName());
|
|
||||||
} else {
|
|
||||||
this.displayName = reformat(userGroup.getColorCode() + player.getName());
|
|
||||||
}
|
|
||||||
this.properties = playerProperties(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getUuid() {
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDisplayName() {
|
|
||||||
return displayName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Property[] getProperties() {
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String reformat(String string) {
|
|
||||||
return ComponentSerializer.toString(TextComponent.fromLegacyText(string));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,103 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 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.tablist;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.Servertype;
|
|
||||||
import de.steamwar.bungeecore.Subserver;
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import de.steamwar.messages.ChatSender;
|
|
||||||
import de.steamwar.network.packets.common.FightInfoPacket;
|
|
||||||
import net.md_5.bungee.BungeeCord;
|
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.protocol.Property;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
public class TablistServer implements TablistPart {
|
|
||||||
|
|
||||||
public static final Property[] GRAY = new Property[]{new Property("textures", "eyJ0aW1lc3RhbXAiOjE0NTU1NzQxMTk0MzMsInByb2ZpbGVJZCI6ImIzYjE4MzQ1MzViZjRiNzU4ZTBjZGJmMGY4MjA2NTZlIiwicHJvZmlsZU5hbWUiOiIxMDExMTEiLCJzaWduYXR1cmVSZXF1aXJlZCI6dHJ1ZSwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlLzZlNzJkMzE0NzczMmQ5NzFkZWZhZTIzMWIzOGQ5NDI0MTRiMDU3YTcxNTFjNTNjNWZkNjI5NmEzYjllZGEwYWIifX19", "ro/ZKHt7278yhCr+CFTcPp/q6wAUlef//85k2DzkfRaZqy0CtGgwisDs2U4pVKvQ2pfXvitzWgbJvD0bLeQ12xWi4c1Fc29LCArosVJoFmrJDHz7N2MlstHT+ynQROb9d2aiFA6uOXfLjPKb1noUZ/YQoZjqcPIvD5oFZtD5DHV5O4hYz0IvgHbIjDqjz6ITsTcKiBlbxNg2loTFxSlW1ZfnNCO+kcAmeyB5NFY3j0e+/AqVANiNoiC3OKsECM/yEx/acf+vKWcT8mQn4wRoIGtxfEU7ZjNtgdh73NvXXBygW+K9AiJ242g8Y06Xxuk8kaNEGmT6H/mM7nbwjZmQQXpi/Pao2gYqyeIofeCPfr8RsGXoDX3nXDAw8/LyhTCHgx+sp6IQYSfGcSMJtoNeTJ0liIFxqn1V9/zKmzOZAPzR6qrQPOjoRFljLAlv7rfzotaEqh/1ldd40GdS8tstczn7f29OQerNDaqvbDb00Gy0STdUr1bVyCDptA54XKjT9WFv7QpBikEculxqSppAXPxD2Fb/ZmphbZx8WEGfG6bVFhf6fQdDAUXlcv8BxjElNPwlolF86M2KJd5VquLluhrCjwID7OK/pffNultAVH+Lxw4QOAXmJqjUrA1KHgyG1S0Cwj/f4E2hdxZJBvkfVtq9qPkd9nignhEoTCTOHf0=")};
|
|
||||||
public static final Property[] LIGHT_GRAY = new Property[]{new Property("textures", "eyJ0aW1lc3RhbXAiOjE0NTU2MjU1OTM5NjIsInByb2ZpbGVJZCI6ImIzYjE4MzQ1MzViZjRiNzU4ZTBjZGJmMGY4MjA2NTZlIiwicHJvZmlsZU5hbWUiOiIxMDExMTEiLCJzaWduYXR1cmVSZXF1aXJlZCI6dHJ1ZSwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlLzc4Y2I3ZmMyMDhiMzM4NTUwNGE4MTQ0MjA0NDI4ZmRjZDYzMjRiZWIzMWNhMmNlODZjYzQyNGI5NjNkODVjIn19fQ==", "R/wZUZRC1dishRdM9a2SSxxW3oYa0XSb/MxHbQpEUA791HxyqjaKLDu0wFX2r2a8ZTeVjzXpNzkg3+PkrA11o8h7lt86MTD1pi/rQqj/WRuoqf2LP+ypbssKV+LU15cYez2cj3QQVcJDXgWEnfSLNuBv6NG8BDUpUAjTWldvu99NCJHUoD0jNMHxY/fu4k5vCgOjaBaKgkjVk2bmUhegusmtMwco+3pYx+y8+gUW8ptx5SnePG+dOwTqLyBFiOt2AQ+gSvbU/jP9aAXgxOwz/b1pMaBWtzVhFU865NHlIdSpIHg/sh3uNah3a7gTgtTvxPQv1OzM/KtqYKiamsrRzAQMzRcs4A7Tp0GakLuxEaz401IwvQ7UGVYLFzGUVLB2MyqtPgifiqQSQxZpiqj9sM5QadhsUw00nfX7mTdW46U0MtNIbby1rLrvgQKoj08zt6LJlhI3yjyawy4iZkgF4oc+PCNwZc93GIbVL9LJaGkXk3RVA+JpGwfMJrGVbL7hl8ibbAcUv7uCEWdkAgZCd6w75jEE4tlhDSPDD4rXbn+FeTZRg2n/PGKtnoTZRzbniiFaNoSAHDZSVRG39xvBDFvtmL3SPaKhzKaifiYrgNn453WtR3kymqdAtPf1GN9d1VltGZ/+vMPwqPJb6thcrlcU64UGHbg1olRkiyZHvY8=")};
|
|
||||||
|
|
||||||
private final ServerInfo server;
|
|
||||||
private final List<Item> players;
|
|
||||||
|
|
||||||
public TablistServer(ServerInfo server) {
|
|
||||||
this(server, server.getPlayers().stream().sorted((p1, p2) -> p1.getName().compareToIgnoreCase(p2.getName())).map(TablistPart.Item::new).collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public TablistServer(ServerInfo server, FightInfoPacket info) {
|
|
||||||
this(server, new ArrayList<>());
|
|
||||||
|
|
||||||
Collection<ProxiedPlayer> onlinePlayers = server.getPlayers();
|
|
||||||
addPlayers(info.getBlueName().substring(0, 2), info.getBluePlayers(), onlinePlayers);
|
|
||||||
addPlayers(info.getRedName().substring(0, 2), info.getRedPlayers(), onlinePlayers);
|
|
||||||
addPlayers("§7", info.getSpectators(), onlinePlayers);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TablistServer(ServerInfo server, List<Item> players) {
|
|
||||||
this.server = server;
|
|
||||||
this.players = players;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String sortKey() {
|
|
||||||
return server.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void print(ChatSender viewer, ProxiedPlayer player, List<Item> tablist, List<Item> direct) {
|
|
||||||
boolean onServer = player.getServer().getInfo() == server;
|
|
||||||
List<Item> items = onServer ? direct : tablist;
|
|
||||||
|
|
||||||
if(!onServer) {
|
|
||||||
items.add(new Item(null, "", GRAY));
|
|
||||||
items.add(new Item(null, "§7§l" + server.getName(), LIGHT_GRAY));
|
|
||||||
}
|
|
||||||
|
|
||||||
teamify(players, player).forEach(items::add);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addPlayers(String prefix, List<Integer> teamPlayers, Collection<ProxiedPlayer> onlinePlayers){
|
|
||||||
teamPlayers.stream().map(SteamwarUser::get).map(
|
|
||||||
user -> onlinePlayers.stream().filter(player -> player.getUniqueId().equals(user.getUUID())).findAny()
|
|
||||||
).filter(Optional::isPresent).map(Optional::get).sorted(
|
|
||||||
(p1, p2) -> p1.getName().compareToIgnoreCase(p2.getName())
|
|
||||||
).forEachOrdered(player -> players.add(new Item(player.getUniqueId(), prefix + player.getName(), Item.playerProperties(player))));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Stream<Item> teamify(List<Item> players, ProxiedPlayer player) {
|
|
||||||
int team = SteamwarUser.get(player.getUniqueId()).getTeam();
|
|
||||||
if (team == 0) return players.stream();
|
|
||||||
return players.stream().map(item -> {
|
|
||||||
ProxiedPlayer p = BungeeCord.getInstance().getPlayer(item.getUuid());
|
|
||||||
if (p == null) return item;
|
|
||||||
Subserver subserver = Subserver.getSubserver(p.getServer().getInfo());
|
|
||||||
if (subserver != null && subserver.getType() == Servertype.ARENA) return item;
|
|
||||||
if (SteamwarUser.get(p.getUniqueId()).getTeam() != team) return item;
|
|
||||||
return new Item(p, true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2022 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.util;
|
|
||||||
|
|
||||||
import net.md_5.bungee.ServerConnection;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.protocol.ChatChain;
|
|
||||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
|
||||||
import net.md_5.bungee.protocol.SeenMessages;
|
|
||||||
import net.md_5.bungee.protocol.packet.ClientChat;
|
|
||||||
import net.md_5.bungee.protocol.packet.ClientCommand;
|
|
||||||
|
|
||||||
import java.util.BitSet;
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
public class Chat19 {
|
|
||||||
private Chat19(){}
|
|
||||||
|
|
||||||
public static void chat(ProxiedPlayer p, String message) {
|
|
||||||
int version = p.getPendingConnection().getVersion();
|
|
||||||
if(version >= ProtocolConstants.MINECRAFT_1_19) {
|
|
||||||
if(message.startsWith("/")) {
|
|
||||||
((ServerConnection) p.getServer()).getCh().write(new ClientCommand(message.substring(1), System.currentTimeMillis(), 0, Collections.emptyMap(), false, new ChatChain(Collections.emptyList(), null), new SeenMessages(0, new BitSet(0))));
|
|
||||||
} else {
|
|
||||||
((ServerConnection) p.getServer()).getCh().write(new ClientChat(message, System.currentTimeMillis(), 0, version < ProtocolConstants.MINECRAFT_1_19_3 ? new byte[0] : null, false, new ChatChain(Collections.emptyList(), null), new SeenMessages(0, new BitSet(0))));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
p.chat(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +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.command;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
|
||||||
|
|
||||||
@UtilityClass
|
|
||||||
class CommandRegistering {
|
|
||||||
|
|
||||||
static void unregister(Command command) {
|
|
||||||
ProxyServer.getInstance().getPluginManager().unregisterCommand(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void register(Command command) {
|
|
||||||
ProxyServer.getInstance().getPluginManager().registerCommand(BungeeCore.get(), command);
|
|
||||||
}
|
|
||||||
}
|
|
@ -19,96 +19,111 @@
|
|||||||
|
|
||||||
package de.steamwar.command;
|
package de.steamwar.command;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
import com.velocitypowered.api.command.SimpleCommand;
|
||||||
import de.steamwar.bungeecore.Message;
|
import de.steamwar.messages.Chatter;
|
||||||
import de.steamwar.messages.ChatSender;
|
import de.steamwar.messages.Message;
|
||||||
import net.md_5.bungee.BungeeCord;
|
import de.steamwar.sql.UserPerm;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import de.steamwar.velocitycore.VelocityCore;
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
import de.steamwar.velocitycore.discord.DiscordBot;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import lombok.Getter;
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
import net.kyori.adventure.text.event.ClickEvent;
|
||||||
import net.md_5.bungee.api.plugin.TabExecutor;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class SWCommand extends AbstractSWCommand<CommandSender> {
|
public class SWCommand extends AbstractSWCommand<Chatter> {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
TypeUtils.init();
|
TypeUtils.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String permission;
|
private final String name;
|
||||||
private Command command;
|
@Getter
|
||||||
|
private final UserPerm permission;
|
||||||
|
private final String[] aliases;
|
||||||
|
|
||||||
private List<String> defaultHelpMessages = new ArrayList<>();
|
private SimpleCommand command;
|
||||||
|
|
||||||
protected SWCommand(String command) {
|
private final List<String> defaultHelpMessages = new ArrayList<>();
|
||||||
this(command, null);
|
|
||||||
|
protected SWCommand(String command, String... aliases) {
|
||||||
|
this(command, null, aliases);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SWCommand(String command, String permission) {
|
protected SWCommand(String command, UserPerm permission, String... aliases) {
|
||||||
this(command, permission, new String[0]);
|
super(Chatter.class, command, aliases);
|
||||||
}
|
this.name = command;
|
||||||
|
|
||||||
protected SWCommand(String command, String permission, String... aliases) {
|
|
||||||
super(CommandSender.class, command, aliases);
|
|
||||||
this.permission = permission;
|
this.permission = permission;
|
||||||
|
this.aliases = aliases;
|
||||||
create = true;
|
create = true;
|
||||||
createAndSafeCommand(command, aliases);
|
createAndSafeCommand(command, aliases);
|
||||||
unregister();
|
unregister();
|
||||||
register();
|
register();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void execute(Chatter sender, String[] args) {
|
||||||
|
execute(sender, null, args);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean create = false;
|
private boolean create = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void createAndSafeCommand(String command, String[] aliases) {
|
protected void createAndSafeCommand(String command, String[] aliases) {
|
||||||
if (!create) return;
|
if (!create) return;
|
||||||
this.command = new TabCompletableCommand(command, permission, aliases) {
|
this.command = new SimpleCommand() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender commandSender, String[] strings) {
|
public void execute(Invocation invocation) {
|
||||||
SWCommand.this.execute(commandSender, null, strings);
|
SWCommand.this.execute(Chatter.of(invocation.source()), invocation.alias(), invocation.arguments());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<String> onTabComplete(CommandSender commandSender, String[] strings) {
|
public List<String> suggest(Invocation invocation) {
|
||||||
return SWCommand.this.tabComplete(commandSender, null, strings);
|
String[] args = invocation.arguments();
|
||||||
|
if(args.length == 0)
|
||||||
|
args = new String[]{""};
|
||||||
|
|
||||||
|
return SWCommand.this.tabComplete(Chatter.of(invocation.source()), invocation.alias(), args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPermission(Invocation invocation) {
|
||||||
|
return permission == null || Chatter.of(invocation.source()).user().perms().contains(permission);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private abstract static class TabCompletableCommand extends Command implements TabExecutor {
|
|
||||||
public TabCompletableCommand(String name, String permission, String... aliases) {
|
|
||||||
super(name, permission, aliases);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unregister() {
|
public void unregister() {
|
||||||
if (command == null) return;
|
if (command == null)
|
||||||
CommandRegistering.unregister(this.command);
|
return;
|
||||||
|
|
||||||
|
VelocityCore.getProxy().getCommandManager().unregister(name);
|
||||||
|
DiscordBot.getCommands().remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void register() {
|
public void register() {
|
||||||
if (command == null) return;
|
if (command == null)
|
||||||
CommandRegistering.register(this.command);
|
return;
|
||||||
|
|
||||||
|
VelocityCore.getProxy().getCommandManager().register(VelocityCore.getProxy().getCommandManager().metaBuilder(name).aliases(aliases).plugin(VelocityCore.get()).build(), command);
|
||||||
|
DiscordBot.getCommands().put(name, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void commandSystemError(CommandSender sender, CommandFrameworkException e) {
|
protected void commandSystemError(Chatter sender, CommandFrameworkException e) {
|
||||||
BungeeCore.get().getLogger().log(Level.SEVERE, e.getMessage(), e);
|
VelocityCore.getLogger().log(Level.SEVERE, e.getMessage(), e);
|
||||||
ChatSender.of(sender).prefixless("COMMAND_SYSTEM_ERROR");
|
sender.prefixless("COMMAND_SYSTEM_ERROR");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void commandSystemWarning(Supplier<String> message) {
|
protected void commandSystemWarning(Supplier<String> message) {
|
||||||
BungeeCore.get().getLogger().log(Level.WARNING, message);
|
VelocityCore.getLogger().log(Level.WARNING, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDefaultHelpMessage(String message) {
|
public void addDefaultHelpMessage(String message) {
|
||||||
@ -116,24 +131,23 @@ public class SWCommand extends AbstractSWCommand<CommandSender> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void sendMessage(CommandSender sender, String message, Object[] args) {
|
protected void sendMessage(Chatter sender, String message, Object[] args) {
|
||||||
ChatSender.of(sender).system(message, args);
|
sender.system(message, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(noTabComplete = true)
|
@Register(noTabComplete = true)
|
||||||
public void internalHelp(ProxiedPlayer p, String... args) {
|
public void internalHelp(Chatter sender, String... args) {
|
||||||
ChatSender chatSender = ChatSender.of(p);
|
|
||||||
try {
|
try {
|
||||||
chatSender.prefixless("COMMAND_HELP_HEAD", command.getName());
|
sender.prefixless("COMMAND_HELP_HEAD", name);
|
||||||
defaultHelpMessages.forEach(chatSender::prefixless);
|
defaultHelpMessages.forEach(sender::prefixless);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
BungeeCore.get().getLogger().log(Level.WARNING, "Failed to send help message", e);
|
VelocityCore.getLogger().log(Level.WARNING, "Failed to send help message", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AtomicInteger atomicInteger = new AtomicInteger();
|
AtomicInteger atomicInteger = new AtomicInteger();
|
||||||
if (args.length != 0) {
|
if (args.length != 0) {
|
||||||
commandList.forEach(subCommand -> {
|
commandList.forEach(subCommand -> {
|
||||||
List<String> tabCompletes = subCommand.tabComplete(p, args);
|
List<String> tabCompletes = subCommand.tabComplete(sender, args);
|
||||||
if (tabCompletes == null || tabCompletes.isEmpty()) {
|
if (tabCompletes == null || tabCompletes.isEmpty()) {
|
||||||
atomicInteger.incrementAndGet();
|
atomicInteger.incrementAndGet();
|
||||||
return;
|
return;
|
||||||
@ -141,7 +155,7 @@ public class SWCommand extends AbstractSWCommand<CommandSender> {
|
|||||||
boolean hasTabCompletes = tabCompletes.stream()
|
boolean hasTabCompletes = tabCompletes.stream()
|
||||||
.anyMatch(s -> s.toLowerCase().startsWith(args[args.length - 1].toLowerCase()));
|
.anyMatch(s -> s.toLowerCase().startsWith(args[args.length - 1].toLowerCase()));
|
||||||
if (hasTabCompletes) {
|
if (hasTabCompletes) {
|
||||||
send(chatSender, subCommand);
|
send(sender, subCommand);
|
||||||
} else {
|
} else {
|
||||||
atomicInteger.incrementAndGet();
|
atomicInteger.incrementAndGet();
|
||||||
}
|
}
|
||||||
@ -149,22 +163,21 @@ public class SWCommand extends AbstractSWCommand<CommandSender> {
|
|||||||
}
|
}
|
||||||
if (args.length == 0 || atomicInteger.get() == commandList.size()) {
|
if (args.length == 0 || atomicInteger.get() == commandList.size()) {
|
||||||
commandList.forEach(subCommand -> {
|
commandList.forEach(subCommand -> {
|
||||||
if (subCommand.validator == null || subCommand.validator.validate(p, p, (s, args1) -> {})) {
|
if (subCommand.validator == null || subCommand.validator.validate(sender, sender, (s, args1) -> {})) {
|
||||||
send(chatSender, subCommand);
|
send(sender, subCommand);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void send(ChatSender chatSender, SubCommand<CommandSender> subCommand) {
|
private void send(Chatter chatter, SubCommand<Chatter> subCommand) {
|
||||||
try {
|
try {
|
||||||
for (String s : subCommand.description) {
|
for (String s : subCommand.description) {
|
||||||
String hover = "§8/§e" + command.getName() + " " + String.join(" ", subCommand.subCommand);
|
String hover = "§8/§e" + name + " " + String.join(" ", subCommand.subCommand);
|
||||||
String suggest = "/" + command.getName() + " " + String.join(" ", subCommand.subCommand);
|
chatter.prefixless(s, new Message("PLAIN_STRING", hover), ClickEvent.suggestCommand("/" + name + " " + String.join(" ", subCommand.subCommand)));
|
||||||
chatSender.prefixless(s, new Message("PLAIN_STRING", hover), new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, suggest));
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
BungeeCore.get().getLogger().log(Level.WARNING, "Failed to send description of registered method '" + subCommand.method + "' with description '" + subCommand.description + "'", e);
|
VelocityCore.getLogger().log(Level.WARNING, "Failed to send description of registered method '%s' with description '%s'".formatted(subCommand.method, Arrays.toString(subCommand.description)), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,11 @@
|
|||||||
|
|
||||||
package de.steamwar.command;
|
package de.steamwar.command;
|
||||||
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import de.steamwar.messages.Chatter;
|
||||||
|
|
||||||
public interface TypeMapper<T> extends AbstractTypeMapper<CommandSender, T> {
|
public interface TypeMapper<T> extends AbstractTypeMapper<Chatter, T> {
|
||||||
/**
|
/**
|
||||||
* The CommandSender can be null!
|
* The CommandSender can be null!
|
||||||
*/
|
*/
|
||||||
T map(CommandSender commandSender, String[] previousArguments, String s);
|
T map(Chatter sender, PreviousArguments previousArguments, String s);
|
||||||
}
|
}
|
||||||
|
@ -19,20 +19,56 @@
|
|||||||
|
|
||||||
package de.steamwar.command;
|
package de.steamwar.command;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.commands.TypeMappers;
|
import com.velocitypowered.api.network.ProtocolVersion;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import de.steamwar.velocitycore.ServerVersion;
|
||||||
|
import de.steamwar.velocitycore.VelocityCore;
|
||||||
|
import de.steamwar.velocitycore.commands.TypeMappers;
|
||||||
|
import de.steamwar.messages.Chatter;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
|
import de.steamwar.sql.Team;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import net.md_5.bungee.BungeeCord;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class TypeUtils {
|
public class TypeUtils {
|
||||||
|
|
||||||
static void init() {
|
static void init() {
|
||||||
SWCommandUtils.addMapper(ProxiedPlayer.class, SWCommandUtils.createMapper(BungeeCord.getInstance()::getPlayer, (s) -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList())));
|
SWCommandUtils.addMapper(Player.class, SWCommandUtils.createMapper(s -> VelocityCore.getProxy().getPlayer(s).orElse(null), s -> VelocityCore.getProxy().getAllPlayers().stream().map(Player::getUsername).collect(Collectors.toList())));
|
||||||
SWCommandUtils.addMapper(SteamwarUser.class, SWCommandUtils.createMapper(SteamwarUser::get, s -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList())));
|
SWCommandUtils.addMapper(SteamwarUser.class, SWCommandUtils.createMapper(SteamwarUser::get, s -> VelocityCore.getProxy().getAllPlayers().stream().map(Player::getUsername).collect(Collectors.toList())));
|
||||||
|
SWCommandUtils.addMapper(ServerVersion.class, new TypeMapper<>() {
|
||||||
|
@Override
|
||||||
|
public ServerVersion map(Chatter sender, PreviousArguments previousArguments, String s) {
|
||||||
|
Player player = sender.getPlayer();
|
||||||
|
if (player != null && s.isEmpty()) {
|
||||||
|
ProtocolVersion version = player.getProtocolVersion();
|
||||||
|
if (version.greaterThan(ProtocolVersion.MINECRAFT_1_19_4)) {
|
||||||
|
return ServerVersion.PAPER_20;
|
||||||
|
} else if (version.greaterThan(ProtocolVersion.MINECRAFT_1_15_2)) {
|
||||||
|
return ServerVersion.PAPER_19;
|
||||||
|
} else if (version.greaterThan(ProtocolVersion.MINECRAFT_1_12_2)) {
|
||||||
|
return ServerVersion.SPIGOT_15;
|
||||||
|
} else {
|
||||||
|
return ServerVersion.SPIGOT_12;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ServerVersion.get(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> tabCompletes(Chatter sender, PreviousArguments previousArguments, String s) {
|
||||||
|
return ServerVersion.chatVersions();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
AbstractTypeMapper<Object, Team> teamMapper = SWCommandUtils.createMapper(Team::get, s -> Team.getAll().stream().flatMap(team -> Stream.of(team.getTeamKuerzel(), team.getTeamName())).collect(Collectors.toList()));
|
||||||
|
TabCompletionCache.add(teamMapper, true, 10, TimeUnit.SECONDS);
|
||||||
|
SWCommandUtils.addMapper(Team.class, teamMapper);
|
||||||
|
|
||||||
TypeMappers.init();
|
TypeMappers.init();
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
package de.steamwar.command;
|
package de.steamwar.command;
|
||||||
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import de.steamwar.messages.Chatter;
|
||||||
|
|
||||||
public interface TypeValidator<T> extends AbstractValidator<CommandSender, T> {
|
public interface TypeValidator<T> extends AbstractValidator<Chatter, T> {}
|
||||||
}
|
|
||||||
|
Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden Mehr anzeigen
In neuem Issue referenzieren
Einen Benutzer sperren