mirror of
https://github.com/RayzsYT/ProAntiTab.git
synced 2026-11-13 12:41:58 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
36145b1ee7 | ||
|
|
5f457c6e4a | ||
|
|
65dc540577 | ||
|
|
c338e29ec4 | ||
|
|
c253f6684b | ||
|
|
aa740ffabf | ||
|
|
e9ffe83a93 | ||
|
|
c83e83bb06 | ||
|
|
b3c2e014c1 | ||
|
|
6631da42e1 | ||
|
|
ac5233582f | ||
|
|
32a1f4351a | ||
|
|
2ff88eeb03 | ||
|
|
62b505450a | ||
|
|
f7fd9dd42a | ||
|
|
acd8e9291a | ||
|
|
50c80fc708 | ||
|
|
bb02672085 | ||
|
|
f2e7efeaa6 | ||
|
|
aa0863e726 | ||
|
|
71cec6933f | ||
|
|
c2d407cd62 | ||
|
|
61adaa19db | ||
|
|
4c1cc0683d | ||
|
|
ce3b42af38 | ||
|
|
61c204ade0 | ||
|
|
e13fae6e67 | ||
|
|
31e4c3caa4 | ||
|
|
bccb77667d | ||
|
|
4ab0791740 | ||
|
|
a9afbad0a2 | ||
|
|
d625212ac1 | ||
|
|
ee23b2d47e | ||
|
|
30714d5b7d | ||
|
|
07734f70bb | ||
|
|
367d0cec7e | ||
|
|
ad00b95b88 | ||
|
|
9530b415c7 | ||
|
|
aff33cf99e | ||
|
|
83666bfce3 | ||
|
|
ca5f5670e5 | ||
|
|
ba15d4700e | ||
|
|
55bc9bb642 | ||
|
|
2728e6c141 | ||
|
|
2fde07aad2 | ||
|
|
aa6877e423 | ||
|
|
5e88bcd9be | ||
|
|
c117048ecb | ||
|
|
5ade086d6c | ||
|
|
78a59912f3 | ||
|
|
4997017f0f | ||
|
|
24ba7e179a | ||
|
|
2d3d8ba220 | ||
|
|
f3ceace3ba | ||
|
|
6b743772cb | ||
|
|
d66c02d0ec | ||
|
|
09764ab98c | ||
|
|
02f54c986b | ||
|
|
eaad46b391 | ||
|
|
29ee010aad | ||
|
|
9210100335 | ||
|
|
621fb6740d | ||
|
|
d26400f6d6 | ||
|
|
5a4674368a | ||
|
|
3b0a0a4db2 | ||
|
|
8263df961b | ||
|
|
d8a425665b | ||
|
|
cca0a12dcf | ||
|
|
b452d8e031 | ||
|
|
0fb3225f7c | ||
|
|
0ee6953180 | ||
|
|
0602616265 | ||
|
|
89b3a01c71 | ||
|
|
e65fea42f3 | ||
|
|
d5e1ac1968 | ||
|
|
70e2d6805b | ||
|
|
0370891b68 | ||
|
|
22f5737980 | ||
|
|
4c99a226be | ||
|
|
80c8dc7e53 | ||
|
|
912732a6c3 | ||
|
|
76dd4722cf | ||
|
|
676b2d1c0a | ||
|
|
133cad70ef | ||
|
|
62355aa6db | ||
|
|
be8b625a90 | ||
|
|
ee4a1da3d5 | ||
|
|
992a3eda18 | ||
|
|
37f02b6902 | ||
|
|
cbdf43174a | ||
|
|
80becff090 | ||
|
|
ffd52212e1 |
No files matched your search
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>de.rayzs.pat</groupId>
|
||||
<artifactId>ProAntiTab</artifactId>
|
||||
<version>1.9.2</version>
|
||||
<version>2.0.8</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
@@ -72,23 +72,10 @@
|
||||
<url>https://repo.william278.net/papiproxybridge</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>skript-releases</id>
|
||||
<name>Skript Repository</name>
|
||||
<url>https://repo.skriptlang.org/releases</url>
|
||||
</repository>
|
||||
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.skriptlang</groupId>
|
||||
<artifactId>Skript</artifactId>
|
||||
<version>2.10.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.folia</groupId>
|
||||
<artifactId>folia-api</artifactId>
|
||||
@@ -106,7 +93,7 @@
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
<version>4.0.23.Final</version>
|
||||
<version>4.2.0.Final</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -233,14 +220,14 @@
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-minimessage</artifactId>
|
||||
<version>4.18.0</version>
|
||||
<version>4.20.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-api</artifactId>
|
||||
<version>4.18.0</version>
|
||||
<version>4.20.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -254,14 +241,14 @@
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bungeecord</artifactId>
|
||||
<version>4.3.3</version>
|
||||
<version>4.3.4</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bukkit</artifactId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.4</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -319,6 +306,14 @@
|
||||
</artifactSet>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>16</source>
|
||||
<target>16</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package de.rayzs.pat.api.brand;
|
||||
|
||||
import de.rayzs.pat.api.brand.impl.*;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.PacketUtils;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.api.brand.impl.*;
|
||||
|
||||
public class CustomServerBrand {
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package de.rayzs.pat.api.brand.impl;
|
||||
|
||||
import de.rayzs.pat.api.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.api.netty.bukkit.BukkitPacketAnalyzer;
|
||||
import de.rayzs.pat.api.brand.ServerBrand;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
@@ -8,7 +10,6 @@ import de.rayzs.pat.plugin.BukkitLoader;
|
||||
import de.rayzs.pat.utils.scheduler.PATScheduler;
|
||||
import de.rayzs.pat.utils.scheduler.PATSchedulerTask;
|
||||
import io.netty.channel.Channel;
|
||||
import de.rayzs.pat.api.brand.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import de.rayzs.pat.utils.*;
|
||||
@@ -18,17 +19,19 @@ import java.util.*;
|
||||
|
||||
public class BukkitServerBrand implements ServerBrand {
|
||||
|
||||
private static final List<Player> MODIFIED_BRAND_PLAYERS = new ArrayList<>();
|
||||
private static final Server SERVER = Bukkit.getServer();
|
||||
private static String BRAND = Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().get(0);
|
||||
private static PATSchedulerTask TASK;
|
||||
private static boolean INITIALIZED = false;
|
||||
private static boolean INITIALIZED = false, NO_PREP_CHANNELS = false;
|
||||
private static Class<?> brandPayloadClass, clientBoundCustomPacketPayloadPacketClass, customPacketPayloadPacketClass;
|
||||
|
||||
@Override
|
||||
public void initializeTask() {
|
||||
|
||||
if(Reflection.isWeird()) {
|
||||
if (Reflection.isWeird()) {
|
||||
|
||||
NO_PREP_CHANNELS = Reflection.getMinor() >= 22 || (Reflection.getMinor() == 21 && Reflection.getRelease() >= 7);
|
||||
|
||||
if (brandPayloadClass == null)
|
||||
brandPayloadClass = Reflection.getClass("net.minecraft.network.protocol.common.custom.BrandPayload");
|
||||
|
||||
@@ -40,7 +43,7 @@ public class BukkitServerBrand implements ServerBrand {
|
||||
}
|
||||
|
||||
Bukkit.getOnlinePlayers().forEach(this::preparePlayer);
|
||||
if(!INITIALIZED)
|
||||
if (!INITIALIZED)
|
||||
try {
|
||||
Method method = Reflection.getMethodsByParameterAndName(SERVER.getMessenger(), "addToOutgoing", Plugin.class, String.class).get(0);
|
||||
Reflection.invokeMethode(method, SERVER.getMessenger(), BukkitLoader.getPlugin(), CustomServerBrand.CHANNEL_NAME);
|
||||
@@ -53,7 +56,6 @@ public class BukkitServerBrand implements ServerBrand {
|
||||
if(TASK != null && TASK.isActive()) {
|
||||
TASK.cancelTask();
|
||||
TASK = null;
|
||||
MODIFIED_BRAND_PLAYERS.clear();
|
||||
}
|
||||
|
||||
if(!Storage.ConfigSections.Settings.CUSTOM_BRAND.ENABLED) return;
|
||||
@@ -81,12 +83,16 @@ public class BukkitServerBrand implements ServerBrand {
|
||||
if(!(playerObj instanceof Player) || !Storage.ConfigSections.Settings.CUSTOM_BRAND.ENABLED) return;
|
||||
Player player = (Player) playerObj;
|
||||
|
||||
if (NO_PREP_CHANNELS) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Field channelsField = Reflection.getFieldByName(player.getClass(), "channels");
|
||||
Set<String> channels = (Set<String>) channelsField.get(player);
|
||||
channels.add(CustomServerBrand.CHANNEL_NAME);
|
||||
Reflection.closeAccess(channelsField);
|
||||
if(!MODIFIED_BRAND_PLAYERS.contains(player)) MODIFIED_BRAND_PLAYERS.add(player);
|
||||
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
@@ -112,6 +118,7 @@ public class BukkitServerBrand implements ServerBrand {
|
||||
|
||||
Object brandPayloadObj = brandPayloadClass.getDeclaredConstructor(String.class).newInstance(MessageTranslator.replaceMessage(player, customBrand)),
|
||||
customPacketPayloadPacket = clientBoundCustomPacketPayloadPacketClass.getDeclaredConstructor(customPacketPayloadPacketClass).newInstance(brandPayloadObj);
|
||||
|
||||
channel.pipeline().writeAndFlush(customPacketPayloadPacket);
|
||||
|
||||
} catch (Exception exception) {
|
||||
@@ -123,13 +130,4 @@ public class BukkitServerBrand implements ServerBrand {
|
||||
public PacketUtils.BrandManipulate createPacket(Object playerObj) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isModified(Player player) {
|
||||
if(!Storage.ConfigSections.Settings.CUSTOM_BRAND.ENABLED || Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY != -1) return false;
|
||||
return MODIFIED_BRAND_PLAYERS.contains(player);
|
||||
}
|
||||
|
||||
public static void removeFromModified(Player player) {
|
||||
MODIFIED_BRAND_PLAYERS.remove(player);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package de.rayzs.pat.api.command;
|
||||
|
||||
import de.rayzs.pat.utils.*;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public abstract class ProCommand {
|
||||
|
||||
private final String name;
|
||||
private final List<String> aliases;
|
||||
|
||||
protected boolean proxyOnly = false, serverCommand = false;
|
||||
|
||||
public ProCommand(String name, String... aliases) {
|
||||
this.name = name.toLowerCase();
|
||||
this.aliases = aliases != null && !aliases[0].isBlank() ? Arrays.asList(aliases) : new ArrayList<>();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isProxyOnly() {
|
||||
return proxyOnly;
|
||||
}
|
||||
|
||||
public boolean isServerCommand() {
|
||||
return serverCommand;
|
||||
}
|
||||
|
||||
public List<String> getAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
public boolean isCommand(String label) {
|
||||
String commandName = StringUtils.getFirstArg(label);
|
||||
|
||||
if (name.equalsIgnoreCase(commandName))
|
||||
return true;
|
||||
|
||||
return !aliases.isEmpty() && aliases.stream().anyMatch(commandName::equalsIgnoreCase);
|
||||
}
|
||||
|
||||
public abstract boolean execute(CommandSender sender, String[] args);
|
||||
public abstract List<String> tabComplete(CommandSender sender, String[] args);
|
||||
}
|
||||
@@ -21,8 +21,10 @@ public class BackendUpdater {
|
||||
if(isRunning()) return;
|
||||
|
||||
TASK = PATScheduler.createScheduler(() -> {
|
||||
if (shouldRun()) Communicator.sendRequest();
|
||||
else stop();
|
||||
if (shouldRun())
|
||||
Communicator.sendRequest();
|
||||
else
|
||||
stop();
|
||||
}, 5, 20);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,26 +1,42 @@
|
||||
package de.rayzs.pat.api.communication;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import de.rayzs.pat.api.communication.client.ClientInfo;
|
||||
import de.rayzs.pat.api.communication.client.impl.*;
|
||||
import de.rayzs.pat.api.communication.client.impl.BungeeClientInfo;
|
||||
import de.rayzs.pat.api.communication.client.impl.VelocityClientInfo;
|
||||
import de.rayzs.pat.api.communication.impl.BukkitClient;
|
||||
import de.rayzs.pat.api.communication.impl.BungeeClient;
|
||||
import de.rayzs.pat.api.communication.impl.VelocityClient;
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import de.rayzs.pat.api.storage.blacklist.impl.*;
|
||||
import de.rayzs.pat.api.communication.impl.*;
|
||||
import de.rayzs.pat.plugin.BukkitLoader;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import de.rayzs.pat.utils.group.*;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import java.util.*;
|
||||
import de.rayzs.pat.api.storage.blacklist.impl.GeneralBlacklist;
|
||||
import de.rayzs.pat.api.storage.blacklist.impl.GroupBlacklist;
|
||||
import de.rayzs.pat.plugin.BukkitLoader;
|
||||
import de.rayzs.pat.utils.CommunicationPackets;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
import de.rayzs.pat.utils.group.TinyGroup;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
|
||||
public class Communicator {
|
||||
|
||||
private static final Client CLIENT = Reflection.isVelocityServer() ? new VelocityClient() : Reflection.isProxyServer() ? new BungeeClient() : new BukkitClient();
|
||||
private static final Client CLIENT =
|
||||
Reflection.isVelocityServer() ? new VelocityClient()
|
||||
: Reflection.isProxyServer() ? new BungeeClient()
|
||||
: new BukkitClient();
|
||||
|
||||
private static final UUID SERVER_ID = UUID.randomUUID();
|
||||
|
||||
public static final List<ClientInfo> CLIENTS = new ArrayList<>();
|
||||
private static final ExpireCache<String, ClientInfo> QUEUE_CLIENTS = new ExpireCache<>(15, TimeUnit.SECONDS);
|
||||
public static long LAST_DATA_UPDATE = System.currentTimeMillis(), LAST_SENT_REQUEST = 0, LAST_BUKKIT_SYNC = System.currentTimeMillis();
|
||||
|
||||
public static int SERVER_DATA_SYNC_COUNT = 0;
|
||||
public static long LAST_DATA_UPDATE = System.currentTimeMillis(),
|
||||
LAST_SENT_REQUEST = 0,
|
||||
LAST_BUKKIT_SYNC = System.currentTimeMillis();
|
||||
|
||||
public static void sendPacket(Object packet) {
|
||||
CLIENT.send(packet);
|
||||
@@ -31,52 +47,76 @@ public class Communicator {
|
||||
}
|
||||
|
||||
public static void receiveInformation(String serverName, Object packet) {
|
||||
if(packet instanceof CommunicationPackets.RequestPacket) {
|
||||
CommunicationPackets.RequestPacket requestPacket = (CommunicationPackets.RequestPacket) packet;
|
||||
if (!requestPacket.isToken(Storage.TOKEN)) return;
|
||||
ClientInfo client = getClientByName(serverName);
|
||||
|
||||
if (packet instanceof CommunicationPackets.RequestPacket) {
|
||||
|
||||
CommunicationPackets.RequestPacket requestPacket = (CommunicationPackets.RequestPacket) packet;
|
||||
|
||||
if (!requestPacket.isToken(Storage.TOKEN))
|
||||
return;
|
||||
|
||||
ClientInfo client = getClientByName(serverName);
|
||||
if (client == null) {
|
||||
client = Reflection.isVelocityServer() ? new VelocityClientInfo(requestPacket.getServerId(), serverName) : new BungeeClientInfo(requestPacket.getServerId(), serverName);
|
||||
client = Reflection.isVelocityServer()
|
||||
? new VelocityClientInfo(requestPacket.getServerId(), serverName)
|
||||
: new BungeeClientInfo(requestPacket.getServerId(), serverName);
|
||||
|
||||
CLIENTS.add(client);
|
||||
}
|
||||
|
||||
if (!client.compareId(requestPacket.getServerId())) client.setId(requestPacket.getServerId());
|
||||
if (!client.compareId(requestPacket.getServerId()))
|
||||
client.setId(requestPacket.getServerId());
|
||||
|
||||
syncData(client.getId());
|
||||
return;
|
||||
}
|
||||
|
||||
if(packet instanceof CommunicationPackets.ForcePermissionResetPacket) {
|
||||
if(Reflection.isProxyServer()) return;
|
||||
CommunicationPackets.ForcePermissionResetPacket permissionResetPacket = (CommunicationPackets.ForcePermissionResetPacket) packet;
|
||||
if(!permissionResetPacket.isToken(Storage.TOKEN)) return;
|
||||
if (packet instanceof CommunicationPackets.ForcePermissionResetPacket) {
|
||||
if (Reflection.isProxyServer())
|
||||
return;
|
||||
|
||||
CommunicationPackets.ForcePermissionResetPacket permissionResetPacket = (CommunicationPackets.ForcePermissionResetPacket) packet;
|
||||
if (!permissionResetPacket.isToken(Storage.TOKEN))
|
||||
return;
|
||||
|
||||
if (permissionResetPacket.hasTarget())
|
||||
PermissionUtil.setPlayerPermissions(permissionResetPacket.getTargetUUID());
|
||||
else
|
||||
PermissionUtil.reloadPermissions();
|
||||
|
||||
if(permissionResetPacket.hasTarget()) PermissionUtil.setPlayerPermissions(permissionResetPacket.getTargetUUID());
|
||||
else PermissionUtil.reloadPermissions();
|
||||
return;
|
||||
}
|
||||
|
||||
if(packet instanceof CommunicationPackets.BackendDataPacket) {
|
||||
if (packet instanceof CommunicationPackets.BackendDataPacket) {
|
||||
CommunicationPackets.BackendDataPacket backendDataPacket = (CommunicationPackets.BackendDataPacket) packet;
|
||||
if (!backendDataPacket.isToken(Storage.TOKEN)) return;
|
||||
if (!backendDataPacket.isToken(Storage.TOKEN))
|
||||
return;
|
||||
|
||||
Storage.SERVER_NAME = backendDataPacket.getServerName();
|
||||
return;
|
||||
}
|
||||
|
||||
if(packet instanceof CommunicationPackets.FeedbackPacket) {
|
||||
if (packet instanceof CommunicationPackets.FeedbackPacket) {
|
||||
CommunicationPackets.FeedbackPacket feedbackPacket = (CommunicationPackets.FeedbackPacket) packet;
|
||||
if (!feedbackPacket.isToken(Storage.TOKEN)) return;
|
||||
if (!feedbackPacket.isToken(Storage.TOKEN))
|
||||
return;
|
||||
|
||||
String serverId = feedbackPacket.getServerId();
|
||||
|
||||
ClientInfo client = getClientByName(serverName);
|
||||
if (client == null) {
|
||||
client = Reflection.isVelocityServer() ? new VelocityClientInfo(feedbackPacket.getServerId(), serverName) : new BungeeClientInfo(feedbackPacket.getServerId(), serverName);
|
||||
client = Reflection.isVelocityServer()
|
||||
? new VelocityClientInfo(feedbackPacket.getServerId(), serverName)
|
||||
: new BungeeClientInfo(feedbackPacket.getServerId(), serverName);
|
||||
|
||||
CLIENTS.add(client);
|
||||
}
|
||||
|
||||
if (!client.compareId(feedbackPacket.getServerId())) client.setId(feedbackPacket.getServerId());
|
||||
if (client.hasSentFeedback()) return;
|
||||
if (!client.compareId(feedbackPacket.getServerId()))
|
||||
client.setId(feedbackPacket.getServerId());
|
||||
|
||||
if (client.hasSentFeedback())
|
||||
return;
|
||||
|
||||
client.setFeedback(true);
|
||||
client.syncTime();
|
||||
SERVER_DATA_SYNC_COUNT++;
|
||||
@@ -86,9 +126,10 @@ public class Communicator {
|
||||
return;
|
||||
}
|
||||
|
||||
if(packet instanceof CommunicationPackets.PacketBundle) {
|
||||
if (packet instanceof CommunicationPackets.PacketBundle) {
|
||||
CommunicationPackets.PacketBundle packetBundle = (CommunicationPackets.PacketBundle) packet;
|
||||
if(!packetBundle.isToken(Storage.TOKEN) || !packetBundle.isId(SERVER_ID.toString())) return;
|
||||
if (!packetBundle.isToken(Storage.TOKEN) || !packetBundle.isId(SERVER_ID.toString()))
|
||||
return;
|
||||
|
||||
Storage.USE_VELOCITY = packetBundle.isVelocity();
|
||||
LAST_BUKKIT_SYNC = System.currentTimeMillis();
|
||||
@@ -101,20 +142,24 @@ public class Communicator {
|
||||
}
|
||||
|
||||
public static void syncData(String serverId) {
|
||||
if (Storage.ConfigSections.Settings.DISABLE_SYNC.DISABLED) return;
|
||||
if (Storage.ConfigSections.Settings.DISABLE_SYNC.DISABLED)
|
||||
return;
|
||||
|
||||
LAST_DATA_UPDATE = System.currentTimeMillis();
|
||||
ClientInfo clientInfo;
|
||||
|
||||
if(serverId == null) {
|
||||
SERVER_DATA_SYNC_COUNT = 0;
|
||||
CLIENTS.forEach(currentClient -> syncData(currentClient.getId()));
|
||||
return;
|
||||
|
||||
} else {
|
||||
clientInfo = getClientById(serverId);
|
||||
if(clientInfo != null) clientInfo.setFeedback(false);
|
||||
|
||||
SERVER_DATA_SYNC_COUNT = SERVER_DATA_SYNC_COUNT -1;
|
||||
if(SERVER_DATA_SYNC_COUNT <= 0) SERVER_DATA_SYNC_COUNT = 0;
|
||||
if (clientInfo != null)
|
||||
clientInfo.setFeedback(false);
|
||||
|
||||
SERVER_DATA_SYNC_COUNT = Math.max(0, SERVER_DATA_SYNC_COUNT -1);
|
||||
}
|
||||
|
||||
CommunicationPackets.CommandsPacket commandsPacket = new CommunicationPackets.CommandsPacket();
|
||||
@@ -123,13 +168,18 @@ public class Communicator {
|
||||
List<String> commands = new ArrayList<>();
|
||||
String tempServerName = "";
|
||||
|
||||
if(clientInfo != null && clientInfo.getName() != null) {
|
||||
tempServerName = clientInfo.getName().toLowerCase();
|
||||
if(!Storage.Blacklist.isOnIgnoredServer(tempServerName))
|
||||
if (clientInfo != null && clientInfo.getName() != null) {
|
||||
tempServerName = clientInfo.getName();
|
||||
|
||||
if (!Storage.Blacklist.isIgnoredServer(tempServerName))
|
||||
commands.addAll(Storage.Blacklist.getBlacklist().getCommands());
|
||||
|
||||
List<GeneralBlacklist> serverBlacklists = Storage.Blacklist.getBlacklists(clientInfo.getName());
|
||||
serverBlacklists.stream().filter(serverBlacklist -> serverBlacklist != null && serverBlacklist.getCommands() != null).forEach(serverBlacklist -> commands.addAll(serverBlacklist.getCommands()));
|
||||
List<GeneralBlacklist> serverBlacklists = Storage.Blacklist.getServerBlacklists(clientInfo.getName());
|
||||
serverBlacklists.stream().filter(serverBlacklist ->
|
||||
serverBlacklist != null && serverBlacklist.getCommands() != null
|
||||
).forEach(serverBlacklist ->
|
||||
commands.addAll(serverBlacklist.getCommands())
|
||||
);
|
||||
}
|
||||
|
||||
final String serverName = tempServerName;
|
||||
@@ -137,7 +187,8 @@ public class Communicator {
|
||||
|
||||
TinyGroup tinyGroup;
|
||||
for (Group group : GroupManager.getGroups()) {
|
||||
if(groups.stream().anyMatch(cTG -> cTG.getGroupName().equals(group.getGroupName()))) continue;
|
||||
if (groups.stream().anyMatch(cTG -> cTG.getGroupName().equals(group.getGroupName())))
|
||||
continue;
|
||||
|
||||
tinyGroup = new TinyGroup(group.getGroupName(), group.getPriority(), group.getAllCommands(serverName));
|
||||
for (GroupBlacklist groupBlacklist : group.getAllServerGroupBlacklist(serverName))
|
||||
@@ -168,11 +219,6 @@ public class Communicator {
|
||||
sendPacket(new CommunicationPackets.ForcePermissionResetPacket(Storage.TOKEN));
|
||||
}
|
||||
|
||||
public static void sendFeedback(UUID targetUUID) {
|
||||
if(Reflection.isProxyServer())
|
||||
sendPacket(new CommunicationPackets.ForcePermissionResetPacket(Storage.TOKEN, targetUUID));
|
||||
}
|
||||
|
||||
public static void sendFeedback() {
|
||||
sendPacket(new CommunicationPackets.FeedbackPacket(Storage.TOKEN, SERVER_ID.toString()));
|
||||
}
|
||||
@@ -188,18 +234,4 @@ public class Communicator {
|
||||
public static ClientInfo getClientByName(String name) {
|
||||
return CLIENTS.isEmpty() ? null : CLIENTS.stream().filter(client -> client != null && client.getName().equalsIgnoreCase(name)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public static ClientInfo getQueueClientById(String id) {
|
||||
return QUEUE_CLIENTS.get(id);
|
||||
}
|
||||
|
||||
public static void resetAllFeedbacks() {
|
||||
CLIENTS.forEach(client -> client.setFeedback(false));
|
||||
}
|
||||
|
||||
public static List<String> getRegisteredServerNames() {
|
||||
List<String> result = new ArrayList<>();
|
||||
CLIENTS.stream().filter(client -> client != null && client.getName() != null).forEach(client -> result.add(client.getName()));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,8 @@ public abstract class ClientInfo {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public abstract void sendBytes(byte[] bytes);
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
@@ -26,8 +28,6 @@ public abstract class ClientInfo {
|
||||
this.id = serverId;
|
||||
}
|
||||
|
||||
public abstract void sendBytes(byte[] bytes);
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -16,37 +16,11 @@ public class BungeeClientInfo extends ClientInfo {
|
||||
|
||||
@Override
|
||||
public void sendBytes(byte[] bytes) {
|
||||
ProxyServer.getInstance().getServers().entrySet().stream().filter(entry -> entry.getKey().equalsIgnoreCase(getName())).forEach(entry -> entry.getValue().sendData(Client.CHANNEL_NAME, bytes));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return super.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return super.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyncTime() {
|
||||
return super.getSyncTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFeedback(boolean state) {
|
||||
super.setFeedback(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(String serverId) {
|
||||
super.setId(serverId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
super.setName(name);
|
||||
ProxyServer.getInstance().getServers().entrySet().stream().filter(entry ->
|
||||
entry.getKey().equalsIgnoreCase(getName())
|
||||
).forEach(entry ->
|
||||
entry.getValue().sendData(Client.CHANNEL_NAME, bytes)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,36 +16,10 @@ public class VelocityClientInfo extends ClientInfo {
|
||||
|
||||
@Override
|
||||
public void sendBytes(byte[] bytes) {
|
||||
VelocityLoader.getServer().getAllServers().stream().filter(server -> server.getServerInfo().getName().equalsIgnoreCase(getName())).forEach(server -> server.sendPluginMessage(VelocityClient.getIdentifier(), bytes));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return super.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return super.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyncTime() {
|
||||
return super.getSyncTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFeedback(boolean state) {
|
||||
super.setFeedback(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(String serverId) {
|
||||
super.setId(serverId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
super.setName(name);
|
||||
VelocityLoader.getServer().getAllServers().stream().filter(server ->
|
||||
server.getServerInfo().getName().equalsIgnoreCase(getName())
|
||||
).forEach(server ->
|
||||
server.sendPluginMessage(VelocityClient.getIdentifier(), bytes)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -19,18 +19,31 @@ public class BukkitClient implements Client, PluginMessageListener {
|
||||
|
||||
@Override
|
||||
public void send(Object packet) {
|
||||
try { SERVER.sendPluginMessage(BukkitLoader.getPlugin(), CHANNEL_NAME, CommunicationPackets.convertToBytes(packet));
|
||||
} catch (Throwable throwable) { throwable.printStackTrace(); }
|
||||
try {
|
||||
|
||||
SERVER.sendPluginMessage(BukkitLoader.getPlugin(), CHANNEL_NAME, CommunicationPackets.convertToBytes(packet));
|
||||
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginMessageReceived(String channel, Player player, byte[] bytes) {
|
||||
if(!channel.equals(CHANNEL_NAME)) return;
|
||||
|
||||
if (!channel.equals(CHANNEL_NAME))
|
||||
return;
|
||||
|
||||
try {
|
||||
Object packetObj = CommunicationPackets.buildFromBytes(bytes);
|
||||
if(!CommunicationPackets.isPacket(packetObj)) return;
|
||||
|
||||
if (!CommunicationPackets.isPacket(packetObj))
|
||||
return;
|
||||
|
||||
PATScheduler.createScheduler(() -> Communicator.receiveInformation("proxy", packetObj));
|
||||
} catch (Throwable throwable) { throwable.printStackTrace(); }
|
||||
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,21 +21,37 @@ public class BungeeClient implements Client, Listener {
|
||||
|
||||
@Override
|
||||
public void send(Object packet) {
|
||||
for(ServerInfo serverInfo : ProxyServer.getInstance().getServers().values()) {
|
||||
try { serverInfo.sendData(CHANNEL_NAME, CommunicationPackets.convertToBytes(packet));
|
||||
} catch (Throwable throwable) { throwable.printStackTrace(); }
|
||||
for (ServerInfo serverInfo : ProxyServer.getInstance().getServers().values()) {
|
||||
|
||||
try {
|
||||
|
||||
serverInfo.sendData(CHANNEL_NAME, CommunicationPackets.convertToBytes(packet));
|
||||
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQueryReceive(PluginMessageEvent event) {
|
||||
if (!event.getTag().equalsIgnoreCase(CHANNEL_NAME)) return;
|
||||
if (!event.getTag().equalsIgnoreCase(CHANNEL_NAME))
|
||||
return;
|
||||
|
||||
try {
|
||||
|
||||
Object packetObj = CommunicationPackets.buildFromBytes(event.getData());
|
||||
if(!CommunicationPackets.isPacket(packetObj)) return;
|
||||
|
||||
if (!CommunicationPackets.isPacket(packetObj))
|
||||
return;
|
||||
|
||||
Server server = (Server) event.getSender();
|
||||
Communicator.receiveInformation(server.getInfo().getName().toLowerCase(), packetObj);
|
||||
} catch (Throwable throwable) { throwable.printStackTrace(); }
|
||||
Communicator.receiveInformation(server.getInfo().getName(), packetObj);
|
||||
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -22,19 +22,30 @@ public class VelocityClient implements Client {
|
||||
@Override
|
||||
public void send(Object packet) {
|
||||
for (RegisteredServer registeredServer : SERVER.getAllServers()) {
|
||||
try { registeredServer.sendPluginMessage(IDENTIFIER, CommunicationPackets.convertToBytes(packet));
|
||||
} catch (Throwable throwable) { throwable.printStackTrace(); }
|
||||
|
||||
try {
|
||||
|
||||
registeredServer.sendPluginMessage(IDENTIFIER, CommunicationPackets.convertToBytes(packet));
|
||||
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onQueryReceive(PluginMessageEvent event) {
|
||||
if (event.getIdentifier() != IDENTIFIER) return;
|
||||
if (event.getIdentifier() != IDENTIFIER)
|
||||
return;
|
||||
|
||||
Object packetObj = CommunicationPackets.buildFromBytes(event.getData());
|
||||
if(!CommunicationPackets.isPacket(packetObj)) return;
|
||||
|
||||
if (!CommunicationPackets.isPacket(packetObj))
|
||||
return;
|
||||
|
||||
ServerConnection server = (ServerConnection) event.getSource();
|
||||
Communicator.receiveInformation(server.getServerInfo().getName().toLowerCase(), packetObj);
|
||||
Communicator.receiveInformation(server.getServerInfo().getName(), packetObj);
|
||||
}
|
||||
|
||||
public static MinecraftChannelIdentifier getIdentifier() {
|
||||
|
||||
@@ -2,6 +2,7 @@ package de.rayzs.pat.api.event;
|
||||
|
||||
import de.rayzs.pat.api.event.events.*;
|
||||
import de.rayzs.pat.utils.CommunicationPackets;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -9,8 +10,8 @@ public class PATEventHandler {
|
||||
|
||||
private static List<PATEvent> EVENTS = new ArrayList<>();
|
||||
|
||||
public static ExecuteCommandEvent callExecuteCommandEvents(Object senderObj, String command, boolean blocked) {
|
||||
ExecuteCommandEvent event = EmptyEvent.createEmptyExecuteCommandEvent(senderObj, command, blocked);
|
||||
public static ExecuteCommandEvent callExecuteCommandEvents(Object senderObj, String command, boolean blocked, boolean notify) {
|
||||
ExecuteCommandEvent event = EmptyEvent.createEmptyExecuteCommandEvent(senderObj, command, blocked, notify);
|
||||
|
||||
for (PATEvent patEvent : EVENTS) {
|
||||
if(patEvent instanceof ExecuteCommandEvent) {
|
||||
@@ -168,8 +169,8 @@ public class PATEventHandler {
|
||||
};
|
||||
}
|
||||
|
||||
public static ExecuteCommandEvent createEmptyExecuteCommandEvent(Object senderObj, String command, boolean blocked) {
|
||||
return new ExecuteCommandEvent(senderObj, command, blocked) {
|
||||
public static ExecuteCommandEvent createEmptyExecuteCommandEvent(Object senderObj, String command, boolean blocked, boolean notify) {
|
||||
return new ExecuteCommandEvent(senderObj, command, blocked, notify) {
|
||||
@Override
|
||||
public void handle(ExecuteCommandEvent event) {
|
||||
|
||||
|
||||
@@ -5,18 +5,24 @@ import de.rayzs.pat.api.event.PATEvent;
|
||||
public abstract class ExecuteCommandEvent extends PATEvent<ExecuteCommandEvent> {
|
||||
|
||||
private final String command;
|
||||
private boolean blocked;
|
||||
private boolean blocked, notify;
|
||||
|
||||
public ExecuteCommandEvent() {
|
||||
super(null);
|
||||
this.blocked = false;
|
||||
this.notify = false;
|
||||
this.command = null;
|
||||
}
|
||||
|
||||
public ExecuteCommandEvent(Object senderObj, String command, boolean blocked) {
|
||||
public ExecuteCommandEvent(Object senderObj, String command, boolean blocked, boolean notify) {
|
||||
super(senderObj);
|
||||
this.blocked = blocked;
|
||||
this.command = command;
|
||||
this.notify = notify;
|
||||
}
|
||||
|
||||
public void setDoesNotify(boolean notify) {
|
||||
this.notify = notify;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
@@ -27,6 +33,10 @@ public abstract class ExecuteCommandEvent extends PATEvent<ExecuteCommandEvent>
|
||||
return blocked;
|
||||
}
|
||||
|
||||
public boolean doesNotify() {
|
||||
return notify;
|
||||
}
|
||||
|
||||
public void setBlocked(boolean blocked) {
|
||||
this.blocked = blocked;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.rayzs.pat.api.netty.bukkit;
|
||||
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import de.rayzs.pat.api.netty.bukkit.handlers.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -32,23 +33,26 @@ public class BukkitPacketAnalyzer {
|
||||
|
||||
public static void sendPacket(UUID uuid, Object object) {
|
||||
Channel channel = INJECTED_PLAYERS.get(uuid);
|
||||
if(channel == null) return;
|
||||
|
||||
if (channel == null)
|
||||
return;
|
||||
|
||||
SENT_PACKET.put(uuid, object);
|
||||
channel.pipeline().writeAndFlush(object);
|
||||
}
|
||||
|
||||
public static boolean inject(Player player) {
|
||||
if(Storage.USE_VELOCITY) return true;
|
||||
if (Storage.USE_VELOCITY)
|
||||
return true;
|
||||
|
||||
try {
|
||||
Channel channel = Reflection.getPlayerChannel(player);
|
||||
if(channel == null) {
|
||||
System.err.println("Failed to inject " + player.getName() + "! Channel is null.");
|
||||
if (channel == null) {
|
||||
Logger.warning("Failed to inject " + player.getName() + "! Channel is null.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(channel.pipeline().names().contains(BukkitPacketAnalyzer.HANDLER_NAME))
|
||||
if (channel.pipeline().names().contains(BukkitPacketAnalyzer.HANDLER_NAME))
|
||||
uninject(channel);
|
||||
|
||||
channel.pipeline().addBefore(BukkitPacketAnalyzer.PIPELINE_NAME, BukkitPacketAnalyzer.HANDLER_NAME, new PacketDecoder(player));
|
||||
@@ -56,25 +60,32 @@ public class BukkitPacketAnalyzer {
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
return false;
|
||||
} return true;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void uninject(UUID uuid) {
|
||||
if(Storage.USE_VELOCITY) return;
|
||||
if (Storage.USE_VELOCITY)
|
||||
return;
|
||||
|
||||
if(BukkitPacketAnalyzer.INJECTED_PLAYERS.containsKey(uuid)) {
|
||||
if (BukkitPacketAnalyzer.INJECTED_PLAYERS.containsKey(uuid)) {
|
||||
Channel channel = BukkitPacketAnalyzer.INJECTED_PLAYERS.get(uuid);
|
||||
uninject(channel);
|
||||
}
|
||||
}
|
||||
|
||||
public static void uninject(Channel channel) {
|
||||
if(Storage.USE_VELOCITY) return;
|
||||
if (Storage.USE_VELOCITY)
|
||||
return;
|
||||
|
||||
if(channel != null) {
|
||||
if (channel != null) {
|
||||
channel.eventLoop().submit(() -> {
|
||||
ChannelPipeline pipeline = channel.pipeline();
|
||||
if (pipeline.names().contains(BukkitPacketAnalyzer.HANDLER_NAME)) pipeline.remove(BukkitPacketAnalyzer.HANDLER_NAME);
|
||||
|
||||
if (pipeline.names().contains(BukkitPacketAnalyzer.HANDLER_NAME))
|
||||
pipeline.remove(BukkitPacketAnalyzer.HANDLER_NAME);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -99,11 +110,19 @@ public class BukkitPacketAnalyzer {
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext channel, Object packetObj) {
|
||||
try {
|
||||
if (!PermissionUtil.hasBypassPermission(player) && packetObj.getClass() != null) {
|
||||
if (packetObj.getClass() != null) {
|
||||
String packetName = packetObj.getClass().getSimpleName();
|
||||
|
||||
if (packetName.equals("PacketPlayInTabComplete") || packetName.equals("ServerboundCommandSuggestionPacket")) {
|
||||
if (!PACKET_HANDLER.handleIncomingPacket(player, packetObj)) return;
|
||||
if (!packetName.equals("PacketPlayInTabComplete") && !packetName.equals("ServerboundCommandSuggestionPacket")) {
|
||||
super.channelRead(channel, packetObj);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!PermissionUtil.hasBypassPermission(player)) {
|
||||
|
||||
if (!PACKET_HANDLER.handleIncomingPacket(player, packetObj))
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,26 +133,38 @@ public class BukkitPacketAnalyzer {
|
||||
@Override
|
||||
public void write(ChannelHandlerContext channel, Object packetObj, ChannelPromise promise) {
|
||||
try {
|
||||
if(packetObj.getClass() != null)
|
||||
if (!PermissionUtil.hasBypassPermission(player)) {
|
||||
String packetName = packetObj.getClass().getSimpleName();
|
||||
if (packetName.equals("PacketPlayOutTabComplete") || packetName.equals("ClientboundCommandSuggestionsPacket")) {
|
||||
|
||||
UUID uuid = player.getUniqueId();
|
||||
if(packetObj.getClass() != null) {
|
||||
String packetName = packetObj.getClass().getSimpleName();
|
||||
|
||||
if((packetName.equals("ClientboundCommandSuggestionsPacket") || Reflection.isFoliaServer()) && SENT_PACKET.contains(player.getUniqueId())) {
|
||||
Object newPacketObj = SENT_PACKET.get(uuid);
|
||||
SENT_PACKET.remove(uuid);
|
||||
super.write(channel, newPacketObj, promise);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!PACKET_HANDLER.handleOutgoingPacket(player, packetObj)) return;
|
||||
}
|
||||
if (!packetName.equals("PacketPlayOutTabComplete") && !packetName.equals("ClientboundCommandSuggestionsPacket")) {
|
||||
super.write(channel, packetObj, promise);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!PermissionUtil.hasBypassPermission(player)) {
|
||||
|
||||
UUID uuid = player.getUniqueId();
|
||||
Object sentPacketObj = SENT_PACKET.get(uuid);
|
||||
|
||||
if (sentPacketObj != null) {
|
||||
if (sentPacketObj == packetObj) {
|
||||
SENT_PACKET.remove(uuid);
|
||||
super.write(channel, sentPacketObj, promise);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!PACKET_HANDLER.handleOutgoingPacket(player, packetObj))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
super.write(channel, packetObj, promise);
|
||||
} catch (Throwable exception) { exception.printStackTrace(); }
|
||||
|
||||
} catch (Throwable exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,21 @@
|
||||
package de.rayzs.pat.api.netty.bukkit.handlers;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
import de.rayzs.pat.api.event.events.FilteredTabCompletionEvent;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.api.netty.bukkit.BukkitPacketAnalyzer;
|
||||
import de.rayzs.pat.api.netty.bukkit.BukkitPacketHandler;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.BukkitLoader;
|
||||
import de.rayzs.pat.api.netty.bukkit.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import java.lang.reflect.Field;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
|
||||
public class LegacyPacketHandler implements BukkitPacketHandler {
|
||||
|
||||
@@ -31,53 +36,69 @@ public class LegacyPacketHandler implements BukkitPacketHandler {
|
||||
public boolean handleOutgoingPacket(Player player, Object packetObj) throws Exception {
|
||||
String input = BukkitPacketAnalyzer.getPlayerInput(player);
|
||||
|
||||
if(input == null) return false;
|
||||
if(input == null)
|
||||
return false;
|
||||
|
||||
boolean cancelsBeforeHand;
|
||||
int spaces = 0;
|
||||
|
||||
if(input.startsWith("/")) {
|
||||
if (input.startsWith("/")) {
|
||||
input = input.replace("/", "");
|
||||
if(input.contains(" ")) {
|
||||
|
||||
if (input.contains(" ")) {
|
||||
String[] split = input.split(" ");
|
||||
spaces = split.length;
|
||||
if(spaces > 0) input = split[0];
|
||||
if (spaces > 0)
|
||||
input = split[0];
|
||||
}
|
||||
|
||||
cancelsBeforeHand = Storage.Blacklist.isBlocked(player, input, !Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED);
|
||||
if(!cancelsBeforeHand) cancelsBeforeHand = Storage.ConfigSections.Settings.CUSTOM_VERSION.isTabCompletable(input) || Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isTabCompletable(input);
|
||||
cancelsBeforeHand = Storage.Blacklist.canPlayerAccessTab(player, input);
|
||||
|
||||
if (!cancelsBeforeHand)
|
||||
cancelsBeforeHand = Storage.ConfigSections.Settings.CUSTOM_VERSION.isTabCompletable(input) || Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isTabCompletable(input);
|
||||
} else return true;
|
||||
|
||||
for (Field field : Reflection.getFields(packetObj)) {
|
||||
field.setAccessible(true);
|
||||
Object result = field.get(packetObj);
|
||||
|
||||
if (!(result instanceof String[])) continue;
|
||||
if (!(result instanceof String[]))
|
||||
continue;
|
||||
|
||||
List<String> newResultList = new ArrayList<>();
|
||||
String[] tR = (String[]) result;
|
||||
|
||||
String tempName;
|
||||
|
||||
if(spaces == 0) {
|
||||
boolean doesBypassNamespace = Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.doesBypass(player);
|
||||
|
||||
if (spaces == 0) {
|
||||
for (String s : tR) {
|
||||
if(!BukkitLoader.isLoaded()) continue;
|
||||
if(!s.startsWith("/")) {
|
||||
if (!BukkitLoader.isLoaded())
|
||||
continue;
|
||||
|
||||
if (!s.startsWith("/")) {
|
||||
newResultList.add(s);
|
||||
continue;
|
||||
}
|
||||
|
||||
tempName = s.replaceFirst("/", "");
|
||||
|
||||
if (!Storage.Blacklist.isBlocked(player, tempName, !Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED))
|
||||
if (!doesBypassNamespace && Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.isCommand(tempName))
|
||||
continue;
|
||||
|
||||
if (!Storage.Blacklist.canPlayerAccessTab(player, tempName))
|
||||
newResultList.add(s);
|
||||
}
|
||||
} else {
|
||||
if(!cancelsBeforeHand) {
|
||||
if (!cancelsBeforeHand) {
|
||||
FilteredTabCompletionEvent filteredTabCompletionEvent = PATEventHandler.callFilteredTabCompletionEvents(player.getUniqueId(), input, Arrays.asList(tR));
|
||||
if(!filteredTabCompletionEvent.isCancelled()) {
|
||||
|
||||
if (!filteredTabCompletionEvent.isCancelled()) {
|
||||
List<String> suggestions = Arrays.stream(tR).filter(s -> filteredTabCompletionEvent.getCompletion().contains(s)).collect(Collectors.toList());
|
||||
newResultList.addAll(suggestions);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,24 +1,32 @@
|
||||
package de.rayzs.pat.api.netty.bukkit.handlers;
|
||||
|
||||
import de.rayzs.pat.api.event.events.FilteredTabCompletionEvent;
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
import com.mojang.brigadier.suggestion.*;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.BukkitLoader;
|
||||
import de.rayzs.pat.api.netty.bukkit.*;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import de.rayzs.pat.utils.scheduler.PATScheduler;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.mojang.brigadier.suggestion.Suggestion;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
import de.rayzs.pat.api.event.events.FilteredTabCompletionEvent;
|
||||
import de.rayzs.pat.api.netty.bukkit.BukkitPacketAnalyzer;
|
||||
import de.rayzs.pat.api.netty.bukkit.BukkitPacketHandler;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.BukkitLoader;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import de.rayzs.pat.utils.scheduler.PATScheduler;
|
||||
|
||||
public class ModernPacketHandler implements BukkitPacketHandler {
|
||||
|
||||
private static boolean modifiable = true;
|
||||
|
||||
@Override
|
||||
public boolean handleIncomingPacket(Player player, Object packetObj) throws Exception {
|
||||
Field stringField = Reflection.getFirstFieldByType(packetObj.getClass(), "String", Reflection.SearchOption.ENDS);
|
||||
@@ -29,9 +37,18 @@ public class ModernPacketHandler implements BukkitPacketHandler {
|
||||
}
|
||||
|
||||
String text = (String) stringField.get(packetObj);
|
||||
if(Storage.ConfigSections.Settings.PATCH_EXPLOITS.isMalicious(text)) {
|
||||
MessageTranslator.send(Bukkit.getConsoleSender(), Storage.ConfigSections.Settings.PATCH_EXPLOITS.ALERT_MESSAGE.get().replace("%player%", player.getName()));
|
||||
PATScheduler.createScheduler(() -> player.kickPlayer(ChatColor.translateAlternateColorCodes('&', Storage.ConfigSections.Settings.PATCH_EXPLOITS.KICK_MESSAGE.get())));
|
||||
if (Storage.ConfigSections.Settings.PATCH_EXPLOITS.isMalicious(text)) {
|
||||
MessageTranslator.send(
|
||||
Bukkit.getConsoleSender(),
|
||||
Storage.ConfigSections.Settings.PATCH_EXPLOITS.ALERT_MESSAGE.get().replace("%player%", player.getName())
|
||||
);
|
||||
|
||||
PATScheduler.createScheduler(() ->
|
||||
player.kickPlayer(
|
||||
StringUtils.replace(Storage.ConfigSections.Settings.PATCH_EXPLOITS.KICK_MESSAGE.get(), "&", "§")
|
||||
)
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -43,7 +60,9 @@ public class ModernPacketHandler implements BukkitPacketHandler {
|
||||
public boolean handleOutgoingPacket(Player player, Object packetObj) throws Exception {
|
||||
Object suggestionObj;
|
||||
String rawInput = BukkitPacketAnalyzer.getPlayerInput(player), input = rawInput;
|
||||
if(input == null) return false;
|
||||
|
||||
if(input == null)
|
||||
return false;
|
||||
|
||||
|
||||
boolean is121Packet = packetObj.getClass().getSimpleName().equals("ClientboundCommandSuggestionsPacket"),
|
||||
@@ -58,11 +77,13 @@ public class ModernPacketHandler implements BukkitPacketHandler {
|
||||
if(spaces > 0) input = split[0];
|
||||
}
|
||||
|
||||
cancelsBeforeHand = Storage.Blacklist.isBlocked(player, input, !Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED);
|
||||
if(!cancelsBeforeHand) cancelsBeforeHand = Storage.ConfigSections.Settings.CUSTOM_VERSION.isTabCompletable(input) || Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isTabCompletable(input);
|
||||
cancelsBeforeHand = !Storage.Blacklist.canPlayerAccessTab(player, input);
|
||||
|
||||
if (!cancelsBeforeHand)
|
||||
cancelsBeforeHand = Storage.ConfigSections.Settings.CUSTOM_VERSION.isTabCompletable(input) || Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isTabCompletable(input);
|
||||
}
|
||||
|
||||
if(is121Packet || Reflection.isFoliaServer() && packetObj.getClass().getSimpleName().equals("PacketPlayOutTabComplete")) {
|
||||
if (is121Packet || Reflection.isFoliaServer() && packetObj.getClass().getSimpleName().equals("PacketPlayOutTabComplete")) {
|
||||
try {
|
||||
Field suggestionsField = Reflection.getFieldsByTypeNormal(packetObj.getClass(), "List", Reflection.SearchOption.ENDS).get(0);
|
||||
List<?> suggestionsTmp = (List<?>) suggestionsField.get(packetObj),
|
||||
@@ -74,7 +95,9 @@ public class ModernPacketHandler implements BukkitPacketHandler {
|
||||
length = (int) intFields.get(2).get(packetObj);
|
||||
|
||||
Class<?> clientboundCommandSuggestionsPacketClass = Class.forName("net.minecraft.network.protocol.game." + (packetObj.getClass().getSimpleName().equals("PacketPlayOutTabComplete") ? "PacketPlayOutTabComplete" : "ClientboundCommandSuggestionsPacket"));
|
||||
if ((input.isEmpty() || cancelsBeforeHand) && Reflection.isWeird()) return false;
|
||||
if ((input.isEmpty() || cancelsBeforeHand) && Reflection.isWeird())
|
||||
return false;
|
||||
|
||||
if (spaces >= 1 && cancelsBeforeHand || !BukkitLoader.isLoaded()) {
|
||||
suggestions.clear();
|
||||
return true;
|
||||
@@ -83,8 +106,9 @@ public class ModernPacketHandler implements BukkitPacketHandler {
|
||||
if (spaces == 0) {
|
||||
suggestions.removeIf(suggestion -> {
|
||||
String command = getSuggestionFromEntry(suggestion);
|
||||
return Storage.Blacklist.isBlocked(player, command);
|
||||
return !Storage.Blacklist.canPlayerAccessTab(player, command);
|
||||
});
|
||||
|
||||
return true;
|
||||
|
||||
} else {
|
||||
@@ -107,54 +131,124 @@ public class ModernPacketHandler implements BukkitPacketHandler {
|
||||
}
|
||||
|
||||
if(!suggestions.isEmpty()) {
|
||||
|
||||
Object clientboundCommandSuggestionsPacketObj = clientboundCommandSuggestionsPacketClass
|
||||
.getConstructor(int.class, int.class, int.class, List.class)
|
||||
.newInstance(id, start, length, suggestions);
|
||||
|
||||
BukkitPacketAnalyzer.sendPacket(player.getUniqueId(), clientboundCommandSuggestionsPacketObj);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
} catch (Throwable throwable) { throwable.printStackTrace(); }
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
|
||||
return !cancelsBeforeHand;
|
||||
}
|
||||
|
||||
|
||||
if (Reflection.getMinor() < 17) {
|
||||
Field suggestionsField = Reflection.getFieldsByType(packetObj.getClass(), "Suggestions", Reflection.SearchOption.ENDS).get(0);
|
||||
if (suggestionsField == null) return false;
|
||||
suggestionObj = suggestionsField.get(packetObj);
|
||||
} else {
|
||||
Method suggestionsMethod = Reflection.getMethodsByReturnType(packetObj.getClass(), "Suggestions", Reflection.SearchOption.ENDS).get(0);
|
||||
if (suggestionsMethod == null) return false;
|
||||
List<Method> methods = Reflection.getMethodsByReturnType(packetObj.getClass(), "Suggestions", Reflection.SearchOption.ENDS);
|
||||
|
||||
if (methods.isEmpty()) return false;
|
||||
Method suggestionsMethod = methods.get(0);
|
||||
|
||||
if (suggestionsMethod == null)
|
||||
return false;
|
||||
|
||||
suggestionObj = suggestionsMethod.invoke(packetObj);
|
||||
}
|
||||
|
||||
Suggestions suggestions = (Suggestions) suggestionObj;
|
||||
|
||||
if((input.isEmpty() || cancelsBeforeHand) && Reflection.isWeird()) return false;
|
||||
if((input.isEmpty() || cancelsBeforeHand) && Reflection.isWeird()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(spaces >= 1 && cancelsBeforeHand || !BukkitLoader.isLoaded()) {
|
||||
suggestions.getList().clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
if(spaces == 0) {
|
||||
|
||||
suggestions.getList().removeIf(suggestion -> {
|
||||
String command = suggestion.getText();
|
||||
return Storage.Blacklist.isBlocked(player, command);
|
||||
return !Storage.Blacklist.canPlayerAccessTab(player, command);
|
||||
});
|
||||
|
||||
return true;
|
||||
|
||||
} else {
|
||||
List<String> suggestionsAsString = new ArrayList<>();
|
||||
for (Suggestion suggestion : suggestions.getList())
|
||||
suggestionsAsString.add(suggestion.getText());
|
||||
|
||||
FilteredTabCompletionEvent filteredTabCompletionEvent = PATEventHandler.callFilteredTabCompletionEvents(player.getUniqueId(), rawInput, suggestionsAsString);
|
||||
if(filteredTabCompletionEvent.isCancelled()) suggestions.getList().clear();
|
||||
suggestions.getList().removeIf(suggestion -> !filteredTabCompletionEvent.getCompletion().contains(suggestion.getText()));
|
||||
return !suggestions.getList().isEmpty();
|
||||
|
||||
if (modifiable) {
|
||||
|
||||
try {
|
||||
|
||||
if (filteredTabCompletionEvent.isCancelled())
|
||||
suggestions.getList().clear();
|
||||
else
|
||||
suggestions.getList().removeIf(suggestion -> !filteredTabCompletionEvent.getCompletion().contains(suggestion.getText()));
|
||||
|
||||
return !suggestions.getList().isEmpty();
|
||||
|
||||
} catch (UnsupportedOperationException exception) {
|
||||
modifiable = false;
|
||||
}
|
||||
}
|
||||
|
||||
return handleUnmodifiableTabCompletion(player, packetObj, suggestions, filteredTabCompletionEvent);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean handleUnmodifiableTabCompletion(Player player, Object packetObj, Suggestions suggestions, FilteredTabCompletionEvent filteredTabCompletionEvent) {
|
||||
List<Suggestion> filteredSuggestionsList = new ArrayList<>();
|
||||
|
||||
if (!filteredTabCompletionEvent.isCancelled())
|
||||
for (Suggestion suggestion : suggestions.getList()) {
|
||||
if (filteredTabCompletionEvent.getCompletion().contains(suggestion.getText())) {
|
||||
filteredSuggestionsList.add(suggestion);
|
||||
}
|
||||
}
|
||||
|
||||
Suggestions filteredSuggestions = new Suggestions(suggestions.getRange(), filteredSuggestionsList);
|
||||
|
||||
try {
|
||||
int val = -1;
|
||||
|
||||
Method method = Reflection.getMethodByName(packetObj.getClass(), "e");
|
||||
if (method != null) {
|
||||
val = (int) method.invoke(packetObj);
|
||||
}
|
||||
|
||||
if (val == -1) {
|
||||
Logger.warning("Failed to read packet input!");
|
||||
return false;
|
||||
}
|
||||
|
||||
Object packet = Reflection.getConstructor(packetObj.getClass(), int.class, Suggestions.class)
|
||||
.newInstance(val, filteredSuggestions);
|
||||
|
||||
BukkitPacketAnalyzer.sendPacket(player.getUniqueId(), packet);
|
||||
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private String getSuggestionFromEntry(Object suggestionObj) {
|
||||
try {
|
||||
List<Field> fields = Reflection.getFieldsByTypeNormal(suggestionObj.getClass(), "String", Reflection.SearchOption.ENDS);
|
||||
|
||||
@@ -1,28 +1,37 @@
|
||||
package de.rayzs.pat.api.netty.proxy;
|
||||
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import de.rayzs.pat.api.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.api.communication.client.ClientInfo;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import de.rayzs.pat.api.communication.Communicator;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.PacketWrapper;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.protocol.packet.*;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import com.mojang.brigadier.builder.*;
|
||||
import java.lang.reflect.Field;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import io.netty.channel.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
|
||||
import de.rayzs.pat.api.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.api.communication.Communicator;
|
||||
import de.rayzs.pat.api.communication.client.ClientInfo;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.utils.CommandsCache;
|
||||
import de.rayzs.pat.utils.node.CommandNodeHelper;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||
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.plugin.Command;
|
||||
import net.md_5.bungee.protocol.PacketWrapper;
|
||||
import net.md_5.bungee.protocol.packet.Commands;
|
||||
import net.md_5.bungee.protocol.packet.PluginMessage;
|
||||
import net.md_5.bungee.protocol.packet.TabCompleteResponse;
|
||||
|
||||
public class BungeePacketAnalyzer {
|
||||
|
||||
@@ -33,10 +42,20 @@ public class BungeePacketAnalyzer {
|
||||
private static final HashMap<ProxiedPlayer, String> PLAYER_INPUT_CACHE = new HashMap<>();
|
||||
|
||||
private static final com.mojang.brigadier.Command DUMMY_COMMAND = (context) -> 0;
|
||||
|
||||
private static final List<String> PLUGIN_COMMANDS = new ArrayList<>();
|
||||
|
||||
private static Class<?> channelWrapperClass, serverConnectionClass;
|
||||
|
||||
private static final List<String> PROXY_COMMANDS;
|
||||
|
||||
static {
|
||||
PROXY_COMMANDS = ProxyServer.getInstance().getPluginManager().getCommands().stream().map(entry -> {
|
||||
String key = entry.getKey();
|
||||
return key.startsWith("/") ? key.substring(1) : key;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
public static void injectAll() {
|
||||
ProxyServer.getInstance().getPlayers().forEach(BungeePacketAnalyzer::inject);
|
||||
}
|
||||
@@ -69,21 +88,25 @@ public class BungeePacketAnalyzer {
|
||||
channel = (Channel) Reflection.getFieldsByType(channelWrapperClass, "Channel", Reflection.SearchOption.ENDS).get(0).get(channelWrapperObj);
|
||||
|
||||
if(channel == null) {
|
||||
System.err.println("Failed to inject " + player.getName() + "! Channel is null.");
|
||||
Logger.warning("Failed to inject " + player.getName() + "! Channel is null.");
|
||||
return false;
|
||||
}
|
||||
|
||||
channelField.setAccessible(false);
|
||||
|
||||
if(channel.pipeline().names().contains(BungeePacketAnalyzer.HANDLER_NAME))
|
||||
if (channel.pipeline().names().contains(BungeePacketAnalyzer.HANDLER_NAME))
|
||||
uninject(player);
|
||||
|
||||
channel.pipeline().addAfter(BungeePacketAnalyzer.PIPELINE_NAME, BungeePacketAnalyzer.HANDLER_NAME, new PacketDecoder(player));
|
||||
BungeePacketAnalyzer.INJECTED_PLAYERS.put(player, channel);
|
||||
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
return false;
|
||||
} return true;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void uninject(ProxiedPlayer player) {
|
||||
@@ -96,7 +119,9 @@ public class BungeePacketAnalyzer {
|
||||
BungeePacketAnalyzer.INJECTED_PLAYERS.remove(player);
|
||||
channel.eventLoop().submit(() -> {
|
||||
ChannelPipeline pipeline = channel.pipeline();
|
||||
if (pipeline.names().contains(BungeePacketAnalyzer.HANDLER_NAME)) pipeline.remove(BungeePacketAnalyzer.HANDLER_NAME);
|
||||
|
||||
if (pipeline.names().contains(BungeePacketAnalyzer.HANDLER_NAME))
|
||||
pipeline.remove(BungeePacketAnalyzer.HANDLER_NAME);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -108,50 +133,68 @@ public class BungeePacketAnalyzer {
|
||||
return input;
|
||||
}
|
||||
|
||||
public static void insertPlayerInput(ProxiedPlayer player, String text) {
|
||||
PLAYER_INPUT_CACHE.put(player, text.toLowerCase());
|
||||
}
|
||||
private static void modifyCommands(ProxiedPlayer player, Commands commands) {
|
||||
ServerInfo serverInfo = player.getServer().getInfo();
|
||||
String serverName = serverInfo.getName();
|
||||
|
||||
private static void modifyCommands(ProxiedPlayer player, Commands commands, List<String> list) {
|
||||
final String serverName = player.getServer().getInfo().getName();
|
||||
final boolean turn = Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED;
|
||||
list.clear();
|
||||
CommandNodeHelper helper = new CommandNodeHelper<CommandNode>(commands.getRoot());
|
||||
|
||||
Map<String, CommandsCache> cache = Storage.getLoader().getCommandsCacheMap();
|
||||
|
||||
if (!cache.containsKey(serverName))
|
||||
cache.put(serverName, new CommandsCache());
|
||||
|
||||
CommandsCache commandsCache = cache.get(serverName);
|
||||
|
||||
List<String> commandsAsString = new ArrayList<String>(PROXY_COMMANDS);
|
||||
commandsAsString.addAll(helper.getChildrenNames());
|
||||
|
||||
commandsCache.handleCommands(commandsAsString, serverName);
|
||||
|
||||
List<String> playerCommands = commandsCache.getPlayerCommands(commandsAsString, player, player.getUniqueId(), serverName);
|
||||
|
||||
helper.removeIf(str -> !playerCommands.contains(str));
|
||||
|
||||
for (Map.Entry<String, Command> command : ProxyServer.getInstance().getPluginManager().getCommands()) {
|
||||
if (!ProxyServer.getInstance().getDisabledCommands().contains(command.getKey()) && commands.getRoot().getChild(command.getKey()) == null && command.getValue().hasPermission(player)) {
|
||||
|
||||
List<String> commandsToCheck =
|
||||
new ArrayList<>(Arrays.asList(command.getValue().getAliases()));
|
||||
if(!commandsToCheck.contains(command.getValue().getName()))
|
||||
commandsToCheck.add(command.getValue().getName());
|
||||
if(!commandsToCheck.contains(command.getKey()))
|
||||
commandsToCheck.add(command.getKey());
|
||||
if (ProxyServer.getInstance().getDisabledCommands().contains(command.getKey()))
|
||||
continue;
|
||||
|
||||
commandsToCheck.removeAll(list);
|
||||
commandsToCheck.removeIf(commandName -> commandName.startsWith("/"));
|
||||
if (commands.getRoot().getChild(command.getKey()) != null)
|
||||
continue;
|
||||
|
||||
for (String commandName : commandsToCheck) {
|
||||
if (!list.contains(commandName)) {
|
||||
if (!Storage.Blacklist.isBlocked(player, commandName, !turn, serverName)) {
|
||||
list.add(commandName);
|
||||
CommandNode dummy = LiteralArgumentBuilder.literal(commandName)
|
||||
.executes(DUMMY_COMMAND)
|
||||
.then(RequiredArgumentBuilder.argument("args", StringArgumentType.greedyString())
|
||||
.suggests(Commands.SuggestionRegistry.ASK_SERVER).executes(DUMMY_COMMAND))
|
||||
.build();
|
||||
if (!command.getValue().hasPermission(player))
|
||||
continue;
|
||||
|
||||
commands.getRoot().addChild(dummy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
String commandName = command.getKey();
|
||||
commandName = commandName.startsWith("/") ? commandName.substring(1) : commandName;
|
||||
|
||||
if (!playerCommands.contains(commandName))
|
||||
continue;
|
||||
|
||||
CommandNode dummy = createDummyCommandNode(command.getKey());
|
||||
commands.getRoot().addChild(dummy);
|
||||
}
|
||||
|
||||
// Disabled temporarily
|
||||
// PROXY_COMMANDS.stream().filter(playerCommands::contains).forEach(helper::add);
|
||||
// SubArgsModule.handleCommandNode(player.getUniqueId(), helper);
|
||||
}
|
||||
|
||||
private static CommandNode createDummyCommandNode(String command) {
|
||||
return LiteralArgumentBuilder
|
||||
.literal(command)
|
||||
.executes(DUMMY_COMMAND)
|
||||
.then(RequiredArgumentBuilder
|
||||
.argument("args", (ArgumentType) StringArgumentType.greedyString())
|
||||
.suggests(Commands.SuggestionRegistry.ASK_SERVER)
|
||||
.executes(DUMMY_COMMAND))
|
||||
.build();
|
||||
}
|
||||
|
||||
private static class PacketDecoder extends MessageToMessageDecoder<PacketWrapper> {
|
||||
|
||||
private final ProxiedPlayer player;
|
||||
private final List<String> commands = new ArrayList<>();
|
||||
|
||||
private PacketDecoder(ProxiedPlayer player) {
|
||||
this.player = player;
|
||||
@@ -171,7 +214,8 @@ public class BungeePacketAnalyzer {
|
||||
|
||||
} else if (wrapper.packet instanceof Commands) {
|
||||
Commands response = (Commands) wrapper.packet;
|
||||
modifyCommands(player, response, commands);
|
||||
modifyCommands(player, response);
|
||||
|
||||
player.unsafe().sendPacket(response);
|
||||
return;
|
||||
|
||||
@@ -186,36 +230,39 @@ public class BungeePacketAnalyzer {
|
||||
return;
|
||||
|
||||
boolean cancelsBeforeHand = false;
|
||||
String playerInput = getPlayerInput(player), server = player.getServer().getInfo().getName();
|
||||
int spaces = 0;
|
||||
|
||||
if(playerInput.contains(" ")) {
|
||||
String[] split = playerInput.split(" ");
|
||||
spaces = split.length;
|
||||
if(spaces > 0) playerInput = split[0];
|
||||
String rawPlayerInput = getPlayerInput(player);
|
||||
int spaces = rawPlayerInput.contains(" ") ? rawPlayerInput.split(" ").length : 0;
|
||||
|
||||
String playerInput = StringUtils.getFirstArg(rawPlayerInput),
|
||||
server = player.getServer().getInfo().getName();
|
||||
|
||||
if (!playerInput.equals("/")) {
|
||||
cancelsBeforeHand = !Storage.Blacklist.canPlayerAccessTab(player, StringUtils.replaceFirst(playerInput, "/", ""), server);
|
||||
|
||||
if (!cancelsBeforeHand)
|
||||
cancelsBeforeHand = !Storage.ConfigSections.Settings.CUSTOM_VERSION.isTabCompletable(StringUtils.replaceFirst(playerInput, "/", "")) || Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isTabCompletable(StringUtils.replaceFirst(playerInput, "/", ""));
|
||||
}
|
||||
|
||||
if(!playerInput.equals("/")) {
|
||||
cancelsBeforeHand = Storage.Blacklist.isBlocked(player, StringUtils.replaceFirst(playerInput, "/", ""), !Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED, server);
|
||||
|
||||
if(!cancelsBeforeHand) cancelsBeforeHand = Storage.ConfigSections.Settings.CUSTOM_VERSION.isTabCompletable(StringUtils.replaceFirst(playerInput, "/", "")) || Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isTabCompletable(StringUtils.replaceFirst(playerInput, "/", ""));
|
||||
}
|
||||
final String cursor = playerInput;
|
||||
if(cursor.startsWith("/")) {
|
||||
if(spaces == 0) {
|
||||
|
||||
if (cursor.startsWith("/")) {
|
||||
if (spaces == 0) {
|
||||
List<String> suggestions = new ArrayList<>(response.getCommands());
|
||||
|
||||
if (Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED) {
|
||||
setPluginCommands();
|
||||
|
||||
Storage.Blacklist.getAllBlacklists(server).forEach(blacklist -> blacklist.getCommands().stream().filter(command -> !suggestions.contains("/" + command)).forEach(command -> {
|
||||
Storage.Blacklist.getServerBlacklists(server).forEach(blacklist -> blacklist.getCommands().stream().filter(command -> !suggestions.contains("/" + command)).forEach(command -> {
|
||||
if (BungeePacketAnalyzer.PLUGIN_COMMANDS.contains(command))
|
||||
suggestions.add("/" + command);
|
||||
}));
|
||||
|
||||
BungeePacketAnalyzer.PLUGIN_COMMANDS.stream().filter(command -> !suggestions.contains(command)).forEach(command -> {
|
||||
if(command.startsWith("/")) command = StringUtils.replaceFirst(command, "/", "");
|
||||
if(PermissionUtil.hasBypassPermission(player, command, server)) {
|
||||
if (command.startsWith("/"))
|
||||
command = StringUtils.replaceFirst(command, "/", "");
|
||||
|
||||
if (Storage.Blacklist.canPlayerAccessTab(player, command, server)) {
|
||||
suggestions.add("/" + command);
|
||||
}
|
||||
});
|
||||
@@ -224,17 +271,24 @@ public class BungeePacketAnalyzer {
|
||||
|
||||
} else {
|
||||
BungeePacketAnalyzer.PLUGIN_COMMANDS.stream().filter(command -> !suggestions.contains(command)).forEach(suggestions::add);
|
||||
|
||||
suggestions.removeIf(command -> {
|
||||
if(command.startsWith("/")) command = StringUtils.replaceFirst(command, "/", "");
|
||||
return Storage.Blacklist.isBlocked(player, command, true, server, true);
|
||||
if (command.startsWith("/"))
|
||||
command = StringUtils.replaceFirst(command, "/", "");
|
||||
|
||||
return !Storage.Blacklist.canPlayerAccessTab(player, command, server);
|
||||
});
|
||||
|
||||
response.getCommands().clear();
|
||||
suggestions.forEach(command -> response.getCommands().add(command));
|
||||
}
|
||||
|
||||
if (response.getCommands().isEmpty()) return;
|
||||
if (response.getCommands().isEmpty())
|
||||
return;
|
||||
|
||||
} else {
|
||||
if(cancelsBeforeHand) return;
|
||||
if (cancelsBeforeHand)
|
||||
return;
|
||||
}
|
||||
|
||||
player.unsafe().sendPacket(new TabCompleteResponse(response.getCommands()));
|
||||
|
||||
@@ -1,37 +1,46 @@
|
||||
package de.rayzs.pat.api.netty.proxy;
|
||||
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.proxy.crypto.SignedChatCommand;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.packet.AvailableCommandsPacket;
|
||||
import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket;
|
||||
import com.velocitypowered.proxy.protocol.packet.TabCompleteRequestPacket;
|
||||
import com.velocitypowered.proxy.protocol.packet.TabCompleteResponsePacket;
|
||||
import com.velocitypowered.proxy.protocol.packet.chat.session.UnsignedPlayerCommandPacket;
|
||||
|
||||
import de.rayzs.pat.api.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
import de.rayzs.pat.api.event.events.FilteredTabCompletionEvent;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.VelocityLoader;
|
||||
import de.rayzs.pat.plugin.listeners.velocity.VelocityBlockCommandListener;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.utils.CommandsCache;
|
||||
import de.rayzs.pat.utils.PacketUtils;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import com.velocitypowered.proxy.protocol.packet.*;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import de.rayzs.pat.plugin.VelocityLoader;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelDuplexHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class VelocityPacketAnalyzer {
|
||||
|
||||
public static final ConcurrentHashMap<Player, Channel> INJECTED_PLAYERS = new ConcurrentHashMap<>();
|
||||
|
||||
private static final String PIPELINE_NAME = "pat-velocity-handler", HANDLER_NAME = "handler";
|
||||
private static final HashMap<Player, String> PLAYER_INPUT_CACHE = new HashMap<>();
|
||||
private static HashMap<String, CommandsCache> COMMANDS_CACHE_MAP = new HashMap<>();
|
||||
|
||||
private static Class<?> minecraftConnectionClass, connectedPlayerConnectionClass, signedChatCommandPacketClass;
|
||||
|
||||
@@ -65,7 +74,7 @@ public class VelocityPacketAnalyzer {
|
||||
channel = (Channel) Reflection.getMethodsByName(minecraftConnectionClass, "getChannel").get(0).invoke(minecraftConnectionObj);
|
||||
|
||||
if(channel == null) {
|
||||
System.out.println("Failed to inject " + player.getUsername() + "! Channel is null.");
|
||||
Logger.warning("Failed to inject " + player.getUsername() + "! Channel is null.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -122,16 +131,17 @@ public class VelocityPacketAnalyzer {
|
||||
|
||||
MinecraftPacket packet = (MinecraftPacket) msg;
|
||||
|
||||
if(packet.getClass().getSimpleName().equals("SignedChatCommand")) {
|
||||
if (packet.getClass().getSimpleName().equals("SignedChatCommand")) {
|
||||
|
||||
try {
|
||||
if(signedChatCommandPacketClass == null)
|
||||
if (signedChatCommandPacketClass == null)
|
||||
signedChatCommandPacketClass = Class.forName("com.velocitypowered.proxy.crypto.SignedChatCommand");
|
||||
|
||||
Object signedChatCommandPacket = signedChatCommandPacketClass.cast(packet);
|
||||
Field commandField = signedChatCommandPacket.getClass().getField("command");
|
||||
String command = (String) commandField.get(signedChatCommandPacket);
|
||||
|
||||
if(!VelocityBlockCommandListener.handleCommand(player, command))
|
||||
if (!VelocityBlockCommandListener.handleCommand(player, command).getResult().isAllowed())
|
||||
return;
|
||||
|
||||
} catch (Exception exception) {
|
||||
@@ -139,18 +149,18 @@ public class VelocityPacketAnalyzer {
|
||||
}
|
||||
}
|
||||
|
||||
if(packet instanceof UnsignedPlayerCommandPacket) {
|
||||
if (packet instanceof UnsignedPlayerCommandPacket) {
|
||||
|
||||
UnsignedPlayerCommandPacket unsignedPlayerCommandPacket = (UnsignedPlayerCommandPacket) packet;
|
||||
if(VelocityBlockCommandListener.handleCommand(player, unsignedPlayerCommandPacket.getCommand()))
|
||||
if (!VelocityBlockCommandListener.handleCommand(player, unsignedPlayerCommandPacket.getCommand()).getResult().isAllowed())
|
||||
return;
|
||||
}
|
||||
|
||||
if(packet instanceof TabCompleteRequestPacket) {
|
||||
if (packet instanceof TabCompleteRequestPacket) {
|
||||
TabCompleteRequestPacket request = (TabCompleteRequestPacket) msg;
|
||||
if(request.getCommand() != null) {
|
||||
if (request.getCommand() != null) {
|
||||
|
||||
if(Storage.ConfigSections.Settings.PATCH_EXPLOITS.isMalicious(request.getCommand())) {
|
||||
if (Storage.ConfigSections.Settings.PATCH_EXPLOITS.isMalicious(request.getCommand())) {
|
||||
MessageTranslator.send(VelocityLoader.getServer().getConsoleCommandSource(), Storage.ConfigSections.Settings.PATCH_EXPLOITS.ALERT_MESSAGE.get().replace("%player%", player.getUsername()));
|
||||
player.disconnect(LegacyComponentSerializer.legacyAmpersand().deserialize(Storage.ConfigSections.Settings.PATCH_EXPLOITS.KICK_MESSAGE.get()));
|
||||
} else {
|
||||
@@ -170,7 +180,7 @@ public class VelocityPacketAnalyzer {
|
||||
|
||||
MinecraftPacket packet = (MinecraftPacket) msg;
|
||||
|
||||
if(packet instanceof PluginMessagePacket) {
|
||||
if (packet instanceof PluginMessagePacket) {
|
||||
PluginMessagePacket pluginMessagePacket = (PluginMessagePacket) packet;
|
||||
if(CustomServerBrand.isEnabled() && CustomServerBrand.isBrandTag(pluginMessagePacket.getChannel()) && !player.getCurrentServer().isPresent()) {
|
||||
PacketUtils.BrandManipulate brandManipulatePacket = CustomServerBrand.createBrandPacket(player);
|
||||
@@ -178,7 +188,8 @@ public class VelocityPacketAnalyzer {
|
||||
return;
|
||||
}
|
||||
|
||||
} else if(packet instanceof TabCompleteResponsePacket) {
|
||||
} else if (packet instanceof TabCompleteResponsePacket) {
|
||||
|
||||
if (!PermissionUtil.hasBypassPermission(player) && player.getCurrentServer().isPresent()) {
|
||||
TabCompleteResponsePacket response = (TabCompleteResponsePacket) packet;
|
||||
|
||||
@@ -193,49 +204,58 @@ public class VelocityPacketAnalyzer {
|
||||
}
|
||||
|
||||
if(!playerInput.equals("/")) {
|
||||
cancelsBeforeHand = Storage.Blacklist.isBlocked(player, StringUtils.replaceFirst(playerInput, "/", ""), !Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED, server);
|
||||
if(!cancelsBeforeHand) cancelsBeforeHand = Storage.ConfigSections.Settings.CUSTOM_VERSION.isTabCompletable(StringUtils.replaceFirst(playerInput, "/", "")) || Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isTabCompletable(StringUtils.replaceFirst(playerInput, "/", ""));
|
||||
cancelsBeforeHand = !Storage.Blacklist.canPlayerAccessTab(player, StringUtils.replaceFirst(playerInput, "/", ""), server);
|
||||
|
||||
if(!cancelsBeforeHand)
|
||||
cancelsBeforeHand = Storage.ConfigSections.Settings.CUSTOM_VERSION.isTabCompletable(StringUtils.replaceFirst(playerInput, "/", "")) || Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isTabCompletable(StringUtils.replaceFirst(playerInput, "/", ""));
|
||||
}
|
||||
|
||||
final String cursor = playerInput;
|
||||
|
||||
if(!cursor.startsWith("/") && spaces < 2 && player.getProtocolVersion().getProtocol() >= 754) {
|
||||
if (!cursor.startsWith("/") && spaces < 2 && player.getProtocolVersion().getProtocol() >= 754) {
|
||||
Logger.debug("Player won't receive TabCompleteResponsePacket because the client protocol id is " + player.getProtocolVersion().getProtocol() + "! This doesn't makes sense, that's why.");
|
||||
return;
|
||||
}
|
||||
|
||||
if(cursor.startsWith("/")) {
|
||||
if (cursor.startsWith("/")) {
|
||||
if (spaces == 0) {
|
||||
response.getOffers().removeIf(offer -> {
|
||||
String command = offer.getText();
|
||||
if (command.startsWith("/")) command = StringUtils.replaceFirst(command, "/", "");
|
||||
|
||||
return Storage.Blacklist.isBlocked(player, command, !Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED, player.getCurrentServer().get().getServerInfo().getName(), !Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED);
|
||||
return !Storage.Blacklist.canPlayerAccessTab(player, command, player.getCurrentServer().get().getServerInfo().getName());
|
||||
});
|
||||
} else {
|
||||
if (cancelsBeforeHand) return;
|
||||
|
||||
List<String> suggestionsAsString = new ArrayList<>();
|
||||
|
||||
response.getOffers().forEach(offer -> suggestionsAsString.add(offer.getText()));
|
||||
|
||||
FilteredTabCompletionEvent filteredTabCompletionEvent = PATEventHandler.callFilteredTabCompletionEvents(player.getUniqueId(), rawPlayerInput, suggestionsAsString);
|
||||
if(filteredTabCompletionEvent.isCancelled()) return;
|
||||
response.getOffers().removeIf(offer -> !filteredTabCompletionEvent.getCompletion().contains(offer.getText()));
|
||||
if (filteredTabCompletionEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(response.getOffers().isEmpty()) return;
|
||||
response.getOffers().removeIf(offer -> !filteredTabCompletionEvent.getCompletion().contains(offer.getText()));
|
||||
if (response.getOffers().isEmpty()) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if(packet instanceof AvailableCommandsPacket) {
|
||||
} else if (packet instanceof AvailableCommandsPacket) {
|
||||
|
||||
if (!PermissionUtil.hasBypassPermission(player) && player.getCurrentServer().isPresent()) {
|
||||
AvailableCommandsPacket commands = (AvailableCommandsPacket) packet;
|
||||
|
||||
if(!commands.getRootNode().getChildren().isEmpty()) {
|
||||
String serverName = player.getCurrentServer().get().getServer().getServerInfo().getName();
|
||||
Map<String, CommandsCache> cache = Storage.getLoader().getCommandsCacheMap();
|
||||
|
||||
if (!COMMANDS_CACHE_MAP.containsKey(serverName))
|
||||
COMMANDS_CACHE_MAP.put(serverName, new CommandsCache().reverse());
|
||||
CommandsCache commandsCache = COMMANDS_CACHE_MAP.get(serverName);
|
||||
if (!cache.containsKey(serverName))
|
||||
cache.put(serverName, new CommandsCache());
|
||||
|
||||
CommandsCache commandsCache = cache.get(serverName);
|
||||
|
||||
List<String> commandsAsString = new ArrayList<>();
|
||||
commands.getRootNode().getChildren().stream().filter(command -> command != null && command.getName() != null).forEach(command -> commandsAsString.add(command.getName()));
|
||||
@@ -246,7 +266,7 @@ public class VelocityPacketAnalyzer {
|
||||
final boolean newer = player.getProtocolVersion().getProtocol() > 340;
|
||||
final List<String> playerCommands = commandsCache.getPlayerCommands(commandsAsString, player, player.getUniqueId(), serverName);
|
||||
|
||||
if(commands.getRootNode().getChildren().size() == 1 && newer
|
||||
if (commands.getRootNode().getChildren().size() == 1 && newer
|
||||
&& commands.getRootNode().getChild("args") != null
|
||||
&& commands.getRootNode().getChild("args").getChildren().isEmpty()) {
|
||||
|
||||
@@ -254,7 +274,15 @@ public class VelocityPacketAnalyzer {
|
||||
return;
|
||||
}
|
||||
|
||||
commands.getRootNode().getChildren().removeIf(command -> command == null || command.getName() == null || playerCommands.contains(command.getName()));
|
||||
commands.getRootNode().getChildren().removeIf(command -> {
|
||||
if (command == null || command.getName() == null)
|
||||
return true;
|
||||
|
||||
if (command.getName().equals("args"))
|
||||
return false;
|
||||
|
||||
return !playerCommands.contains(command.getName());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,82 @@
|
||||
package de.rayzs.pat.api.storage;
|
||||
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
import de.rayzs.pat.api.storage.placeholders.commands.general.*;
|
||||
import de.rayzs.pat.api.storage.placeholders.commands.group.*;
|
||||
import de.rayzs.pat.api.storage.blacklist.BlacklistCreator;
|
||||
import de.rayzs.pat.api.storage.storages.ConfigStorage;
|
||||
import de.rayzs.pat.api.storage.placeholders.general.*;
|
||||
import de.rayzs.pat.api.storage.placeholders.groups.*;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import de.rayzs.pat.api.storage.config.messages.*;
|
||||
import de.rayzs.pat.api.storage.config.settings.*;
|
||||
import de.rayzs.pat.api.storage.blacklist.impl.*;
|
||||
import de.rayzs.pat.api.storage.storages.*;
|
||||
import de.rayzs.pat.utils.configuration.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import de.rayzs.pat.utils.group.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import de.rayzs.pat.plugin.*;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import de.rayzs.pat.api.communication.Communicator;
|
||||
import de.rayzs.pat.plugin.listeners.bukkit.BukkitAntiTabListener;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.plugin.modules.SubArgsModule;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
import de.rayzs.pat.api.storage.blacklist.BlacklistCreator;
|
||||
import de.rayzs.pat.api.storage.blacklist.impl.GeneralBlacklist;
|
||||
import de.rayzs.pat.api.storage.blacklist.impl.GeneralIgnoredServers;
|
||||
import de.rayzs.pat.api.storage.config.messages.BlacklistSection;
|
||||
import de.rayzs.pat.api.storage.config.messages.CommandFailedSection;
|
||||
import de.rayzs.pat.api.storage.config.messages.GroupSection;
|
||||
import de.rayzs.pat.api.storage.config.messages.HelpSection;
|
||||
import de.rayzs.pat.api.storage.config.messages.InfoSection;
|
||||
import de.rayzs.pat.api.storage.config.messages.NoPermissionSection;
|
||||
import de.rayzs.pat.api.storage.config.messages.NotificationSection;
|
||||
import de.rayzs.pat.api.storage.config.messages.OnlyForProxySection;
|
||||
import de.rayzs.pat.api.storage.config.messages.PermsCheckSection;
|
||||
import de.rayzs.pat.api.storage.config.messages.PostDebugSection;
|
||||
import de.rayzs.pat.api.storage.config.messages.PrefixSection;
|
||||
import de.rayzs.pat.api.storage.config.messages.ReloadSection;
|
||||
import de.rayzs.pat.api.storage.config.messages.ServerListSection;
|
||||
import de.rayzs.pat.api.storage.config.messages.StatsSection;
|
||||
import de.rayzs.pat.api.storage.config.messages.UpdatePermissionsSection;
|
||||
import de.rayzs.pat.api.storage.config.settings.AutoLowercaseCommandsSection;
|
||||
import de.rayzs.pat.api.storage.config.settings.BlockNamespaceCommandsSection;
|
||||
import de.rayzs.pat.api.storage.config.settings.CancelCommandSection;
|
||||
import de.rayzs.pat.api.storage.config.settings.CustomBrandSection;
|
||||
import de.rayzs.pat.api.storage.config.settings.CustomPluginsSection;
|
||||
import de.rayzs.pat.api.storage.config.settings.CustomProtocolPingSection;
|
||||
import de.rayzs.pat.api.storage.config.settings.CustomUnknownCommandSection;
|
||||
import de.rayzs.pat.api.storage.config.settings.CustomVersionSection;
|
||||
import de.rayzs.pat.api.storage.config.settings.DisableSyncSection;
|
||||
import de.rayzs.pat.api.storage.config.settings.HandleThroughProxySection;
|
||||
import de.rayzs.pat.api.storage.config.settings.PatchExploitSection;
|
||||
import de.rayzs.pat.api.storage.config.settings.TurnBlacklistToWhitelistSection;
|
||||
import de.rayzs.pat.api.storage.config.settings.UpdateSection;
|
||||
import de.rayzs.pat.api.storage.placeholders.commands.general.ListCommandsPlaceholder;
|
||||
import de.rayzs.pat.api.storage.placeholders.commands.general.ListReversedCommandsPlaceholder;
|
||||
import de.rayzs.pat.api.storage.placeholders.commands.general.ListSizeCommandsPlaceholder;
|
||||
import de.rayzs.pat.api.storage.placeholders.commands.general.ListSortedCommandsPlaceholder;
|
||||
import de.rayzs.pat.api.storage.placeholders.commands.group.ListGroupCommandsPlaceholder;
|
||||
import de.rayzs.pat.api.storage.placeholders.commands.group.ListGroupReversedCommandsPlaceholder;
|
||||
import de.rayzs.pat.api.storage.placeholders.commands.group.ListGroupSizeCommandsPlaceholder;
|
||||
import de.rayzs.pat.api.storage.placeholders.commands.group.ListGroupSortedCommandsPlaceholder;
|
||||
import de.rayzs.pat.api.storage.placeholders.general.GeneralCurrentVersionPlaceholder;
|
||||
import de.rayzs.pat.api.storage.placeholders.general.GeneralNewestVersionPlaceholder;
|
||||
import de.rayzs.pat.api.storage.placeholders.general.GeneralPrefixPlaceholder;
|
||||
import de.rayzs.pat.api.storage.placeholders.general.GeneralUserPlaceholder;
|
||||
import de.rayzs.pat.api.storage.placeholders.groups.ListGroupsPlaceholder;
|
||||
import de.rayzs.pat.api.storage.placeholders.groups.ListGroupsReversedPlaceholder;
|
||||
import de.rayzs.pat.api.storage.placeholders.groups.ListGroupsSortedPlaceholder;
|
||||
import de.rayzs.pat.api.storage.placeholders.groups.ListSizeGroupsPlaceholder;
|
||||
import de.rayzs.pat.api.storage.placeholders.messages.BlockedBaseCommandPlaceholder;
|
||||
import de.rayzs.pat.api.storage.placeholders.messages.BlockedSubCommandPlaceholder;
|
||||
import de.rayzs.pat.api.storage.placeholders.messages.UnknownCommandPlaceholder;
|
||||
import de.rayzs.pat.api.storage.storages.ConfigStorage;
|
||||
import de.rayzs.pat.api.storage.storages.DisabledServersStorage;
|
||||
import de.rayzs.pat.api.storage.storages.IgnoredServersStorage;
|
||||
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
|
||||
import de.rayzs.pat.plugin.PluginLoader;
|
||||
import de.rayzs.pat.utils.ExpireCache;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.configuration.ConfigurationBuilder;
|
||||
import de.rayzs.pat.utils.configuration.Configurator;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
import de.rayzs.pat.utils.message.replacer.PlaceholderReplacer;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
|
||||
public class Storage {
|
||||
|
||||
private static PluginLoader LOADER;
|
||||
|
||||
public static final List<UUID> NOTIFY_PLAYERS = new ArrayList<>();
|
||||
|
||||
public static String TOKEN = "", SERVER_NAME = null, CURRENT_VERSION = "", NEWER_VERSION = "";
|
||||
@@ -30,16 +85,71 @@ public class Storage {
|
||||
public static boolean USE_LUCKPERMS = false, USE_PLACEHOLDERAPI = false, USE_PAPIPROXYBRIDGE = false, USE_VIAVERSION = false, USE_VELOCITY = false, USE_SIMPLECLOUD;
|
||||
public static long LAST_SYNC = System.currentTimeMillis();
|
||||
|
||||
public static void initialize(PluginLoader loader, String currentVersion) {
|
||||
LOADER = loader;
|
||||
CURRENT_VERSION = currentVersion;
|
||||
}
|
||||
|
||||
public static void loadAll(boolean loadBlacklist) {
|
||||
loadConfig();
|
||||
loadToken();
|
||||
if(loadBlacklist) Blacklist.loadAll();
|
||||
|
||||
if (TOKEN != null && !TOKEN.isEmpty()) {
|
||||
int tokenLength = TOKEN.length(), cutIndex = Math.max(1, tokenLength - 3);
|
||||
String censoredTokenDisplay = "*".repeat(cutIndex) + TOKEN.substring(cutIndex);
|
||||
Logger.info("Token found! (" + censoredTokenDisplay + ")");
|
||||
}
|
||||
|
||||
if (loadBlacklist) Blacklist.loadAll();
|
||||
|
||||
PATEventHandler.callUpdatePluginEvents();
|
||||
}
|
||||
|
||||
public static void loadToken() {
|
||||
TOKEN = Reflection.isProxyServer() ? (String) Files.TOKEN.getOrSet("token", UUID.randomUUID().toString()) : ConfigSections.Settings.HANDLE_THROUGH_PROXY.TOKEN;
|
||||
|
||||
boolean invalidEnv = false;
|
||||
|
||||
if (Reflection.isProxyServer()) {
|
||||
boolean loadFromEnv = (Boolean) Files.TOKEN.getOrSet("load-from-env.enabled", false);
|
||||
String envVariable = (String) Files.TOKEN.getOrSet("load-from-env.name", "PAT_TOKEN");
|
||||
|
||||
if (loadFromEnv) {
|
||||
Logger.info("Looking up token from environment variable: " + envVariable);
|
||||
TOKEN = System.getenv(envVariable);
|
||||
|
||||
if (TOKEN != null) {
|
||||
return;
|
||||
} else invalidEnv = true;
|
||||
}
|
||||
|
||||
TOKEN = (String) Files.TOKEN.getOrSet("token", UUID.randomUUID().toString());
|
||||
|
||||
if (invalidEnv)
|
||||
Logger.warning("Environment variable not found! Using default Token from the token.yml instead.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean loadFromEnv = ConfigSections.Settings.HANDLE_THROUGH_PROXY.LOAD_FROM_ENV;
|
||||
String envVariable = ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENV_NAME;
|
||||
|
||||
if (loadFromEnv) {
|
||||
TOKEN = System.getenv(envVariable);
|
||||
|
||||
if (TOKEN != null) {
|
||||
return;
|
||||
} else invalidEnv = true;
|
||||
|
||||
}
|
||||
|
||||
TOKEN = ConfigSections.Settings.HANDLE_THROUGH_PROXY.TOKEN;
|
||||
|
||||
if (invalidEnv)
|
||||
Logger.warning("Environment variable not found! Using default Token from the config.yml instead.");
|
||||
}
|
||||
|
||||
public static void loadConfig() {
|
||||
@@ -47,34 +157,104 @@ public class Storage {
|
||||
ConfigSections.Messages.initialize();
|
||||
ConfigSections.SECTIONS.forEach(ConfigStorage::load);
|
||||
|
||||
if(USE_PLACEHOLDERAPI)
|
||||
if (USE_PLACEHOLDERAPI)
|
||||
ConfigSections.PLACEHOLDERS.forEach(PlaceholderStorage::load);
|
||||
}
|
||||
|
||||
public static void handleChange() {
|
||||
handleChange(null);
|
||||
}
|
||||
|
||||
public static void handleChange(String server) {
|
||||
|
||||
if (Reflection.isProxyServer()) {
|
||||
|
||||
boolean isVelocity = Reflection.isVelocityServer();
|
||||
|
||||
if (server != null) {
|
||||
|
||||
Storage.Blacklist.clearServerBlacklists(server);
|
||||
Storage.Blacklist.loadCachedServerBlacklists(server);
|
||||
|
||||
List<String> associatedServers = getServers()
|
||||
.stream()
|
||||
.filter(s -> !s.equals(server) && isServer(server, s))
|
||||
.toList();
|
||||
|
||||
associatedServers.forEach(s -> {
|
||||
Storage.Blacklist.clearServerBlacklists(s);
|
||||
Storage.Blacklist.loadCachedServerBlacklists(s);
|
||||
});
|
||||
|
||||
if (isVelocity) {
|
||||
|
||||
associatedServers.forEach(s -> {
|
||||
List<UUID> playerIds = Storage.getLoader().getPlayerIdsByServer(s);
|
||||
List<String> commands = new ArrayList<>(SubArgsModule.getServerCommands(s));
|
||||
|
||||
playerIds.forEach(playerId -> {
|
||||
List<String> playerCommands = new ArrayList<>(commands);
|
||||
playerCommands.addAll(SubArgsModule.getGroupCommands(playerId, s));
|
||||
|
||||
PATEventHandler.callUpdatePlayerCommandsEvents(playerId, playerCommands, true);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (isVelocity) {
|
||||
List<UUID> playerIds = Storage.getLoader().getPlayerIds();
|
||||
|
||||
playerIds.forEach(playerId -> {
|
||||
List<String> playerCommands = new ArrayList<>(SubArgsModule.getServerCommands(playerId));
|
||||
playerCommands.addAll(SubArgsModule.getGroupCommands(playerId));
|
||||
|
||||
PATEventHandler.callUpdatePlayerCommandsEvents(playerId, playerCommands, false);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
GroupManager.clearServerGroupBlacklists();
|
||||
Communicator.syncData();
|
||||
|
||||
Storage.getLoader().updateCommandCache();
|
||||
Communicator.sendPermissionReset();
|
||||
return;
|
||||
}
|
||||
|
||||
PermissionUtil.reloadPermissions();
|
||||
|
||||
if (Reflection.getMinor() >= 13) {
|
||||
BukkitAntiTabListener.handleTabCompletion();
|
||||
}
|
||||
}
|
||||
|
||||
public static PluginLoader getLoader() {
|
||||
return LOADER;
|
||||
}
|
||||
|
||||
public static List<String> getServers() {
|
||||
return getServers(false);
|
||||
}
|
||||
|
||||
public static List<String> getServers(boolean withBlacklist) {
|
||||
List<String> servers = new ArrayList<>();
|
||||
if(Reflection.isVelocityServer())
|
||||
servers.addAll(VelocityLoader.getServerNames());
|
||||
else if(Reflection.isProxyServer())
|
||||
servers.addAll(BungeeLoader.getServerNames());
|
||||
public static List<String> getServers(boolean includingServerSpecifics) {
|
||||
List<String> servers = LOADER.getServerNames();
|
||||
|
||||
if(includingServerSpecifics) {
|
||||
servers.addAll(Blacklist.getBlacklists().stream().map(Map.Entry::getKey).toList());
|
||||
}
|
||||
|
||||
if(withBlacklist) Blacklist.getBlacklistServers().stream().filter(server -> !servers.contains(server.toLowerCase())).forEach(server -> servers.add(server.toLowerCase()));
|
||||
return servers;
|
||||
}
|
||||
|
||||
public static boolean isServer(String originServer, Set<String> targetServers) {
|
||||
List<String> list = new ArrayList<>(targetServers);
|
||||
return isServer(originServer, list);
|
||||
}
|
||||
|
||||
public static boolean isServer(String targetServers, List<String> servers) {
|
||||
for (String originServer : servers)
|
||||
if(isServer(originServer, targetServers))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -82,10 +262,11 @@ public class Storage {
|
||||
originServer = originServer.toLowerCase();
|
||||
targetServer = targetServer.toLowerCase();
|
||||
|
||||
if(originServer.endsWith("*")) {
|
||||
originServer = originServer.replace("*", "");
|
||||
if (originServer.endsWith("*")) {
|
||||
originServer = originServer.substring(0, originServer.length() - 2);
|
||||
return targetServer.startsWith(originServer);
|
||||
}
|
||||
|
||||
return originServer.equalsIgnoreCase(targetServer);
|
||||
}
|
||||
|
||||
@@ -107,6 +288,7 @@ public class Storage {
|
||||
|
||||
public static class Settings {
|
||||
|
||||
public static AutoLowercaseCommandsSection AUTO_LOWERCASE_COMMANDS = new AutoLowercaseCommandsSection();
|
||||
public static BlockNamespaceCommandsSection BLOCK_NAMESPACE_COMMANDS = new BlockNamespaceCommandsSection();
|
||||
public static HandleThroughProxySection HANDLE_THROUGH_PROXY = new HandleThroughProxySection();
|
||||
public static PatchExploitSection PATCH_EXPLOITS = new PatchExploitSection();
|
||||
@@ -146,10 +328,15 @@ public class Storage {
|
||||
|
||||
public static class Placeholders {
|
||||
|
||||
public static GeneralPrefixPlaceholder PREFIX = new GeneralPrefixPlaceholder();
|
||||
public static GeneralUserPlaceholder USER = new GeneralUserPlaceholder();
|
||||
public static GeneralCurrentVersionPlaceholder CURRENT_VERSION = new GeneralCurrentVersionPlaceholder();
|
||||
public static GeneralNewestVersionPlaceholder NEWEST_VERSION = new GeneralNewestVersionPlaceholder();
|
||||
|
||||
public static BlockedBaseCommandPlaceholder BLOCKED_BASE_COMMAND = new BlockedBaseCommandPlaceholder();
|
||||
public static BlockedSubCommandPlaceholder BLOCKED_SUB_COMMAND = new BlockedSubCommandPlaceholder();
|
||||
public static UnknownCommandPlaceholder UNKNOWN_COMMAND = new UnknownCommandPlaceholder();
|
||||
|
||||
public static ListGroupsPlaceholder LIST_GROUP = new ListGroupsPlaceholder();
|
||||
public static ListGroupsReversedPlaceholder LIST_GROUP_REVERSED = new ListGroupsReversedPlaceholder();
|
||||
public static ListGroupsSortedPlaceholder LIST_GROUP_SORTED = new ListGroupsSortedPlaceholder();
|
||||
@@ -170,20 +357,26 @@ public class Storage {
|
||||
public static String findAndReplace(Player player, String request) {
|
||||
String result = null, param = "";
|
||||
|
||||
if(USE_PLACEHOLDERAPI)
|
||||
if(USE_PLACEHOLDERAPI) {
|
||||
for (PlaceholderStorage storage : PLACEHOLDERS) {
|
||||
if(!storage.getRequest().startsWith(request)) continue;
|
||||
if (!storage.getRequest().startsWith(request)) continue;
|
||||
|
||||
if(storage.getRequest().endsWith("group_") && request.contains("group_"))
|
||||
if (storage.getRequest().endsWith("group_") && request.contains("group_"))
|
||||
param = request.split("group_")[1];
|
||||
|
||||
result = storage.onRequest(player, param);
|
||||
if(result == null) continue;
|
||||
if (result == null) continue;
|
||||
else result = result.replace("\\n", "\n");
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Second time because of nested placeholders
|
||||
if (result != null && result.contains("%")) {
|
||||
result = PlaceholderReplacer.replace(player, result);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -191,9 +384,34 @@ public class Storage {
|
||||
|
||||
public static class Blacklist {
|
||||
|
||||
private static final HashMap<String, GeneralBlacklist> SERVER_BLACKLISTS = new HashMap<>();
|
||||
public enum BlockType {
|
||||
CHAT("[CMD]"),
|
||||
TAB("[TAB]"),
|
||||
NEGATE("!"),
|
||||
|
||||
BOTH("");
|
||||
|
||||
private final String text;
|
||||
|
||||
BlockType(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.text;
|
||||
}
|
||||
}
|
||||
|
||||
private static final BlockType[] BLOCK_TYPES = BlockType.values();
|
||||
|
||||
private static final GeneralBlacklist BLACKLIST = BlacklistCreator.createGeneralBlacklist();
|
||||
private static final IgnoredServersStorage IGNORED_SERVERS = new GeneralIgnoredServers();
|
||||
private static final DisabledServersStorage DISABLED_SERVERS = new DisabledServersStorage();
|
||||
|
||||
// General server-specific list (e.g: server-*)
|
||||
private static final HashMap<String, GeneralBlacklist> SERVER_BLACKLISTS = new HashMap<>();
|
||||
// Temporary list for all servers (e.g: server-1)
|
||||
private static final ExpireCache<String, List<GeneralBlacklist>> CACHED_SERVER_BLACKLIST = new ExpireCache<>(1, TimeUnit.HOURS);
|
||||
|
||||
public static void loadAll() {
|
||||
@@ -201,275 +419,212 @@ public class Storage {
|
||||
SERVER_BLACKLISTS.clear();
|
||||
BLACKLIST.load();
|
||||
|
||||
if(!Reflection.isProxyServer()) return;
|
||||
if(!Reflection.isProxyServer())
|
||||
return;
|
||||
|
||||
IGNORED_SERVERS.load();
|
||||
DISABLED_SERVERS.load();
|
||||
|
||||
BLACKLIST.getConfig().getKeys("global.servers", true).forEach(key -> {
|
||||
GeneralBlacklist blacklist = BlacklistCreator.createGeneralBlacklist(key);
|
||||
blacklist.load();
|
||||
|
||||
SERVER_BLACKLISTS.put(key, blacklist);
|
||||
});
|
||||
|
||||
loadAllCachedServerBlacklists();
|
||||
}
|
||||
|
||||
public static boolean isOnIgnoredServer(String server) {
|
||||
return IGNORED_SERVERS.isListed(server);
|
||||
private static void loadAllCachedServerBlacklists() {
|
||||
getServers().forEach(Blacklist::loadCachedServerBlacklists);
|
||||
}
|
||||
|
||||
public static boolean isBlockedGloballyOnServer(boolean blocked, String server, boolean turn) {
|
||||
if(isOnIgnoredServer(server)) return turn;
|
||||
else return blocked;
|
||||
private static void loadCachedServerBlacklists(String server) {
|
||||
List<GeneralBlacklist> blacklists = SERVER_BLACKLISTS.entrySet().stream()
|
||||
.filter(entry ->
|
||||
isServer(entry.getKey(), server)
|
||||
).map(entry ->
|
||||
entry.getValue()
|
||||
).toList();
|
||||
|
||||
CACHED_SERVER_BLACKLIST.put(server, blacklists);
|
||||
}
|
||||
|
||||
public static List<String> getBlacklistServers() {
|
||||
return new ArrayList<>(SERVER_BLACKLISTS.keySet());
|
||||
public static GeneralBlacklist getServerBlacklist(String server) {
|
||||
GeneralBlacklist blacklist = SERVER_BLACKLISTS.get(server);
|
||||
if(blacklist != null) {
|
||||
return blacklist;
|
||||
}
|
||||
|
||||
blacklist = BlacklistCreator.createGeneralBlacklist(server);
|
||||
blacklist.load();
|
||||
|
||||
SERVER_BLACKLISTS.put(server, blacklist);
|
||||
return blacklist;
|
||||
}
|
||||
|
||||
public static Set<Map.Entry<String, GeneralBlacklist>> getBlacklists() {
|
||||
return SERVER_BLACKLISTS.entrySet();
|
||||
}
|
||||
|
||||
public static GeneralBlacklist getBlacklist() {
|
||||
return BLACKLIST;
|
||||
}
|
||||
|
||||
public static GeneralBlacklist getBlacklist(String server) {
|
||||
GeneralBlacklist blacklist;
|
||||
public static List<GeneralBlacklist> getServerBlacklists(String server) {
|
||||
if (!CACHED_SERVER_BLACKLIST.contains(server)) {
|
||||
loadCachedServerBlacklists(server);
|
||||
}
|
||||
|
||||
if(!SERVER_BLACKLISTS.containsKey(server)) {
|
||||
blacklist = BlacklistCreator.createGeneralBlacklist(server);
|
||||
blacklist.load();
|
||||
SERVER_BLACKLISTS.put(server, blacklist);
|
||||
} else blacklist = SERVER_BLACKLISTS.get(server);
|
||||
|
||||
return SERVER_BLACKLISTS.getOrDefault(server, blacklist);
|
||||
}
|
||||
|
||||
public static List<GeneralBlacklist> getAllBlacklists(String server) {
|
||||
List<GeneralBlacklist> blacklists = getBlacklists(server);
|
||||
if (isOnIgnoredServer(server)) return blacklists;
|
||||
|
||||
blacklists.add(Storage.Blacklist.getBlacklist());
|
||||
return blacklists;
|
||||
return CACHED_SERVER_BLACKLIST.get(server);
|
||||
}
|
||||
|
||||
public static void clearServerBlacklists(String server) {
|
||||
CACHED_SERVER_BLACKLIST.remove(server.toLowerCase());
|
||||
CACHED_SERVER_BLACKLIST.remove(server);
|
||||
}
|
||||
|
||||
public static List<GeneralBlacklist> getBlacklists(String server) {
|
||||
final String finalServer = server.toLowerCase();
|
||||
|
||||
if (CACHED_SERVER_BLACKLIST.contains(finalServer))
|
||||
return CACHED_SERVER_BLACKLIST.get(finalServer);
|
||||
|
||||
List<GeneralBlacklist> blacklists = new ArrayList<>();
|
||||
SERVER_BLACKLISTS.entrySet()
|
||||
.stream().filter(entry -> entry.getKey().endsWith("*")
|
||||
? isServer(entry.getKey(), finalServer)
|
||||
: entry.getKey().equalsIgnoreCase(finalServer))
|
||||
.forEach(entry -> blacklists.add(entry.getValue()));
|
||||
|
||||
return CACHED_SERVER_BLACKLIST.putAndGet(finalServer, blacklists);
|
||||
public static boolean isDisabledServer(String server) {
|
||||
return DISABLED_SERVERS.isListed(server);
|
||||
}
|
||||
|
||||
public static boolean isListed(String command, String server) {
|
||||
boolean turn = ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED,
|
||||
blocked = isBlockedGloballyOnServer(isBlocked(command, server), server, turn);
|
||||
public static boolean isIgnoredServer(String server) {
|
||||
return IGNORED_SERVERS.isListed(server);
|
||||
}
|
||||
|
||||
if(!blocked) for (GeneralBlacklist blacklist : getBlacklists(server)) {
|
||||
blocked = blacklist.isBlocked(command, server, !turn);
|
||||
if(blocked) break;
|
||||
public static boolean canPlayerAccess(Object player, String command, BlockType type) {
|
||||
return canPlayerAccess(player, command, type, null);
|
||||
}
|
||||
|
||||
public static boolean canPlayerAccessChat(Object player, String command) {
|
||||
return canPlayerAccess(player, command, BlockType.CHAT, null);
|
||||
}
|
||||
|
||||
|
||||
public static boolean canPlayerAccessChat(Object player, String command, String server) {
|
||||
return canPlayerAccess(player, command, BlockType.CHAT, server);
|
||||
}
|
||||
|
||||
public static boolean canPlayerAccessTab(Object player, String command) {
|
||||
return canPlayerAccess(player, command, BlockType.TAB, null);
|
||||
}
|
||||
|
||||
public static boolean canPlayerAccessTab(Object player, String command, String server) {
|
||||
return canPlayerAccess(player, command, BlockType.TAB, server);
|
||||
}
|
||||
|
||||
public static boolean canPlayerAccess(Object player, String command, BlockType type, String server) {
|
||||
boolean blocked = isBlocked(command, type, server);
|
||||
|
||||
if (!blocked) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return blocked;
|
||||
}
|
||||
|
||||
public static boolean isListed(String command, boolean intensive, String server) {
|
||||
boolean turn = ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED,
|
||||
blocked = isBlockedGloballyOnServer(isListed(command, intensive), server, turn);
|
||||
|
||||
if(!blocked) for (GeneralBlacklist blacklist : getBlacklists(server)) {
|
||||
blocked = blacklist.isListed(command, intensive);
|
||||
if(blocked) break;
|
||||
if (PermissionUtil.hasBypassPermission(player, command)) {
|
||||
return true;
|
||||
}
|
||||
return blocked;
|
||||
|
||||
return GroupManager.canAccessCommand(player, command, type, server);
|
||||
}
|
||||
|
||||
public static boolean doesGroupBypass(Object playerObj, String command, boolean intensive, String server) {
|
||||
int priority = -1;
|
||||
for (Group group : GroupManager.getGroups()) {
|
||||
for (GroupBlacklist groupBlacklist : group.getAllServerGroupBlacklist(server)) {
|
||||
public static boolean isBlockedChat(String command) {
|
||||
return isBlocked(command, BlockType.CHAT, null);
|
||||
}
|
||||
|
||||
if(priority == -1 || group.getPriority() <= priority)
|
||||
if(group.hasPermission(playerObj)) {
|
||||
priority = group.getPriority();
|
||||
if (groupBlacklist.isListed(command, intensive)) return true;
|
||||
}
|
||||
public static boolean isBlockedTab(String command) {
|
||||
return isBlocked(command, BlockType.TAB, null);
|
||||
}
|
||||
|
||||
public static boolean isBlockedChat(String command, String server) {
|
||||
return isBlocked(command, BlockType.CHAT, server);
|
||||
}
|
||||
|
||||
public static boolean isBlockedTab(String command, String server) {
|
||||
return isBlocked(command, BlockType.TAB, server);
|
||||
}
|
||||
|
||||
public static boolean isBlocked(String command, BlockType type) {
|
||||
return isBlocked(command, type, null);
|
||||
}
|
||||
|
||||
public static boolean isBlocked(String command, BlockType type, String server) {
|
||||
boolean listed = isListed(command, type, server),
|
||||
turn = ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED;
|
||||
|
||||
if (turn) {
|
||||
return !listed;
|
||||
} else {
|
||||
return listed;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static boolean isListed(String unmodifiedCommand, BlockType type, String server) {
|
||||
if (server != null && isDisabledServer(server))
|
||||
return false;
|
||||
|
||||
boolean turn = Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED;
|
||||
boolean listed = false;
|
||||
|
||||
if (type == BlockType.NEGATE)
|
||||
turn = !turn;
|
||||
|
||||
String command = type.toString() + unmodifiedCommand;
|
||||
|
||||
if (server == null || !isIgnoredServer(server))
|
||||
listed = BLACKLIST.isListed(command, !turn);
|
||||
|
||||
if (server == null) {
|
||||
|
||||
if (!listed && type != BlockType.BOTH)
|
||||
return isListed(unmodifiedCommand, BlockType.BOTH, null);
|
||||
|
||||
return listed;
|
||||
}
|
||||
|
||||
List<GeneralBlacklist> blacklists = new ArrayList<>(getServerBlacklists(server));
|
||||
if (blacklists.isEmpty())
|
||||
blacklists.add(BLACKLIST);
|
||||
|
||||
for (GeneralBlacklist blacklist : blacklists) {
|
||||
if (listed && turn) {
|
||||
break;
|
||||
}
|
||||
|
||||
listed = blacklist.isListed(command, turn);
|
||||
}
|
||||
|
||||
return false;
|
||||
if (!listed && type != BlockType.BOTH) {
|
||||
return isListed(unmodifiedCommand, BlockType.BOTH, server);
|
||||
}
|
||||
|
||||
return listed;
|
||||
}
|
||||
|
||||
public static boolean doesGroupBypass(Object playerObj, String command, boolean intensive, boolean convert, boolean slash, String server) {
|
||||
int priority = -1;
|
||||
for (Group group : GroupManager.getGroups()) {
|
||||
for (GroupBlacklist groupBlacklist : group.getAllServerGroupBlacklist(server, true)) {
|
||||
if(priority == -1 || group.getPriority() <= priority)
|
||||
if(group.hasPermission(playerObj)) {
|
||||
priority = group.getPriority();
|
||||
if (groupBlacklist.isListed(command, intensive, convert, slash)) return true;
|
||||
}
|
||||
public static class BlockTypeFetcher {
|
||||
|
||||
public static BlockType getType(String command) {
|
||||
for (BlockType blockType : BLOCK_TYPES) {
|
||||
if (!command.startsWith(blockType.toString()))
|
||||
continue;
|
||||
|
||||
return blockType;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isListed(Object playerObj, String command, boolean intensive, String server) {
|
||||
if(GroupManager.getGroupsByServer(server).stream().anyMatch(group -> isInListed(command, group.getAllCommands(server), intensive) && group.hasPermission(playerObj)))
|
||||
return false;
|
||||
|
||||
boolean listed = isListed(command, intensive);
|
||||
|
||||
if(!listed) for (GeneralBlacklist blacklist : getBlacklists(server)) {
|
||||
listed = blacklist.isListed(command, intensive);
|
||||
if(listed) break;
|
||||
}
|
||||
return listed;
|
||||
}
|
||||
|
||||
public static boolean isListed(Object playerObj, String command, boolean intensive, boolean listed, String server) {
|
||||
if(GroupManager.getGroupsByServer(server).stream().anyMatch(group -> isInListed(command, group.getAllCommands(server), intensive) && group.hasPermission(playerObj)))
|
||||
return false;
|
||||
|
||||
if(!listed) for (GeneralBlacklist blacklist : getBlacklists(server)) {
|
||||
listed = blacklist.isListed(command, intensive);
|
||||
if(listed) break;
|
||||
}
|
||||
return listed;
|
||||
}
|
||||
|
||||
public static boolean isListed(Object playerObj, String command, boolean intensive, boolean listed, boolean slash, String server) {
|
||||
return isListed(playerObj, command, intensive, listed, slash, server, false);
|
||||
}
|
||||
|
||||
public static boolean isListed(Object playerObj, String command, boolean intensive, boolean listed, boolean slash, String server, boolean instantReturn) {
|
||||
if(GroupManager.getGroupsByServer(server).stream().anyMatch(group -> isInListed(command, group.getAllCommands(server), intensive) && group.hasPermission(playerObj)))
|
||||
return false;
|
||||
|
||||
if(listed) return true;
|
||||
|
||||
for (GeneralBlacklist blacklist : getBlacklists(server)) {
|
||||
listed = blacklist.isListed(command, intensive, true, slash);
|
||||
if(instantReturn) return listed;
|
||||
|
||||
if(listed) break;
|
||||
public static String modify(String command) {
|
||||
BlockType type = getType(command);
|
||||
return modify(command, type);
|
||||
}
|
||||
|
||||
return listed;
|
||||
}
|
||||
public static String modify(String command, BlockType type) {
|
||||
if (type == null || type == BlockType.BOTH || command.length() <= type.toString().length() || !command.startsWith(type.toString()))
|
||||
return command;
|
||||
|
||||
public static boolean isBlocked(String command, boolean intensive, String server) {
|
||||
return isBlocked(command, intensive, server, false);
|
||||
}
|
||||
|
||||
public static boolean isBlocked(Object targetObj, String command, boolean intensive, String server) {
|
||||
return isBlocked(targetObj, command, intensive, server, false);
|
||||
}
|
||||
|
||||
public static boolean isBlocked(String command, boolean intensive, String server, boolean focusOnBlock) {
|
||||
server = server.toLowerCase();
|
||||
|
||||
boolean turn = ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED,
|
||||
blocked,
|
||||
blockedGlobal = isBlockedGloballyOnServer(BLACKLIST.isBlockedIgnorePermission(command, intensive), server, turn),
|
||||
blockedServer = false;
|
||||
|
||||
if(focusOnBlock && blockedGlobal) return true;
|
||||
|
||||
for (GeneralBlacklist blacklist : getBlacklists(server)) {
|
||||
if(focusOnBlock && blacklist.isBlocked(command, intensive))
|
||||
return true;
|
||||
|
||||
blockedServer = blacklist.isBlockedIgnorePermission(command, intensive);
|
||||
break;
|
||||
return command.substring(type.toString().length());
|
||||
}
|
||||
|
||||
blocked = turn ? blockedGlobal && blockedServer : blockedServer || blockedGlobal;
|
||||
|
||||
// The reason which there's no tab-completion and also why every server-based list needs to exist to avoid this issue.
|
||||
|
||||
if (turn && !blocked
|
||||
&& CACHED_SERVER_BLACKLIST.contains(server)
|
||||
&& CACHED_SERVER_BLACKLIST.get(server).isEmpty())
|
||||
blocked = true;
|
||||
|
||||
return blocked;
|
||||
}
|
||||
|
||||
public static boolean isBlocked(Object targetObj, String command, boolean intensive, String server, boolean focusOnBlock) {
|
||||
if(server != null) server = server.toLowerCase();
|
||||
|
||||
if(doesGroupBypass(targetObj, command, intensive, server))
|
||||
return false;
|
||||
|
||||
boolean blocked = isBlocked(command, intensive, server, focusOnBlock);
|
||||
|
||||
if(blocked)
|
||||
if(PermissionUtil.hasBypassPermission(targetObj, command))
|
||||
blocked = false;
|
||||
|
||||
return blocked;
|
||||
}
|
||||
|
||||
public static boolean isListed(String command) {
|
||||
return BLACKLIST.isListed(command);
|
||||
}
|
||||
|
||||
public static boolean isListed(String command, boolean intensive) {
|
||||
return BLACKLIST.isListed(command, intensive);
|
||||
}
|
||||
|
||||
public static boolean isListed(String command, boolean intensive, boolean convert) {
|
||||
return BLACKLIST.isListed(command, intensive, convert);
|
||||
}
|
||||
|
||||
public static boolean isListed(String command, boolean intensive, boolean convert, boolean slash) {
|
||||
return BLACKLIST.isListed(command, intensive, convert, slash);
|
||||
}
|
||||
|
||||
public static boolean isBlocked(Object targetObj, String command) {
|
||||
return BLACKLIST.isBlocked(targetObj, command);
|
||||
}
|
||||
|
||||
public static boolean isBlocked(Object targetObj, String command, boolean intensive) {
|
||||
return BLACKLIST.isBlocked(targetObj, command, intensive);
|
||||
}
|
||||
|
||||
public static boolean isBlocked(Object targetObj, String command, boolean intensive, boolean convert, boolean slash) {
|
||||
return BLACKLIST.isBlocked(targetObj, command, intensive, convert, slash);
|
||||
}
|
||||
|
||||
public static boolean isBlocked(String command, boolean intensive, boolean convert) {
|
||||
return BLACKLIST.isBlocked(command, intensive, convert);
|
||||
}
|
||||
|
||||
public static boolean isBlocked(String command, boolean intensive, boolean convert, boolean slash) {
|
||||
return BLACKLIST.isBlocked(command, intensive, convert);
|
||||
}
|
||||
|
||||
public static String convertCommand(String command, boolean intensive, boolean lowercase) {
|
||||
return BLACKLIST.convertCommand(command, intensive, lowercase);
|
||||
}
|
||||
|
||||
public static String convertCommand(String command, boolean intensive, boolean lowercase, boolean slash) {
|
||||
return BLACKLIST.convertCommand(command, intensive, lowercase, slash);
|
||||
}
|
||||
|
||||
public static boolean isInListed(String command, List<String> commandList, boolean intensive) {
|
||||
command = StringUtils.replaceFirst(command, "/", "");
|
||||
command = convertCommand(command, intensive, false);
|
||||
|
||||
for (String commands : commandList)
|
||||
if(commands.equals(command)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@ public class BlacklistCreator {
|
||||
}
|
||||
|
||||
public static GeneralBlacklist createGeneralBlacklist(String server) {
|
||||
server = server.toLowerCase();
|
||||
return new GeneralBlacklist("servers." + server + ".commands");
|
||||
}
|
||||
|
||||
@@ -19,20 +18,18 @@ public class BlacklistCreator {
|
||||
}
|
||||
|
||||
public static GroupBlacklist createGroupBlacklist(String group, String server, boolean ignoreExist) {
|
||||
server = server.toLowerCase();
|
||||
if (!exist(group, server) && !ignoreExist)
|
||||
return null;
|
||||
|
||||
return new GroupBlacklist(group, "servers." + server + ".commands");
|
||||
}
|
||||
|
||||
public static boolean exist(String server) {
|
||||
server = server.toLowerCase();
|
||||
Object obj = Storage.Blacklist.getBlacklist().getConfig().get("global.servers." + server);
|
||||
return obj != null;
|
||||
}
|
||||
|
||||
public static boolean exist(String group, String server) {
|
||||
server = server.toLowerCase();
|
||||
Object obj = Storage.Blacklist.getBlacklist().getConfig().get("groups." + group + ".servers." + server);
|
||||
return obj != null;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import de.rayzs.pat.utils.Reflection;
|
||||
public class BlacklistSection extends ConfigStorage {
|
||||
|
||||
public String CLEAR, CLEAR_CONFIRM, CLEAR_SERVER, CLEAR_SERVER_CONFIRM, CLEAR_SERVER_NOT_FOUND;
|
||||
public String LIST_MESSAGE, LIST_SPLITTER, LIST_COMMAND, LIST_SERVER_MESSAGE, LIST_SERVER_SPLITTER, LIST_SERVER_COMMAND;
|
||||
public String LIST_MESSAGE, LIST_SPLITTER, LIST_SERVER_MESSAGE, LIST_SERVER_SPLITTER;
|
||||
|
||||
public String ADD_SUCCESS, ADD_FAILED;
|
||||
public String REMOVE_SUCCESS, REMOVE_FAILED;
|
||||
@@ -26,8 +26,7 @@ public class BlacklistSection extends ConfigStorage {
|
||||
CLEAR_CONFIRM = new ConfigSectionHelper<String>(this, "clear-confirmation", "&4Warning! &7This command will &cclear the entire list&7! &7Repeat the &esame command &7to confirm this action.").getOrSet();
|
||||
|
||||
LIST_MESSAGE = new ConfigSectionHelper<String>(this, "list.message", "&7Listed commands (&f%size%&7)&8: &f%commands%").getOrSet();
|
||||
LIST_SPLITTER = new ConfigSectionHelper<String>(this, "list.splitter", "&7, ").getOrSet();
|
||||
LIST_COMMAND = new ConfigSectionHelper<String>(this, "list.command", "&f%command%").getOrSet();
|
||||
LIST_SPLITTER = new ConfigSectionHelper<String>(this, "list.splitter", "&7, &f").getOrSet();
|
||||
|
||||
ADD_SUCCESS = new ConfigSectionHelper<String>(this, "add.success", "&aSuccessfully added %command% into the list!").getOrSet();
|
||||
ADD_FAILED = new ConfigSectionHelper<String>(this, "add.failed", "&c%command% is already in the list!").getOrSet();
|
||||
@@ -41,8 +40,7 @@ public class BlacklistSection extends ConfigStorage {
|
||||
CLEAR_SERVER_NOT_FOUND = new ConfigSectionHelper<String>(this, "clear-server-not-found", "&cThe server %server% does not have any commands!").getOrSet();
|
||||
|
||||
LIST_SERVER_MESSAGE = new ConfigSectionHelper<String>(this, "list.message-server", "&7Listed commands of %server% (&f%size%&7)&8: &f%commands%").getOrSet();
|
||||
LIST_SERVER_SPLITTER = new ConfigSectionHelper<String>(this, "list.splitter-server", "&7, ").getOrSet();
|
||||
LIST_SERVER_COMMAND = new ConfigSectionHelper<String>(this, "list.command-server", "&f%command%").getOrSet();
|
||||
LIST_SERVER_SPLITTER = new ConfigSectionHelper<String>(this, "list.splitter-server", "&7, &f").getOrSet();
|
||||
|
||||
ADD_SERVER_SUCCESS = new ConfigSectionHelper<String>(this, "add.success-server", "&aSuccessfully added %command% into the list of %server%!").getOrSet();
|
||||
ADD_SERVER_FAILED = new ConfigSectionHelper<String>(this, "add.failed-server", "&c%command% is already in the list of %server%!").getOrSet();
|
||||
|
||||
@@ -10,8 +10,8 @@ public class GroupSection extends ConfigStorage {
|
||||
public String CLEAR, CLEAR_CONFIRM, CLEAR_SERVER, CLEAR_SERVER_CONFIRM;
|
||||
public String PRIORITY_SUCCESS, PRIORITY_FAILED;
|
||||
|
||||
public String LIST_MESSAGE, LIST_SPLITTER, LIST_COMMAND, LIST_SERVER_MESSAGE, LIST_SERVER_SPLITTER, LIST_SERVER_COMMAND;
|
||||
public String LIST_GROUP_MESSAGE, LIST_GROUP_SPLITTER, LIST_GROUP_GROUPS, LIST_GROUP_SERVER_MESSAGE, LIST_GROUP_SERVER_SPLITTER, LIST_GROUP_SERVER_GROUPS;
|
||||
public String LIST_MESSAGE, LIST_SPLITTER, LIST_SERVER_MESSAGE, LIST_SERVER_SPLITTER;
|
||||
public String LIST_GROUP_MESSAGE, LIST_GROUP_SPLITTER, LIST_GROUP_SERVER_MESSAGE, LIST_GROUP_SERVER_SPLITTER;
|
||||
public String LIST_PRIORITY_MESSAGE, LIST_PRIORITY_SPLITTER, LIST_PRIORITY_GROUPS;
|
||||
|
||||
public String ADD_SUCCESS, ADD_FAILED;
|
||||
@@ -41,16 +41,14 @@ public class GroupSection extends ConfigStorage {
|
||||
PRIORITY_FAILED = new ConfigSectionHelper<String>(this, "priority.failed", "&cInvalid priority! Please choose a number which is greater than 0.").getOrSet();
|
||||
|
||||
LIST_MESSAGE = new ConfigSectionHelper<String>(this, "list.message", "&7Listed commands of group %group% (&f%size%&7)&8: &f%commands%").getOrSet();
|
||||
LIST_SPLITTER = new ConfigSectionHelper<String>(this, "list.splitter", "&7, ").getOrSet();
|
||||
LIST_COMMAND = new ConfigSectionHelper<String>(this, "list.command", "&f").getOrSet();
|
||||
LIST_SPLITTER = new ConfigSectionHelper<String>(this, "list.splitter", "&7, &f").getOrSet();
|
||||
|
||||
LIST_PRIORITY_MESSAGE = new ConfigSectionHelper<String>(this, "list-priorities.message", "&7List of all group priorities (&f%size%&7)&8: &f%groups%").getOrSet();
|
||||
LIST_PRIORITY_SPLITTER = new ConfigSectionHelper<String>(this, "list-priorities.splitter", "\\n").getOrSet();
|
||||
LIST_PRIORITY_GROUPS = new ConfigSectionHelper<String>(this, "list-priorities.group", "&8- &e%priority%&8: &f%group%").getOrSet();
|
||||
LIST_PRIORITY_GROUPS = new ConfigSectionHelper<String>(this, "list-priorities.group", "&8- &e%priority%&8: &e%group%").getOrSet();
|
||||
|
||||
LIST_GROUP_MESSAGE = new ConfigSectionHelper<String>(this, "list-groups.message", "&7All groups (&f%size%&7)&8: &f%groups%").getOrSet();
|
||||
LIST_GROUP_SPLITTER = new ConfigSectionHelper<String>(this, "list-groups.splitter", "&7, ").getOrSet();
|
||||
LIST_GROUP_GROUPS = new ConfigSectionHelper<String>(this, "list-groups.command", "&f").getOrSet();
|
||||
LIST_GROUP_SPLITTER = new ConfigSectionHelper<String>(this, "list-groups.splitter", "&7, &f").getOrSet();
|
||||
|
||||
ADD_SUCCESS = new ConfigSectionHelper<String>(this, "add.success", "&aSuccessfully added %command% into the list of group %group%!").getOrSet();
|
||||
ADD_FAILED = new ConfigSectionHelper<String>(this, "add.failed", "&c%command% is already in the list of group %group%!").getOrSet();
|
||||
@@ -69,12 +67,10 @@ public class GroupSection extends ConfigStorage {
|
||||
CLEAR_SERVER_CONFIRM = new ConfigSectionHelper<String>(this, "clear-confirmation-server", "&4Warning! &7This command will &cclear the entire list&7 of this group for %server%! &7Repeat the &esame command &7to confirm this action.").getOrSet();
|
||||
|
||||
LIST_SERVER_MESSAGE = new ConfigSectionHelper<String>(this, "list.message-server", "&7Listed commands of group %group% from %server% (&f%size%&7)&8: &f%commands%").getOrSet();
|
||||
LIST_SERVER_SPLITTER = new ConfigSectionHelper<String>(this, "list.splitter-server", "&7, ").getOrSet();
|
||||
LIST_SERVER_COMMAND = new ConfigSectionHelper<String>(this, "list.command-server", "&f%group%").getOrSet();
|
||||
LIST_SERVER_SPLITTER = new ConfigSectionHelper<String>(this, "list.splitter-server", "&7, &f").getOrSet();
|
||||
|
||||
LIST_GROUP_SERVER_MESSAGE = new ConfigSectionHelper<String>(this, "list-groups.message-server", "&7All groups from %server% (&f%size%&7)&8: &f%groups%").getOrSet();
|
||||
LIST_GROUP_SERVER_SPLITTER = new ConfigSectionHelper<String>(this, "list-groups.splitter-server", "&7, ").getOrSet();
|
||||
LIST_GROUP_SERVER_GROUPS = new ConfigSectionHelper<String>(this, "list-groups.command-server", "&f%group%").getOrSet();
|
||||
LIST_GROUP_SERVER_SPLITTER = new ConfigSectionHelper<String>(this, "list-groups.splitter-server", "&7, &f").getOrSet();
|
||||
|
||||
ADD_SERVER_SUCCESS = new ConfigSectionHelper<String>(this, "add.success-server", "&aSuccessfully added %command% into the list of group %group% for %server%!").getOrSet();
|
||||
ADD_SERVER_FAILED = new ConfigSectionHelper<String>(this, "add.failed-server", "&c%command% is already in the list of group %group% of %server%!").getOrSet();
|
||||
|
||||
@@ -7,7 +7,7 @@ import de.rayzs.pat.utils.Reflection;
|
||||
public class ServerListSection extends ConfigStorage {
|
||||
|
||||
public String SERVER_DOES_NOT_EXIST, GROUP_DOES_NOT_EXIST;
|
||||
public String LIST_SERVER_MESSAGE, LIST_SERVER_SPLITTER, LIST_SERVER_COMMAND, LIST_GROUP_MESSAGE, LIST_GROUP_SPLITTER, LIST_GROUP_COMMAND;
|
||||
public String LIST_SERVER_MESSAGE, LIST_SERVER_SPLITTER, LIST_GROUP_MESSAGE, LIST_GROUP_SPLITTER;
|
||||
|
||||
public ServerListSection() {
|
||||
super("server-list");
|
||||
@@ -22,11 +22,9 @@ public class ServerListSection extends ConfigStorage {
|
||||
GROUP_DOES_NOT_EXIST = new ConfigSectionHelper<String>(this, "group-does-not-exist", "&cGroup %group% does not exist for %server%!").getOrSet();
|
||||
|
||||
LIST_SERVER_MESSAGE = new ConfigSectionHelper<String>(this, "list.server.message", "&7Listed commands of %server% (&f%size%&7)&8: &f%commands%").getOrSet();
|
||||
LIST_SERVER_SPLITTER = new ConfigSectionHelper<String>(this, "list.server.splitter", "&7, ").getOrSet();
|
||||
LIST_SERVER_COMMAND = new ConfigSectionHelper<String>(this, "list.server.command", "&f%command%").getOrSet();
|
||||
LIST_SERVER_SPLITTER = new ConfigSectionHelper<String>(this, "list.server.splitter", "&7, &f").getOrSet();
|
||||
|
||||
LIST_GROUP_MESSAGE = new ConfigSectionHelper<String>(this, "list.group.message", "&7Listed commands of %group% from %server% (&f%size%&7)&8: &f%commands%").getOrSet();
|
||||
LIST_GROUP_SPLITTER = new ConfigSectionHelper<String>(this, "list.group.splitter", "&7, ").getOrSet();
|
||||
LIST_GROUP_COMMAND = new ConfigSectionHelper<String>(this, "list.group.command", "&f%command%").getOrSet();
|
||||
LIST_GROUP_SPLITTER = new ConfigSectionHelper<String>(this, "list.group.splitter", "&7, &f").getOrSet();
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package de.rayzs.pat.api.storage.config.settings;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.api.storage.storages.ConfigStorage;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
|
||||
public class AutoLowercaseCommandsSection extends ConfigStorage {
|
||||
|
||||
public boolean ENABLED;
|
||||
|
||||
public AutoLowercaseCommandsSection() {
|
||||
super("auto-lowercase-commands");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
|
||||
if (Reflection.isProxyServer())
|
||||
return;
|
||||
|
||||
ENABLED = new ConfigSectionHelper<Boolean>(this, "enabled", true).getOrSet();
|
||||
}
|
||||
|
||||
public boolean isCommand(String command) {
|
||||
if(!ENABLED) return false;
|
||||
|
||||
return !StringUtils.isLowercased(command);
|
||||
}
|
||||
|
||||
public boolean doesBypass(Object targetObj) {
|
||||
return !ENABLED || PermissionUtil.hasPermission(targetObj, "auto-lowercase");
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -1,13 +1,11 @@
|
||||
package de.rayzs.pat.api.storage.config.settings;
|
||||
|
||||
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
|
||||
import de.rayzs.pat.api.storage.storages.ConfigStorage;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.api.storage.storages.ConfigStorage;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class BlockNamespaceCommandsSection extends ConfigStorage {
|
||||
|
||||
public boolean ENABLED;
|
||||
|
||||
+25
-5
@@ -1,13 +1,20 @@
|
||||
package de.rayzs.pat.api.storage.config.settings;
|
||||
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
|
||||
import de.rayzs.pat.api.storage.storages.ConfigStorage;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.configuration.helper.MultipleMessagesHelper;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class CustomProtocolPingSection extends ConfigStorage {
|
||||
|
||||
public boolean ENABLED, ALWAYS_SHOW, HIDE_PLAYERS, USE_EXTEND_AS_MAX_COUNT;
|
||||
public boolean ENABLED, ALWAYS_SHOW, HIDE_PLAYERS, USE_EXTEND_AS_MAX_COUNT, USE_CUSTOM_PLAYERLIST;
|
||||
public String PROTOCOL;
|
||||
|
||||
public MultipleMessagesHelper PLAYERLIST;
|
||||
|
||||
public int EXTEND_COUNT;
|
||||
|
||||
public CustomProtocolPingSection() {
|
||||
@@ -17,17 +24,30 @@ public class CustomProtocolPingSection extends ConfigStorage {
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
if(!Reflection.isProxyServer()) {
|
||||
if(!Reflection.isPaper() || Reflection.getMinor() < 12)
|
||||
|
||||
if (!Reflection.isProxyServer() && (!Reflection.isPaper() || Reflection.getMinor() < 12))
|
||||
return;
|
||||
}
|
||||
|
||||
ENABLED = new ConfigSectionHelper<Boolean>(this, "enabled", true).getOrSet();
|
||||
ALWAYS_SHOW = new ConfigSectionHelper<Boolean>(this, "always-show", Reflection.isProxyServer() || Reflection.isPaper()).getOrSet();
|
||||
USE_EXTEND_AS_MAX_COUNT = new ConfigSectionHelper<Boolean>(this, "use-as-maxplayers", false).getOrSet();
|
||||
PROTOCOL = new ConfigSectionHelper<String>(this, "protocol", "&f&lProAntiTab &7(&a%online%&7/&c%max%&7)").getOrSet();
|
||||
EXTEND_COUNT = new ConfigSectionHelper<Integer>(this, "extend-online-count", 1).getOrSet();
|
||||
if(Reflection.isProxyServer()) return;
|
||||
|
||||
HIDE_PLAYERS = new ConfigSectionHelper<Boolean>(this, "hide-players", true).getOrSet();
|
||||
|
||||
USE_CUSTOM_PLAYERLIST = new ConfigSectionHelper<Boolean>(this, "custom-playerlist.enabled", false).getOrSet();
|
||||
PLAYERLIST = new MultipleMessagesHelper(this, "custom-playerlist.list", Arrays.asList(
|
||||
"&8> &7Online players: &f%online%&7/&c%max%",
|
||||
"&8> &7Using &fProAntiTab"
|
||||
));
|
||||
|
||||
|
||||
|
||||
if (HIDE_PLAYERS && USE_CUSTOM_PLAYERLIST) {
|
||||
Logger.warning("You can't use both 'hide-players' and 'custom-playerlist' at the same time! (Section: custom-protocol-ping)");
|
||||
Logger.warning("You gotta choose what feature from those two you want to use.");
|
||||
Logger.warning("In order to avoid any problems, the 'custom-playerlist' feature has been temporarily disabled.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,10 @@ import de.rayzs.pat.utils.Reflection;
|
||||
public class HandleThroughProxySection extends ConfigStorage {
|
||||
|
||||
public boolean ENABLED;
|
||||
|
||||
public boolean LOAD_FROM_ENV;
|
||||
public String ENV_NAME;
|
||||
|
||||
public String TOKEN;
|
||||
|
||||
public HandleThroughProxySection() {
|
||||
@@ -20,5 +24,8 @@ public class HandleThroughProxySection extends ConfigStorage {
|
||||
|
||||
ENABLED = new ConfigSectionHelper<Boolean>(this, "enabled", false).getOrSet();
|
||||
TOKEN = new ConfigSectionHelper<String>(this, "token", "insert-token-of-proxy-here").getOrSet();
|
||||
|
||||
LOAD_FROM_ENV = new ConfigSectionHelper<Boolean>(this, "load-from-env.enabled", false).getOrSet();
|
||||
ENV_NAME = new ConfigSectionHelper<String>(this, "load-from-env.name", false).getOrSet();
|
||||
}
|
||||
}
|
||||
+4
-9
@@ -4,28 +4,23 @@ import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
|
||||
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ListCommandsPlaceholder extends PlaceholderStorage {
|
||||
|
||||
public ListCommandsPlaceholder() { super("list_commands"); }
|
||||
|
||||
public String COMMAND, SPLITTER;
|
||||
public String SPLITTER;
|
||||
|
||||
@Override
|
||||
public String onRequest(Player player, String param) {
|
||||
return StringUtils.buildStringList(
|
||||
Storage.Blacklist.getBlacklist().getCommands(),
|
||||
SPLITTER,
|
||||
COMMAND,
|
||||
"%command%"
|
||||
);
|
||||
return StringUtils.getStringList(Storage.Blacklist.getBlacklist().getCommands(), SPLITTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7-> ").getOrSet();
|
||||
COMMAND = new ConfigSectionHelper<String>(this, "command", "&f%command%\\n").getOrSet();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7, &e").getOrSet();
|
||||
}
|
||||
}
|
||||
+3
-10
@@ -10,23 +10,16 @@ public class ListReversedCommandsPlaceholder extends PlaceholderStorage {
|
||||
|
||||
public ListReversedCommandsPlaceholder() { super("list_reversed_commands"); }
|
||||
|
||||
public String COMMAND, SPLITTER;
|
||||
public String SPLITTER;
|
||||
|
||||
@Override
|
||||
public String onRequest(Player player, String param) {
|
||||
return StringUtils.buildSortedStringList(
|
||||
Storage.Blacklist.getBlacklist().getCommands(),
|
||||
SPLITTER,
|
||||
COMMAND,
|
||||
"%command%",
|
||||
true
|
||||
);
|
||||
return StringUtils.getReversedStringList(Storage.Blacklist.getBlacklist().getCommands(), SPLITTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7-> ").getOrSet();
|
||||
COMMAND = new ConfigSectionHelper<String>(this, "command", "&f%command%\\n").getOrSet();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7, &e").getOrSet();
|
||||
}
|
||||
}
|
||||
+3
-10
@@ -10,23 +10,16 @@ public class ListSortedCommandsPlaceholder extends PlaceholderStorage {
|
||||
|
||||
public ListSortedCommandsPlaceholder() { super("list_sorted_commands"); }
|
||||
|
||||
public String COMMAND, SPLITTER;
|
||||
public String SPLITTER;
|
||||
|
||||
@Override
|
||||
public String onRequest(Player player, String param) {
|
||||
return StringUtils.buildSortedStringList(
|
||||
Storage.Blacklist.getBlacklist().getCommands(),
|
||||
SPLITTER,
|
||||
COMMAND,
|
||||
"%command%",
|
||||
false
|
||||
);
|
||||
return StringUtils.getSortedStringList(Storage.Blacklist.getBlacklist().getCommands(), SPLITTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7-> ").getOrSet();
|
||||
COMMAND = new ConfigSectionHelper<String>(this, "command", "&f%command%\\n").getOrSet();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7, &e").getOrSet();
|
||||
}
|
||||
}
|
||||
+3
-9
@@ -10,25 +10,19 @@ public class ListGroupCommandsPlaceholder extends PlaceholderStorage {
|
||||
|
||||
public ListGroupCommandsPlaceholder() { super("list_commands_group_"); }
|
||||
|
||||
public String COMMAND, SPLITTER;
|
||||
public String SPLITTER;
|
||||
|
||||
@Override
|
||||
public String onRequest(Player player, String param) {
|
||||
Group group = GroupManager.getGroupByName(param);
|
||||
if(group == null) return null;
|
||||
|
||||
return StringUtils.buildStringList(
|
||||
group.getCommands(),
|
||||
SPLITTER,
|
||||
COMMAND,
|
||||
"%command%"
|
||||
);
|
||||
return StringUtils.getStringList(group.getCommands(), SPLITTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7-> ").getOrSet();
|
||||
COMMAND = new ConfigSectionHelper<String>(this, "command", "&f%command%\\n").getOrSet();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7, &e").getOrSet();
|
||||
}
|
||||
}
|
||||
+3
-10
@@ -10,26 +10,19 @@ public class ListGroupReversedCommandsPlaceholder extends PlaceholderStorage {
|
||||
|
||||
public ListGroupReversedCommandsPlaceholder() { super("list_reversed_commands_group_"); }
|
||||
|
||||
public String COMMAND, SPLITTER;
|
||||
public String SPLITTER;
|
||||
|
||||
@Override
|
||||
public String onRequest(Player player, String param) {
|
||||
Group group = GroupManager.getGroupByName(param);
|
||||
if(group == null) return null;
|
||||
|
||||
return StringUtils.buildSortedStringList(
|
||||
group.getCommands(),
|
||||
SPLITTER,
|
||||
COMMAND,
|
||||
"%command%",
|
||||
true
|
||||
);
|
||||
return StringUtils.getReversedStringList(group.getCommands(), SPLITTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7-> ").getOrSet();
|
||||
COMMAND = new ConfigSectionHelper<String>(this, "command", "&f%command%\\n").getOrSet();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7, &e").getOrSet();
|
||||
}
|
||||
}
|
||||
+3
-10
@@ -10,26 +10,19 @@ public class ListGroupSortedCommandsPlaceholder extends PlaceholderStorage {
|
||||
|
||||
public ListGroupSortedCommandsPlaceholder() { super("list_sorted_commands_group_"); }
|
||||
|
||||
public String COMMAND, SPLITTER;
|
||||
public String SPLITTER;
|
||||
|
||||
@Override
|
||||
public String onRequest(Player player, String param) {
|
||||
Group group = GroupManager.getGroupByName(param);
|
||||
if(group == null) return null;
|
||||
|
||||
return StringUtils.buildSortedStringList(
|
||||
group.getCommands(),
|
||||
SPLITTER,
|
||||
COMMAND,
|
||||
"%command%",
|
||||
false
|
||||
);
|
||||
return StringUtils.getSortedStringList(group.getCommands(), SPLITTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7-> ").getOrSet();
|
||||
COMMAND = new ConfigSectionHelper<String>(this, "command", "&f%command%\\n").getOrSet();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7, &e").getOrSet();
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package de.rayzs.pat.api.storage.placeholders.general;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class GeneralPrefixPlaceholder extends PlaceholderStorage {
|
||||
|
||||
public GeneralPrefixPlaceholder() { super("general_prefix"); }
|
||||
|
||||
@Override
|
||||
public String onRequest(Player player, String param) {
|
||||
if (Storage.ConfigSections.Messages.PREFIX == null) return null;
|
||||
return Storage.ConfigSections.Messages.PREFIX.PREFIX;
|
||||
}
|
||||
}
|
||||
+3
-12
@@ -10,25 +10,16 @@ public class ListGroupsPlaceholder extends PlaceholderStorage {
|
||||
|
||||
public ListGroupsPlaceholder() { super("list_groups"); }
|
||||
|
||||
public String COMMAND, SPLITTER;
|
||||
public String SPLITTER;
|
||||
|
||||
@Override
|
||||
public String onRequest(Player player, String param) {
|
||||
Group group = GroupManager.getGroupByName(param);
|
||||
if(group == null) return null;
|
||||
|
||||
return StringUtils.buildStringList(
|
||||
GroupManager.getGroupNames(),
|
||||
SPLITTER,
|
||||
COMMAND,
|
||||
"%group%"
|
||||
);
|
||||
return StringUtils.getStringList(GroupManager.getGroupNames(), SPLITTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7-> ").getOrSet();
|
||||
COMMAND = new ConfigSectionHelper<String>(this, "group", "&f%group%\\n").getOrSet();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7, &e").getOrSet();
|
||||
}
|
||||
}
|
||||
+3
-13
@@ -10,26 +10,16 @@ public class ListGroupsReversedPlaceholder extends PlaceholderStorage {
|
||||
|
||||
public ListGroupsReversedPlaceholder() { super("list_reversed_groups"); }
|
||||
|
||||
public String COMMAND, SPLITTER;
|
||||
public String SPLITTER;
|
||||
|
||||
@Override
|
||||
public String onRequest(Player player, String param) {
|
||||
Group group = GroupManager.getGroupByName(param);
|
||||
if(group == null) return null;
|
||||
|
||||
return StringUtils.buildSortedStringList(
|
||||
GroupManager.getGroupNames(),
|
||||
SPLITTER,
|
||||
COMMAND,
|
||||
"%group%",
|
||||
true
|
||||
);
|
||||
return StringUtils.getReversedStringList(GroupManager.getGroupNames(), SPLITTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7-> ").getOrSet();
|
||||
COMMAND = new ConfigSectionHelper<String>(this, "group", "&f%group%\\n").getOrSet();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7, &e").getOrSet();
|
||||
}
|
||||
}
|
||||
+3
-13
@@ -10,26 +10,16 @@ public class ListGroupsSortedPlaceholder extends PlaceholderStorage {
|
||||
|
||||
public ListGroupsSortedPlaceholder() { super("list_sorted_groups"); }
|
||||
|
||||
public String COMMAND, SPLITTER;
|
||||
public String SPLITTER;
|
||||
|
||||
@Override
|
||||
public String onRequest(Player player, String param) {
|
||||
Group group = GroupManager.getGroupByName(param);
|
||||
if(group == null) return null;
|
||||
|
||||
return StringUtils.buildSortedStringList(
|
||||
GroupManager.getGroupNames(),
|
||||
SPLITTER,
|
||||
COMMAND,
|
||||
"%command%",
|
||||
false
|
||||
);
|
||||
return StringUtils.getSortedStringList(GroupManager.getGroupNames(), SPLITTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7-> ").getOrSet();
|
||||
COMMAND = new ConfigSectionHelper<String>(this, "group", "&f%group%\\n").getOrSet();
|
||||
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7, &e").getOrSet();
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -11,6 +11,7 @@ public class BlockedBaseCommandPlaceholder extends PlaceholderStorage {
|
||||
|
||||
@Override
|
||||
public String onRequest(Player player, String param) {
|
||||
return StringUtils.buildStringList(Storage.ConfigSections.Settings.CANCEL_COMMAND.BASE_COMMAND_RESPONSE.getLines());
|
||||
if (Storage.ConfigSections.Settings.CANCEL_COMMAND.BASE_COMMAND_RESPONSE == null) return null;
|
||||
return StringUtils.getStringList(Storage.ConfigSections.Settings.CANCEL_COMMAND.BASE_COMMAND_RESPONSE.getLines(), "\n");
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -11,6 +11,7 @@ public class BlockedSubCommandPlaceholder extends PlaceholderStorage {
|
||||
|
||||
@Override
|
||||
public String onRequest(Player player, String param) {
|
||||
return StringUtils.buildStringList(Storage.ConfigSections.Settings.CANCEL_COMMAND.SUB_COMMAND_RESPONSE.getLines());
|
||||
if (Storage.ConfigSections.Settings.CANCEL_COMMAND.SUB_COMMAND_RESPONSE == null) return null;
|
||||
return StringUtils.getStringList(Storage.ConfigSections.Settings.CANCEL_COMMAND.SUB_COMMAND_RESPONSE.getLines(), "\n");
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -11,6 +11,7 @@ public class UnknownCommandPlaceholder extends PlaceholderStorage {
|
||||
|
||||
@Override
|
||||
public String onRequest(Player player, String param) {
|
||||
return StringUtils.buildStringList(Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.MESSAGE.getLines());
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.MESSAGE == null) return null;
|
||||
return StringUtils.getStringList(Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.MESSAGE.getLines(), "\n");
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package de.rayzs.pat.api.storage.storages;
|
||||
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.api.storage.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
||||
@@ -15,154 +17,47 @@ public class BlacklistStorage extends StorageTemplate implements Serializable {
|
||||
}
|
||||
|
||||
public boolean isListed(String command) {
|
||||
return isListed(command, false);
|
||||
return isListed(command, !Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED);
|
||||
}
|
||||
|
||||
public boolean isConverted(String command, boolean intensive) {
|
||||
return !command.contains(" ") && (intensive && !command.contains(":"));
|
||||
}
|
||||
|
||||
public String convertCommand(String command, boolean intensive, boolean lowerCase) {
|
||||
return convertCommand(command, intensive, lowerCase, true);
|
||||
}
|
||||
|
||||
public String convertCommand(String command, boolean intensive, boolean lowerCase, boolean slash) {
|
||||
if(isConverted(command, intensive)) return command;
|
||||
if(lowerCase) command = command.toLowerCase();
|
||||
|
||||
if(slash)
|
||||
if(command.startsWith("/")) command = command.replaceFirst("/", "");
|
||||
|
||||
String[] split;
|
||||
if(command.contains(" ")) {
|
||||
split = command.split(" ");
|
||||
if(split.length > 0) command = split[0];
|
||||
}
|
||||
|
||||
if(intensive && command.contains(":")) {
|
||||
split = command.split(":");
|
||||
if(split.length > 0)
|
||||
command = command.replaceFirst(split[0] + ":", "");
|
||||
}
|
||||
|
||||
return command;
|
||||
}
|
||||
|
||||
public boolean isListed(String command, boolean intensive) {
|
||||
public boolean isListed(String command, boolean ignoreCollons) {
|
||||
if(commands == null) {
|
||||
Logger.warning("&cFailed to check command \"" + command + "\"! PAT couldn't read the commands from the storage.yml at section &4" + getNavigatePath() + "&c! Please ensure that your storage.yml isn't corrupt or contains any spaces or empty commands. If this problem still remains, please join my Discord server to ask for help there. &8(&erayzs.de/discord&8)");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!isConverted(command, intensive)) command = convertCommand(command, intensive, true);
|
||||
if (commands.contains("*"))
|
||||
return true;
|
||||
|
||||
for (String commands : commands) {
|
||||
if(commands == null) continue;
|
||||
if (commands.equals(command)) return true;
|
||||
for (String listedCommand : commands) {
|
||||
if(listedCommand == null)
|
||||
continue;
|
||||
|
||||
if (ignoreCollons) {
|
||||
command = StringUtils.getFirstArg(command);
|
||||
|
||||
if (command.contains(":"))
|
||||
command = command.substring(command.indexOf(':'));
|
||||
}
|
||||
|
||||
if (StringUtils.getFirstArg(listedCommand).equalsIgnoreCase(StringUtils.getFirstArg(command)))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isListed(String command, boolean intensive, boolean convert, boolean slash) {
|
||||
if(commands == null) {
|
||||
Logger.warning("&cFailed to check command \"" + command + "\"! PAT couldn't read the commands from the storage.yml at section &4" + getNavigatePath() + "&c! Please ensure that your storage.yml isn't corrupt or contains any spaces or empty commands. If this problem still remains, please join my Discord server to ask for help there. &8(&erayzs.de/discord&8)");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(convert)
|
||||
if(!isConverted(command, intensive)) command = convertCommand(command, intensive, true, slash);
|
||||
|
||||
for (String commands : commands) {
|
||||
if(commands == null) continue;
|
||||
if (commands.equals(command)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isListed(String command, boolean intensive, boolean convert) {
|
||||
if(commands == null) {
|
||||
Logger.warning("&cFailed to check command \"" + command + "\"! PAT couldn't read the commands from the storage.yml at section &4" + getNavigatePath() + "&c! Please ensure that your storage.yml isn't corrupt or contains any spaces or empty commands. If this problem still remains, please join my Discord server to ask for help there. &8(&erayzs.de/discord&8)");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(convert)
|
||||
if(!isConverted(command, intensive)) command = convertCommand(command, intensive, true);
|
||||
|
||||
for (String commands : commands) {
|
||||
if(commands == null) continue;
|
||||
if (commands.equals(command)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isBlocked(Object targetObj, String command) {
|
||||
return isBlocked(targetObj, command, false);
|
||||
}
|
||||
|
||||
public boolean isBlocked(Object targetObj, String command, boolean intensive) {
|
||||
if(Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED)
|
||||
return !isListed(command, intensive) && !PermissionUtil.hasBypassPermission(targetObj, command);
|
||||
else
|
||||
return isListed(command, intensive) && !PermissionUtil.hasBypassPermission(targetObj, command);
|
||||
}
|
||||
|
||||
public boolean isBlockedIgnorePermission(String command, boolean intensive) {
|
||||
if(Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED)
|
||||
return !isListed(command, intensive);
|
||||
else
|
||||
return isListed(command, intensive);
|
||||
}
|
||||
|
||||
public boolean isBlocked(Object targetObj, String command, boolean intensive, boolean convert) {
|
||||
if(Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED)
|
||||
return !isListed(command, intensive, convert) && !PermissionUtil.hasBypassPermission(targetObj, command);
|
||||
else
|
||||
return isListed(command, intensive, convert) && !PermissionUtil.hasBypassPermission(targetObj, command);
|
||||
}
|
||||
|
||||
public boolean isBlocked(Object targetObj, String command, boolean intensive, boolean convert, boolean slash) {
|
||||
if(Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED)
|
||||
return !isListed(command, intensive, convert, slash) && !PermissionUtil.hasBypassPermission(targetObj, command);
|
||||
else
|
||||
return isListed(command, intensive, convert, slash) && !PermissionUtil.hasBypassPermission(targetObj, command);
|
||||
}
|
||||
|
||||
public boolean isBlocked(String command, boolean intensive) {
|
||||
if(Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED)
|
||||
return !isListed(command, intensive);
|
||||
else
|
||||
return isListed(command, intensive);
|
||||
}
|
||||
|
||||
public boolean isBlocked(String command, boolean intensive, boolean convert) {
|
||||
if(Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED)
|
||||
return !isListed(command, intensive, convert);
|
||||
else
|
||||
return isListed(command, intensive, convert);
|
||||
}
|
||||
|
||||
public boolean isBlocked(String command, boolean intensive, boolean convert, boolean slash) {
|
||||
if(Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED)
|
||||
return !isListed(command, intensive, convert, slash);
|
||||
else
|
||||
return isListed(command, intensive, convert, slash);
|
||||
}
|
||||
|
||||
public void setList(List<String> commands) {
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
public BlacklistStorage add(String command) {
|
||||
command = command.toLowerCase();
|
||||
if(!commands.contains(command))
|
||||
if (!commands.contains(command))
|
||||
commands.add(command);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlacklistStorage remove(String command) {
|
||||
command = command.toLowerCase();
|
||||
commands.remove(command);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package de.rayzs.pat.api.storage.storages;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.api.storage.StorageTemplate;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DisabledServersStorage extends StorageTemplate {
|
||||
|
||||
private List<String> servers = new ArrayList<>();
|
||||
|
||||
public DisabledServersStorage() {
|
||||
super(Storage.Files.STORAGE, "disabled-servers");
|
||||
}
|
||||
|
||||
public DisabledServersStorage add(String server) {
|
||||
server = server.toLowerCase();
|
||||
if(!servers.contains(server))
|
||||
servers.add(server);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DisabledServersStorage remove(String server) {
|
||||
server = server.toLowerCase();
|
||||
servers.remove(server);
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isListed(String server) {
|
||||
if(servers.isEmpty()) return false;
|
||||
return Storage.isServer(server, servers);
|
||||
}
|
||||
|
||||
public boolean isListEmpty() {
|
||||
return servers.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() { getConfig().save(); }
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
if(!Reflection.isProxyServer()) return;
|
||||
getConfig().reload();
|
||||
servers = (ArrayList<String>) getConfig().getOrSet(getNavigatePath(), servers);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ public abstract class PlaceholderStorage extends StorageTemplate {
|
||||
|
||||
public PlaceholderStorage(String request) {
|
||||
super(Storage.Files.PLACEHOLDERS, request);
|
||||
|
||||
this.request = request;
|
||||
Storage.ConfigSections.PLACEHOLDERS.add(this);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
package de.rayzs.pat.plugin;
|
||||
|
||||
import de.rayzs.pat.plugin.modules.subargs.SubArgsModule;
|
||||
import de.rayzs.pat.utils.configuration.updater.ConfigUpdater;
|
||||
import de.rayzs.pat.api.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.plugin.modules.SubArgsModule;
|
||||
import de.rayzs.pat.plugin.process.CommandProcess;
|
||||
import de.rayzs.pat.api.netty.bukkit.BukkitPacketAnalyzer;
|
||||
import de.rayzs.pat.api.communication.BackendUpdater;
|
||||
import de.rayzs.pat.utils.configuration.Configurator;
|
||||
import de.rayzs.pat.utils.configuration.updater.ConfigUpdater;
|
||||
import de.rayzs.pat.utils.group.TinyGroup;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import de.rayzs.pat.utils.adapter.ViaVersionAdapter;
|
||||
import de.rayzs.pat.api.communication.Communicator;
|
||||
import de.rayzs.pat.utils.adapter.LuckPermsAdapter;
|
||||
import de.rayzs.pat.plugin.commands.BukkitCommand;
|
||||
import de.rayzs.pat.api.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.utils.hooks.PlaceholderHook;
|
||||
import de.rayzs.pat.plugin.listeners.bukkit.*;
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
@@ -19,6 +21,7 @@ import de.rayzs.pat.utils.group.GroupManager;
|
||||
import de.rayzs.pat.plugin.metrics.bStats;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.utils.response.action.ActionHandler;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.scheduler.*;
|
||||
@@ -30,20 +33,25 @@ import org.bukkit.plugin.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import java.util.*;
|
||||
|
||||
public class BukkitLoader extends JavaPlugin {
|
||||
public class BukkitLoader extends JavaPlugin implements PluginLoader {
|
||||
|
||||
private static List<String> commands = new ArrayList<>(), allowedCommands = new ArrayList<>();
|
||||
|
||||
private static Plugin plugin;
|
||||
private static java.util.logging.Logger logger;
|
||||
private static boolean loaded = false, checkUpdate = false, suggestions = false;
|
||||
private static boolean loaded = false, suggestions = false;
|
||||
private static Map<String, Command> commandsMap = null;
|
||||
private PATSchedulerTask updaterTask;
|
||||
|
||||
private final List<String> offlinePlayerNames = new ArrayList<>();
|
||||
private long lastCommandsLoad = -1;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
Configurator.createResourcedFile(getDataFolder(), "files\\bukkit-config.yml", "config.yml", false);
|
||||
Configurator.createResourcedFile(getDataFolder(), "files\\bukkit-storage.yml", "storage.yml", false);
|
||||
Configurator.createResourcedFile(getDataFolder(), "files\\bukkit-placeholders.yml", "placeholders.yml", false);
|
||||
Configurator.createResourcedFile(getDataFolder(), "files\\bukkit-custom-responses.yml", "custom-responses.yml", false);
|
||||
Configurator.createResourcedFile("files\\bukkit-config.yml", "config.yml", false);
|
||||
Configurator.createResourcedFile("files\\bukkit-storage.yml", "storage.yml", false);
|
||||
Configurator.createResourcedFile("files\\bukkit-placeholders.yml", "placeholders.yml", false);
|
||||
Configurator.createResourcedFile("files\\bukkit-custom-responses.yml", "custom-responses.yml", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,17 +59,22 @@ public class BukkitLoader extends JavaPlugin {
|
||||
plugin = this;
|
||||
logger = getLogger();
|
||||
|
||||
for (OfflinePlayer offlinePlayerName : Bukkit.getOfflinePlayers()) {
|
||||
offlinePlayerNames.add(offlinePlayerName.getName());
|
||||
}
|
||||
|
||||
loadCommandMap();
|
||||
|
||||
CommandProcess.initialize();
|
||||
Reflection.initialize(getServer());
|
||||
ConfigUpdater.initialize();
|
||||
|
||||
Storage.CURRENT_VERSION = getDescription().getVersion();
|
||||
VersionComparer.setCurrentVersion(Storage.CURRENT_VERSION);
|
||||
Storage.initialize(this, getDescription().getVersion());
|
||||
VersionComparer.get().setCurrentVersion(Storage.CURRENT_VERSION);
|
||||
|
||||
Storage.loadAll(true);
|
||||
|
||||
if(Bukkit.getServer().getPluginManager().getPlugin("PlaceholderAPI") != null)
|
||||
if (Bukkit.getServer().getPluginManager().getPlugin("PlaceholderAPI") != null)
|
||||
new PlaceholderHook().register();
|
||||
|
||||
MessageTranslator.initialize();
|
||||
@@ -70,7 +83,7 @@ public class BukkitLoader extends JavaPlugin {
|
||||
|
||||
PluginManager manager = getServer().getPluginManager();
|
||||
|
||||
if(!Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED) {
|
||||
if (!Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED) {
|
||||
loaded = true;
|
||||
GroupManager.initialize();
|
||||
BukkitPacketAnalyzer.injectAll();
|
||||
@@ -78,12 +91,13 @@ public class BukkitLoader extends JavaPlugin {
|
||||
|
||||
manager.registerEvents(new BukkitPlayerConnectionListener(), this);
|
||||
manager.registerEvents(new BukkitBlockCommandListener(), this);
|
||||
if(Reflection.getMinor() >= 13) {
|
||||
|
||||
if (Reflection.getMinor() >= 13) {
|
||||
suggestions = true;
|
||||
manager.registerEvents(new BukkitAntiTabListener(), this);
|
||||
}
|
||||
|
||||
if(Reflection.isPaper() && Reflection.getMinor() >= 12)
|
||||
if (Reflection.isPaper() && Reflection.getMinor() >= 12)
|
||||
manager.registerEvents(new PaperServerListPing(), this);
|
||||
|
||||
registerCommand("proantitab", "pat");
|
||||
@@ -91,20 +105,23 @@ public class BukkitLoader extends JavaPlugin {
|
||||
|
||||
Storage.PLUGIN_OBJECT = this;
|
||||
|
||||
if(getServer().getPluginManager().getPlugin("LuckPerms") != null) {
|
||||
if (getServer().getPluginManager().getPlugin("LuckPerms") != null) {
|
||||
LuckPermsAdapter.initialize();
|
||||
Bukkit.getOnlinePlayers().forEach(player -> PermissionUtil.setPlayerPermissions(player.getUniqueId()));
|
||||
}
|
||||
|
||||
if(getServer().getPluginManager().getPlugin("ViaVersion") != null)
|
||||
if (getServer().getPluginManager().getPlugin("ViaVersion") != null)
|
||||
ViaVersionAdapter.initialize();
|
||||
|
||||
if(Storage.USE_SIMPLECLOUD)
|
||||
if (Storage.USE_SIMPLECLOUD) {
|
||||
Logger.warning("Detected SimpleCloud. Therefore, MiniMessages are disabled!");
|
||||
}
|
||||
|
||||
ConfigUpdater.broadcastMissingParts();
|
||||
ActionHandler.initialize();
|
||||
SubArgsModule.initialize();
|
||||
|
||||
PATScheduler.createScheduler(this::loadAllCommands);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -123,114 +140,202 @@ public class BukkitLoader extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> getPlayerNames() {
|
||||
List<String> result = new LinkedList<>();
|
||||
Bukkit.getServer().getOnlinePlayers().forEach(player -> result.add(player.getName()));
|
||||
return result;
|
||||
@Override
|
||||
public void handleReload() {
|
||||
loadAllCommands();
|
||||
}
|
||||
|
||||
public static UUID getUUIDByName(String playerName) {
|
||||
Player player = Bukkit.getServer().getPlayer(playerName);
|
||||
@Override
|
||||
public boolean doesCommandExist(String command) {
|
||||
if (commandsMap == null)
|
||||
return false;
|
||||
|
||||
loadAllCommands();
|
||||
|
||||
return getAllCommands().contains(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getConsoleSender() {
|
||||
return Bukkit.getConsoleSender();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPlayerObjByName(String name) {
|
||||
return Bukkit.getPlayer(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPlayerObjByUUID(UUID uuid) {
|
||||
return Bukkit.getPlayer(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCommandCache() {}
|
||||
|
||||
@Override
|
||||
public HashMap<String, CommandsCache> getCommandsCacheMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayerOnline(String playerName) {
|
||||
return Bukkit.getPlayer(playerName) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesPlayerExist(String playerName) {
|
||||
return ArrayUtils.containsIgnoreCase(getPlayerNames(), playerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerServerName(UUID uuid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UUID> getPlayerIdsByServer(String server) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getOnlinePlayerNames(String serverName) {
|
||||
return getOnlinePlayerNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UUID> getPlayerIds() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getOnlinePlayerNames() {
|
||||
return new ArrayList<>(Bukkit.getServer().getOnlinePlayers().stream().map(Player::getName).toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getOfflinePlayerNames() {
|
||||
return offlinePlayerNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPlayerNames() {
|
||||
List<String> playerNames = new ArrayList<>(offlinePlayerNames);
|
||||
|
||||
playerNames.addAll(getOnlinePlayerNames());
|
||||
|
||||
return playerNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNameByUUID(UUID uuid) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
return player != null ? player.getName() : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUIDByName(String playerName) {
|
||||
Player player = Bukkit.getPlayer(playerName);
|
||||
return player != null ? player.getUniqueId() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getServerNames() {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
public void startUpdaterTask() {
|
||||
if (!Storage.ConfigSections.Settings.UPDATE.ENABLED) return;
|
||||
if (!Storage.ConfigSections.Settings.UPDATE.ENABLED)
|
||||
return;
|
||||
|
||||
updaterTask = PATScheduler.createAsyncScheduler(() -> {
|
||||
String result = new ConnectionBuilder().setUrl("https://www.rayzs.de/proantitab/api/version.php")
|
||||
.setProperties("ProAntiTab", "4654").connect().getResponse();
|
||||
|
||||
if(result == null) result = "internet";
|
||||
Storage.NEWER_VERSION = result;
|
||||
VersionComparer.setNewestVersion(Storage.NEWER_VERSION);
|
||||
|
||||
if(VersionComparer.isDeveloperVersion()) {
|
||||
if (VersionComparer.get().computeComparison())
|
||||
updaterTask.cancelTask();
|
||||
Logger.info("§8[§fPAT | Bukkit§8] §7Please be aware that you are currently using a §bdeveloper §7version of ProAntiTab. Bugs, errors and a lot of debug messages might be included.");
|
||||
|
||||
} else if(!checkUpdate && (VersionComparer.isNewest() || VersionComparer.isUnreleased())) {
|
||||
updaterTask.cancelTask();
|
||||
checkUpdate = true;
|
||||
|
||||
if(VersionComparer.isUnreleased()) {
|
||||
Logger.info("§8[§fPAT | Bukkit§8] §7Please be aware that you are currently using an §eunreleased §7version of ProAntiTab.");
|
||||
return;
|
||||
}
|
||||
|
||||
Storage.ConfigSections.Settings.UPDATE.UPDATED.getLines().forEach(Logger::warning);
|
||||
|
||||
} else if(VersionComparer.isOutdated()) {
|
||||
updaterTask.cancelTask();
|
||||
Storage.OUTDATED = true;
|
||||
Storage.ConfigSections.Settings.UPDATE.OUTDATED.getLines().forEach(Logger::warning);
|
||||
|
||||
} else if(!Storage.NEWER_VERSION.equals(Storage.CURRENT_VERSION)) {
|
||||
updaterTask.cancelTask();
|
||||
switch (result) {
|
||||
case "internet":
|
||||
Logger.warning("Failed to build connection to website! (No internet?)");
|
||||
break;
|
||||
case "unknown":
|
||||
Logger.warning("Failed to build connection to website! (Firewall enabled or website down?)");
|
||||
break;
|
||||
case "exception":
|
||||
Logger.warning("Failed to build connection to website! (Outdated java version?)");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}, 20L, 20L * Storage.ConfigSections.Settings.UPDATE.PERIOD);
|
||||
}
|
||||
|
||||
public static void synchronize(CommunicationPackets.PacketBundle packetBundle) {
|
||||
Storage.LAST_SYNC = System.currentTimeMillis();
|
||||
Communicator.sendFeedback();
|
||||
|
||||
CommunicationPackets.UnknownCommandPacket unknownCommandPacket = packetBundle.getUnknownCommandPacket();
|
||||
CommunicationPackets.CommandsPacket commandsPacket = packetBundle.getCommandsPacket();
|
||||
CommunicationPackets.GroupsPacket groupsPacket = packetBundle.getGroupsPacket();
|
||||
CommunicationPackets.NamespaceCommandsPacket namespaceCommandsPacket = packetBundle.getNamespaceCommandsPacket();
|
||||
CommunicationPackets.MessagePacket messagePacket = packetBundle.getMessagePacket();
|
||||
|
||||
if(!Storage.USE_VELOCITY) {
|
||||
CommunicationPackets.CommandsPacket commandsPacket = packetBundle.getCommandsPacket();
|
||||
CommunicationPackets.GroupsPacket groupsPacket = packetBundle.getGroupsPacket();
|
||||
CommunicationPackets.NamespaceCommandsPacket namespaceCommandsPacket = packetBundle.getNamespaceCommandsPacket();
|
||||
boolean updatedList = false;
|
||||
|
||||
if(Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.ENABLED != namespaceCommandsPacket.isEnabled())
|
||||
Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.ENABLED = namespaceCommandsPacket.isEnabled();
|
||||
if (!messagePacket.getBaseBlockedMessage().getLines().isEmpty())
|
||||
Storage.ConfigSections.Settings.CANCEL_COMMAND.BASE_COMMAND_RESPONSE = messagePacket.getBaseBlockedMessage();
|
||||
|
||||
if (commandsPacket.getCommands() == null || commandsPacket.getCommands().isEmpty())
|
||||
Storage.Blacklist.getBlacklist().setList(new ArrayList<>());
|
||||
if (!messagePacket.getSubBlockedMessage().getLines().isEmpty())
|
||||
Storage.ConfigSections.Settings.CANCEL_COMMAND.SUB_COMMAND_RESPONSE = messagePacket.getSubBlockedMessage();
|
||||
|
||||
else if (!ArrayUtils.compareStringArrays(Storage.Blacklist.getBlacklist().getCommands(), commandsPacket.getCommands())) {
|
||||
if(Reflection.getMinor() >= 13) BukkitAntiTabListener.setChangeStatus();
|
||||
Storage.Blacklist.getBlacklist().setList(commandsPacket.getCommands());
|
||||
if (!messagePacket.getPrefix().isEmpty())
|
||||
Storage.ConfigSections.Messages.PREFIX.PREFIX = messagePacket.getPrefix();
|
||||
|
||||
if (Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.ENABLED != namespaceCommandsPacket.isEnabled())
|
||||
Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.ENABLED = namespaceCommandsPacket.isEnabled();
|
||||
|
||||
if (commandsPacket.getCommands() == null || commandsPacket.getCommands().isEmpty())
|
||||
Storage.Blacklist.getBlacklist().setList(new ArrayList<>());
|
||||
|
||||
else if (!ArrayUtils.compareStringArrays(Storage.Blacklist.getBlacklist().getCommands(), commandsPacket.getCommands())) {
|
||||
updatedList = true;
|
||||
Storage.Blacklist.getBlacklist().setList(commandsPacket.getCommands());
|
||||
}
|
||||
|
||||
if (Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED != commandsPacket.turnBlacklistToWhitelistEnabled())
|
||||
Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED = commandsPacket.turnBlacklistToWhitelistEnabled();
|
||||
|
||||
Map<String, List<String>> cpyCache = new HashMap<>();
|
||||
GroupManager.getGroups().forEach(group -> {
|
||||
cpyCache.put(group.getGroupName(), group.getCommands());
|
||||
});
|
||||
|
||||
GroupManager.clearAllGroups();
|
||||
|
||||
for (TinyGroup group : groupsPacket.getGroups()) {
|
||||
List<String> currentExistingList = cpyCache.get(group.getGroupName());
|
||||
if (
|
||||
!updatedList
|
||||
&& currentExistingList != null
|
||||
&& !ArrayUtils.compareStringArrays(currentExistingList, group.getCommands())
|
||||
) {
|
||||
updatedList = true;
|
||||
}
|
||||
|
||||
if (Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED != commandsPacket.turnBlacklistToWhitelistEnabled())
|
||||
Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED = commandsPacket.turnBlacklistToWhitelistEnabled();
|
||||
|
||||
GroupManager.clearAllGroups();
|
||||
groupsPacket.getGroups().forEach(group -> GroupManager.setGroup(group.getGroupName(), group.getPriority(), group.getCommands()));
|
||||
GroupManager.setGroup(group.getGroupName(), group.getPriority(), group.getCommands());
|
||||
}
|
||||
|
||||
Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.MESSAGE = unknownCommandPacket.getMessage();
|
||||
if(Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.ENABLED != unknownCommandPacket.isEnabled())
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.ENABLED != unknownCommandPacket.isEnabled())
|
||||
Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.ENABLED = unknownCommandPacket.isEnabled();
|
||||
|
||||
if(!loaded) loaded = true;
|
||||
if (!loaded)
|
||||
loaded = true;
|
||||
|
||||
if(Reflection.getMinor() >= 16) {
|
||||
if (Reflection.getMinor() >= 13) {
|
||||
|
||||
if (Storage.USE_VELOCITY)
|
||||
if (updatedList) {
|
||||
BukkitAntiTabListener.updateCommands();
|
||||
Logger.debug("Force server to load all players tab-completion due to received sync!");
|
||||
}
|
||||
|
||||
Logger.debug("Force server to load all players tab-completion due to received sync!");
|
||||
BukkitAntiTabListener.handleTabCompletion(Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED ? Storage.Blacklist.getBlacklist().getCommands() : getNotBlockedCommands());
|
||||
}
|
||||
|
||||
PATEventHandler.callReceiveSyncEvents(packetBundle);
|
||||
}
|
||||
|
||||
public static boolean doesCommandExist(String command, boolean replace) {
|
||||
if(commandsMap == null) return false;
|
||||
if(replace) command = StringUtils.replaceFirst(command, "/", "");
|
||||
return getAllCommands().contains(command);
|
||||
public static List<String> getAllCommands() {
|
||||
return new ArrayList<>(commands);
|
||||
}
|
||||
|
||||
public static List<String> getAllowedCommands() {
|
||||
return new ArrayList<>(allowedCommands);
|
||||
}
|
||||
|
||||
private void loadCommandMap() {
|
||||
@@ -241,44 +346,66 @@ public class BukkitLoader extends JavaPlugin {
|
||||
SimpleCommandMap simpleCommandMap = (SimpleCommandMap) commandMapField.get(Bukkit.getPluginManager());
|
||||
Field knownCommandsField = SimpleCommandMap.class.getDeclaredField("knownCommands");
|
||||
knownCommandsField.setAccessible(true);
|
||||
commandsMap = (Map<String, Command>)knownCommandsField.get(simpleCommandMap);
|
||||
commandsMap = (Map<String, Command>) knownCommandsField.get(simpleCommandMap);
|
||||
}
|
||||
}catch (Throwable ignored) { }
|
||||
} catch (Throwable ignored) { }
|
||||
|
||||
if(commandsMap == null)
|
||||
if (commandsMap == null) {
|
||||
Logger.warning("Failed to get server commands!");
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> getNotBlockedCommands() {
|
||||
List<String> commands = new ArrayList<>();
|
||||
Bukkit.getHelpMap().getHelpTopics().stream()
|
||||
.filter(topic -> !topic.getName().contains(":") && topic.getName().startsWith("/") && !Storage.Blacklist.getBlacklist().isListed(topic.getName().replaceFirst("/", "")))
|
||||
.forEach(topic -> commands.add(topic.getName().replaceFirst("/", "")));
|
||||
return commands;
|
||||
private void loadAllCommands() {
|
||||
|
||||
if (lastCommandsLoad != -1 && System.currentTimeMillis() - lastCommandsLoad < 1000)
|
||||
return;
|
||||
|
||||
List<String> result = new ArrayList<>();
|
||||
|
||||
if (commandsMap == null) {
|
||||
result.addAll(
|
||||
Bukkit.getHelpMap().getHelpTopics().stream()
|
||||
.map(topic -> {
|
||||
String name = topic.getName();
|
||||
|
||||
if (name.startsWith("/"))
|
||||
name = name.substring(1);
|
||||
|
||||
return name;
|
||||
}).toList()
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
commandsMap.entrySet().forEach(entry -> {
|
||||
String key = entry.getKey();
|
||||
Command command = entry.getValue();
|
||||
|
||||
result.add(key);
|
||||
|
||||
if (!command.getAliases().isEmpty()) {
|
||||
result.addAll(command.getAliases());
|
||||
}
|
||||
});
|
||||
|
||||
boolean turn = Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED;
|
||||
List<String> allowedCommands = new ArrayList<>(result).stream().filter(command -> {
|
||||
|
||||
if (turn) {
|
||||
return Storage.Blacklist.getBlacklist().isListed(command);
|
||||
} else {
|
||||
return !Storage.Blacklist.getBlacklist().isListed(command);
|
||||
}
|
||||
|
||||
}).toList();
|
||||
|
||||
lastCommandsLoad = System.currentTimeMillis();
|
||||
|
||||
BukkitLoader.commands = result;
|
||||
BukkitLoader.allowedCommands = allowedCommands;
|
||||
}
|
||||
|
||||
public static List<String> getAllCommands() {
|
||||
if(commandsMap == null) return getNotBlockedCommands();
|
||||
|
||||
List<String> result = new LinkedList<>();
|
||||
for (String command : commandsMap.keySet()) if(!result.contains(command)) result.add(command);
|
||||
|
||||
if(Reflection.getMinor() == 20 && Reflection.getRelease() >= 5 || Reflection.getMinor() >= 21)
|
||||
for (String s : commandsMap.keySet())
|
||||
if (commandsMap.containsKey(s)) {
|
||||
if(!commandsMap.get(s).getAliases().isEmpty()) {
|
||||
for (String alias : commandsMap.get(s).getAliases())
|
||||
if (!result.contains(alias)) result.add(alias);
|
||||
|
||||
} else if(Bukkit.getServer().getCommandAliases().get(s) != null)
|
||||
for (String alias : Bukkit.getServer().getCommandAliases().get(s))
|
||||
if (!result.contains(alias)) result.add(alias);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static boolean useSuggestions() {
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
package de.rayzs.pat.plugin;
|
||||
|
||||
|
||||
import de.rayzs.pat.utils.configuration.updater.ConfigUpdater;
|
||||
import de.rayzs.pat.plugin.modules.subargs.SubArgsModule;
|
||||
import de.rayzs.pat.api.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.plugin.process.CommandProcess;
|
||||
import de.rayzs.pat.plugin.modules.SubArgsModule;
|
||||
import de.rayzs.pat.api.netty.proxy.BungeePacketAnalyzer;
|
||||
import de.rayzs.pat.utils.configuration.Configurator;
|
||||
import de.rayzs.pat.utils.configuration.updater.ConfigUpdater;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import de.rayzs.pat.utils.adapter.LuckPermsAdapter;
|
||||
import de.rayzs.pat.api.communication.Communicator;
|
||||
import de.rayzs.pat.utils.response.action.ActionHandler;
|
||||
import net.md_5.bungee.api.scheduler.ScheduledTask;
|
||||
import de.rayzs.pat.plugin.commands.BungeeCommand;
|
||||
import de.rayzs.pat.api.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.plugin.listeners.bungee.*;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
@@ -25,19 +26,22 @@ import net.md_5.bungee.api.plugin.*;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import java.util.*;
|
||||
|
||||
public class BungeeLoader extends Plugin {
|
||||
public class BungeeLoader extends Plugin implements PluginLoader {
|
||||
|
||||
private ScheduledTask updaterTask;
|
||||
|
||||
private static Plugin plugin;
|
||||
private static java.util.logging.Logger logger;
|
||||
private ScheduledTask updaterTask;
|
||||
|
||||
private static boolean checkUpdate = false;
|
||||
private static final HashMap<String, CommandsCache> commandsCacheMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
Configurator.createResourcedFile(getDataFolder(), "files\\proxy-config.yml", "config.yml", false);
|
||||
Configurator.createResourcedFile(getDataFolder(), "files\\proxy-storage.yml", "storage.yml", false);
|
||||
Configurator.createResourcedFile(getDataFolder(), "files\\proxy-placeholders.yml", "placeholders.yml", false);
|
||||
Configurator.createResourcedFile(getDataFolder(), "files\\proxy-custom-responses.yml", "custom-responses.yml", false);
|
||||
Configurator.createResourcedFile("files\\proxy-config.yml", "config.yml", false);
|
||||
Configurator.createResourcedFile("files\\proxy-storage.yml", "storage.yml", false);
|
||||
Configurator.createResourcedFile("files\\proxy-placeholders.yml", "placeholders.yml", false);
|
||||
Configurator.createResourcedFile("files\\proxy-custom-responses.yml", "custom-responses.yml", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,12 +49,14 @@ public class BungeeLoader extends Plugin {
|
||||
plugin = this;
|
||||
logger = getLogger();
|
||||
|
||||
CommandProcess.initialize();
|
||||
Reflection.initialize(getProxy());
|
||||
ConfigUpdater.initialize();
|
||||
|
||||
Storage.USE_SIMPLECLOUD = Reflection.doesClassExist("eu.thesimplecloud.plugin.startup.CloudPlugin");
|
||||
Storage.CURRENT_VERSION = getDescription().getVersion();
|
||||
VersionComparer.setCurrentVersion(Storage.CURRENT_VERSION);
|
||||
|
||||
Storage.initialize(this, getDescription().getVersion());
|
||||
VersionComparer.get().setCurrentVersion(Storage.CURRENT_VERSION);
|
||||
|
||||
Storage.loadAll(true);
|
||||
|
||||
@@ -67,7 +73,7 @@ public class BungeeLoader extends Plugin {
|
||||
manager.registerListener(this, new BungeeBlockCommandListener());
|
||||
manager.registerListener(this, new BungeePingListener());
|
||||
|
||||
if(Reflection.isPaper())
|
||||
if (Reflection.isPaper())
|
||||
manager.registerListener(this, new WaterfallAntiTabListener());
|
||||
|
||||
startUpdaterTask();
|
||||
@@ -107,59 +113,135 @@ public class BungeeLoader extends Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> getPlayerNames() {
|
||||
List<String> result = new LinkedList<>();
|
||||
ProxyServer.getInstance().getPlayers().forEach(player -> result.add(player.getName()));
|
||||
return result;
|
||||
@Override
|
||||
public void handleReload() {}
|
||||
|
||||
@Override
|
||||
public boolean doesCommandExist(String command) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static UUID getUUIDByName(String playerName) {
|
||||
ProxiedPlayer proxiedPlayer = ProxyServer.getInstance().getPlayer(playerName);
|
||||
return proxiedPlayer != null ? proxiedPlayer.getUniqueId() : null;
|
||||
@Override
|
||||
public Object getConsoleSender() {
|
||||
return ProxyServer.getInstance().getConsole();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPlayerObjByName(String name) {
|
||||
return plugin.getProxy().getPlayer(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPlayerObjByUUID(UUID uuid) {
|
||||
return plugin.getProxy().getPlayer(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, CommandsCache> getCommandsCacheMap() {
|
||||
return commandsCacheMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCommandCache() {
|
||||
new ArrayList<>(commandsCacheMap.values()).forEach(CommandsCache::reset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerServerName(UUID uuid) {
|
||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid);
|
||||
|
||||
if (player == null || player.getServer() == null || player.getServer().getInfo() == null)
|
||||
return null;
|
||||
|
||||
return player.getServer().getInfo().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UUID> getPlayerIds() {
|
||||
return new ArrayList<>(ProxyServer.getInstance().getPlayers().stream().map(ProxiedPlayer::getUniqueId).toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UUID> getPlayerIdsByServer(String server) {
|
||||
List<UUID> uuids = new ArrayList<>();
|
||||
|
||||
getServerNames().stream()
|
||||
.filter(serverName -> Storage.isServer(server, serverName))
|
||||
.forEach(serverName -> {
|
||||
ServerInfo serverInfo = ProxyServer.getInstance().getServerInfo(serverName);
|
||||
|
||||
if (serverInfo == null)
|
||||
return;
|
||||
|
||||
uuids.addAll(serverInfo.getPlayers().stream().map(ProxiedPlayer::getUniqueId).toList());
|
||||
});
|
||||
|
||||
return uuids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getOnlinePlayerNames(String serverName) {
|
||||
return new ArrayList<>(ProxyServer.getInstance().getPlayers().stream()
|
||||
.filter(player -> {
|
||||
if (player == null || player.getServer() == null || player.getServer().getInfo() == null)
|
||||
return false;
|
||||
|
||||
return player.getServer().getInfo().getName().equalsIgnoreCase(serverName);
|
||||
|
||||
}).map(ProxiedPlayer::getName).toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayerOnline(String playerName) {
|
||||
return ProxyServer.getInstance().getPlayer(playerName) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesPlayerExist(String playerName) {
|
||||
return isPlayerOnline(playerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getOnlinePlayerNames() {
|
||||
return new ArrayList<>(ProxyServer.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getOfflinePlayerNames() {
|
||||
return new ArrayList<>(ProxyServer.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPlayerNames() {
|
||||
return new ArrayList<>(ProxyServer.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNameByUUID(UUID uuid) {
|
||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid);
|
||||
return player != null ? player.getName() : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUIDByName(String playerName) {
|
||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(playerName);
|
||||
return player != null ? player.getUniqueId() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getServerNames() {
|
||||
return new ArrayList<>(ProxyServer.getInstance().getServers().keySet().stream().toList());
|
||||
}
|
||||
|
||||
public void startUpdaterTask() {
|
||||
if (!Storage.ConfigSections.Settings.UPDATE.ENABLED) return;
|
||||
if (!Storage.ConfigSections.Settings.UPDATE.ENABLED)
|
||||
return;
|
||||
|
||||
updaterTask = getProxy().getScheduler().schedule(this, () -> {
|
||||
String result = new ConnectionBuilder().setUrl("https://www.rayzs.de/proantitab/api/version.php")
|
||||
.setProperties("ProAntiTab", "4654").connect().getResponse();
|
||||
Storage.NEWER_VERSION = result;
|
||||
VersionComparer.setNewestVersion(Storage.NEWER_VERSION);
|
||||
|
||||
if(VersionComparer.isDeveloperVersion()) {
|
||||
if (VersionComparer.get().computeComparison())
|
||||
getProxy().getScheduler().cancel(updaterTask);
|
||||
Logger.info("§8[§fPAT | Proxy§8] §7Please be aware that you are currently using a §bdeveloper §7version of ProAntiTab. Bugs, errors and a lot of debug messages might be included.");
|
||||
|
||||
} else if(!checkUpdate && (VersionComparer.isNewest() || VersionComparer.isUnreleased())) {
|
||||
getProxy().getScheduler().cancel(updaterTask);
|
||||
checkUpdate = true;
|
||||
|
||||
if(VersionComparer.isUnreleased()) {
|
||||
Logger.info("§8[§fPAT | Proxy§8] §7Please be aware that you are currently using an §eunreleased §7version of ProAntiTab.");
|
||||
return;
|
||||
}
|
||||
|
||||
checkUpdate = true;
|
||||
Storage.ConfigSections.Settings.UPDATE.UPDATED.getLines().forEach(Logger::warning);
|
||||
|
||||
} else if(VersionComparer.isOutdated()) {
|
||||
Storage.OUTDATED = true;
|
||||
Storage.ConfigSections.Settings.UPDATE.OUTDATED.getLines().forEach(Logger::warning);
|
||||
|
||||
} else if(!Storage.NEWER_VERSION.equals(Storage.CURRENT_VERSION)) {
|
||||
getProxy().getScheduler().cancel(updaterTask);
|
||||
switch (result) {
|
||||
case "internet":
|
||||
Logger.warning("Failed to build connection to website! (No internet?)");
|
||||
break;
|
||||
case "unknown":
|
||||
Logger.warning("Failed to build connection to website! (Firewall enabled or website down?)");
|
||||
break;
|
||||
case "exception":
|
||||
Logger.warning("Failed to build connection to website! (Outdated java version?)");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}, 20L, Storage.ConfigSections.Settings.UPDATE.PERIOD, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@@ -183,12 +265,4 @@ public class BungeeLoader extends Plugin {
|
||||
public static java.util.logging.Logger getPluginLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
public static List<String> getServerNames() {
|
||||
List<String> servers = new LinkedList<>();
|
||||
for (String serverName : ProxyServer.getInstance().getServers().keySet())
|
||||
servers.add(serverName.toLowerCase());
|
||||
|
||||
return servers;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package de.rayzs.pat.plugin;
|
||||
|
||||
import de.rayzs.pat.utils.CommandsCache;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface PluginLoader {
|
||||
|
||||
void handleReload();
|
||||
boolean doesCommandExist(String command);
|
||||
|
||||
HashMap<String, CommandsCache> getCommandsCacheMap();
|
||||
|
||||
void updateCommandCache();
|
||||
|
||||
List<String> getServerNames();
|
||||
|
||||
Object getConsoleSender();
|
||||
|
||||
Object getPlayerObjByName(String name);
|
||||
Object getPlayerObjByUUID(UUID uuid);
|
||||
|
||||
UUID getUUIDByName(String playerName);
|
||||
String getNameByUUID(UUID uuid);
|
||||
|
||||
String getPlayerServerName(UUID uuid);
|
||||
|
||||
boolean isPlayerOnline(String playerName);
|
||||
boolean doesPlayerExist(String playerName);
|
||||
|
||||
List<String> getOnlinePlayerNames(String server);
|
||||
|
||||
List<UUID> getPlayerIdsByServer(String server);
|
||||
List<UUID> getPlayerIds();
|
||||
|
||||
List<String> getPlayerNames();
|
||||
List<String> getOnlinePlayerNames();
|
||||
List<String> getOfflinePlayerNames();
|
||||
}
|
||||
@@ -3,18 +3,22 @@ package de.rayzs.pat.plugin;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import de.rayzs.pat.plugin.modules.subargs.SubArgsModule;
|
||||
import de.rayzs.pat.utils.configuration.updater.ConfigUpdater;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import de.rayzs.pat.api.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
import de.rayzs.pat.plugin.modules.SubArgsModule;
|
||||
import de.rayzs.pat.plugin.process.CommandProcess;
|
||||
import de.rayzs.pat.utils.CommandsCache;
|
||||
import de.rayzs.pat.plugin.metrics.impl.VelocityMetrics;
|
||||
import com.velocitypowered.api.scheduler.ScheduledTask;
|
||||
import de.rayzs.pat.utils.configuration.Configurator;
|
||||
import de.rayzs.pat.utils.configuration.updater.ConfigUpdater;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import de.rayzs.pat.plugin.commands.VelocityCommand;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import de.rayzs.pat.api.communication.Communicator;
|
||||
import de.rayzs.pat.utils.adapter.LuckPermsAdapter;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import de.rayzs.pat.api.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.plugin.listeners.velocity.*;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
import de.rayzs.pat.utils.ConnectionBuilder;
|
||||
@@ -34,26 +38,34 @@ import java.util.*;
|
||||
|
||||
@Plugin(name = "ProAntiTab",
|
||||
id = "proantitab",
|
||||
version = "1.9.2",
|
||||
version = "2.0.8",
|
||||
authors = "Rayzs_YT",
|
||||
description = "Hide more than just your plugins. Hide almost everything!",
|
||||
url = "https://www.rayzs.de/products/proantitab/page",
|
||||
dependencies = {
|
||||
@Dependency(id = "luckperms", optional = true),
|
||||
@Dependency(id = "papiproxybridge", optional = true)
|
||||
})
|
||||
public class VelocityLoader {
|
||||
public class VelocityLoader implements PluginLoader {
|
||||
|
||||
private static VelocityLoader instance;
|
||||
|
||||
private static ProxyServer server;
|
||||
private static org.slf4j.Logger logger;
|
||||
|
||||
private final EventManager manager;
|
||||
private final VelocityMetrics.Factory metricsFactory;
|
||||
private ScheduledTask updaterTask;
|
||||
|
||||
private static final HashMap<String, CommandsCache> commandsCacheMap = new HashMap<>();
|
||||
private static boolean checkUpdate = false;
|
||||
|
||||
@Inject
|
||||
public VelocityLoader(ProxyServer server, VelocityMetrics.Factory metricsFactory) {
|
||||
public VelocityLoader(ProxyServer server, org.slf4j.Logger logger, VelocityMetrics.Factory metricsFactory) {
|
||||
VelocityLoader.instance = this;
|
||||
VelocityLoader.server = server;
|
||||
VelocityLoader.logger = logger;
|
||||
|
||||
this.manager = server.getEventManager();
|
||||
this.metricsFactory = metricsFactory;
|
||||
}
|
||||
@@ -62,28 +74,28 @@ public class VelocityLoader {
|
||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||
PluginContainer pluginContainer = server.getPluginManager().getPlugin("proantitab").get();
|
||||
|
||||
Configurator.createResourcedFile("./plugins/ProAntiTab", "files\\proxy-config.yml", "config.yml", false);
|
||||
Configurator.createResourcedFile("./plugins/ProAntiTab", "files\\proxy-storage.yml", "storage.yml", false);
|
||||
Configurator.createResourcedFile("./plugins/ProAntiTab", "files\\proxy-placeholders.yml", "placeholders.yml", false);
|
||||
Configurator.createResourcedFile("./plugins/ProAntiTab", "files\\proxy-custom-responses.yml", "custom-responses.yml", false);
|
||||
Configurator.createResourcedFile("files\\proxy-config.yml", "config.yml", false);
|
||||
Configurator.createResourcedFile("files\\proxy-storage.yml", "storage.yml", false);
|
||||
Configurator.createResourcedFile("files\\proxy-placeholders.yml", "placeholders.yml", false);
|
||||
Configurator.createResourcedFile("files\\proxy-custom-responses.yml", "custom-responses.yml", false);
|
||||
|
||||
CommandProcess.initialize();
|
||||
Reflection.initialize(server);
|
||||
ConfigUpdater.initialize();
|
||||
|
||||
Storage.USE_SIMPLECLOUD = Reflection.doesClassExist("eu.thesimplecloud.plugin.startup.CloudPlugin");
|
||||
Storage.CURRENT_VERSION = pluginContainer.getDescription().getVersion().get();
|
||||
VersionComparer.setCurrentVersion(Storage.CURRENT_VERSION);
|
||||
Storage.initialize(this, pluginContainer.getDescription().getVersion().get());
|
||||
VersionComparer.get().setCurrentVersion(Storage.CURRENT_VERSION);
|
||||
|
||||
Storage.loadAll(true);
|
||||
MessageTranslator.initialize();
|
||||
CustomServerBrand.initialize();
|
||||
GroupManager.initialize();
|
||||
|
||||
|
||||
metricsFactory.make(this, 21638);
|
||||
|
||||
server.getCommandManager().register("bpat", new VelocityCommand(), "bungeeproantitab");
|
||||
server.getEventManager().register(this, new VelocityBlockCommandListener(server));
|
||||
//server.getEventManager().register(this, new VelocityBlockCommandListener(server));
|
||||
server.getEventManager().register(this, new VelocityAntiTabListener(server));
|
||||
server.getEventManager().register(this, new VelocityConnectionListener(server, this));
|
||||
server.getEventManager().register(this, new VelocityPingListener(server));
|
||||
@@ -95,10 +107,10 @@ public class VelocityLoader {
|
||||
|
||||
Storage.PLUGIN_OBJECT = this;
|
||||
|
||||
if(server.getPluginManager().getPlugin("luckperms").isPresent())
|
||||
if (server.getPluginManager().getPlugin("luckperms").isPresent())
|
||||
LuckPermsAdapter.initialize();
|
||||
|
||||
if(server.getPluginManager().getPlugin("papiproxybridge").isPresent()) {
|
||||
if (server.getPluginManager().getPlugin("papiproxybridge").isPresent()) {
|
||||
Storage.USE_PAPIPROXYBRIDGE = true;
|
||||
Logger.info("Successfully hooked into PAPIProxyBridge!");
|
||||
}
|
||||
@@ -111,85 +123,169 @@ public class VelocityLoader {
|
||||
SubArgsModule.initialize();
|
||||
}
|
||||
|
||||
public static org.slf4j.Logger getPluginLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
public static void delayedPermissionsReload() {
|
||||
server.getScheduler().buildTask(VelocityLoader.instance, () -> {
|
||||
PermissionUtil.reloadPermissions();
|
||||
VelocityAntiTabListener.updateCommands();
|
||||
Storage.getLoader().updateCommandCache();
|
||||
}).delay(1, TimeUnit.SECONDS).schedule();
|
||||
}
|
||||
|
||||
public static List<String> getPlayerNames() {
|
||||
List<String> result = new LinkedList<>();
|
||||
server.getAllPlayers().forEach(player -> result.add(player.getUsername()));
|
||||
return result;
|
||||
public static void delayedPlayerReload(UUID uuid) {
|
||||
server.getScheduler().buildTask(VelocityLoader.instance, () -> {
|
||||
String serverName = Storage.getLoader().getPlayerServerName(uuid);
|
||||
List<String> commands = new ArrayList<>(SubArgsModule.getServerCommands(serverName));
|
||||
|
||||
commands.addAll(SubArgsModule.getGroupCommands(uuid, serverName));
|
||||
|
||||
PATEventHandler.callUpdatePlayerCommandsEvents(uuid, commands, true);
|
||||
}).delay(1, TimeUnit.SECONDS).schedule();
|
||||
}
|
||||
|
||||
public static UUID getUUIDByName(String playerName) {
|
||||
if (!server.getPlayer(playerName).isPresent()) return null;
|
||||
return server.getPlayer(playerName).get().getUniqueId();
|
||||
@Override
|
||||
public void handleReload() {}
|
||||
|
||||
@Override
|
||||
public boolean doesCommandExist(String command) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getConsoleSender() {
|
||||
return server.getConsoleCommandSource();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPlayerObjByName(String name) {
|
||||
return server.getPlayer(name).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPlayerObjByUUID(UUID uuid) {
|
||||
return server.getPlayer(uuid).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCommandCache() {
|
||||
new ArrayList<>(commandsCacheMap.values()).forEach(CommandsCache::reset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, CommandsCache> getCommandsCacheMap() {
|
||||
return commandsCacheMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayerOnline(String playerName) {
|
||||
return server.getPlayer(playerName).isPresent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesPlayerExist(String playerName) {
|
||||
return isPlayerOnline(playerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UUID> getPlayerIdsByServer(String serverName) {
|
||||
List<UUID> uuids = new ArrayList<>();
|
||||
|
||||
getServerNames().stream()
|
||||
.filter(originServerName -> Storage.isServer(serverName, originServerName))
|
||||
.forEach(originServerName -> {
|
||||
Optional<RegisteredServer> optionalRegServerInfo = server.getServer(serverName);
|
||||
|
||||
if (optionalRegServerInfo.isEmpty())
|
||||
return;
|
||||
|
||||
RegisteredServer regServerInfo = optionalRegServerInfo.get();
|
||||
uuids.addAll(regServerInfo.getPlayersConnected().stream().map(Player::getUniqueId).toList());
|
||||
});
|
||||
|
||||
return uuids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerServerName(UUID uuid) {
|
||||
Optional<Player> optPlayer = server.getPlayer(uuid);
|
||||
|
||||
if (optPlayer.isEmpty())
|
||||
return null;
|
||||
|
||||
Player player = optPlayer.get();
|
||||
Optional<ServerConnection> optConnection = player.getCurrentServer();
|
||||
|
||||
if (optConnection.isEmpty())
|
||||
return null;
|
||||
|
||||
ServerConnection connection = optConnection.get();
|
||||
return connection.getServer().getServerInfo().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UUID> getPlayerIds() {
|
||||
return server.getAllPlayers().stream().map(Player::getUniqueId).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getOnlinePlayerNames(String serverName) {
|
||||
return server.getAllPlayers().stream()
|
||||
.filter(player -> {
|
||||
Optional<ServerConnection> optConnection = player.getCurrentServer();
|
||||
|
||||
if (optConnection.isEmpty())
|
||||
return false;
|
||||
|
||||
ServerConnection connection = optConnection.get();
|
||||
return connection.getServer().getServerInfo().getName().equalsIgnoreCase(serverName);
|
||||
|
||||
}).map(Player::getUsername).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getOnlinePlayerNames() {
|
||||
return server.getAllPlayers().stream().map(Player::getUsername).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getOfflinePlayerNames() {
|
||||
return server.getAllPlayers().stream().map(Player::getUsername).toList();
|
||||
}
|
||||
|
||||
public List<String> getPlayerNames() {
|
||||
return server.getAllPlayers().stream().map(Player::getUsername).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNameByUUID(UUID uuid) {
|
||||
Player player = server.getPlayer(uuid).orElse(null);
|
||||
return player != null ? player.getUsername() : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUIDByName(String playerName) {
|
||||
Player player = server.getPlayer(playerName).orElse(null);
|
||||
return player != null ? player.getUniqueId() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getServerNames() {
|
||||
return new ArrayList<>(server.getAllServers().stream().map(registeredServer -> registeredServer.getServerInfo().getName()).toList());
|
||||
}
|
||||
|
||||
public void startUpdaterTask() {
|
||||
if (!Storage.ConfigSections.Settings.UPDATE.ENABLED) return;
|
||||
|
||||
updaterTask = server.getScheduler().buildTask(this, () -> {
|
||||
String result = new ConnectionBuilder().setUrl("https://www.rayzs.de/proantitab/api/version.php")
|
||||
.setProperties("ProAntiTab", "4654").connect().getResponse();
|
||||
|
||||
Storage.NEWER_VERSION = result;
|
||||
VersionComparer.setNewestVersion(Storage.NEWER_VERSION);
|
||||
|
||||
if(VersionComparer.isDeveloperVersion()) {
|
||||
if (VersionComparer.get().computeComparison())
|
||||
updaterTask.cancel();
|
||||
MessageTranslator.send(server.getConsoleCommandSource(), "<dark_gray>[</dark_gray><white>PAT | Proxy</white><dark_gray>]</dark_gray> <gray>Please be aware that you are currently using a</gray> <aqua>developer</aqua> <gray>version of ProAntiTab. Bugs, errors and a lot of debug messages might be included.</gray>");
|
||||
|
||||
} else if(!checkUpdate && (VersionComparer.isNewest() || VersionComparer.isUnreleased())) {
|
||||
updaterTask.cancel();
|
||||
checkUpdate = true;
|
||||
|
||||
if(VersionComparer.isUnreleased()) {
|
||||
MessageTranslator.send(server.getConsoleCommandSource(), "<dark_gray>[</dark_gray><white>PAT | Proxy</white><dark_gray>]</dark_gray> <gray>Please be aware that you are currently using an</gray> <yellow>unreleased</yellow> <gray>version of ProAntiTab.</gray>");
|
||||
return;
|
||||
}
|
||||
|
||||
checkUpdate = true;
|
||||
MessageTranslator.send(server.getConsoleCommandSource(), Storage.ConfigSections.Settings.UPDATE.UPDATED.getLines());
|
||||
|
||||
} else if(VersionComparer.isOutdated()) {
|
||||
Storage.OUTDATED = true;
|
||||
MessageTranslator.send(server.getConsoleCommandSource(), Storage.ConfigSections.Settings.UPDATE.OUTDATED.getLines());
|
||||
|
||||
} else if(!Storage.NEWER_VERSION.equals(Storage.CURRENT_VERSION)) {
|
||||
updaterTask.cancel();
|
||||
switch (result) {
|
||||
case "internet":
|
||||
Logger.warning("[PAT | Proxy] Failed to build connection to website! (No internet?)");
|
||||
break;
|
||||
case "unknown":
|
||||
Logger.warning("[PAT | Proxy] Failed to build connection to website! (Firewall enabled or website down?)");
|
||||
break;
|
||||
case "exception":
|
||||
Logger.warning("[PAT | Proxy] Failed to build connection to website! (Outdated java version?)");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}).delay(1, TimeUnit.SECONDS).repeat(Storage.ConfigSections.Settings.UPDATE.PERIOD, TimeUnit.SECONDS).schedule();
|
||||
}
|
||||
|
||||
public static String getServerNameByPlayerUUID(UUID uuid) {
|
||||
Optional<Player> optPlayer = server.getPlayer(uuid);
|
||||
if(!optPlayer.isPresent()) return null;
|
||||
|
||||
Player player = optPlayer.get();
|
||||
Optional<ServerConnection> optServer = player.getCurrentServer();
|
||||
if(!optServer.isPresent()) return null;
|
||||
|
||||
ServerConnection server = optServer.get();
|
||||
if(server.getServerInfo() == null) return null;
|
||||
|
||||
return server.getServerInfo().getName();
|
||||
}
|
||||
|
||||
public static ProxyServer getServer() {
|
||||
return server;
|
||||
}
|
||||
@@ -197,10 +293,4 @@ public class VelocityLoader {
|
||||
public static VelocityLoader getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static List<String> getServerNames() {
|
||||
List<String> servers = new ArrayList<>();
|
||||
server.getAllServers().forEach(server -> servers.add(server.getServerInfo().getName().toLowerCase()));
|
||||
return servers;
|
||||
}
|
||||
}
|
||||
@@ -8,19 +8,20 @@ import java.util.List;
|
||||
public class BukkitCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
|
||||
public boolean onCommand(CommandSender commandSender, Command command, String label, String[] strings) {
|
||||
if(commandSender instanceof Player) {
|
||||
Player player = (Player) commandSender;
|
||||
CommandProcess.handleCommand(player, strings, s);
|
||||
|
||||
CommandProcess.handleCommand(player, strings, label);
|
||||
return true;
|
||||
}
|
||||
|
||||
CommandProcess.handleCommand(commandSender, strings, s);
|
||||
CommandProcess.handleCommand(commandSender, strings, label);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) {
|
||||
public List<String> onTabComplete(CommandSender commandSender, Command command, String label, String[] strings) {
|
||||
return CommandProcess.handleTabComplete(commandSender, strings);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import de.rayzs.pat.plugin.process.CommandProcess;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.plugin.*;
|
||||
|
||||
public class BungeeCommand extends Command implements TabExecutor {
|
||||
public class BungeeCommand extends Command implements TabExecutor {
|
||||
|
||||
public BungeeCommand(String name) {
|
||||
super(name);
|
||||
|
||||
@@ -12,6 +12,8 @@ import org.bukkit.entity.Player;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import org.bukkit.event.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class BukkitAntiTabListener implements Listener {
|
||||
@@ -24,18 +26,21 @@ public class BukkitAntiTabListener implements Listener {
|
||||
UUID uuid = player.getUniqueId();
|
||||
String uuidSubstring = uuid.toString().substring(uuid.toString().length() - 5);
|
||||
|
||||
if(Storage.USE_VELOCITY || player.isOp()) {
|
||||
if (Storage.USE_VELOCITY || player.isOp()) {
|
||||
Logger.debug("Doesn't even tried to create the commands list for player with uuid " + uuidSubstring + ". (Veloctiy? " + Storage.USE_VELOCITY + ". OP? " + player.isOp() + ")");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!BukkitLoader.isLoaded()) {
|
||||
if (!BukkitLoader.isLoaded()) {
|
||||
event.getCommands().clear();
|
||||
Logger.debug("Doesn't even tried to create the commands list for player with uuid " + uuidSubstring + ". (not loaded)");
|
||||
return;
|
||||
}
|
||||
|
||||
if(event.getCommands().isEmpty()) {
|
||||
if (Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED)
|
||||
return;
|
||||
|
||||
if (event.getCommands().isEmpty()) {
|
||||
Logger.debug("No available commands to filter! Ignoring rest of the code until at least one command is listed in there.");
|
||||
return;
|
||||
}
|
||||
@@ -48,69 +53,29 @@ public class BukkitAntiTabListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if(Storage.USE_VIAVERSION)
|
||||
if(Reflection.getMinor() >= 16 && ViaVersionAdapter.getPlayerProtocol(uuid) < 754)
|
||||
event.getCommands().clear();
|
||||
final List<String> playerCommands = COMMANDS_CACHE.getPlayerCommands(new ArrayList<>(event.getCommands()), player, player.getUniqueId());
|
||||
FilteredSuggestionEvent filteredSuggestionEvent = PATEventHandler.callFilteredSuggestionEvents(player, playerCommands);
|
||||
|
||||
final List<String> playerCommands = COMMANDS_CACHE.getPlayerCommands(event.getCommands(), player, player.getUniqueId());
|
||||
event.getCommands().clear();
|
||||
|
||||
FilteredSuggestionEvent filteredSuggestionEvent = PATEventHandler.callFilteredSuggestionEvents(player, playerCommands);
|
||||
if(filteredSuggestionEvent.isCancelled()) return;
|
||||
if (filteredSuggestionEvent.isCancelled())
|
||||
return;
|
||||
|
||||
event.getCommands().addAll(filteredSuggestionEvent.getSuggestions());
|
||||
|
||||
Logger.debug("Player with uuid " + uuidSubstring + " has a total of " + playerCommands.size() + " commands.");
|
||||
}
|
||||
|
||||
public static void updateCommands(Player player) {
|
||||
if(notUpdatablePlayer(player.getUniqueId())) return;
|
||||
if(Reflection.getMinor() >= 16) player.updateCommands();
|
||||
}
|
||||
|
||||
public static void updateCommands() {
|
||||
if(Reflection.getMinor() >= 16) Bukkit.getOnlinePlayers().forEach(BukkitAntiTabListener::updateCommands);
|
||||
}
|
||||
|
||||
public static void setChangeStatus() {
|
||||
COMMANDS_CACHE.updateChangeState();
|
||||
}
|
||||
|
||||
public static void handleTabCompletion(List<String> commands) {
|
||||
if(Storage.USE_VELOCITY) return;
|
||||
COMMANDS_CACHE.reset();
|
||||
Bukkit.getOnlinePlayers().forEach(player -> handleTabCompletion(player, commands));
|
||||
}
|
||||
|
||||
public static void handleTabCompletion() {
|
||||
COMMANDS_CACHE.reset();
|
||||
Bukkit.getOnlinePlayers().forEach(BukkitAntiTabListener::handleTabCompletion);
|
||||
}
|
||||
|
||||
public static void handleTabCompletion(Player player) {
|
||||
handleTabCompletion(player, getCommands());
|
||||
}
|
||||
|
||||
public static List<String> getCommands() {
|
||||
return Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED
|
||||
? Storage.Blacklist.getBlacklist().getCommands() : BukkitLoader.getAllCommands();
|
||||
}
|
||||
|
||||
public static void handleTabCompletion(UUID uuid) {
|
||||
if(notUpdatablePlayer(uuid)) return;
|
||||
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if(player == null) return;
|
||||
handleTabCompletion(player);
|
||||
private static boolean notUpdatablePlayer(UUID uuid) {
|
||||
return Storage.USE_VIAVERSION && Reflection.getMinor() >= 16 && ViaVersionAdapter.getPlayerProtocol(uuid) < 754;
|
||||
}
|
||||
|
||||
public static void handleTabCompletion(UUID uuid, List<String> commands) {
|
||||
if(notUpdatablePlayer(uuid)) return;
|
||||
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if(player == null) return;
|
||||
handleTabCompletion(player, commands);
|
||||
}
|
||||
// --------------- LUCKPERMS SECTIONS --------------- //
|
||||
|
||||
public static void luckpermsNetworkSync() {
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(BukkitLoader.getPlugin(), PermissionUtil::reloadPermissions, 40);
|
||||
@@ -120,9 +85,38 @@ public class BukkitAntiTabListener implements Listener {
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(BukkitLoader.getPlugin(), () -> PermissionUtil.reloadPermissions(uuid));
|
||||
}
|
||||
|
||||
public static void updateCommands() {
|
||||
Bukkit.getOnlinePlayers().forEach(BukkitAntiTabListener::updateCommands);
|
||||
}
|
||||
|
||||
public static void updateCommands(Player player) {
|
||||
if (Reflection.getMinor() >= 13 && !notUpdatablePlayer(player.getUniqueId()))
|
||||
player.updateCommands();
|
||||
}
|
||||
|
||||
|
||||
// --------------- UPDATE SECTIONS --------------- //
|
||||
|
||||
public static void handleTabCompletion() {
|
||||
COMMANDS_CACHE.reset();
|
||||
Bukkit.getOnlinePlayers().forEach(BukkitAntiTabListener::handleTabCompletion);
|
||||
}
|
||||
|
||||
public static void handleTabCompletion(UUID uuid) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
handleTabCompletion(player);
|
||||
}
|
||||
|
||||
public static void handleTabCompletion(Player player) {
|
||||
handleTabCompletion(player, getCommands());
|
||||
}
|
||||
|
||||
public static void handleTabCompletion(Player player, List<String> commands) {
|
||||
if(Storage.USE_VELOCITY) return;
|
||||
if(notUpdatablePlayer(player.getUniqueId())) return;
|
||||
if (notUpdatablePlayer(player.getUniqueId()))
|
||||
return;
|
||||
|
||||
List<String> dummy = new ArrayList<>(commands);
|
||||
PlayerCommandSendEvent event = new PlayerCommandSendEvent(player, dummy);
|
||||
@@ -130,11 +124,4 @@ public class BukkitAntiTabListener implements Listener {
|
||||
updateCommands(player);
|
||||
}
|
||||
|
||||
private static boolean notUpdatablePlayer(UUID uuid) {
|
||||
if(Storage.USE_VIAVERSION)
|
||||
return Reflection.getMinor() >= 16 && ViaVersionAdapter.getPlayerProtocol(uuid) < 754;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
+82
-101
@@ -1,18 +1,22 @@
|
||||
package de.rayzs.pat.plugin.listeners.bukkit;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
import de.rayzs.pat.api.event.events.ExecuteCommandEvent;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.BukkitLoader;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import de.rayzs.pat.api.event.*;
|
||||
import org.bukkit.event.*;
|
||||
import java.util.List;
|
||||
import org.bukkit.*;
|
||||
|
||||
public class BukkitBlockCommandListener implements Listener {
|
||||
|
||||
@@ -20,11 +24,20 @@ public class BukkitBlockCommandListener implements Listener {
|
||||
public void onUnknownCommandRecognition(PlayerCommandPreprocessEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
World world = player.getWorld();
|
||||
String rawCommand = StringUtils.getFirstArg(event.getMessage()), command = StringUtils.replaceFirst(rawCommand, "/", "");
|
||||
|
||||
if(!Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.ENABLED || event.isCancelled()) return;
|
||||
if(BukkitLoader.doesCommandExist(command, false)) return;
|
||||
if(Bukkit.getHelpMap().getHelpTopic(rawCommand) != null) return;
|
||||
String rawCommand = StringUtils.getFirstArg(event.getMessage()),
|
||||
command = rawCommand.substring(1);
|
||||
|
||||
if (!Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.ENABLED || event.isCancelled()) return;
|
||||
|
||||
if (PermissionUtil.hasBypassPermission(player))
|
||||
return;
|
||||
|
||||
if (Storage.getLoader().doesCommandExist(command))
|
||||
return;
|
||||
|
||||
if (Bukkit.getHelpMap().getHelpTopic(rawCommand) != null)
|
||||
return;
|
||||
|
||||
event.setCancelled(true);
|
||||
MessageTranslator.send(player, Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.MESSAGE, "%command%", command, "%world%", world.getName());
|
||||
@@ -33,110 +46,78 @@ public class BukkitBlockCommandListener implements Listener {
|
||||
@EventHandler (priority = EventPriority.LOWEST)
|
||||
public void onPlayerCommandProcess(PlayerCommandPreprocessEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (Storage.ConfigSections.Settings.AUTO_LOWERCASE_COMMANDS.isCommand(StringUtils.getFirstArg(event.getMessage()))) {
|
||||
String command = event.getMessage();
|
||||
|
||||
if (command.contains(" ")) {
|
||||
String[] args = command.split(" ");
|
||||
args[0] = args[0].toLowerCase();
|
||||
command = String.join(" ", args);
|
||||
} else command = command.toLowerCase();
|
||||
|
||||
player.chat(command);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
World world = player.getWorld();
|
||||
String rawCommand = event.getMessage(), command = rawCommand, worldName = world.getName();
|
||||
String command = event.getMessage(),
|
||||
worldName = world.getName();
|
||||
|
||||
command = StringUtils.replaceFirst(command, "/", "");
|
||||
boolean bypassPermission = PermissionUtil.hasBypassPermission(player, command);
|
||||
|
||||
command = command.substring(1);
|
||||
command = StringUtils.getFirstArg(command);
|
||||
command = StringUtils.replaceTriggers(command, "", "\\", "<", ">", "&");
|
||||
|
||||
List<String> notificationMessage = MessageTranslator.replaceMessageList(Storage.ConfigSections.Messages.NOTIFICATION.ALERT, "%player%", player.getName(), "%command%", command, "%world%", worldName);
|
||||
final String displayName = StringUtils.replaceTriggers(command, "", "\\", "<", ">", "&");
|
||||
command = command.toLowerCase();
|
||||
|
||||
if(Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isCommand(command) && !PermissionUtil.hasBypassPermission(player, command)) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, true);
|
||||
if(executeCommandEvent.isBlocked()) event.setCancelled(true);
|
||||
if(executeCommandEvent.isCancelled()) return;
|
||||
|
||||
MessageTranslator.send(player, Storage.ConfigSections.Settings.CUSTOM_PLUGIN.MESSAGE, "%command%", command);
|
||||
|
||||
if(Storage.SEND_CONSOLE_NOTIFICATION) Logger.info(notificationMessage);
|
||||
Storage.NOTIFY_PLAYERS.stream().filter(uuid -> Bukkit.getServer().getPlayer(uuid) != null).forEach(uuid -> {
|
||||
Player target = Bukkit.getServer().getPlayer(uuid);
|
||||
MessageTranslator.send(target, notificationMessage);
|
||||
});
|
||||
List<String> notificationMessage = MessageTranslator.replaceMessageList(
|
||||
Storage.ConfigSections.Messages.NOTIFICATION.ALERT,
|
||||
"%player%", player.getName(),
|
||||
"%command%", displayName,
|
||||
"%world%", worldName);
|
||||
|
||||
if (bypassPermission)
|
||||
return;
|
||||
}
|
||||
|
||||
if(Storage.ConfigSections.Settings.CUSTOM_VERSION.isCommand(command) && !PermissionUtil.hasBypassPermission(player, command)) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, true);
|
||||
if(executeCommandEvent.isBlocked()) event.setCancelled(true);
|
||||
if(executeCommandEvent.isCancelled()) return;
|
||||
|
||||
MessageTranslator.send(player, Storage.ConfigSections.Settings.CUSTOM_VERSION.MESSAGE, "%command%", command);
|
||||
|
||||
if(Storage.SEND_CONSOLE_NOTIFICATION) Logger.info(notificationMessage);
|
||||
Storage.NOTIFY_PLAYERS.stream().filter(uuid -> Bukkit.getServer().getPlayer(uuid) != null).forEach(uuid -> {
|
||||
Player target = Bukkit.getServer().getPlayer(uuid);
|
||||
MessageTranslator.send(target, notificationMessage);
|
||||
});
|
||||
|
||||
if (!Storage.ConfigSections.Settings.CANCEL_COMMAND.ENABLED)
|
||||
return;
|
||||
|
||||
if (Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED)
|
||||
return;
|
||||
}
|
||||
|
||||
if(!Storage.ConfigSections.Settings.CANCEL_COMMAND.ENABLED || Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED || rawCommand.equals("/")) return;
|
||||
List<String> cancelCommandMessage = MessageTranslator.replaceMessageList(Storage.ConfigSections.Settings.CANCEL_COMMAND.BASE_COMMAND_RESPONSE, "%command%", command);
|
||||
if (!Storage.Blacklist.canPlayerAccessChat(player, command)) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(
|
||||
player,
|
||||
event.getMessage(),
|
||||
true,
|
||||
!Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED
|
||||
);
|
||||
|
||||
if(Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED) {
|
||||
if (executeCommandEvent.isBlocked()) {
|
||||
event.setCancelled(true);
|
||||
|
||||
if (!executeCommandEvent.doesNotify())
|
||||
return;
|
||||
|
||||
if (Storage.SEND_CONSOLE_NOTIFICATION)
|
||||
Logger.info(notificationMessage);
|
||||
|
||||
Storage.NOTIFY_PLAYERS.stream().filter(uuid -> Bukkit.getServer().getPlayer(uuid) != null).forEach(uuid -> {
|
||||
Player target = Bukkit.getServer().getPlayer(uuid);
|
||||
MessageTranslator.send(target, notificationMessage);
|
||||
});
|
||||
|
||||
if(Storage.Blacklist.isListed(command, true)) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, false);
|
||||
if(executeCommandEvent.isBlocked()) event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if(PermissionUtil.hasBypassPermission(player, command, false)) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, false);
|
||||
if(executeCommandEvent.isBlocked()) event.setCancelled(true);
|
||||
if (executeCommandEvent.isCancelled())
|
||||
return;
|
||||
}
|
||||
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, true);
|
||||
if(executeCommandEvent.isBlocked()) event.setCancelled(true);
|
||||
if(executeCommandEvent.isCancelled()) return;
|
||||
MessageTranslator.send(player, cancelCommandMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
if(Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.isCommand(command) && !Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.doesBypass(player)) {
|
||||
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, true);
|
||||
if(executeCommandEvent.isBlocked()) event.setCancelled(true);
|
||||
if(executeCommandEvent.isCancelled()) return;
|
||||
|
||||
MessageTranslator.send(player, cancelCommandMessage);
|
||||
|
||||
if(Storage.SEND_CONSOLE_NOTIFICATION) Logger.info(notificationMessage);
|
||||
Storage.NOTIFY_PLAYERS.stream().filter(uuid -> Bukkit.getServer().getPlayer(uuid) != null).forEach(uuid -> {
|
||||
Player target = Bukkit.getServer().getPlayer(uuid);
|
||||
MessageTranslator.send(target, notificationMessage);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Storage.Blacklist.isListed(command, false)) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, false);
|
||||
if(executeCommandEvent.isBlocked()) event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (PermissionUtil.hasBypassPermission(player, command, false)) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, false);
|
||||
if(executeCommandEvent.isBlocked()) event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, true);
|
||||
if(executeCommandEvent.isBlocked()) event.setCancelled(true);
|
||||
if(executeCommandEvent.isCancelled()) return;
|
||||
|
||||
MessageTranslator.send(player, cancelCommandMessage);
|
||||
|
||||
if(Storage.SEND_CONSOLE_NOTIFICATION) Logger.info(notificationMessage);
|
||||
Storage.NOTIFY_PLAYERS.stream().filter(uuid -> Bukkit.getServer().getPlayer(uuid) != null).forEach(uuid -> {
|
||||
Player target = Bukkit.getServer().getPlayer(uuid);
|
||||
MessageTranslator.send(target, notificationMessage);
|
||||
});
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, event.getMessage(), false, false);
|
||||
if (executeCommandEvent.isBlocked())
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
+18
-7
@@ -1,15 +1,16 @@
|
||||
package de.rayzs.pat.plugin.listeners.bukkit;
|
||||
|
||||
import de.rayzs.pat.api.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
import de.rayzs.pat.api.event.events.ServerPlayersChangeEvent;
|
||||
import de.rayzs.pat.api.netty.bukkit.BukkitPacketAnalyzer;
|
||||
import de.rayzs.pat.api.brand.impl.BukkitServerBrand;
|
||||
import de.rayzs.pat.api.communication.BackendUpdater;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import de.rayzs.pat.api.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.BukkitLoader;
|
||||
import de.rayzs.pat.utils.scheduler.PATScheduler;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.*;
|
||||
@@ -31,11 +32,22 @@ public class BukkitPlayerConnectionListener implements Listener {
|
||||
if(CustomServerBrand.isEnabled())
|
||||
CustomServerBrand.sendBrandToPlayer(player);
|
||||
|
||||
if(!BukkitPacketAnalyzer.inject(player)) player.kickPlayer("Failed to inject player!");
|
||||
if(!BukkitPacketAnalyzer.inject(player)) {
|
||||
|
||||
PATScheduler.createScheduler(() -> {
|
||||
if (player.isOnline()) {
|
||||
if (!BukkitPacketAnalyzer.inject(player)) {
|
||||
Logger.warning("Failed to inject into player! (" + player.getName() + ")" );
|
||||
player.kickPlayer("Failed to inject player!");
|
||||
}
|
||||
}
|
||||
}, 10);
|
||||
|
||||
}
|
||||
|
||||
if(Storage.OUTDATED && PermissionUtil.hasPermission(player, "joinupdate")) {
|
||||
Bukkit.getScheduler().runTaskLater(BukkitLoader.getPlugin(), () -> {
|
||||
if(player.isOnline()) {
|
||||
PATScheduler.createScheduler(() -> {
|
||||
if (player.isOnline()) {
|
||||
MessageTranslator.send(player, Storage.ConfigSections.Settings.UPDATE.OUTDATED.getLines());
|
||||
}
|
||||
}, 20);
|
||||
@@ -50,14 +62,13 @@ public class BukkitPlayerConnectionListener implements Listener {
|
||||
BukkitPacketAnalyzer.uninject(player.getUniqueId());
|
||||
PermissionUtil.resetPermissions(player.getUniqueId());
|
||||
if(Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY != -1) return;
|
||||
BukkitServerBrand.removeFromModified(player);
|
||||
}
|
||||
|
||||
@EventHandler (priority = EventPriority.LOWEST)
|
||||
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if(Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY != -1) return;
|
||||
BukkitServerBrand.removeFromModified(player);
|
||||
|
||||
CustomServerBrand.sendBrandToPlayer(player);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,29 @@
|
||||
package de.rayzs.pat.plugin.listeners.bukkit;
|
||||
|
||||
import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
|
||||
import com.destroystokyo.paper.profile.PlayerProfile;
|
||||
import com.destroystokyo.paper.profile.ProfileProperty;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.ExpireCache;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.message.replacer.PlaceholderReplacer;
|
||||
import org.bukkit.event.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.profile.PlayerTextures;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.plaf.BorderUIResource;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class PaperServerListPing implements Listener {
|
||||
|
||||
private static final ExpireCache<Integer, List<ProtocolHoverLine>> CACHED_PROTOCOL_NAMES = new ExpireCache<>(1, TimeUnit.SECONDS);
|
||||
private static final UUID RANDOM_UUID = UUID.randomUUID();
|
||||
private static final int CACHE_KEY = 0;
|
||||
|
||||
@EventHandler (priority = EventPriority.LOWEST)
|
||||
public void onPaperServerListPing(PaperServerListPingEvent event) {
|
||||
if(!Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.ENABLED) return;
|
||||
@@ -17,16 +33,194 @@ public class PaperServerListPing implements Listener {
|
||||
onlineExtend = online + Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.EXTEND_COUNT,
|
||||
max = Bukkit.getMaxPlayers();
|
||||
|
||||
if(Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.USE_EXTEND_AS_MAX_COUNT)
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.USE_EXTEND_AS_MAX_COUNT)
|
||||
event.setMaxPlayers(onlineExtend);
|
||||
|
||||
String versionName = Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.PROTOCOL.replace("%online_extended%", String.valueOf(onlineExtend)).replace("%online%", String.valueOf(online)).replace("%max%", String.valueOf(max));
|
||||
if(Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.HIDE_PLAYERS)
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.HIDE_PLAYERS) {
|
||||
event.getPlayerSample().clear();
|
||||
event.setHidePlayers(true);
|
||||
}
|
||||
|
||||
else if (Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.USE_CUSTOM_PLAYERLIST) {
|
||||
List<ProtocolHoverLine> cachedPlayerNames = CACHED_PROTOCOL_NAMES.get(CACHE_KEY);
|
||||
|
||||
event.getPlayerSample().clear();
|
||||
|
||||
if(versionName.contains("%"))
|
||||
PlaceholderReplacer.replace(null, versionName);
|
||||
if (cachedPlayerNames != null) {
|
||||
|
||||
event.setVersion(versionName);
|
||||
event.getPlayerSample().addAll(cachedPlayerNames);
|
||||
|
||||
} else {
|
||||
|
||||
Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.PLAYERLIST.getLines().forEach(line -> {
|
||||
|
||||
if (line.contains("%players%")) {
|
||||
List<String> playerNames = Storage.getLoader().getOnlinePlayerNames();
|
||||
|
||||
playerNames = playerNames.size() > 30
|
||||
? playerNames.subList(0, 30)
|
||||
: playerNames;
|
||||
|
||||
for (String currentPlayerName : playerNames) {
|
||||
String playerName = StringUtils.replace(line,
|
||||
"%players%", currentPlayerName, "&", "§"
|
||||
);
|
||||
|
||||
event.getPlayerSample().add(new ProtocolHoverLine(playerName, RANDOM_UUID));
|
||||
}
|
||||
|
||||
} else {
|
||||
String playerName = replaceString(line, online, onlineExtend, max);
|
||||
|
||||
if (playerName.contains("\n")) {
|
||||
String[] nameSplit = playerName.split("\n");
|
||||
nameSplit = nameSplit.length > 30
|
||||
? Arrays.copyOfRange(nameSplit, 0, 30)
|
||||
: nameSplit;
|
||||
|
||||
for (String name : nameSplit) {
|
||||
event.getPlayerSample().add(new ProtocolHoverLine(name, RANDOM_UUID));
|
||||
}
|
||||
|
||||
} else {
|
||||
event.getPlayerSample().add(new ProtocolHoverLine(playerName, RANDOM_UUID));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
event.setVersion(replaceString(versionName, online, onlineExtend, max));
|
||||
}
|
||||
|
||||
private String replaceString(String string, int online, int onlineExtend, int max) {
|
||||
String replaced = string
|
||||
.replace("&", "§")
|
||||
.replace("%online_extended%", String.valueOf(onlineExtend))
|
||||
.replace("%online%", String.valueOf(online))
|
||||
.replace("%max%", String.valueOf(max));
|
||||
|
||||
return replaced.contains("%") ? PlaceholderReplacer.replace(null, replaced) : replaced;
|
||||
}
|
||||
|
||||
private static class ProtocolHoverLine implements PlayerProfile {
|
||||
|
||||
private String name, id;
|
||||
|
||||
public ProtocolHoverLine(String name, UUID id) {
|
||||
this.name = name;
|
||||
this.id = id.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable UUID getUniqueId() {
|
||||
return UUID.fromString(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String setName(@Nullable String s) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable UUID getId() {
|
||||
return getUniqueId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable UUID setId(@Nullable UUID uuid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PlayerTextures getTextures() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTextures(@Nullable PlayerTextures playerTextures) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ProfileProperty> getProperties() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasProperty(@Nullable String s) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProperty(@NotNull ProfileProperty profileProperty) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProperties(@NotNull Collection<ProfileProperty> collection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeProperty(@Nullable String s) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearProperties() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComplete() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean completeFromCache() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean completeFromCache(boolean b) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean completeFromCache(boolean b, boolean b1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean complete(boolean b) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean complete(boolean b, boolean b1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CompletableFuture<PlayerProfile> update() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.profile.@NotNull PlayerProfile clone() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
package de.rayzs.pat.plugin.listeners.bungee;
|
||||
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
import de.rayzs.pat.api.event.events.FilteredSuggestionEvent;
|
||||
import de.rayzs.pat.api.event.events.FilteredTabCompletionEvent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import net.md_5.bungee.api.event.*;
|
||||
import net.md_5.bungee.event.*;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.TabCompleteEvent;
|
||||
import net.md_5.bungee.api.event.TabCompleteResponseEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import java.util.List;
|
||||
|
||||
public class BungeeAntiTabListener implements Listener {
|
||||
|
||||
@@ -17,21 +19,49 @@ public class BungeeAntiTabListener implements Listener {
|
||||
if(!(event.getSender() instanceof ProxiedPlayer)) return;
|
||||
|
||||
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
|
||||
if(PermissionUtil.hasBypassPermission(player)) return;
|
||||
if(Storage.Blacklist.isBlocked(player, event.getCursor(), !Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED, player.getServer().getInfo().getName()))
|
||||
event.getSuggestions().clear();
|
||||
|
||||
ServerInfo serverInfo = player.getServer().getInfo();
|
||||
String serverName = serverInfo.getName();
|
||||
String cursor = event.getCursor().substring(1);
|
||||
|
||||
if (event.getSuggestions().isEmpty())
|
||||
return;
|
||||
|
||||
if (Storage.Blacklist.isDisabledServer(serverName))
|
||||
return;
|
||||
|
||||
if (PermissionUtil.hasBypassPermission(player))
|
||||
return;
|
||||
|
||||
FilteredTabCompletionEvent filteredTabCompletionEvent = PATEventHandler.callFilteredTabCompletionEvents(player, cursor, event.getSuggestions());
|
||||
List<String> suggestions = filteredTabCompletionEvent.getCompletion();
|
||||
|
||||
event.getSuggestions().removeIf(suggestion -> !suggestions.contains(suggestion));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTabComplete(TabCompleteResponseEvent event) {
|
||||
if(!(event.getSender() instanceof ProxiedPlayer)) return;
|
||||
// Ignoring this at first, due to transfer to the packet-based solution only. Hehe
|
||||
|
||||
/*
|
||||
if (!(event.getSender() instanceof ProxiedPlayer))
|
||||
return;
|
||||
|
||||
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
|
||||
if(PermissionUtil.hasBypassPermission(player)) return;
|
||||
|
||||
event.getSuggestions().removeIf(command -> Storage.Blacklist.isBlocked(player, command, !Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED, player.getServer().getInfo().getName()));
|
||||
ServerInfo serverInfo = player.getServer().getInfo();
|
||||
String serverName = serverInfo.getName();
|
||||
|
||||
if (Storage.Blacklist.isDisabledServer(serverName))
|
||||
return;
|
||||
|
||||
if(PermissionUtil.hasBypassPermission(player))
|
||||
return;
|
||||
|
||||
event.getSuggestions().removeIf(command -> !Storage.Blacklist.canPlayerAccessTab(player, command, serverName));
|
||||
|
||||
FilteredSuggestionEvent filteredSuggestionEvent = PATEventHandler.callFilteredSuggestionEvents(player, event.getSuggestions());
|
||||
if(filteredSuggestionEvent.isCancelled()) event.getSuggestions().clear();
|
||||
if (filteredSuggestionEvent.isCancelled()) event.getSuggestions().clear();
|
||||
*/
|
||||
}
|
||||
}
|
||||
+42
-103
@@ -3,146 +3,85 @@ package de.rayzs.pat.plugin.listeners.bungee;
|
||||
import de.rayzs.pat.api.event.events.ExecuteCommandEvent;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.event.ChatEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import net.md_5.bungee.api.connection.*;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.api.event.*;
|
||||
import net.md_5.bungee.event.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BungeeBlockCommandListener implements Listener {
|
||||
|
||||
@EventHandler (priority = EventPriority.HIGHEST)
|
||||
public void onChat(ChatEvent event) {
|
||||
if(event.isCancelled()) return;
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
Connection connection = event.getSender();
|
||||
if(!(connection instanceof ProxiedPlayer) || !event.getMessage().startsWith("/")) return;
|
||||
if (! (connection instanceof ProxiedPlayer) || !event.getMessage().startsWith("/"))
|
||||
return;
|
||||
|
||||
ProxiedPlayer player = (ProxiedPlayer) connection;
|
||||
String serverName = player.getServer().getInfo().getName();
|
||||
String command = event.getMessage();
|
||||
|
||||
String rawCommand = event.getMessage(), command = rawCommand.toLowerCase();
|
||||
boolean bypassPermission = PermissionUtil.hasBypassPermission(player, command);
|
||||
|
||||
command = StringUtils.replaceFirst(command, "/", "");
|
||||
if (bypassPermission)
|
||||
return;
|
||||
|
||||
command = command.startsWith("/") ? command.substring(1) : command;
|
||||
command = StringUtils.getFirstArg(command);
|
||||
command = StringUtils.replaceTriggers(command, "", "\\", "<", ">", "&");
|
||||
|
||||
if(PermissionUtil.hasBypassPermission(player, command, false)) return;
|
||||
final String displayCommand = StringUtils.replaceTriggers(command, "", "\\", "<", ">", "&");
|
||||
|
||||
if(rawCommand.equals("/")) return;
|
||||
ServerInfo serverInfo = player.getServer().getInfo();
|
||||
String serverName = serverInfo != null ? serverInfo.getName() : "unknown";
|
||||
List<String> notificationMessage = MessageTranslator.replaceMessageList(Storage.ConfigSections.Messages.NOTIFICATION.ALERT, "%player%", player.getName(), "%command%", command, "%server%", serverName);
|
||||
command = command.toLowerCase();
|
||||
|
||||
if(Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isCommand(command) && !PermissionUtil.hasBypassPermission(player, command)) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, true);
|
||||
if(executeCommandEvent.isBlocked()) event.setCancelled(true);
|
||||
if(executeCommandEvent.isCancelled()) return;
|
||||
|
||||
MessageTranslator.send(player, Storage.ConfigSections.Settings.CUSTOM_PLUGIN.MESSAGE, "%command%", rawCommand.replaceFirst("/", ""));
|
||||
|
||||
if(Storage.SEND_CONSOLE_NOTIFICATION) Logger.info(notificationMessage);
|
||||
Storage.NOTIFY_PLAYERS.forEach(uuid -> {
|
||||
ProxiedPlayer proxiedPlayer = ProxyServer.getInstance().getPlayer(uuid);
|
||||
if(proxiedPlayer != null) MessageTranslator.send(proxiedPlayer, notificationMessage);
|
||||
});
|
||||
List<String> notificationMessage = MessageTranslator.replaceMessageList(
|
||||
Storage.ConfigSections.Messages.NOTIFICATION.ALERT,
|
||||
"%player%", player.getName(),
|
||||
"%command%", displayCommand,
|
||||
"%server%", serverName);
|
||||
|
||||
if (!Storage.ConfigSections.Settings.CANCEL_COMMAND.ENABLED)
|
||||
return;
|
||||
}
|
||||
|
||||
if(Storage.ConfigSections.Settings.CUSTOM_VERSION.isCommand(command) && !PermissionUtil.hasBypassPermission(player, command)) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, true);
|
||||
if(executeCommandEvent.isBlocked()) event.setCancelled(true);
|
||||
if(executeCommandEvent.isCancelled()) return;
|
||||
if (!Storage.Blacklist.canPlayerAccessChat(player, command, serverName)) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(
|
||||
player,
|
||||
event.getMessage(),
|
||||
true,
|
||||
!Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED
|
||||
);
|
||||
|
||||
MessageTranslator.send(player, Storage.ConfigSections.Settings.CUSTOM_VERSION.MESSAGE, "%command%", rawCommand.replaceFirst("/", ""));
|
||||
if (executeCommandEvent.isBlocked()) {
|
||||
event.setCancelled(true);
|
||||
|
||||
if(Storage.SEND_CONSOLE_NOTIFICATION) Logger.info(notificationMessage);
|
||||
Storage.NOTIFY_PLAYERS.forEach(uuid -> {
|
||||
ProxiedPlayer proxiedPlayer = ProxyServer.getInstance().getPlayer(uuid);
|
||||
if(proxiedPlayer != null) MessageTranslator.send(proxiedPlayer, notificationMessage);
|
||||
});
|
||||
if (!executeCommandEvent.doesNotify())
|
||||
return;
|
||||
|
||||
return;
|
||||
}
|
||||
if (Storage.SEND_CONSOLE_NOTIFICATION)
|
||||
Logger.info(notificationMessage);
|
||||
|
||||
if(!Storage.ConfigSections.Settings.CANCEL_COMMAND.ENABLED) return;
|
||||
Storage.NOTIFY_PLAYERS.forEach(uuid -> {
|
||||
Object p = Storage.getLoader().getPlayerObjByUUID(uuid);
|
||||
|
||||
List<String> cancelCommandMessage = MessageTranslator.replaceMessageList(Storage.ConfigSections.Settings.CANCEL_COMMAND.BASE_COMMAND_RESPONSE, "%command%", command);
|
||||
if (p != null) {
|
||||
MessageTranslator.send(p, notificationMessage);
|
||||
}
|
||||
});
|
||||
|
||||
boolean listed, serverListed, ignored;
|
||||
if(Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED) {
|
||||
if(Storage.Blacklist.doesGroupBypass(player, command, true, true, false, serverName)) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, false);
|
||||
if(executeCommandEvent.isBlocked()) event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
listed = Storage.Blacklist.isListed(command, false, true, false);
|
||||
serverListed = Storage.Blacklist.isListed(player, command, false, listed, false, serverName, true);
|
||||
ignored = Storage.Blacklist.isOnIgnoredServer(serverName);
|
||||
|
||||
if(ignored ? !listed && serverListed : serverListed) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, false);
|
||||
if(executeCommandEvent.isBlocked()) event.setCancelled(true);
|
||||
if (executeCommandEvent.isCancelled())
|
||||
return;
|
||||
}
|
||||
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, true);
|
||||
if(executeCommandEvent.isBlocked()) event.setCancelled(true);
|
||||
if(executeCommandEvent.isCancelled()) return;
|
||||
|
||||
MessageTranslator.send(player, cancelCommandMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
if(Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.isCommand(command) && !Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.doesBypass(player)) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, true);
|
||||
if(executeCommandEvent.isBlocked()) event.setCancelled(true);
|
||||
if(executeCommandEvent.isCancelled()) return;
|
||||
|
||||
MessageTranslator.send(player, cancelCommandMessage);
|
||||
|
||||
if(Storage.SEND_CONSOLE_NOTIFICATION) Logger.info(notificationMessage);
|
||||
Storage.NOTIFY_PLAYERS.forEach(uuid -> {
|
||||
ProxiedPlayer proxiedPlayer = ProxyServer.getInstance().getPlayer(uuid);
|
||||
if(proxiedPlayer != null) MessageTranslator.send(proxiedPlayer, notificationMessage);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(Storage.Blacklist.doesGroupBypass(player, command, true, true, false, serverName)) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, false);
|
||||
if(executeCommandEvent.isBlocked()) event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
listed = Storage.Blacklist.isListed(command, true, true, false);
|
||||
serverListed = Storage.Blacklist.isListed(player, command, true, listed, false, serverName);
|
||||
ignored = Storage.Blacklist.isOnIgnoredServer(serverName);
|
||||
|
||||
if(!listed && !serverListed || listed && serverListed && ignored) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, false);
|
||||
if(executeCommandEvent.isBlocked()) event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, true);
|
||||
if(executeCommandEvent.isBlocked()) event.setCancelled(true);
|
||||
if(executeCommandEvent.isCancelled()) return;
|
||||
|
||||
MessageTranslator.send(player, cancelCommandMessage);
|
||||
|
||||
if(Storage.SEND_CONSOLE_NOTIFICATION) Logger.info(notificationMessage);
|
||||
Storage.NOTIFY_PLAYERS.forEach(uuid -> {
|
||||
ProxiedPlayer proxiedPlayer = ProxyServer.getInstance().getPlayer(uuid);
|
||||
if(proxiedPlayer != null) MessageTranslator.send(proxiedPlayer, notificationMessage);
|
||||
});
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, event.getMessage(), false, false);
|
||||
if (executeCommandEvent.isBlocked())
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,12 @@ import de.rayzs.pat.plugin.logger.Logger;
|
||||
import net.md_5.bungee.api.event.ProxyPingEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.BungeeLoader;
|
||||
import de.rayzs.pat.plugin.*;
|
||||
import net.md_5.bungee.event.*;
|
||||
import net.md_5.bungee.api.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BungeePingListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
@@ -26,12 +28,37 @@ public class BungeePingListener implements Listener {
|
||||
}
|
||||
|
||||
ServerPing serverPing = event.getResponse();
|
||||
ServerPing.Protocol newProtocol = new ServerPing.Protocol(Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.PROTOCOL.replace("%online_extended%", String.valueOf(onlineExtend)).replace("%online%", String.valueOf(online)).replace("%max%", String.valueOf(max)), !Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.ALWAYS_SHOW ? serverPing.getVersion().getProtocol() : 0);
|
||||
|
||||
int protocol = Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.ALWAYS_SHOW ? -1 : serverPing.getVersion().getProtocol();
|
||||
String version = replaceString(Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.PROTOCOL, online, onlineExtend, max);
|
||||
|
||||
ServerPing.Protocol newProtocol = new ServerPing.Protocol(version, protocol);
|
||||
serverPing.setVersion(newProtocol);
|
||||
|
||||
if(Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.USE_EXTEND_AS_MAX_COUNT)
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.USE_EXTEND_AS_MAX_COUNT)
|
||||
serverPing.getPlayers().setMax(onlineExtend);
|
||||
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.HIDE_PLAYERS)
|
||||
serverPing.getPlayers().setSample(new ServerPing.PlayerInfo[0]);
|
||||
else if (Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.USE_CUSTOM_PLAYERLIST) {
|
||||
List<String> lines = Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.PLAYERLIST.getLines();
|
||||
ServerPing.PlayerInfo[] playerInfos = new ServerPing.PlayerInfo[lines.size()];
|
||||
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
playerInfos[i] = new ServerPing.PlayerInfo(replaceString(lines.get(i), online, onlineExtend, max), "");
|
||||
}
|
||||
|
||||
serverPing.getPlayers().setSample(playerInfos);
|
||||
}
|
||||
|
||||
event.setResponse(serverPing);
|
||||
}
|
||||
|
||||
private String replaceString(String string, int online, int onlineExtend, int max) {
|
||||
return string
|
||||
.replace("&", "§")
|
||||
.replace("%online_extended%", String.valueOf(onlineExtend))
|
||||
.replace("%online%", String.valueOf(online))
|
||||
.replace("%max%", String.valueOf(max));
|
||||
}
|
||||
}
|
||||
+9
-3
@@ -1,12 +1,12 @@
|
||||
package de.rayzs.pat.plugin.listeners.bungee;
|
||||
|
||||
import de.rayzs.pat.api.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
import de.rayzs.pat.api.event.events.ServerPlayersChangeEvent;
|
||||
import de.rayzs.pat.api.netty.proxy.BungeePacketAnalyzer;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import de.rayzs.pat.api.brand.CustomServerBrand;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.BungeeLoader;
|
||||
@@ -43,7 +43,10 @@ public class BungeePlayerConnectionListener implements Listener {
|
||||
ProxiedPlayer player = event.getPlayer();
|
||||
|
||||
BungeePacketAnalyzer.inject(player);
|
||||
if(Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY != -1) return;
|
||||
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY != -1)
|
||||
return;
|
||||
|
||||
CustomServerBrand.sendBrandToPlayer(player);
|
||||
}
|
||||
|
||||
@@ -54,7 +57,10 @@ public class BungeePlayerConnectionListener implements Listener {
|
||||
|
||||
PermissionUtil.resetPermissions(player.getUniqueId());
|
||||
BungeePacketAnalyzer.uninject(player);
|
||||
if(Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY != -1) return;
|
||||
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY != -1)
|
||||
return;
|
||||
|
||||
CustomServerBrand.sendBrandToPlayer(player);
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,43 @@
|
||||
package de.rayzs.pat.plugin.listeners.bungee;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
import de.rayzs.pat.api.event.events.FilteredSuggestionEvent;
|
||||
import io.github.waterfallmc.waterfall.event.ProxyDefineCommandsEvent;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.CommandsCache;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import io.github.waterfallmc.waterfall.event.ProxyDefineCommandsEvent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import de.rayzs.pat.utils.CommandsCache;
|
||||
import net.md_5.bungee.event.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
|
||||
public class WaterfallAntiTabListener implements Listener {
|
||||
|
||||
private static final HashMap<String, CommandsCache> COMMANDS_CACHE_MAP = new HashMap<>();
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onProxyDefineCommands(ProxyDefineCommandsEvent event) {
|
||||
|
||||
System.out.println("CALL");
|
||||
|
||||
if(!(event.getReceiver() instanceof ProxiedPlayer) || event.getCommands().isEmpty()) return;
|
||||
|
||||
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
|
||||
String serverName = player.getServer().getInfo().getName();
|
||||
|
||||
if(!COMMANDS_CACHE_MAP.containsKey(serverName))
|
||||
COMMANDS_CACHE_MAP.put(serverName, new CommandsCache().reverse());
|
||||
if (Storage.Blacklist.isDisabledServer(serverName))
|
||||
return;
|
||||
|
||||
CommandsCache commandsCache = COMMANDS_CACHE_MAP.get(serverName);
|
||||
Map<String, CommandsCache> cache = Storage.getLoader().getCommandsCacheMap();
|
||||
|
||||
if(!cache.containsKey(serverName))
|
||||
cache.put(serverName, new CommandsCache());
|
||||
|
||||
CommandsCache commandsCache = cache.get(serverName);
|
||||
List<String> commandsAsString = new ArrayList<>();
|
||||
HashMap<String, Command> commandsMap = new HashMap<>(event.getCommands());
|
||||
|
||||
@@ -43,13 +53,10 @@ public class WaterfallAntiTabListener implements Listener {
|
||||
if(filteredSuggestionEvent.isCancelled()) event.getCommands().clear();
|
||||
|
||||
for (String commandName : filteredSuggestionEvent.getSuggestions()) {
|
||||
if(!event.getCommands().containsKey(commandName)) event.getCommands().put(commandName, commandsMap.get(commandName));
|
||||
|
||||
if (!event.getCommands().containsKey(commandName))
|
||||
event.getCommands().put(commandName, commandsMap.get(commandName));
|
||||
|
||||
}
|
||||
|
||||
commandsMap = null;
|
||||
}
|
||||
|
||||
public static void updateCommands() {
|
||||
new ArrayList<>(COMMANDS_CACHE_MAP.values()).forEach(CommandsCache::reset);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,26 @@
|
||||
package de.rayzs.pat.plugin.listeners.velocity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.velocitypowered.api.event.PostOrder;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.command.PlayerAvailableCommandsEvent;
|
||||
import com.velocitypowered.api.event.player.TabCompleteEvent;
|
||||
import de.rayzs.pat.api.event.events.FilteredSuggestionEvent;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
import de.rayzs.pat.api.event.events.FilteredSuggestionEvent;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.CommandsCache;
|
||||
import com.velocitypowered.api.proxy.*;
|
||||
import com.velocitypowered.api.event.*;
|
||||
import java.util.*;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
|
||||
public class VelocityAntiTabListener {
|
||||
|
||||
private static ProxyServer server;
|
||||
private static final HashMap<String, CommandsCache> COMMANDS_CACHE_MAP = new HashMap<>();
|
||||
|
||||
public VelocityAntiTabListener(ProxyServer server) {
|
||||
VelocityAntiTabListener.server = server;
|
||||
@@ -23,9 +29,14 @@ public class VelocityAntiTabListener {
|
||||
@Subscribe (order = PostOrder.LAST)
|
||||
public void onTabComplete(TabCompleteEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if(PermissionUtil.hasBypassPermission(player) || event.getSuggestions().isEmpty() || !player.getCurrentServer().isPresent()) return;
|
||||
String serverName = player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "unknown";
|
||||
|
||||
event.getSuggestions().removeIf(command -> Storage.Blacklist.isBlocked(player, command, !Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED, player.getCurrentServer().get().getServerInfo().getName()));
|
||||
if (Storage.Blacklist.isDisabledServer(serverName))
|
||||
return;
|
||||
|
||||
if (PermissionUtil.hasBypassPermission(player) || event.getSuggestions().isEmpty() || !player.getCurrentServer().isPresent()) return;
|
||||
|
||||
event.getSuggestions().removeIf(command -> !Storage.Blacklist.canPlayerAccessTab(player, command, serverName));
|
||||
FilteredSuggestionEvent filteredSuggestionEvent = PATEventHandler.callFilteredSuggestionEvents(player, event.getSuggestions());
|
||||
if(filteredSuggestionEvent.isCancelled()) event.getSuggestions().clear();
|
||||
}
|
||||
@@ -34,33 +45,44 @@ public class VelocityAntiTabListener {
|
||||
public void onPlayerAvailableCommands(PlayerAvailableCommandsEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if(event.getRootNode().getChildren().isEmpty() || !player.getCurrentServer().isPresent()) return;
|
||||
if(event.getRootNode().getChildren().isEmpty() || !player.getCurrentServer().isPresent())
|
||||
return;
|
||||
|
||||
String serverName = player.getCurrentServer().get().getServer().getServerInfo().getName();
|
||||
|
||||
if(!COMMANDS_CACHE_MAP.containsKey(serverName))
|
||||
COMMANDS_CACHE_MAP.put(serverName, new CommandsCache().reverse());
|
||||
CommandsCache commandsCache = COMMANDS_CACHE_MAP.get(serverName);
|
||||
Map<String, CommandsCache> cache = Storage.getLoader().getCommandsCacheMap();
|
||||
|
||||
if(!cache.containsKey(serverName))
|
||||
cache.put(serverName, new CommandsCache());
|
||||
|
||||
CommandsCache commandsCache = cache.get(serverName);
|
||||
|
||||
List<String> commandsAsString = new ArrayList<>();
|
||||
event.getRootNode().getChildren().stream().filter(command -> command != null && command.getName() != null).forEach(command -> commandsAsString.add(command.getName()));
|
||||
commandsCache.handleCommands(commandsAsString, serverName);
|
||||
|
||||
if(PermissionUtil.hasBypassPermission(player)) return;
|
||||
|
||||
final boolean newer = player.getProtocolVersion().getProtocol() > 340;
|
||||
final List<String> playerCommands = commandsCache.getPlayerCommands(commandsAsString, player, player.getUniqueId(), serverName);
|
||||
|
||||
if(event.getRootNode().getChildren().size() == 1 && newer
|
||||
&& event.getRootNode().getChild("args") != null
|
||||
&& event.getRootNode().getChild("args").getChildren().isEmpty())
|
||||
if (PermissionUtil.hasBypassPermission(player))
|
||||
return;
|
||||
|
||||
if(event.getRootNode().getChildren().size() == 1 && newer && event.getRootNode().getChild("args") != null) return;
|
||||
event.getRootNode().getChildren().removeIf(command -> command == null || command.getName() == null || playerCommands.contains(command.getName()));
|
||||
}
|
||||
final boolean newer = player.getProtocolVersion().getProtocol() > 340, argsChildrenExist = event.getRootNode().getChild("args") != null;
|
||||
final List<String> playerCommands = commandsCache.getPlayerCommands(commandsAsString, player, player.getUniqueId(), serverName);
|
||||
|
||||
public static void updateCommands() {
|
||||
new ArrayList<>(COMMANDS_CACHE_MAP.values()).forEach(CommandsCache::reset);
|
||||
if (event.getRootNode().getChildren().size() == 1
|
||||
&& newer && argsChildrenExist
|
||||
&& event.getRootNode().getChild("args").getChildren().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(event.getRootNode().getChildren().size() == 1 && newer && argsChildrenExist) return;
|
||||
|
||||
event.getRootNode().getChildren().removeIf(command -> {
|
||||
if (command == null || command.getName() == null)
|
||||
return true;
|
||||
|
||||
if (command.getName().equals("args"))
|
||||
return false;
|
||||
|
||||
return !playerCommands.contains(command.getName());
|
||||
});
|
||||
}
|
||||
}
|
||||
+51
-219
@@ -3,257 +3,89 @@ package de.rayzs.pat.plugin.listeners.velocity;
|
||||
import com.velocitypowered.api.event.command.CommandExecuteEvent;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import de.rayzs.pat.api.event.events.ExecuteCommandEvent;
|
||||
import de.rayzs.pat.plugin.VelocityLoader;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import com.velocitypowered.api.event.*;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.api.event.*;
|
||||
import java.util.List;
|
||||
|
||||
public class VelocityBlockCommandListener {
|
||||
|
||||
private final ProxyServer server;
|
||||
|
||||
public VelocityBlockCommandListener(ProxyServer server) {
|
||||
this.server = server;
|
||||
public static CommandExecuteEvent handleCommand(Player player, String command) {
|
||||
return handleCommand(new CommandExecuteEvent(player, command));
|
||||
}
|
||||
|
||||
@Subscribe (order = PostOrder.EARLY)
|
||||
public void onCommandExecute(CommandExecuteEvent event) {
|
||||
if(!event.getResult().isAllowed()) return;
|
||||
CommandSource commandSource = event.getCommandSource();
|
||||
public static CommandExecuteEvent handleCommand(CommandExecuteEvent event) {
|
||||
if(!event.getResult().isAllowed())
|
||||
return event;
|
||||
|
||||
if(!(commandSource instanceof Player)) return;
|
||||
CommandSource commandSource = event.getCommandSource();
|
||||
Object consoleSender = Storage.getLoader().getConsoleSender();
|
||||
|
||||
if(! (commandSource instanceof Player))
|
||||
return event;
|
||||
|
||||
Player player = (Player) commandSource;
|
||||
String rawCommand = event.getCommand(), command = rawCommand,
|
||||
serverName = player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "unknown";
|
||||
String command = StringUtils.getFirstArg(event.getCommand());
|
||||
|
||||
command = StringUtils.replaceFirst(command, "/", "");
|
||||
command = StringUtils.getFirstArg(command);
|
||||
command = StringUtils.replaceTriggers(command, "", "\\", "<", ">", "&");
|
||||
String serverName = player.getCurrentServer().isPresent()
|
||||
? player.getCurrentServer().get().getServerInfo().getName()
|
||||
: "unknown";
|
||||
|
||||
if(PermissionUtil.hasBypassPermission(player, command, false)) return;
|
||||
boolean bypassPermission = PermissionUtil.hasBypassPermission(player, command);
|
||||
|
||||
List<String> notificationMessage = MessageTranslator.replaceMessageList(Storage.ConfigSections.Messages.NOTIFICATION.ALERT, "%player%", player.getUsername(), "%command%", command, "%server%", serverName);
|
||||
if (bypassPermission)
|
||||
return event;
|
||||
|
||||
if(Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isCommand(command)) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, true);
|
||||
if(executeCommandEvent.isBlocked()) event.setResult(CommandExecuteEvent.CommandResult.denied());
|
||||
if(executeCommandEvent.isCancelled()) return;
|
||||
final String displayCommand = StringUtils.replaceTriggers(command, "", "\\", "<", ">", "&");
|
||||
|
||||
MessageTranslator.send(player, Storage.ConfigSections.Settings.CUSTOM_PLUGIN.MESSAGE, "%command%", command.replaceFirst("/", ""));
|
||||
command = command.toLowerCase();
|
||||
|
||||
if(Storage.SEND_CONSOLE_NOTIFICATION) MessageTranslator.send(server.getConsoleCommandSource(), notificationMessage);
|
||||
Storage.NOTIFY_PLAYERS.stream().filter(uuid -> server.getPlayer(uuid).isPresent()).forEach(uuid -> MessageTranslator.send(server.getPlayer(uuid).get(), notificationMessage));
|
||||
|
||||
return;
|
||||
}
|
||||
List<String> notificationMessage = MessageTranslator.replaceMessageList(
|
||||
Storage.ConfigSections.Messages.NOTIFICATION.ALERT,
|
||||
"%player%", player.getUsername(),
|
||||
"%command%", displayCommand,
|
||||
"%server%", serverName
|
||||
);
|
||||
|
||||
if(Storage.ConfigSections.Settings.CUSTOM_VERSION.isCommand(command)) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, true);
|
||||
if(executeCommandEvent.isBlocked()) event.setResult(CommandExecuteEvent.CommandResult.denied());
|
||||
if(executeCommandEvent.isCancelled()) return;
|
||||
if (!Storage.ConfigSections.Settings.CANCEL_COMMAND.ENABLED)
|
||||
return event;
|
||||
|
||||
MessageTranslator.send(player, Storage.ConfigSections.Settings.CUSTOM_VERSION.MESSAGE, "%command%", command.replaceFirst("/", ""));
|
||||
if (!Storage.Blacklist.canPlayerAccessChat(player, command, serverName)) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(
|
||||
player,
|
||||
event.getCommand(),
|
||||
true,
|
||||
!Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED);
|
||||
|
||||
if(Storage.SEND_CONSOLE_NOTIFICATION) MessageTranslator.send(server.getConsoleCommandSource(), notificationMessage);
|
||||
Storage.NOTIFY_PLAYERS.stream().filter(uuid -> server.getPlayer(uuid).isPresent()).forEach(uuid -> MessageTranslator.send(server.getPlayer(uuid).get(), notificationMessage));
|
||||
if (executeCommandEvent.isBlocked()) {
|
||||
event.setResult(CommandExecuteEvent.CommandResult.denied());
|
||||
|
||||
return;
|
||||
}
|
||||
if (!executeCommandEvent.doesNotify())
|
||||
return event;
|
||||
|
||||
if(!Storage.ConfigSections.Settings.CANCEL_COMMAND.ENABLED) return;
|
||||
List<String> cancelCommandMessage = MessageTranslator.replaceMessageList(Storage.ConfigSections.Settings.CANCEL_COMMAND.BASE_COMMAND_RESPONSE, "%command%", command.replaceFirst("/", ""));
|
||||
if (Storage.SEND_CONSOLE_NOTIFICATION)
|
||||
MessageTranslator.send(consoleSender, notificationMessage);
|
||||
|
||||
boolean listed, serverListed, ignored;
|
||||
|
||||
if(Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED) {
|
||||
if(Storage.Blacklist.doesGroupBypass(player, command, false, true, false, player.getCurrentServer().get().getServerInfo().getName())) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, false);
|
||||
if(executeCommandEvent.isBlocked()) event.setResult(CommandExecuteEvent.CommandResult.denied());
|
||||
return;
|
||||
Storage.NOTIFY_PLAYERS.stream().forEach(uuid -> {
|
||||
Object p = Storage.getLoader().getPlayerObjByUUID(uuid);
|
||||
if (p != null) {
|
||||
MessageTranslator.send(p, notificationMessage);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
listed = Storage.Blacklist.isListed(command, false, true, false);
|
||||
serverListed = Storage.Blacklist.isListed(player, command, false, listed, false, serverName);
|
||||
ignored = Storage.Blacklist.isOnIgnoredServer(serverName);
|
||||
|
||||
if(ignored ? !listed && serverListed : serverListed) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, false);
|
||||
if(executeCommandEvent.isBlocked()) event.setResult(CommandExecuteEvent.CommandResult.denied());
|
||||
return;
|
||||
}
|
||||
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, true);
|
||||
if(executeCommandEvent.isBlocked()) event.setResult(CommandExecuteEvent.CommandResult.denied());
|
||||
if(executeCommandEvent.isCancelled()) return;
|
||||
|
||||
MessageTranslator.send(player, cancelCommandMessage);
|
||||
return;
|
||||
if (executeCommandEvent.isCancelled())
|
||||
return event;
|
||||
}
|
||||
|
||||
if(Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.isCommand(command) && !Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.doesBypass(player)) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, true);
|
||||
if(executeCommandEvent.isBlocked()) event.setResult(CommandExecuteEvent.CommandResult.denied());
|
||||
if(executeCommandEvent.isCancelled()) return;
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, event.getCommand(), false, false);
|
||||
if (executeCommandEvent.isBlocked())
|
||||
event.setResult(CommandExecuteEvent.CommandResult.denied());
|
||||
|
||||
MessageTranslator.send(player, cancelCommandMessage);
|
||||
|
||||
if(Storage.SEND_CONSOLE_NOTIFICATION) MessageTranslator.send(server.getConsoleCommandSource(), notificationMessage);
|
||||
Storage.NOTIFY_PLAYERS.stream().filter(uuid -> server.getPlayer(uuid).isPresent()).forEach(uuid -> MessageTranslator.send(server.getPlayer(uuid).get(), notificationMessage));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(Storage.Blacklist.doesGroupBypass(player, command, true, true, false, player.getCurrentServer().get().getServerInfo().getName())) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, false);
|
||||
if(executeCommandEvent.isBlocked()) event.setResult(CommandExecuteEvent.CommandResult.denied());
|
||||
return;
|
||||
}
|
||||
|
||||
listed = Storage.Blacklist.isListed(command, true, true, false);
|
||||
serverListed = Storage.Blacklist.isListed(player, command, true, listed, false, serverName);
|
||||
ignored = Storage.Blacklist.isOnIgnoredServer(serverName);
|
||||
|
||||
if(!listed && !serverListed || listed && serverListed && ignored) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, false);
|
||||
if(executeCommandEvent.isBlocked()) event.setResult(CommandExecuteEvent.CommandResult.denied());
|
||||
return;
|
||||
}
|
||||
|
||||
if(Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.isCommand(command) && Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.doesBypass(player.getUniqueId())) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, false);
|
||||
if(executeCommandEvent.isBlocked()) event.setResult(CommandExecuteEvent.CommandResult.denied());
|
||||
return;
|
||||
}
|
||||
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, rawCommand, true);
|
||||
if(executeCommandEvent.isBlocked()) event.setResult(CommandExecuteEvent.CommandResult.denied());
|
||||
if(executeCommandEvent.isCancelled()) return;
|
||||
|
||||
MessageTranslator.send(player, cancelCommandMessage);
|
||||
|
||||
if(Storage.SEND_CONSOLE_NOTIFICATION) MessageTranslator.send(server.getConsoleCommandSource(), notificationMessage);
|
||||
Storage.NOTIFY_PLAYERS.stream().filter(uuid -> server.getPlayer(uuid).isPresent()).forEach(uuid -> MessageTranslator.send(server.getPlayer(uuid).get(), notificationMessage));
|
||||
}
|
||||
|
||||
public static boolean handleCommand(Player player, String commandSource) {
|
||||
String command = commandSource,
|
||||
serverName = player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "unknown";
|
||||
|
||||
boolean blocked = false;
|
||||
|
||||
command = StringUtils.replaceFirst(command, "/", "");
|
||||
command = StringUtils.getFirstArg(command);
|
||||
command = StringUtils.replaceTriggers(command, "", "\\", "<", ">", "&");
|
||||
|
||||
if (PermissionUtil.hasBypassPermission(player, command, false)) return false;
|
||||
List<String> notificationMessage = MessageTranslator.replaceMessageList(Storage.ConfigSections.Messages.NOTIFICATION.ALERT, "%player%", player.getUsername(), "%command%", command, "%server%", serverName);
|
||||
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isCommand(command)) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, commandSource, true);
|
||||
if (executeCommandEvent.isBlocked()) blocked = true;
|
||||
if (executeCommandEvent.isCancelled()) return false;
|
||||
|
||||
MessageTranslator.send(player, Storage.ConfigSections.Settings.CUSTOM_PLUGIN.MESSAGE, "%command%", command.replaceFirst("/", ""));
|
||||
|
||||
if (Storage.SEND_CONSOLE_NOTIFICATION)
|
||||
MessageTranslator.send(VelocityLoader.getServer().getConsoleCommandSource(), notificationMessage);
|
||||
Storage.NOTIFY_PLAYERS.stream().filter(uuid -> VelocityLoader.getServer().getPlayer(uuid).isPresent()).forEach(uuid -> MessageTranslator.send(VelocityLoader.getServer().getPlayer(uuid).get(), notificationMessage));
|
||||
|
||||
return blocked;
|
||||
}
|
||||
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_VERSION.isCommand(command)) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, commandSource, true);
|
||||
if (executeCommandEvent.isBlocked()) blocked = true;
|
||||
if (executeCommandEvent.isCancelled()) return false;
|
||||
|
||||
MessageTranslator.send(player, Storage.ConfigSections.Settings.CUSTOM_VERSION.MESSAGE, "%command%", command);
|
||||
|
||||
if (Storage.SEND_CONSOLE_NOTIFICATION)
|
||||
MessageTranslator.send(VelocityLoader.getServer().getConsoleCommandSource(), notificationMessage);
|
||||
Storage.NOTIFY_PLAYERS.stream().filter(uuid -> VelocityLoader.getServer().getPlayer(uuid).isPresent()).forEach(uuid -> MessageTranslator.send(VelocityLoader.getServer().getPlayer(uuid).get(), notificationMessage));
|
||||
|
||||
return blocked;
|
||||
}
|
||||
|
||||
if (!Storage.ConfigSections.Settings.CANCEL_COMMAND.ENABLED) return false;
|
||||
List<String> cancelCommandMessage = MessageTranslator.replaceMessageList(Storage.ConfigSections.Settings.CANCEL_COMMAND.BASE_COMMAND_RESPONSE, "%command%", command.replaceFirst("/", ""));
|
||||
boolean listed, serverListed, ignored;
|
||||
|
||||
if (Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED) {
|
||||
|
||||
if (Storage.Blacklist.doesGroupBypass(player, command, false, true, false, player.getCurrentServer().get().getServerInfo().getName())) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, commandSource, false);
|
||||
return executeCommandEvent.isBlocked();
|
||||
}
|
||||
|
||||
listed = Storage.Blacklist.isListed(command, false, true, false);
|
||||
serverListed = Storage.Blacklist.isListed(player, command, false, listed, false, serverName, true);
|
||||
ignored = Storage.Blacklist.isOnIgnoredServer(serverName);
|
||||
|
||||
if (ignored ? !listed && serverListed : serverListed) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, commandSource, false);
|
||||
return executeCommandEvent.isBlocked();
|
||||
}
|
||||
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, commandSource, true);
|
||||
|
||||
if (executeCommandEvent.isBlocked()) blocked = true;
|
||||
if (executeCommandEvent.isCancelled()) return true;
|
||||
|
||||
MessageTranslator.send(player, cancelCommandMessage);
|
||||
return blocked;
|
||||
}
|
||||
|
||||
if (Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.isCommand(command) && !Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.doesBypass(player)) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, commandSource, true);
|
||||
if (executeCommandEvent.isBlocked()) blocked = true;
|
||||
if (executeCommandEvent.isCancelled()) return false;
|
||||
|
||||
MessageTranslator.send(player, cancelCommandMessage);
|
||||
|
||||
if (Storage.SEND_CONSOLE_NOTIFICATION)
|
||||
MessageTranslator.send(VelocityLoader.getServer().getConsoleCommandSource(), notificationMessage);
|
||||
Storage.NOTIFY_PLAYERS.stream().filter(uuid -> VelocityLoader.getServer().getPlayer(uuid).isPresent()).forEach(uuid -> MessageTranslator.send(VelocityLoader.getServer().getPlayer(uuid).get(), notificationMessage));
|
||||
|
||||
return blocked;
|
||||
}
|
||||
|
||||
if (Storage.Blacklist.doesGroupBypass(player, command, true, true, false, player.getCurrentServer().get().getServerInfo().getName())) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, commandSource, false);
|
||||
return executeCommandEvent.isBlocked();
|
||||
}
|
||||
|
||||
listed = Storage.Blacklist.isListed(command, true, true, false);
|
||||
serverListed = Storage.Blacklist.isListed(player, command, true, listed, false, serverName);
|
||||
ignored = Storage.Blacklist.isOnIgnoredServer(serverName);
|
||||
|
||||
if (!listed && !serverListed || listed && serverListed && ignored) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, commandSource, false);
|
||||
return executeCommandEvent.isBlocked();
|
||||
}
|
||||
|
||||
if (Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.isCommand(command) && Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.doesBypass(player.getUniqueId())) {
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, commandSource, false);
|
||||
return executeCommandEvent.isBlocked();
|
||||
}
|
||||
|
||||
ExecuteCommandEvent executeCommandEvent = PATEventHandler.callExecuteCommandEvents(player, commandSource, true);
|
||||
if (executeCommandEvent.isBlocked()) blocked = true;
|
||||
if (executeCommandEvent.isCancelled()) return true;
|
||||
|
||||
MessageTranslator.send(player, cancelCommandMessage);
|
||||
|
||||
if (Storage.SEND_CONSOLE_NOTIFICATION)
|
||||
MessageTranslator.send(VelocityLoader.getServer().getConsoleCommandSource(), notificationMessage);
|
||||
Storage.NOTIFY_PLAYERS.stream().filter(uuid -> VelocityLoader.getServer().getPlayer(uuid).isPresent()).forEach(uuid -> MessageTranslator.send(VelocityLoader.getServer().getPlayer(uuid).get(), notificationMessage));
|
||||
return blocked;
|
||||
return event;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,12 +1,12 @@
|
||||
package de.rayzs.pat.plugin.listeners.velocity;
|
||||
|
||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||
import de.rayzs.pat.api.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
import de.rayzs.pat.api.event.events.ServerPlayersChangeEvent;
|
||||
import de.rayzs.pat.api.netty.proxy.VelocityPacketAnalyzer;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import de.rayzs.pat.api.brand.CustomServerBrand;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.player.*;
|
||||
import de.rayzs.pat.plugin.VelocityLoader;
|
||||
|
||||
@@ -5,10 +5,12 @@ import com.velocitypowered.api.proxy.server.ServerPing;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import java.util.UUID;
|
||||
|
||||
public class VelocityPingListener {
|
||||
|
||||
private static ProxyServer server;
|
||||
private static final UUID RANDOM_UUID = UUID.randomUUID();
|
||||
|
||||
public VelocityPingListener(ProxyServer server) {
|
||||
VelocityPingListener.server = server;
|
||||
@@ -16,15 +18,42 @@ public class VelocityPingListener {
|
||||
|
||||
@Subscribe
|
||||
public void onProxyPing(ProxyPingEvent event) {
|
||||
if(!Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.ENABLED) return;
|
||||
if (!Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.ENABLED) return;
|
||||
|
||||
ServerPing oldPing = event.getPing();
|
||||
ServerPing.Builder builder = oldPing.asBuilder();
|
||||
|
||||
int online = server.getPlayerCount(),
|
||||
onlineExtend = online + Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.EXTEND_COUNT,
|
||||
max = server.getConfiguration().getShowMaxPlayers();
|
||||
ServerPing oldServerPing = event.getPing(), newServerPing;
|
||||
ServerPing.Version newVersion = new ServerPing.Version(!Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.ALWAYS_SHOW ? oldServerPing.getVersion().getProtocol() : -1, Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.PROTOCOL.replace("%online_extended%", String.valueOf(onlineExtend)).replace("%online%", String.valueOf(online)).replace("%max%", String.valueOf(max)));
|
||||
newServerPing = oldServerPing.asBuilder().version(newVersion).build();
|
||||
max = server.getConfiguration().getShowMaxPlayers(),
|
||||
protocol = Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.ALWAYS_SHOW ? -1 : oldPing.getVersion().getProtocol(),
|
||||
extend = online + Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.EXTEND_COUNT;
|
||||
|
||||
event.setPing(newServerPing);
|
||||
|
||||
builder.version(new ServerPing.Version(protocol,
|
||||
replaceString(Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.PROTOCOL, online, extend, max))
|
||||
);
|
||||
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.USE_EXTEND_AS_MAX_COUNT)
|
||||
builder.maximumPlayers(extend);
|
||||
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.HIDE_PLAYERS)
|
||||
builder.clearSamplePlayers();
|
||||
else if (Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.USE_CUSTOM_PLAYERLIST) {
|
||||
builder.clearSamplePlayers();
|
||||
Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.PLAYERLIST.getLines().forEach(line ->
|
||||
builder.samplePlayers(new ServerPing.SamplePlayer(replaceString(line, online, extend, max), RANDOM_UUID))
|
||||
);
|
||||
}
|
||||
|
||||
event.setPing(builder.build());
|
||||
}
|
||||
|
||||
|
||||
private String replaceString(String string, int online, int onlineExtend, int max) {
|
||||
return string
|
||||
.replace("&", "§")
|
||||
.replace("%online_extended%", String.valueOf(onlineExtend))
|
||||
.replace("%online%", String.valueOf(online))
|
||||
.replace("%max%", String.valueOf(max));
|
||||
}
|
||||
}
|
||||
@@ -1,68 +1,54 @@
|
||||
package de.rayzs.pat.plugin.logger;
|
||||
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import de.rayzs.pat.plugin.logger.impl.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.logging.Level;
|
||||
import de.rayzs.pat.plugin.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Logger {
|
||||
|
||||
private static final ArrayList<String> LOGS = new ArrayList<>();
|
||||
private static final SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm:ss:SS");
|
||||
private final static LoggerTemplate LOGGER =
|
||||
Reflection.isVelocityServer() ? new VelocityLogger()
|
||||
: Reflection.isProxyServer() ? new BungeeLogger()
|
||||
: new BukkitLogger();
|
||||
|
||||
private final static java.util.logging.Logger LOGGER =
|
||||
Reflection.isVelocityServer() ? null
|
||||
: Reflection.isProxyServer()
|
||||
? BungeeLoader.getPluginLogger()
|
||||
: BukkitLoader.getPluginLogger();
|
||||
public static void info(List<String> messages) {
|
||||
LOGGER.info(messages);
|
||||
}
|
||||
|
||||
public static void info(List<String> texts) { texts.forEach(text -> send(Priority.INFO, text)); }
|
||||
public static void warning(List<String> texts) { texts.forEach(text -> send(Priority.WARNING, text)); }
|
||||
public static void info(String text) { send(Priority.INFO, text); }
|
||||
public static void warning(String text) { send(Priority.WARNING, text); }
|
||||
public static void debug(String text) { send(Priority.DEBUG, text); }
|
||||
public static void warning(List<String> messages) {
|
||||
LOGGER.warn(messages);
|
||||
}
|
||||
|
||||
protected static void send(Priority priority, String text) {
|
||||
text = MessageTranslator.replaceMessage(text);
|
||||
public static void debug(List<String> messages) {
|
||||
LOGGER.debug(messages);
|
||||
}
|
||||
|
||||
String time = TIME_FORMAT.format(new Date(System.currentTimeMillis()));
|
||||
if(time.length() != 12) time = time.substring(0, 9) + 0 + time.split(":")[3];
|
||||
LOGS.add("[" + priority.name() + " |" + time + "] " + MessageTranslator.colorless(text));
|
||||
public static void info(String message) {
|
||||
LOGGER.info(message);
|
||||
}
|
||||
|
||||
if(priority == Priority.DEBUG) return;
|
||||
public static void warning(String message) {
|
||||
LOGGER.warn(message);
|
||||
}
|
||||
|
||||
if(LOGGER == null) {
|
||||
System.out.println(text);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean hasColors = text.contains("§");
|
||||
if(hasColors) {
|
||||
if (Reflection.isProxyServer()) MessageTranslator.send(ProxyServer.getInstance().getConsole(), text);
|
||||
else MessageTranslator.send(Bukkit.getServer().getConsoleSender(), text);
|
||||
return;
|
||||
}
|
||||
|
||||
Level level = Level.parse(priority.name());
|
||||
LOGGER.log(level, text);
|
||||
public static void debug(String message) {
|
||||
LOGGER.debug(message);
|
||||
}
|
||||
|
||||
public static String post() throws IOException {
|
||||
ArrayList<String> clonedLogs = (ArrayList<String>) LOGS.clone();
|
||||
ArrayList<String> clonedLogs = new ArrayList<>(LOGGER.getLogs());
|
||||
int startIndex = clonedLogs.size() > 980 ? clonedLogs.size() - 980 : 0;
|
||||
StringBuilder textBuilder = new StringBuilder("[ProAntiTab " + Storage.CURRENT_VERSION + " | " + (Reflection.isProxyServer() ? Reflection.isVelocityServer() ? "Velocity" : "Proxy" : Reflection.isPaper() ? "Paper" : "Bukkit") + "]" + (Reflection.getRawVersionName() != null ? " Server version: " + Reflection.getVersionName() + " " + Reflection.getRawVersionName().replace("_", ".") : "") + "\n" + (startIndex != 0 ? "... another part is split!\n\n" : ""));
|
||||
|
||||
for(int i = startIndex; i < clonedLogs.size(); i++) {
|
||||
if (clonedLogs.get(i) == null) continue;
|
||||
for (int i = startIndex; i < clonedLogs.size(); i++) {
|
||||
if (clonedLogs.get(i) == null)
|
||||
continue;
|
||||
|
||||
String line = clonedLogs.get(i);
|
||||
textBuilder.append("\n");
|
||||
textBuilder.append(line);
|
||||
@@ -91,6 +77,4 @@ public class Logger {
|
||||
response = response.substring(response.indexOf(":") + 2, response.length() - 2);
|
||||
return "https://haste.rayzs.de/" + response + ".txt";
|
||||
}
|
||||
|
||||
protected enum Priority { INFO, WARNING, DEBUG }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package de.rayzs.pat.plugin.logger;
|
||||
|
||||
public enum LoggerPriority { INFO, WARNING, DEBUG }
|
||||
@@ -0,0 +1,23 @@
|
||||
package de.rayzs.pat.plugin.logger;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
|
||||
public interface LoggerTemplate {
|
||||
|
||||
SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm:ss:SS");
|
||||
|
||||
List<String> getLogs();
|
||||
|
||||
void info(List<String> messages);
|
||||
void warn(List<String> messages);
|
||||
void debug(List<String> messages);
|
||||
|
||||
void send(LoggerPriority priority, List<String> messages);
|
||||
|
||||
void info(String message);
|
||||
void warn(String message);
|
||||
void debug(String message);
|
||||
|
||||
void send(LoggerPriority priority, String message);
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package de.rayzs.pat.plugin.logger.impl;
|
||||
|
||||
import de.rayzs.pat.plugin.BukkitLoader;
|
||||
import de.rayzs.pat.plugin.logger.LoggerPriority;
|
||||
import de.rayzs.pat.plugin.logger.LoggerTemplate;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class BukkitLogger implements LoggerTemplate {
|
||||
|
||||
private final List<String> LOGS = new ArrayList<>();
|
||||
private final java.util.logging.Logger logger = BukkitLoader.getPluginLogger();
|
||||
|
||||
@Override
|
||||
public List<String> getLogs() {
|
||||
return LOGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(List<String> messages) {
|
||||
messages.forEach(this::info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(List<String> messages) {
|
||||
messages.forEach(this::warn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(List<String> messages) {
|
||||
messages.forEach(this::debug);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(LoggerPriority priority, List<String> messages) {
|
||||
messages.forEach(message -> send(priority, message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String message) {
|
||||
send(LoggerPriority.INFO, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String message) {
|
||||
send(LoggerPriority.WARNING, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String message) {
|
||||
send(LoggerPriority.DEBUG, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(LoggerPriority priority, String message) {
|
||||
message = MessageTranslator.replaceMessage(message);
|
||||
|
||||
String time = TIME_FORMAT.format(new Date(System.currentTimeMillis()));
|
||||
if(time.length() != 12) time = time.substring(0, 9) + 0 + time.split(":")[3];
|
||||
LOGS.add("[" + priority.name() + " | " + time + "] " + MessageTranslator.colorless(message));
|
||||
|
||||
if (priority == LoggerPriority.DEBUG)
|
||||
return;
|
||||
|
||||
if (message.contains("§")) {
|
||||
MessageTranslator.send(Bukkit.getServer().getConsoleSender(), message);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (priority) {
|
||||
case INFO -> logger.info(message);
|
||||
case WARNING -> logger.warning(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package de.rayzs.pat.plugin.logger.impl;
|
||||
|
||||
import de.rayzs.pat.plugin.BungeeLoader;
|
||||
import de.rayzs.pat.plugin.logger.LoggerPriority;
|
||||
import de.rayzs.pat.plugin.logger.LoggerTemplate;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class BungeeLogger implements LoggerTemplate {
|
||||
|
||||
private final List<String> LOGS = new ArrayList<>();
|
||||
private final java.util.logging.Logger logger = BungeeLoader.getPluginLogger();
|
||||
|
||||
@Override
|
||||
public List<String> getLogs() {
|
||||
return LOGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(List<String> messages) {
|
||||
messages.forEach(this::info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(List<String> messages) {
|
||||
messages.forEach(this::warn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(List<String> messages) {
|
||||
messages.forEach(this::debug);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(LoggerPriority priority, List<String> messages) {
|
||||
messages.forEach(message -> send(priority, message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String message) {
|
||||
send(LoggerPriority.INFO, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String message) {
|
||||
send(LoggerPriority.WARNING, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String message) {
|
||||
send(LoggerPriority.DEBUG, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(LoggerPriority priority, String message) {
|
||||
message = MessageTranslator.replaceMessage(message);
|
||||
|
||||
String time = TIME_FORMAT.format(new Date(System.currentTimeMillis()));
|
||||
if(time.length() != 12) time = time.substring(0, 9) + 0 + time.split(":")[3];
|
||||
LOGS.add("[" + priority.name() + " | " + time + "] " + MessageTranslator.colorless(message));
|
||||
|
||||
if (priority == LoggerPriority.DEBUG)
|
||||
return;
|
||||
|
||||
if (message.contains("§")) {
|
||||
MessageTranslator.send(ProxyServer.getInstance().getConsole(), message);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (priority) {
|
||||
case INFO -> logger.info(message);
|
||||
case WARNING -> logger.warning(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package de.rayzs.pat.plugin.logger.impl;
|
||||
|
||||
import de.rayzs.pat.plugin.VelocityLoader;
|
||||
import de.rayzs.pat.plugin.logger.LoggerPriority;
|
||||
import de.rayzs.pat.plugin.logger.LoggerTemplate;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class VelocityLogger implements LoggerTemplate {
|
||||
|
||||
private final List<String> LOGS = new ArrayList<>();
|
||||
private final Logger logger = VelocityLoader.getPluginLogger();
|
||||
|
||||
@Override
|
||||
public List<String> getLogs() {
|
||||
return LOGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(List<String> messages) {
|
||||
messages.forEach(this::info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(List<String> messages) {
|
||||
messages.forEach(this::warn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(List<String> messages) {
|
||||
messages.forEach(this::debug);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(LoggerPriority priority, List<String> messages) {
|
||||
messages.forEach(message -> send(priority, message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String message) {
|
||||
send(LoggerPriority.INFO, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String message) {
|
||||
send(LoggerPriority.WARNING, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String message) {
|
||||
send(LoggerPriority.DEBUG, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(LoggerPriority priority, String message) {
|
||||
message = MessageTranslator.replaceMessage(message);
|
||||
|
||||
String time = TIME_FORMAT.format(new Date(System.currentTimeMillis()));
|
||||
if(time.length() != 12) time = time.substring(0, 9) + 0 + time.split(":")[3];
|
||||
LOGS.add("[" + priority.name() + " | " + time + "] " + MessageTranslator.colorless(message));
|
||||
|
||||
if (priority == LoggerPriority.DEBUG)
|
||||
return;
|
||||
|
||||
if (message.contains("§")) {
|
||||
MessageTranslator.send(VelocityLoader.getServer().getConsoleCommandSource(), message);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (priority) {
|
||||
case INFO -> logger.info(message);
|
||||
case WARNING -> logger.warn(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.rayzs.pat.plugin.metrics.impl;
|
||||
|
||||
import de.rayzs.pat.utils.scheduler.PATScheduler;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
@@ -171,7 +172,7 @@ public class BukkitMetrics {
|
||||
}
|
||||
// Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
|
||||
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
|
||||
Bukkit.getScheduler().runTask(plugin, this::submitData);
|
||||
PATScheduler.createScheduler(this::submitData);
|
||||
};
|
||||
|
||||
// Many servers tend to restart at a fixed time at xx:00 which causes an uneven distribution of requests on the
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
package de.rayzs.pat.plugin.modules;
|
||||
|
||||
import de.rayzs.pat.api.storage.blacklist.impl.GeneralBlacklist;
|
||||
import de.rayzs.pat.plugin.modules.events.ExecuteCommand;
|
||||
import de.rayzs.pat.plugin.modules.events.TabCompletion;
|
||||
import de.rayzs.pat.plugin.modules.events.UpdateList;
|
||||
import de.rayzs.pat.utils.node.CommandNodeHelper;
|
||||
import de.rayzs.pat.utils.response.ResponseHandler;
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.subargs.*;
|
||||
import java.util.stream.Collectors;
|
||||
import de.rayzs.pat.utils.group.*;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import java.util.*;
|
||||
|
||||
public class SubArgsModule {
|
||||
|
||||
public static List<String> GENERAL_LIST, BLOCKED_MESSAGE, PLAYER_NAMES, ONLINE_PLAYERS;
|
||||
public static HashMap<UUID, Arguments> PLAYER_COMMANDS = new HashMap<>();
|
||||
|
||||
public static void initialize() {
|
||||
updateList();
|
||||
updateMessages();
|
||||
updatePlayerNames();
|
||||
|
||||
PATEventHandler.register(new TabCompletion());
|
||||
PATEventHandler.register(new ExecuteCommand());
|
||||
|
||||
PATEventHandler.register(UpdateList.UPDATE_PLUGIN_EVENT);
|
||||
PATEventHandler.register(UpdateList.RECEIVE_SYNC_EVENT);
|
||||
PATEventHandler.register(UpdateList.UPDATE_PLAYER_COMMANDS_EVENT);
|
||||
PATEventHandler.register(UpdateList.SERVER_PLAYERS_CHANGE_EVENT);
|
||||
}
|
||||
|
||||
public static void updatePlayerNames() {
|
||||
PLAYER_NAMES = Storage.getLoader().getPlayerNames();
|
||||
ONLINE_PLAYERS = Storage.getLoader().getOnlinePlayerNames();
|
||||
}
|
||||
|
||||
public static List<String> getPlayerNames() {
|
||||
return PLAYER_NAMES;
|
||||
}
|
||||
|
||||
public static List<String> getOnlinePlayerNames() {
|
||||
return ONLINE_PLAYERS;
|
||||
}
|
||||
|
||||
public static void updateList() {
|
||||
GENERAL_LIST = Storage.Blacklist.getBlacklist().getCommands().stream().filter(command -> command.contains(" ")).collect(Collectors.toList());
|
||||
|
||||
Arguments.ARGUMENTS.clearArguments();
|
||||
|
||||
GENERAL_LIST.forEach(command -> Arguments.ARGUMENTS.buildArgumentStacks(command));
|
||||
SubArgsModule.PLAYER_COMMANDS = new HashMap<>();
|
||||
}
|
||||
|
||||
public static void updateMessages() {
|
||||
Storage.Files.CUSTOM_RESPONSES.reload();
|
||||
ResponseHandler.update();
|
||||
}
|
||||
|
||||
public static void handleCommandNode(UUID uuid, CommandNodeHelper helper) {
|
||||
if (!Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED)
|
||||
return;
|
||||
|
||||
Arguments arguments = PLAYER_COMMANDS.get(uuid);
|
||||
if (arguments == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ArgumentSource source = arguments.TAB_ARGUMENTS;
|
||||
if (source == null) return;
|
||||
|
||||
List<String> inputs = source.getAllInputs().stream().filter(str -> !str.contains("%")).toList();
|
||||
List<String> allEntries = inputs.stream().map(StringUtils::getFirstArg).toList();
|
||||
|
||||
helper.removeIf(allEntries::contains);
|
||||
inputs.forEach(helper::add);
|
||||
}
|
||||
|
||||
public static List<String> getServerCommands(UUID uuid) {
|
||||
return getServerCommands(Storage.getLoader().getPlayerServerName(uuid));
|
||||
}
|
||||
|
||||
public static List<String> getServerCommands(String serverName) {
|
||||
List<String> commands = new ArrayList<>(Storage.Blacklist.getBlacklist().getCommands());
|
||||
if (!Reflection.isProxyServer())
|
||||
return commands;
|
||||
|
||||
if (serverName == null)
|
||||
return commands;
|
||||
|
||||
List<GeneralBlacklist> blacklists = Storage.Blacklist.getServerBlacklists(serverName);
|
||||
for (GeneralBlacklist blacklist : blacklists)
|
||||
commands.addAll(blacklist.getCommands());
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
public static List<String> getGroupCommands(UUID uuid) {
|
||||
return getGroupCommands(uuid, null);
|
||||
}
|
||||
|
||||
public static List<String> getGroupCommands(UUID uuid, String serverName) {
|
||||
List<String> commands = new ArrayList<>();
|
||||
List<Group> groups = GroupManager.getPlayerGroups(uuid);
|
||||
|
||||
if (serverName == null) {
|
||||
groups.forEach(group -> commands.addAll(group.getCommands()));
|
||||
return commands;
|
||||
}
|
||||
|
||||
groups.forEach(group -> {
|
||||
|
||||
commands.addAll(group.getCommands());
|
||||
|
||||
List<String> associatedServerNames = group.getBlacklistServerNames(serverName);
|
||||
|
||||
associatedServerNames.forEach(s -> {
|
||||
commands.addAll(group.getCommands(s));
|
||||
});
|
||||
|
||||
});
|
||||
return commands;
|
||||
}
|
||||
|
||||
public static String replacePlaceholders(String input) {
|
||||
String[] split = input.split(" ");
|
||||
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
String s = split[i];
|
||||
|
||||
boolean number = NumberUtils.isDigit(split[i]),
|
||||
online = Storage.getLoader().isPlayerOnline(s),
|
||||
general = Storage.getLoader().doesPlayerExist(s);
|
||||
|
||||
if (number) {
|
||||
split[i] = "%numbers%";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (online && general) {
|
||||
split[i] = "%both_players%";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (online) {
|
||||
split[i] = "%online_players%";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (general)
|
||||
split[i] = "%players%";
|
||||
}
|
||||
|
||||
return String.join(" ", split);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package de.rayzs.pat.plugin.modules.events;
|
||||
|
||||
import de.rayzs.pat.api.event.events.ExecuteCommandEvent;
|
||||
import de.rayzs.pat.plugin.modules.SubArgsModule;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import de.rayzs.pat.utils.response.ResponseHandler;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.utils.sender.CommandSenderHandler;
|
||||
import de.rayzs.pat.utils.subargs.*;
|
||||
import de.rayzs.pat.utils.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ExecuteCommand extends ExecuteCommandEvent {
|
||||
|
||||
@Override
|
||||
public void handle(ExecuteCommandEvent event) {
|
||||
String command = event.getCommand();
|
||||
command = command.startsWith("/")
|
||||
? command.substring(1)
|
||||
: command;
|
||||
|
||||
final String displayCommand = StringUtils.replaceTriggers(
|
||||
command, "",
|
||||
"\\", "<", ">", "&"
|
||||
);
|
||||
|
||||
CommandSender sender = CommandSenderHandler.from(event.getSenderObj());
|
||||
|
||||
if (sender == null)
|
||||
return;
|
||||
|
||||
UUID uuid = sender.getUniqueId();
|
||||
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isCommand(command)) {
|
||||
|
||||
MessageTranslator.send(
|
||||
event.getSenderObj(),
|
||||
Storage.ConfigSections.Settings.CUSTOM_PLUGIN.MESSAGE,
|
||||
"%command%", StringUtils.getFirstArg(displayCommand)
|
||||
);
|
||||
|
||||
event.setBlocked(true);
|
||||
event.setCancelled(true);
|
||||
event.setDoesNotify(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Storage.ConfigSections.Settings.CUSTOM_VERSION.isCommand(command)) {
|
||||
|
||||
MessageTranslator.send(
|
||||
event.getSenderObj(),
|
||||
Storage.ConfigSections.Settings.CUSTOM_VERSION.MESSAGE,
|
||||
"%command%", StringUtils.getFirstArg(displayCommand)
|
||||
);
|
||||
|
||||
event.setBlocked(true);
|
||||
event.setCancelled(true);
|
||||
event.setDoesNotify(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (command.contains(" ") && !canPlayerExecute(sender, command)) {
|
||||
event.setBlocked(true);
|
||||
event.setCancelled(true);
|
||||
|
||||
MessageTranslator.send(event.getSenderObj(),
|
||||
ResponseHandler.getResponse(uuid, event.getCommand()),
|
||||
"%command%", displayCommand);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.isBlocked())
|
||||
return;
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
MessageTranslator.send(
|
||||
event.getSenderObj(),
|
||||
ResponseHandler.getResponse(uuid, event.getCommand(), Storage.ConfigSections.Settings.CANCEL_COMMAND.BASE_COMMAND_RESPONSE.getLines()),
|
||||
"%command%", StringUtils.getFirstArg(displayCommand)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
private boolean canPlayerExecute(CommandSender sender, String command) {
|
||||
boolean turn = Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED;
|
||||
boolean listed = false;
|
||||
|
||||
Arguments arguments = SubArgsModule.PLAYER_COMMANDS.getOrDefault(sender.getUniqueId(), Arguments.ARGUMENTS);
|
||||
List<String> commands = new ArrayList<>(arguments.CHAT_ARGUMENTS.getGeneralArgument().getInputs());
|
||||
|
||||
final String unmodifiable = command;
|
||||
final String firstArgUnmodifiable = StringUtils.getFirstArg(unmodifiable);
|
||||
|
||||
if (commands.stream().noneMatch(c -> StringUtils.getFirstArg(c).equalsIgnoreCase(firstArgUnmodifiable))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
commands = commands.stream().map(c -> {
|
||||
if (c.contains("%hidden")) {
|
||||
return c.replace("%hidden_", "%");
|
||||
}
|
||||
|
||||
return c;
|
||||
}).toList();
|
||||
|
||||
List<String> placeholderCommands = commands.stream().filter(s ->
|
||||
StringUtils.getFirstArg(s).equalsIgnoreCase(firstArgUnmodifiable) && s.contains("%")
|
||||
).toList();
|
||||
|
||||
if (!placeholderCommands.isEmpty()) {
|
||||
command = SubArgsModule.replacePlaceholders(command);
|
||||
}
|
||||
|
||||
String cpyCommand;
|
||||
for (String c : commands) {
|
||||
cpyCommand = command;
|
||||
|
||||
if (listed)
|
||||
break;
|
||||
|
||||
if (cpyCommand.contains("%both_players%")) {
|
||||
if (c.contains("%online_players%"))
|
||||
cpyCommand = StringUtils.replace(command, "%both_players%", "%online_players%");
|
||||
if (c.contains("%players%"))
|
||||
cpyCommand = StringUtils.replace(command, "%both_players%", "%players%");
|
||||
}
|
||||
|
||||
boolean ends = c.endsWith("_-");
|
||||
if (ends) {
|
||||
c = StringUtils.replace(c, "_-", "");
|
||||
|
||||
if (c.endsWith(" "))
|
||||
c = StringUtils.replaceLast(c, " ", "");
|
||||
}
|
||||
|
||||
listed = c.equalsIgnoreCase(cpyCommand) || cpyCommand.startsWith(c + " ");
|
||||
|
||||
if (listed && ends && cpyCommand.length() > c.length()) {
|
||||
listed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return turn == listed;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package de.rayzs.pat.plugin.modules.events;
|
||||
|
||||
import de.rayzs.pat.api.event.events.FilteredTabCompletionEvent;
|
||||
import de.rayzs.pat.plugin.modules.SubArgsModule;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import de.rayzs.pat.utils.sender.CommandSenderHandler;
|
||||
import de.rayzs.pat.utils.subargs.Arguments;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class TabCompletion extends FilteredTabCompletionEvent {
|
||||
|
||||
@Override
|
||||
public void handle(FilteredTabCompletionEvent event) {
|
||||
String cursor = StringUtils.replaceFirst(event.getCursor(), "/", "");
|
||||
|
||||
if (event.getCompletion().isEmpty()) return;
|
||||
|
||||
UUID uuid = event.getSenderObj() instanceof UUID
|
||||
? (UUID) event.getSenderObj()
|
||||
: CommandSenderHandler.from(event.getSenderObj()).getUniqueId();
|
||||
|
||||
Arguments arguments = SubArgsModule.PLAYER_COMMANDS.getOrDefault(uuid, Arguments.ARGUMENTS);
|
||||
List<String> possibilities = event.getCompletion(), result = new ArrayList<>(arguments.getResultTab(cursor));
|
||||
|
||||
if (Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED) {
|
||||
possibilities = result;
|
||||
|
||||
if (result.contains("%numbers%")) {
|
||||
possibilities.remove("%numbers%");
|
||||
possibilities.addAll(event.getCompletion().stream().filter(NumberUtils::isDigit).toList());
|
||||
|
||||
if (possibilities.isEmpty())
|
||||
possibilities.add("///////////");
|
||||
}
|
||||
|
||||
if (result.contains("%players%")) {
|
||||
possibilities.remove("%players%");
|
||||
possibilities.addAll(SubArgsModule.getPlayerNames());
|
||||
}
|
||||
|
||||
if (result.contains("%online_players%")) {
|
||||
possibilities.remove("%online_players%");
|
||||
possibilities.addAll(SubArgsModule.getOnlinePlayerNames());
|
||||
}
|
||||
|
||||
if (result.contains("%hidden_players%")) {
|
||||
possibilities.remove("%hidden_players%");
|
||||
|
||||
possibilities.addAll(event.getCompletion().stream().filter(completion -> {
|
||||
if (SubArgsModule.getPlayerNames().contains(completion))
|
||||
return false;
|
||||
|
||||
return result.contains(completion);
|
||||
}).toList());
|
||||
|
||||
if (possibilities.isEmpty())
|
||||
possibilities.add("///////////");
|
||||
|
||||
}
|
||||
|
||||
if (result.contains("%hidden_online_players%")) {
|
||||
possibilities.remove("%hidden_online_players%");
|
||||
|
||||
possibilities.addAll(event.getCompletion().stream().filter(completion -> {
|
||||
if (SubArgsModule.getOnlinePlayerNames().contains(completion))
|
||||
return false;
|
||||
|
||||
return result.contains(completion);
|
||||
}).toList());
|
||||
|
||||
if (possibilities.isEmpty())
|
||||
possibilities.add("///////////");
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (result.contains("%numbers%"))
|
||||
possibilities.removeIf(NumberUtils::isDigit);
|
||||
|
||||
if (result.contains("%players%"))
|
||||
possibilities.removeIf(possibility -> SubArgsModule.getPlayerNames().contains(possibility));
|
||||
|
||||
if (result.contains("%online_players%"))
|
||||
possibilities.removeIf(possibility -> SubArgsModule.getOnlinePlayerNames().contains(possibility));
|
||||
|
||||
possibilities.removeAll(result);
|
||||
}
|
||||
|
||||
cursor = StringUtils.getFirstArg(cursor.toLowerCase());
|
||||
if (possibilities.isEmpty() && !SubArgsModule.GENERAL_LIST.contains(cursor)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCompletion(possibilities);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package de.rayzs.pat.plugin.modules.events;
|
||||
|
||||
import de.rayzs.pat.plugin.modules.SubArgsModule;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.sender.CommandSenderHandler;
|
||||
import de.rayzs.pat.api.event.events.*;
|
||||
import de.rayzs.pat.utils.subargs.Arguments;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class UpdateList {
|
||||
|
||||
public static UpdatePluginEvent UPDATE_PLUGIN_EVENT = new UpdatePluginEvent() {
|
||||
@Override
|
||||
public void handle(UpdatePluginEvent event) {
|
||||
SubArgsModule.updateMessages();
|
||||
SubArgsModule.updateList();
|
||||
}
|
||||
};
|
||||
|
||||
public static ServerPlayersChangeEvent SERVER_PLAYERS_CHANGE_EVENT = new ServerPlayersChangeEvent() {
|
||||
@Override
|
||||
public void handle(ServerPlayersChangeEvent event) {
|
||||
SubArgsModule.updatePlayerNames();
|
||||
}
|
||||
};
|
||||
|
||||
public static ReceiveSyncEvent RECEIVE_SYNC_EVENT = new ReceiveSyncEvent() {
|
||||
@Override
|
||||
public void handle(ReceiveSyncEvent event) {
|
||||
SubArgsModule.updateList();
|
||||
}
|
||||
};
|
||||
|
||||
public static UpdatePlayerCommandsEvent UPDATE_PLAYER_COMMANDS_EVENT = new UpdatePlayerCommandsEvent() {
|
||||
@Override
|
||||
public void handle(UpdatePlayerCommandsEvent event) {
|
||||
final UUID uuid = event.getSenderObj() instanceof UUID
|
||||
? (UUID) event.getSenderObj()
|
||||
: CommandSenderHandler.from(event.getSenderObj()).getUniqueId();
|
||||
|
||||
final Arguments argument = SubArgsModule.PLAYER_COMMANDS.getOrDefault(uuid, new Arguments());
|
||||
final String serverName = Storage.getLoader().getPlayerServerName(uuid);
|
||||
|
||||
argument.clearArguments();
|
||||
|
||||
if (Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED) {
|
||||
for (String command : event.getCommands())
|
||||
argument.buildArgumentStacks(command);
|
||||
|
||||
for (String command : argument.CHAT_ARGUMENTS.getGeneralArgument().getInputs())
|
||||
argument.CHAT_ARGUMENTS.buildArguments(Storage.Blacklist.BlockTypeFetcher.modify(command));
|
||||
|
||||
for (String command : argument.TAB_ARGUMENTS.getGeneralArgument().getInputs())
|
||||
argument.TAB_ARGUMENTS.buildArguments(Storage.Blacklist.BlockTypeFetcher.modify(command));
|
||||
|
||||
for (String command : SubArgsModule.getGroupCommands(uuid, serverName))
|
||||
argument.buildArgumentStacks(command);
|
||||
|
||||
for (String command : SubArgsModule.getServerCommands(uuid))
|
||||
argument.buildArgumentStacks(command);
|
||||
|
||||
} else {
|
||||
List<String> groupCommands = SubArgsModule.getGroupCommands(uuid, serverName);
|
||||
|
||||
for (String command : argument.CHAT_ARGUMENTS.getGeneralArgument().getInputs()) {
|
||||
if (groupCommands.contains(command)) continue;
|
||||
|
||||
argument.CHAT_ARGUMENTS.buildArguments(Storage.Blacklist.BlockTypeFetcher.modify(command));
|
||||
}
|
||||
|
||||
for (String command : argument.TAB_ARGUMENTS.getGeneralArgument().getInputs()) {
|
||||
if (groupCommands.contains(command)) continue;
|
||||
|
||||
argument.TAB_ARGUMENTS.buildArguments(Storage.Blacklist.BlockTypeFetcher.modify(command));
|
||||
}
|
||||
}
|
||||
|
||||
SubArgsModule.PLAYER_COMMANDS.putIfAbsent(uuid, argument);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
package de.rayzs.pat.plugin.modules.subargs;
|
||||
|
||||
import de.rayzs.pat.api.storage.blacklist.impl.GeneralBlacklist;
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import de.rayzs.pat.plugin.modules.subargs.events.*;
|
||||
import de.rayzs.pat.utils.response.ResponseHandler;
|
||||
import de.rayzs.pat.api.event.PATEventHandler;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.subargs.*;
|
||||
import java.util.stream.Collectors;
|
||||
import de.rayzs.pat.utils.group.*;
|
||||
import de.rayzs.pat.plugin.*;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import java.util.*;
|
||||
|
||||
public class SubArgsModule {
|
||||
|
||||
public static List<String> GENERAL_LIST, BLOCKED_MESSAGE, PLAYER_NAMES;
|
||||
public static HashMap<UUID, Argument> PLAYER_COMMANDS = new HashMap<>();
|
||||
|
||||
public static void initialize() {
|
||||
updateList();
|
||||
updateMessages();
|
||||
updatePlayerNames();
|
||||
|
||||
PATEventHandler.register(new TabCompletion());
|
||||
PATEventHandler.register(new ExecuteCommand());
|
||||
|
||||
PATEventHandler.register(UpdateList.UPDATE_PLUGIN_EVENT);
|
||||
PATEventHandler.register(UpdateList.RECEIVE_SYNC_EVENT);
|
||||
PATEventHandler.register(UpdateList.UPDATE_PLAYER_COMMANDS_EVENT);
|
||||
PATEventHandler.register(UpdateList.SERVER_PLAYERS_CHANGE_EVENT);
|
||||
}
|
||||
|
||||
public static void updatePlayerNames() {
|
||||
PLAYER_NAMES = Reflection.isProxyServer()
|
||||
? Reflection.isVelocityServer()
|
||||
? VelocityLoader.getPlayerNames()
|
||||
: BungeeLoader.getPlayerNames()
|
||||
: BukkitLoader.getPlayerNames();
|
||||
}
|
||||
|
||||
public static List<String> getPlayerNames() {
|
||||
return PLAYER_NAMES;
|
||||
}
|
||||
|
||||
public static void updateList() {
|
||||
GENERAL_LIST = Storage.Blacklist.getBlacklist().getCommands().stream().filter(command -> command.contains(" ")).collect(Collectors.toList());
|
||||
|
||||
Argument.clearArguments();
|
||||
GENERAL_LIST.forEach(Argument::buildArguments);
|
||||
SubArgsModule.PLAYER_COMMANDS = new HashMap<>();
|
||||
}
|
||||
|
||||
public static void updateMessages() {
|
||||
Storage.Files.CUSTOM_RESPONSES.reload();
|
||||
ResponseHandler.update();
|
||||
}
|
||||
|
||||
public static List<String> getServerCommands(UUID uuid) {
|
||||
List<String> commands = new ArrayList<>();
|
||||
if(!Reflection.isProxyServer()) return commands;
|
||||
|
||||
String serverName = Reflection.isVelocityServer() ? VelocityLoader.getServerNameByPlayerUUID(uuid) : BungeeLoader.getServerNameByPlayerUUID(uuid);
|
||||
if(serverName == null) return commands;
|
||||
|
||||
List<GeneralBlacklist> blacklists = Storage.Blacklist.getBlacklists(serverName);
|
||||
for (GeneralBlacklist blacklist : blacklists)
|
||||
commands.addAll(blacklist.getCommands());
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
public static List<String> getGroupCommands(UUID uuid) {
|
||||
List<String> commands = new ArrayList<>();
|
||||
List<Group> groups = new ArrayList<>();
|
||||
|
||||
Group currentGroup;
|
||||
for (String permission : Objects.requireNonNull(PermissionUtil.getPermissions(uuid))) {
|
||||
if(!permission.startsWith("proantitab.group.")) continue;
|
||||
currentGroup = GroupManager.getGroupByName(StringUtils.replaceFirst(permission, "proantitab.group.", ""));
|
||||
if(currentGroup != null && !groups.contains(currentGroup)) groups.add(currentGroup);
|
||||
}
|
||||
|
||||
if(!groups.isEmpty()) {
|
||||
int highestPriority = groups.stream().mapToInt(Group::getPriority).filter(group -> group <= 9999).min().orElse(9999);
|
||||
groups.removeIf(group -> group.getPriority() > highestPriority);
|
||||
for (Group group : groups) commands.addAll(group.getCommands().stream().filter(command -> command.contains(" ")).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
return commands;
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
package de.rayzs.pat.plugin.modules.subargs.events;
|
||||
|
||||
import de.rayzs.pat.api.event.events.ExecuteCommandEvent;
|
||||
import de.rayzs.pat.plugin.modules.subargs.SubArgsModule;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import de.rayzs.pat.utils.response.ResponseHandler;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.subargs.*;
|
||||
import de.rayzs.pat.utils.*;
|
||||
|
||||
public class ExecuteCommand extends ExecuteCommandEvent {
|
||||
|
||||
@Override
|
||||
public void handle(ExecuteCommandEvent event) {
|
||||
String command = StringUtils.replaceFirst(event.getCommand(), "/", "");
|
||||
CommandSender sender = new CommandSender(event.getSenderObj());
|
||||
|
||||
/* Removed due to the fact that it is not required after all.
|
||||
if(PermissionUtil.hasBypassPermission(event.getSenderObj(), command.contains(" ") ? command.split(" ")[0] : command))
|
||||
return;
|
||||
*/
|
||||
|
||||
if(command.contains(" ") && shouldCommandBeBlocked(sender, event, command)) {
|
||||
event.setBlocked(true);
|
||||
event.setCancelled(true);
|
||||
MessageTranslator.send(event.getSenderObj(), ResponseHandler.getResponse(sender.getUniqueId(), event.getCommand()), "%command%", event.getCommand());
|
||||
return;
|
||||
}
|
||||
|
||||
if(!event.isBlocked()) return;
|
||||
|
||||
if(Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isCommand(command) || Storage.ConfigSections.Settings.CUSTOM_VERSION.isCommand(command))
|
||||
return;
|
||||
|
||||
event.setCancelled(true);
|
||||
MessageTranslator.send(event.getSenderObj(), ResponseHandler.getResponse(sender.getUniqueId(), event.getCommand(), Storage.ConfigSections.Settings.CANCEL_COMMAND.BASE_COMMAND_RESPONSE.getLines()), "%command%", event.getCommand());
|
||||
}
|
||||
|
||||
private boolean shouldCommandBeBlocked(CommandSender sender, ExecuteCommandEvent event, String command) {
|
||||
boolean listed = false,
|
||||
turn = Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED,
|
||||
blocked = event.isBlocked(),
|
||||
ignored = false,
|
||||
useFilter = false,
|
||||
tooBig = false;
|
||||
|
||||
String[] split, originCommandSplit, copiedOriginCommandSplit;
|
||||
String tmpCommand;
|
||||
for (String s : SubArgsModule.PLAYER_COMMANDS.getOrDefault(sender.getUniqueId(), Argument.getGeneralArgument()).getInputs()) {
|
||||
if(s.contains("%hidden_online_players%")) continue;
|
||||
tmpCommand = command;
|
||||
|
||||
if(s.split(" ")[0].equalsIgnoreCase(tmpCommand.split(" ")[0]))
|
||||
useFilter = true;
|
||||
|
||||
originCommandSplit = tmpCommand.split(" ");
|
||||
split = s.split(" ");
|
||||
int i;
|
||||
|
||||
for(i = 0; i < split.length; i++) {
|
||||
if(!split[i].equals("%online_players%")) continue;
|
||||
|
||||
boolean foundPlayer = false;
|
||||
for (String playerName : SubArgsModule.getPlayerNames()) {
|
||||
if(i >= originCommandSplit.length) continue;
|
||||
if(!playerName.equalsIgnoreCase(originCommandSplit[i])) continue;
|
||||
|
||||
foundPlayer = true;
|
||||
originCommandSplit[i] = "%online_players%";
|
||||
break;
|
||||
}
|
||||
|
||||
if(!foundPlayer) {
|
||||
|
||||
copiedOriginCommandSplit = originCommandSplit.clone();
|
||||
copiedOriginCommandSplit[copiedOriginCommandSplit.length-1] = null;
|
||||
String c = String.join(" ", copiedOriginCommandSplit);
|
||||
|
||||
if(s.startsWith(c)) return turn;
|
||||
}
|
||||
|
||||
tmpCommand = String.join(" ", originCommandSplit);
|
||||
}
|
||||
|
||||
if (!tmpCommand.toLowerCase().startsWith(StringUtils.replaceFirst(s.toLowerCase(), " _-", "")))
|
||||
continue;
|
||||
|
||||
if (!listed) listed = true;
|
||||
if (s.endsWith(" _-")) ignored = true;
|
||||
|
||||
tooBig = originCommandSplit.length > s.replace(" _-", "").split(" ").length;
|
||||
}
|
||||
|
||||
return !(blocked || !useFilter) && turn != listed || ignored && tooBig;
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package de.rayzs.pat.plugin.modules.subargs.events;
|
||||
|
||||
import de.rayzs.pat.api.event.events.FilteredTabCompletionEvent;
|
||||
import de.rayzs.pat.plugin.modules.subargs.SubArgsModule;
|
||||
import de.rayzs.pat.utils.subargs.Argument;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import java.util.stream.Collectors;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import java.util.*;
|
||||
|
||||
public class TabCompletion extends FilteredTabCompletionEvent {
|
||||
|
||||
@Override
|
||||
public void handle(FilteredTabCompletionEvent event) {
|
||||
String cursor = StringUtils.replaceFirst(event.getCursor(), "/", "");
|
||||
if (event.getCompletion().isEmpty()) return;
|
||||
|
||||
UUID uuid = event.getSenderObj() instanceof UUID ? (UUID) event.getSenderObj() : new CommandSender(event.getSenderObj()).getUniqueId();
|
||||
Argument argument = SubArgsModule.PLAYER_COMMANDS.getOrDefault(uuid, Argument.getGeneralArgument());
|
||||
List<String> possibilities = event.getCompletion(), result = new ArrayList<>(argument.getResult(cursor));
|
||||
|
||||
if(Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED) {
|
||||
possibilities = result;
|
||||
|
||||
if(result.contains("%online_players%")) {
|
||||
possibilities.remove("%online_players%");
|
||||
possibilities.addAll(SubArgsModule.getPlayerNames());
|
||||
}
|
||||
|
||||
if(result.contains("%hidden_online_players%")) {
|
||||
possibilities.remove("%hidden_online_players%");
|
||||
possibilities.addAll(event.getCompletion().stream().filter(completion -> {
|
||||
if(SubArgsModule.getPlayerNames().contains(completion)) return false;
|
||||
return result.contains(completion);
|
||||
}).collect(Collectors.toList()));
|
||||
|
||||
if(possibilities.isEmpty()) possibilities.add("///////////");
|
||||
}
|
||||
|
||||
} else {
|
||||
if(result.contains("%online_players%"))
|
||||
possibilities.removeIf(possibility -> SubArgsModule.getPlayerNames().contains(possibility));
|
||||
|
||||
possibilities.removeAll(result);
|
||||
}
|
||||
|
||||
cursor = StringUtils.getFirstArg(cursor.toLowerCase());
|
||||
if(possibilities.isEmpty() && !SubArgsModule.GENERAL_LIST.contains(cursor)) return;
|
||||
|
||||
event.setCompletion(possibilities);
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package de.rayzs.pat.plugin.modules.subargs.events;
|
||||
|
||||
import de.rayzs.pat.plugin.modules.subargs.SubArgsModule;
|
||||
import de.rayzs.pat.utils.subargs.Argument;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.CommandSender;
|
||||
import de.rayzs.pat.api.event.events.*;
|
||||
import java.util.*;
|
||||
|
||||
public class UpdateList {
|
||||
|
||||
public static UpdatePluginEvent UPDATE_PLUGIN_EVENT = new UpdatePluginEvent() {
|
||||
@Override
|
||||
public void handle(UpdatePluginEvent event) {
|
||||
SubArgsModule.updateMessages();
|
||||
SubArgsModule.updateList();
|
||||
}
|
||||
};
|
||||
|
||||
public static ServerPlayersChangeEvent SERVER_PLAYERS_CHANGE_EVENT = new ServerPlayersChangeEvent() {
|
||||
@Override
|
||||
public void handle(ServerPlayersChangeEvent event) {
|
||||
SubArgsModule.updatePlayerNames();
|
||||
}
|
||||
};
|
||||
|
||||
public static ReceiveSyncEvent RECEIVE_SYNC_EVENT = new ReceiveSyncEvent() {
|
||||
@Override
|
||||
public void handle(ReceiveSyncEvent event) {
|
||||
SubArgsModule.updateList();
|
||||
}
|
||||
};
|
||||
|
||||
public static UpdatePlayerCommandsEvent UPDATE_PLAYER_COMMANDS_EVENT = new UpdatePlayerCommandsEvent() {
|
||||
@Override
|
||||
public void handle(UpdatePlayerCommandsEvent event) {
|
||||
final UUID uuid = event.getSenderObj() instanceof UUID ? (UUID) event.getSenderObj() : new CommandSender(event.getSenderObj()).getUniqueId();
|
||||
final Argument argument = SubArgsModule.PLAYER_COMMANDS.getOrDefault(uuid, new Argument());
|
||||
|
||||
argument.clearAllArguments();
|
||||
|
||||
if(Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED) {
|
||||
for (String command : event.getCommands())
|
||||
argument.buildArgumentStacks(command);
|
||||
|
||||
for(String command : Argument.getGeneralArgument().getInputs())
|
||||
argument.buildArgumentStacks(command);
|
||||
|
||||
for (String command : SubArgsModule.getGroupCommands(uuid))
|
||||
argument.buildArgumentStacks(command);
|
||||
|
||||
for (String command : SubArgsModule.getServerCommands(uuid))
|
||||
argument.buildArgumentStacks(command);
|
||||
} else {
|
||||
List<String> groupCommands = SubArgsModule.getGroupCommands(uuid);
|
||||
for (String command : Argument.getGeneralArgument().getInputs()) {
|
||||
if(groupCommands.contains(command)) continue;
|
||||
argument.buildArgumentStacks(command);
|
||||
}
|
||||
}
|
||||
|
||||
SubArgsModule.PLAYER_COMMANDS.putIfAbsent(uuid, argument);
|
||||
}
|
||||
};
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,47 @@
|
||||
package de.rayzs.pat.plugin.process.impl.local.info;
|
||||
|
||||
import de.rayzs.pat.api.communication.Communicator;
|
||||
import de.rayzs.pat.api.command.ProCommand;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class InfoCommand extends ProCommand {
|
||||
|
||||
public InfoCommand() {
|
||||
super(
|
||||
"info",
|
||||
""
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
|
||||
String message = StringUtils.getStringList(Storage.ConfigSections.Messages.INFO.MESSAGE.getLines(), "\n");
|
||||
|
||||
String syncTime = Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED || Reflection.isProxyServer()
|
||||
? Storage.ConfigSections.Messages.INFO.SYNC_TIME.replace("%time%", TimeConverter.calcAndGetTime(Reflection.isProxyServer()
|
||||
? Communicator.LAST_DATA_UPDATE : Communicator.LAST_BUKKIT_SYNC))
|
||||
: Storage.ConfigSections.Messages.INFO.SYNC_DISABLED;
|
||||
|
||||
String versionStatus = Storage.OUTDATED
|
||||
? Storage.ConfigSections.Messages.INFO.VERSION_OUTDATED
|
||||
: Storage.ConfigSections.Messages.INFO.VERSION_UPDATED;
|
||||
|
||||
message = StringUtils.replace(message,
|
||||
"%sync_time%", syncTime,
|
||||
"%version_status%", versionStatus
|
||||
);
|
||||
|
||||
sender.sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package de.rayzs.pat.plugin.process.impl.local.info;
|
||||
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import de.rayzs.pat.api.command.ProCommand;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import java.util.*;
|
||||
|
||||
public class PermsCommand extends ProCommand {
|
||||
|
||||
public PermsCommand() {
|
||||
super(
|
||||
"perms",
|
||||
""
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
if (args.length == 0)
|
||||
return false;
|
||||
|
||||
String name = args[0];
|
||||
UUID uuid = Storage.getLoader().getUUIDByName(name);
|
||||
|
||||
boolean online = uuid != null;
|
||||
|
||||
if (online) {
|
||||
name = Storage.getLoader().getNameByUUID(uuid);
|
||||
}
|
||||
|
||||
sender.sendMessage((online
|
||||
? Storage.ConfigSections.Messages.PERMS_CHECK.MESSAGE.replace("%permissions%", PermissionUtil.getPermissionsAsString(uuid))
|
||||
: Storage.ConfigSections.Messages.PERMS_CHECK.PLAYER_NOT_ONLINE
|
||||
).replace("%player%", name)
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
return args.length < 2 ? Storage.getLoader().getPlayerNames() : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package de.rayzs.pat.plugin.process.impl.local.info;
|
||||
|
||||
import de.rayzs.pat.api.communication.client.ClientInfo;
|
||||
import de.rayzs.pat.api.communication.Communicator;
|
||||
import de.rayzs.pat.api.command.ProCommand;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class StatsCommand extends ProCommand {
|
||||
|
||||
public StatsCommand() {
|
||||
super(
|
||||
"stats",
|
||||
""
|
||||
);
|
||||
|
||||
proxyOnly = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
boolean backend = Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED && !Reflection.isProxyServer();
|
||||
|
||||
if(backend) {
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.NO_PROXY.MESSAGE);
|
||||
return true;
|
||||
}
|
||||
|
||||
final int length = Communicator.CLIENTS.size() - 1;
|
||||
boolean tmpFound = false;
|
||||
|
||||
StringBuilder statsBuilder = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < Communicator.CLIENTS.size(); i++) {
|
||||
ClientInfo client = Communicator.CLIENTS.get(i);
|
||||
|
||||
if (!client.hasSentFeedback())
|
||||
continue;
|
||||
|
||||
if (!tmpFound)
|
||||
tmpFound = true;
|
||||
|
||||
statsBuilder.append(StringUtils.replace(Storage.ConfigSections.Messages.STATS.SERVER,
|
||||
"%updated%", client.getSyncTime(), "%servername%", client.getName()
|
||||
));
|
||||
|
||||
if (i <= length)
|
||||
statsBuilder.append(Storage.ConfigSections.Messages.STATS.SPLITTER);
|
||||
}
|
||||
|
||||
final boolean found = tmpFound;
|
||||
|
||||
Storage.ConfigSections.Messages.STATS.STATISTIC.getLines().forEach(message -> {
|
||||
|
||||
message = StringUtils.replace(message,
|
||||
"%server_count%", String.valueOf(Communicator.SERVER_DATA_SYNC_COUNT),
|
||||
"%last_sync_time%", TimeConverter.calcAndGetTime(Communicator.LAST_DATA_UPDATE),
|
||||
"%servers%", found ? statsBuilder.toString() : Storage.ConfigSections.Messages.STATS.NO_SERVER
|
||||
);
|
||||
|
||||
sender.sendMessage(message);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package de.rayzs.pat.plugin.process.impl.local.info;
|
||||
|
||||
import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import de.rayzs.pat.api.command.ProCommand;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import java.util.*;
|
||||
|
||||
public class UpdateCommand extends ProCommand {
|
||||
|
||||
public UpdateCommand() {
|
||||
super(
|
||||
"update",
|
||||
""
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
if (args.length == 0) {
|
||||
PermissionUtil.reloadPermissions();
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.UPDATE_PERMISSIONS.UPDATE_ALL);
|
||||
return true;
|
||||
}
|
||||
|
||||
String name = args[0];
|
||||
UUID uuid = Storage.getLoader().getUUIDByName(name);
|
||||
|
||||
boolean exist = uuid != null;
|
||||
|
||||
if (exist) {
|
||||
name = Storage.getLoader().getNameByUUID(uuid);
|
||||
}
|
||||
|
||||
String message = exist
|
||||
? Storage.ConfigSections.Messages.UPDATE_PERMISSIONS.UPDATE_SPECIFIC
|
||||
: Storage.ConfigSections.Messages.UPDATE_PERMISSIONS.PLAYER_NOT_ONLINE;
|
||||
|
||||
message = message.replace("%target%", name);
|
||||
|
||||
if (exist) {
|
||||
PermissionUtil.reloadPermissions(uuid);
|
||||
}
|
||||
|
||||
sender.sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
return args.length < 2 ? Storage.getLoader().getPlayerNames() : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package de.rayzs.pat.plugin.process.impl.local.modify;
|
||||
|
||||
import de.rayzs.pat.api.command.ProCommand;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.api.storage.blacklist.impl.GroupBlacklist;
|
||||
import de.rayzs.pat.plugin.BukkitLoader;
|
||||
import de.rayzs.pat.utils.group.*;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class AddCommand extends ProCommand {
|
||||
|
||||
public AddCommand() {
|
||||
super(
|
||||
"add",
|
||||
""
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
|
||||
if (args.length == 0)
|
||||
return false;
|
||||
|
||||
boolean backend = Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED && !Reflection.isProxyServer();
|
||||
|
||||
if (backend) {
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.NO_PROXY.MESSAGE);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
String fullString = String.join(" ", args);
|
||||
String command = fullString;
|
||||
|
||||
if (!command.startsWith("\"")) {
|
||||
command = args[0];
|
||||
} else {
|
||||
|
||||
command = command.substring(1);
|
||||
int lastIndex = command.indexOf("\"");
|
||||
|
||||
if (lastIndex == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
command = command.substring(0, lastIndex);
|
||||
|
||||
fullString = fullString.replace("\"" + command + "\"", ":::");
|
||||
args = fullString.split(" ");
|
||||
}
|
||||
|
||||
command = StringUtils.replaceTriggers(command, "", "\\.", "'", "\"");
|
||||
|
||||
if (command.isEmpty())
|
||||
return false;
|
||||
|
||||
final int length = args.length;
|
||||
|
||||
if (length == 1) {
|
||||
boolean exist = command.contains(" ")
|
||||
? Storage.Blacklist.getBlacklist().getCommands().contains(command)
|
||||
: Storage.Blacklist.getBlacklist().isListed(command);
|
||||
|
||||
if (!exist) {
|
||||
Storage.Blacklist.getBlacklist().add(command).save();
|
||||
Storage.handleChange();
|
||||
}
|
||||
|
||||
String message = exist ? Storage.ConfigSections.Messages.BLACKLIST.ADD_FAILED : Storage.ConfigSections.Messages.BLACKLIST.ADD_SUCCESS;
|
||||
message = StringUtils.replace(message, "%command%", command);
|
||||
|
||||
sender.sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
String groupName = args[1];
|
||||
Group group = GroupManager.getGroupByName(groupName);
|
||||
|
||||
if (group == null) {
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST.replace("%group%", groupName));
|
||||
return true;
|
||||
}
|
||||
|
||||
GroupBlacklist blacklist = group.getGeneralGroupBlacklist();
|
||||
boolean exist = blacklist.getCommands().contains(command);
|
||||
|
||||
if (!exist) {
|
||||
group.add(command);
|
||||
Storage.handleChange();
|
||||
}
|
||||
|
||||
String message = exist ? Storage.ConfigSections.Messages.GROUP.ADD_FAILED : Storage.ConfigSections.Messages.GROUP.ADD_SUCCESS;
|
||||
message = StringUtils.replace(message, "%group%", groupName, "%command%", command);
|
||||
|
||||
sender.sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
|
||||
if (args.length == 0 || args.length == 1 && !args[0].startsWith("\"")) {
|
||||
if (Reflection.isProxyServer())
|
||||
return null;
|
||||
|
||||
return BukkitLoader.getAllowedCommands();
|
||||
}
|
||||
|
||||
String fullString = String.join(" ", args);
|
||||
String command = fullString;
|
||||
|
||||
if (args[0].startsWith("\"")) {
|
||||
command = command.length() == 1 ? "" : command.substring(1, command.length() - 1);
|
||||
|
||||
int lastIndex = command.indexOf("\"");
|
||||
|
||||
if (lastIndex == -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
command = command.substring(0, lastIndex);
|
||||
args = Arrays.copyOfRange(args, command.split(" ").length - 1, args.length);
|
||||
}
|
||||
|
||||
final int length = args.length;
|
||||
return length == 2 ? GroupManager.getGroupNames() : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package de.rayzs.pat.plugin.process.impl.local.modify;
|
||||
|
||||
import de.rayzs.pat.api.command.ProCommand;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import de.rayzs.pat.utils.group.*;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ClearCommand extends ProCommand {
|
||||
|
||||
private final ExpireCache<UUID, String> CONFIRMATION = new ExpireCache<>(4, TimeUnit.SECONDS);
|
||||
|
||||
public ClearCommand() {
|
||||
super(
|
||||
"clear",
|
||||
"clr"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
|
||||
if (args.length == 0) {
|
||||
final String confirmationString = "clear";
|
||||
|
||||
if (!CONFIRMATION.getOrDefault(sender.getUniqueId(), "").equals(confirmationString)) {
|
||||
CONFIRMATION.put(sender.getUniqueId(), confirmationString);
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.BLACKLIST.CLEAR_CONFIRM);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Storage.Blacklist.getBlacklist().clear().save();
|
||||
Storage.handleChange();
|
||||
|
||||
CONFIRMATION.remove(sender.getUniqueId());
|
||||
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.BLACKLIST.CLEAR);
|
||||
return true;
|
||||
}
|
||||
|
||||
String groupName = args[0];
|
||||
Group group = GroupManager.getGroupByName(groupName);
|
||||
|
||||
if (group == null) {
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST.replace("%group%", groupName));
|
||||
return true;
|
||||
}
|
||||
|
||||
groupName = group.getGroupName();
|
||||
|
||||
final String confirmationString = "clear " + groupName;
|
||||
|
||||
if (!CONFIRMATION.getOrDefault(sender.getUniqueId(), "").equals(confirmationString)) {
|
||||
CONFIRMATION.put(sender.getUniqueId(), confirmationString);
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.CLEAR_CONFIRM);
|
||||
return true;
|
||||
}
|
||||
|
||||
group.clear();
|
||||
Storage.handleChange();
|
||||
|
||||
CONFIRMATION.remove(sender.getUniqueId());
|
||||
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.CLEAR.replace("%group%", groupName));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
return args.length < 2 ? GroupManager.getGroupNames() : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package de.rayzs.pat.plugin.process.impl.local.modify;
|
||||
|
||||
import de.rayzs.pat.api.command.ProCommand;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CreateGroupCommand extends ProCommand {
|
||||
|
||||
public CreateGroupCommand() {
|
||||
super(
|
||||
"creategroup",
|
||||
"cg"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean backend = Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED && !Reflection.isProxyServer();
|
||||
|
||||
if (backend) {
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.NO_PROXY.MESSAGE);
|
||||
return true;
|
||||
}
|
||||
|
||||
String groupName = args[0];
|
||||
Group group = GroupManager.getGroupByName(groupName);
|
||||
boolean registered = group != null;
|
||||
|
||||
if (!registered) {
|
||||
GroupManager.registerGroup(groupName);
|
||||
} else groupName = group.getGroupName();
|
||||
|
||||
String message = registered ? Storage.ConfigSections.Messages.GROUP.ALREADY_EXIST : Storage.ConfigSections.Messages.GROUP.CREATE;
|
||||
message = StringUtils.replace(message, "%group%", groupName);
|
||||
|
||||
sender.sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
return args.length < 2 ? GroupManager.getGroupNames() : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package de.rayzs.pat.plugin.process.impl.local.modify;
|
||||
|
||||
import de.rayzs.pat.api.command.ProCommand;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.utils.ExpireCache;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class DeleteGroupCommand extends ProCommand {
|
||||
|
||||
private final ExpireCache<UUID, String> CONFIRMATION = new ExpireCache<>(4, TimeUnit.SECONDS);
|
||||
|
||||
public DeleteGroupCommand() {
|
||||
super(
|
||||
"deletegroup",
|
||||
"dg"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean backend = Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED && !Reflection.isProxyServer();
|
||||
|
||||
if (backend) {
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.NO_PROXY.MESSAGE);
|
||||
return true;
|
||||
}
|
||||
|
||||
String groupName = args[0];
|
||||
Group group = GroupManager.getGroupByName(groupName);
|
||||
boolean registered = group != null;
|
||||
|
||||
if (!registered) {
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST.replace("%group%", groupName));
|
||||
return true;
|
||||
}
|
||||
|
||||
groupName = group.getGroupName();
|
||||
|
||||
String confirmationString = "deletegroup " + groupName;
|
||||
|
||||
if (!CONFIRMATION.getOrDefault(sender.getUniqueId(), "").equals(confirmationString)) {
|
||||
CONFIRMATION.put(sender.getUniqueId(), confirmationString);
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.DELETE_CONFIRM);
|
||||
return true;
|
||||
}
|
||||
|
||||
GroupManager.unregisterGroup(groupName);
|
||||
CONFIRMATION.remove(sender.getUniqueId());
|
||||
|
||||
String message = registered ? Storage.ConfigSections.Messages.GROUP.DELETE : Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST;
|
||||
message = StringUtils.replace(message, "%group%", groupName);
|
||||
|
||||
sender.sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
return args.length < 2 ? GroupManager.getGroupNames() : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
package de.rayzs.pat.plugin.process.impl.local.modify;
|
||||
|
||||
import de.rayzs.pat.api.command.ProCommand;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.api.storage.blacklist.impl.GroupBlacklist;
|
||||
import de.rayzs.pat.utils.group.*;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class RemoveCommand extends ProCommand {
|
||||
|
||||
public RemoveCommand() {
|
||||
super(
|
||||
"remove",
|
||||
"rem", "rm"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
|
||||
if (args.length == 0)
|
||||
return false;
|
||||
|
||||
boolean backend = Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED && !Reflection.isProxyServer();
|
||||
|
||||
if (backend) {
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.NO_PROXY.MESSAGE);
|
||||
return true;
|
||||
}
|
||||
|
||||
String fullString = String.join(" ", args);
|
||||
String command = fullString;
|
||||
|
||||
if (!command.startsWith("\"")) {
|
||||
command = args[0];
|
||||
} else {
|
||||
|
||||
command = command.substring(1);
|
||||
int lastIndex = command.indexOf("\"");
|
||||
|
||||
if (lastIndex == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
command = command.substring(0, lastIndex);
|
||||
|
||||
fullString = fullString.replace("\"" + command + "\"", ":::");
|
||||
args = fullString.split(" ");
|
||||
}
|
||||
|
||||
command = StringUtils.replaceTriggers(command, "", "\\.", "'", "\"");
|
||||
|
||||
if (command.isEmpty())
|
||||
return false;
|
||||
|
||||
final int length = args.length;
|
||||
|
||||
if (length == 1) {
|
||||
boolean exist = command.contains(" ")
|
||||
? Storage.Blacklist.getBlacklist().getCommands().contains(command)
|
||||
: Storage.Blacklist.getBlacklist().isListed(command);
|
||||
|
||||
if (exist) {
|
||||
Storage.Blacklist.getBlacklist().remove(command).save();
|
||||
Storage.handleChange();
|
||||
}
|
||||
|
||||
String message = !exist ? Storage.ConfigSections.Messages.BLACKLIST.REMOVE_FAILED : Storage.ConfigSections.Messages.BLACKLIST.REMOVE_SUCCESS;
|
||||
message = StringUtils.replace(message, "%command%", command);
|
||||
|
||||
sender.sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
String groupName = args[1];
|
||||
Group group = GroupManager.getGroupByName(groupName);
|
||||
|
||||
if (group == null) {
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST.replace("%group%", groupName));
|
||||
return true;
|
||||
}
|
||||
|
||||
GroupBlacklist blacklist = group.getGeneralGroupBlacklist();
|
||||
boolean exist = blacklist.getCommands().contains(command);
|
||||
|
||||
if (exist) {
|
||||
group.remove(command);
|
||||
Storage.handleChange();
|
||||
}
|
||||
|
||||
String message = !exist ? Storage.ConfigSections.Messages.GROUP.REMOVE_FAILED : Storage.ConfigSections.Messages.GROUP.REMOVE_SUCCESS;
|
||||
message = StringUtils.replace(message, "%group%", groupName, "%command%", command);
|
||||
|
||||
sender.sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
if (args.length == 0 || args.length == 1 && !args[0].startsWith("\"")) {
|
||||
return new ArrayList<>(Storage.Blacklist.getBlacklist().getCommands()).stream().filter(str -> !str.contains(" ")).toList();
|
||||
}
|
||||
|
||||
String fullString = String.join(" ", args);
|
||||
String command = fullString;
|
||||
|
||||
if (args[0].startsWith("\"")) {
|
||||
command = command.length() == 1 ? "" : command.substring(1, command.length() - 1);
|
||||
int lastIndex = command.indexOf("\"");
|
||||
|
||||
if (lastIndex == -1) {
|
||||
|
||||
if (args.length == 1) {
|
||||
Stream<String> stream = new ArrayList<>(Storage.Blacklist.getBlacklist().getCommands())
|
||||
.stream()
|
||||
.filter(str -> str.contains(" "));
|
||||
|
||||
if (!Reflection.isProxyServer())
|
||||
stream = stream.map(str -> "\"" + str + "\"");
|
||||
|
||||
return stream.toList();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
command = command.substring(0, lastIndex);
|
||||
args = Arrays.copyOfRange(args, command.split(" ").length - 1, args.length);
|
||||
}
|
||||
|
||||
final int length = args.length;
|
||||
return length == 2 ? GroupManager.getGroupNames() : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package de.rayzs.pat.plugin.process.impl.local.modify;
|
||||
|
||||
import de.rayzs.pat.api.command.ProCommand;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SetPriorityCommand extends ProCommand {
|
||||
|
||||
public SetPriorityCommand() {
|
||||
super(
|
||||
"setpriority",
|
||||
"sp"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
|
||||
boolean backend = Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED && !Reflection.isProxyServer();
|
||||
|
||||
if (backend) {
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.NO_PROXY.MESSAGE);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length < 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String groupName = args[0];
|
||||
Group group = GroupManager.getGroupByName(groupName);
|
||||
|
||||
if (group == null) {
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST.replace("%group%", groupName));
|
||||
return true;
|
||||
}
|
||||
|
||||
String priorityStr = args[1];
|
||||
|
||||
try {
|
||||
int priority = Integer.parseInt(priorityStr);
|
||||
|
||||
if (priority > 0) {
|
||||
group.setPriority(priority);
|
||||
|
||||
GroupManager.sort();
|
||||
Storage.handleChange();
|
||||
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.PRIORITY_SUCCESS.replace("%group%", group.getGroupName()).replace("%priority%", priorityStr));
|
||||
return true;
|
||||
}
|
||||
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.PRIORITY_FAILED.replace("%group%", groupName).replace("%priority%", priorityStr));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
return args.length < 2 ? GroupManager.getGroupNames() : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package de.rayzs.pat.plugin.process.impl.local.modify.list;
|
||||
|
||||
import de.rayzs.pat.api.command.ProCommand;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.group.*;
|
||||
import java.util.List;
|
||||
|
||||
public class ListCommand extends ProCommand {
|
||||
|
||||
public ListCommand() {
|
||||
super(
|
||||
"list",
|
||||
"ls"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
|
||||
if (args.length == 0) {
|
||||
String commandsListMessage = StringUtils.getStringList(
|
||||
Storage.Blacklist.getBlacklist().getCommands(),
|
||||
Storage.ConfigSections.Messages.BLACKLIST.LIST_SPLITTER
|
||||
);
|
||||
|
||||
String message = Storage.ConfigSections.Messages.BLACKLIST.LIST_MESSAGE;
|
||||
message = StringUtils.replace(message,
|
||||
"%size%", String.valueOf(Storage.Blacklist.getBlacklist().getCommands().size()),
|
||||
"%commands%", commandsListMessage
|
||||
);
|
||||
|
||||
sender.sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
String groupName = args[0];
|
||||
Group group = GroupManager.getGroupByName(groupName);
|
||||
|
||||
if (group == null) {
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST.replace("%group%", groupName));
|
||||
return true;
|
||||
}
|
||||
|
||||
String commandsListMessage = StringUtils.getStringList(
|
||||
group.getCommands(),
|
||||
Storage.ConfigSections.Messages.GROUP.LIST_SPLITTER
|
||||
);
|
||||
|
||||
String message = Storage.ConfigSections.Messages.GROUP.LIST_MESSAGE;
|
||||
message = StringUtils.replace(message,
|
||||
"%group%", groupName,
|
||||
"%size%", String.valueOf(Storage.Blacklist.getBlacklist().getCommands().size()),
|
||||
"%commands%", commandsListMessage
|
||||
);
|
||||
|
||||
sender.sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
return args.length < 2 ? GroupManager.getGroupNames() : null;
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package de.rayzs.pat.plugin.process.impl.local.modify.list;
|
||||
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
import de.rayzs.pat.api.command.ProCommand;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ListGroupsCommand extends ProCommand {
|
||||
|
||||
public ListGroupsCommand() {
|
||||
super(
|
||||
"listgroups",
|
||||
"lg"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
String groupsListMessage = StringUtils.getStringList(
|
||||
GroupManager.getGroupNames(),
|
||||
Storage.ConfigSections.Messages.GROUP.LIST_SPLITTER
|
||||
);
|
||||
|
||||
String message = Storage.ConfigSections.Messages.GROUP.LIST_GROUP_MESSAGE;
|
||||
message = StringUtils.replace(message,
|
||||
"%size%", String.valueOf(Storage.Blacklist.getBlacklist().getCommands().size()),
|
||||
"%groups%", groupsListMessage
|
||||
);
|
||||
|
||||
sender.sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package de.rayzs.pat.plugin.process.impl.local.modify.list;
|
||||
|
||||
import de.rayzs.pat.api.command.ProCommand;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ListPrioritiesCommand extends ProCommand {
|
||||
|
||||
public ListPrioritiesCommand() {
|
||||
super(
|
||||
"listpriorities",
|
||||
"lp"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
|
||||
String groupsPriorityListMessage = buildGroupPriorityMessage(
|
||||
GroupManager.getGroups(),
|
||||
Storage.ConfigSections.Messages.GROUP.LIST_PRIORITY_SPLITTER,
|
||||
Storage.ConfigSections.Messages.GROUP.LIST_PRIORITY_GROUPS
|
||||
);
|
||||
|
||||
String message = StringUtils.replace(groupsPriorityListMessage,
|
||||
"%size%", String.valueOf(GroupManager.getGroups().size()),
|
||||
"%groups%", groupsPriorityListMessage
|
||||
);
|
||||
|
||||
sender.sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
return args.length < 2 ? GroupManager.getGroupNames() : null;
|
||||
}
|
||||
|
||||
private String buildGroupPriorityMessage(List<Group> list, String splitter, String format) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
boolean end;
|
||||
Group group;
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
end = i >= list.size() - 1;
|
||||
group = list.get(i);
|
||||
|
||||
builder.append(format.replace("%group%", group.getGroupName()).replace("%priority%", String.valueOf(group.getPriority())));
|
||||
if (!end && splitter != null) builder.append(splitter);
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package de.rayzs.pat.plugin.process.impl.local.system;
|
||||
|
||||
import de.rayzs.pat.api.command.ProCommand;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class NotifyCommand extends ProCommand {
|
||||
|
||||
public NotifyCommand() {
|
||||
super(
|
||||
"notify",
|
||||
""
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
|
||||
boolean backend = Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED && !Reflection.isProxyServer();
|
||||
|
||||
if (backend) {
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.NO_PROXY.MESSAGE);
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean enabled = false;
|
||||
|
||||
if (sender.isConsole()) {
|
||||
enabled = Storage.SEND_CONSOLE_NOTIFICATION;
|
||||
Storage.SEND_CONSOLE_NOTIFICATION = !Storage.SEND_CONSOLE_NOTIFICATION;
|
||||
} else {
|
||||
enabled = Storage.NOTIFY_PLAYERS.contains(sender.getUniqueId());
|
||||
|
||||
if (enabled)
|
||||
Storage.NOTIFY_PLAYERS.remove(sender.getUniqueId());
|
||||
else
|
||||
Storage.NOTIFY_PLAYERS.add(sender.getUniqueId());
|
||||
}
|
||||
|
||||
String message = enabled
|
||||
? Storage.ConfigSections.Messages.NOTIFICATION.DISABLED
|
||||
: Storage.ConfigSections.Messages.NOTIFICATION.ENABLED;
|
||||
|
||||
sender.sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package de.rayzs.pat.plugin.process.impl.local.system;
|
||||
|
||||
import de.rayzs.pat.api.command.ProCommand;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import java.util.*;
|
||||
|
||||
public class PostDebugCommand extends ProCommand {
|
||||
|
||||
public PostDebugCommand() {
|
||||
super(
|
||||
"postdebug",
|
||||
""
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
|
||||
try {
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.POST_DEBUG.SUCCESS.replace("%link%", Objects.requireNonNull(Logger.post())));
|
||||
} catch (Exception exception) {
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.POST_DEBUG.FAILED);
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package de.rayzs.pat.plugin.process.impl.local.system;
|
||||
|
||||
import de.rayzs.pat.api.communication.BackendUpdater;
|
||||
import de.rayzs.pat.api.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.utils.configuration.updater.ConfigUpdater;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
import de.rayzs.pat.api.command.ProCommand;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import java.util.List;
|
||||
|
||||
public class ReloadCommand extends ProCommand {
|
||||
|
||||
public ReloadCommand() {
|
||||
super(
|
||||
"reload",
|
||||
"rl"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
boolean proxy = Reflection.isProxyServer();
|
||||
boolean backend = Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED && !proxy;
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.RELOAD.LOADING);
|
||||
|
||||
Storage.loadAll(Reflection.isProxyServer() || !backend);
|
||||
CustomServerBrand.initialize();
|
||||
GroupManager.clearAllGroups();
|
||||
GroupManager.initialize();
|
||||
|
||||
if (!proxy) {
|
||||
BackendUpdater.stop();
|
||||
BackendUpdater.start();
|
||||
}
|
||||
|
||||
ConfigUpdater.broadcastMissingParts();
|
||||
|
||||
if (!backend) {
|
||||
Storage.handleChange();
|
||||
}
|
||||
|
||||
ConfigUpdater.initialize();
|
||||
Storage.getLoader().handleReload();
|
||||
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.RELOAD.DONE);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
package de.rayzs.pat.plugin.process.impl.server;
|
||||
|
||||
import de.rayzs.pat.api.command.ProCommand;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.api.storage.blacklist.impl.GeneralBlacklist;
|
||||
import de.rayzs.pat.api.storage.blacklist.impl.GroupBlacklist;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ServAddCommand extends ProCommand {
|
||||
|
||||
public ServAddCommand() {
|
||||
super(
|
||||
"add",
|
||||
""
|
||||
);
|
||||
|
||||
proxyOnly = true;
|
||||
serverCommand = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
|
||||
if (args.length < 2)
|
||||
return false;
|
||||
|
||||
String serverName = args[0];
|
||||
args = Arrays.copyOfRange(args, 1, args.length);
|
||||
|
||||
String fullString = String.join(" ", args);
|
||||
String command = fullString;
|
||||
|
||||
if (!command.startsWith("\"")) {
|
||||
command = args[0];
|
||||
} else {
|
||||
|
||||
command = command.substring(1);
|
||||
int lastIndex = command.indexOf("\"");
|
||||
|
||||
if (lastIndex == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
command = command.substring(0, lastIndex);
|
||||
|
||||
fullString = fullString.replace("\"" + command + "\"", ":::");
|
||||
args = fullString.split(" ");
|
||||
}
|
||||
|
||||
command = StringUtils.replaceTriggers(command, "", "\\.", "'", "\"");
|
||||
|
||||
if (command.isEmpty())
|
||||
return false;
|
||||
|
||||
final int length = args.length;
|
||||
|
||||
if (length == 1) {
|
||||
|
||||
GeneralBlacklist blacklist = Storage.Blacklist.getServerBlacklist(serverName);
|
||||
|
||||
boolean exist = command.contains(" ")
|
||||
? blacklist.getCommands().contains(command)
|
||||
: blacklist.isListed(command);
|
||||
|
||||
if (!exist) {
|
||||
blacklist.add(command).save();
|
||||
Storage.handleChange(serverName);
|
||||
}
|
||||
|
||||
String message = exist
|
||||
? Storage.ConfigSections.Messages.BLACKLIST.ADD_SERVER_FAILED
|
||||
: Storage.ConfigSections.Messages.BLACKLIST.ADD_SERVER_SUCCESS;
|
||||
|
||||
message = StringUtils.replace(message,
|
||||
"%command%", command,
|
||||
"%server%", serverName
|
||||
);
|
||||
|
||||
sender.sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
String groupName = args[1];
|
||||
Group group = GroupManager.getGroupByName(groupName);
|
||||
|
||||
if (group == null) {
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST_SERVER.replace("%group%", groupName));
|
||||
return true;
|
||||
}
|
||||
|
||||
GroupBlacklist groupBlacklist = group.getOrCreateGroupBlacklist(serverName);
|
||||
boolean exist = groupBlacklist != null && groupBlacklist.getCommands().contains(command);
|
||||
|
||||
if (!exist) {
|
||||
group.add(command, serverName);
|
||||
Storage.handleChange(serverName);
|
||||
}
|
||||
|
||||
String message = exist
|
||||
? Storage.ConfigSections.Messages.GROUP.ADD_SERVER_FAILED
|
||||
: Storage.ConfigSections.Messages.GROUP.ADD_SERVER_SUCCESS;
|
||||
|
||||
message = StringUtils.replace(message,
|
||||
"%group%", groupName,
|
||||
"%command%", command,
|
||||
"%server%", serverName
|
||||
);
|
||||
|
||||
sender.sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
|
||||
if (args.length < 2) {
|
||||
return Storage.getServers(true);
|
||||
}
|
||||
|
||||
args = Arrays.copyOfRange(args, 1, args.length);
|
||||
|
||||
String fullString = String.join(" ", args);
|
||||
String command = fullString;
|
||||
|
||||
if (args[0].startsWith("\"")) {
|
||||
command = command.length() == 1 ? "" : command.substring(1, command.length() - 1);
|
||||
|
||||
int lastIndex = command.indexOf("\"");
|
||||
|
||||
if (lastIndex == -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
command = command.substring(0, lastIndex);
|
||||
args = Arrays.copyOfRange(args, command.split(" ").length - 1, args.length);
|
||||
}
|
||||
|
||||
final int length = args.length;
|
||||
return length == 2 ? GroupManager.getGroupNames() : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package de.rayzs.pat.plugin.process.impl.server;
|
||||
|
||||
import de.rayzs.pat.api.command.ProCommand;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.utils.ExpireCache;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ServClearCommand extends ProCommand {
|
||||
|
||||
private final ExpireCache<UUID, String> CONFIRMATION = new ExpireCache<>(4, TimeUnit.SECONDS);
|
||||
|
||||
public ServClearCommand() {
|
||||
super(
|
||||
"clear",
|
||||
"clr"
|
||||
);
|
||||
|
||||
proxyOnly = true;
|
||||
serverCommand = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
|
||||
if (args.length < 1)
|
||||
return false;
|
||||
|
||||
String serverName = args[0];
|
||||
args = Arrays.copyOfRange(args, 1, args.length);
|
||||
|
||||
if (args.length == 0) {
|
||||
final String confirmationString = "clear";
|
||||
|
||||
if (!CONFIRMATION.getOrDefault(sender.getUniqueId(), "").equals(confirmationString)) {
|
||||
CONFIRMATION.put(sender.getUniqueId(), confirmationString);
|
||||
sender.sendMessage(
|
||||
Storage.ConfigSections.Messages.BLACKLIST.CLEAR_SERVER_CONFIRM
|
||||
.replace("%server%", serverName)
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Storage.Blacklist.getServerBlacklist(serverName).clear().save();
|
||||
Storage.handleChange(serverName);
|
||||
|
||||
CONFIRMATION.remove(sender.getUniqueId());
|
||||
|
||||
sender.sendMessage(
|
||||
Storage.ConfigSections.Messages.BLACKLIST.CLEAR_SERVER
|
||||
.replace("%server%", serverName)
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
String groupName = args[0];
|
||||
Group group = GroupManager.getGroupByName(groupName);
|
||||
|
||||
if (group == null) {
|
||||
|
||||
sender.sendMessage(
|
||||
Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST_SERVER
|
||||
.replace("%group%", groupName)
|
||||
.replace("%server%", serverName)
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
groupName = group.getGroupName();
|
||||
|
||||
final String confirmationString = "clear " + groupName;
|
||||
|
||||
if (!CONFIRMATION.getOrDefault(sender.getUniqueId(), "").equals(confirmationString)) {
|
||||
|
||||
CONFIRMATION.put(sender.getUniqueId(), confirmationString);
|
||||
|
||||
sender.sendMessage(
|
||||
Storage.ConfigSections.Messages.GROUP.CLEAR_SERVER_CONFIRM
|
||||
.replace("%group%", groupName)
|
||||
.replace("%server%", serverName)
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
group.clear(serverName);
|
||||
Storage.handleChange(serverName);
|
||||
|
||||
CONFIRMATION.remove(sender.getUniqueId());
|
||||
|
||||
sender.sendMessage(
|
||||
Storage.ConfigSections.Messages.GROUP.CLEAR_SERVER
|
||||
.replace("%group%", groupName)
|
||||
.replace("%server%", serverName)
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
final int length = args.length;
|
||||
return length < 2 ? Storage.Blacklist.getBlacklists().stream().map(Map.Entry::getKey).toList() :
|
||||
length < 3 ? GroupManager.getGroupNames() : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
package de.rayzs.pat.plugin.process.impl.server;
|
||||
|
||||
import de.rayzs.pat.api.command.ProCommand;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.api.storage.blacklist.impl.GeneralBlacklist;
|
||||
import de.rayzs.pat.api.storage.blacklist.impl.GroupBlacklist;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ServRemoveCommand extends ProCommand {
|
||||
|
||||
public ServRemoveCommand() {
|
||||
super(
|
||||
"remove",
|
||||
"rem", "rm"
|
||||
);
|
||||
|
||||
proxyOnly = true;
|
||||
serverCommand = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
|
||||
if (args.length < 2)
|
||||
return false;
|
||||
|
||||
String serverName = args[0];
|
||||
args = Arrays.copyOfRange(args, 1, args.length);
|
||||
|
||||
String fullString = String.join(" ", args);
|
||||
String command = fullString;
|
||||
|
||||
if (!command.startsWith("\"")) {
|
||||
command = args[0];
|
||||
} else {
|
||||
|
||||
command = command.substring(1);
|
||||
int lastIndex = command.indexOf("\"");
|
||||
|
||||
if (lastIndex == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
command = command.substring(0, lastIndex);
|
||||
|
||||
fullString = fullString.replace("\"" + command + "\"", ":::");
|
||||
args = fullString.split(" ");
|
||||
}
|
||||
|
||||
command = StringUtils.replaceTriggers(command, "", "\\.", "'", "\"");
|
||||
|
||||
if (command.isEmpty())
|
||||
return false;
|
||||
|
||||
final int length = args.length;
|
||||
|
||||
if (length == 1) {
|
||||
|
||||
GeneralBlacklist blacklist = Storage.Blacklist.getServerBlacklist(serverName);
|
||||
|
||||
boolean exist = command.contains(" ")
|
||||
? blacklist.getCommands().contains(command)
|
||||
: blacklist.isListed(command);
|
||||
|
||||
if (exist) {
|
||||
blacklist.remove(command).save();
|
||||
Storage.handleChange(serverName);
|
||||
}
|
||||
|
||||
String message = !exist
|
||||
? Storage.ConfigSections.Messages.BLACKLIST.REMOVE_SERVER_FAILED
|
||||
: Storage.ConfigSections.Messages.BLACKLIST.REMOVE_SERVER_SUCCESS;
|
||||
|
||||
message = StringUtils.replace(message,
|
||||
"%command%", command,
|
||||
"%server%", serverName
|
||||
);
|
||||
|
||||
sender.sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
String groupName = args[1];
|
||||
Group group = GroupManager.getGroupByName(groupName);
|
||||
|
||||
if (group == null) {
|
||||
|
||||
sender.sendMessage(
|
||||
Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST_SERVER
|
||||
.replace("%group%", groupName)
|
||||
.replace("%server%", serverName)
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
GroupBlacklist groupBlacklist = group.getOrCreateGroupBlacklist(serverName);
|
||||
boolean exist = groupBlacklist != null && groupBlacklist.getCommands().contains(command);
|
||||
|
||||
if (exist) {
|
||||
group.remove(command, serverName);
|
||||
Storage.handleChange(serverName);
|
||||
}
|
||||
|
||||
String message = !exist
|
||||
? Storage.ConfigSections.Messages.GROUP.REMOVE_SERVER_FAILED
|
||||
: Storage.ConfigSections.Messages.GROUP.REMOVE_SERVER_SUCCESS;
|
||||
|
||||
message = StringUtils.replace(message,
|
||||
"%group%", groupName,
|
||||
"%command%", command,
|
||||
"%server%", serverName
|
||||
);
|
||||
|
||||
sender.sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
if (args.length < 2) {
|
||||
return Storage.Blacklist.getBlacklists().stream().map(Map.Entry::getKey).toList();
|
||||
}
|
||||
|
||||
String serverName = args[0];
|
||||
args = Arrays.copyOfRange(args, 1, args.length);
|
||||
|
||||
String fullString = String.join(" ", args);
|
||||
String command = fullString;
|
||||
|
||||
if (args[0].startsWith("\"")) {
|
||||
command = command.length() == 1 ? "" : command.substring(1, command.length() - 1);
|
||||
int lastIndex = command.indexOf("\"");
|
||||
|
||||
if (lastIndex == -1) {
|
||||
|
||||
if (args.length == 1) {
|
||||
Stream<String> stream = new ArrayList<>(Storage.Blacklist.getServerBlacklist(serverName).getCommands())
|
||||
.stream()
|
||||
.filter(str -> str.contains(" "));
|
||||
|
||||
if (!Reflection.isProxyServer())
|
||||
stream = stream.map(str -> "\"" + str + "\"");
|
||||
|
||||
return stream.toList();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
command = command.substring(0, lastIndex);
|
||||
args = Arrays.copyOfRange(args, command.split(" ").length - 1, args.length);
|
||||
}
|
||||
|
||||
final int length = args.length;
|
||||
return length == 2 ? GroupManager.getGroupNames() : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package de.rayzs.pat.plugin.process.impl.server.list;
|
||||
|
||||
import de.rayzs.pat.api.command.ProCommand;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.api.storage.blacklist.impl.GeneralBlacklist;
|
||||
import de.rayzs.pat.utils.sender.CommandSender;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ServListCommand extends ProCommand {
|
||||
|
||||
public ServListCommand() {
|
||||
super(
|
||||
"list",
|
||||
"ls"
|
||||
);
|
||||
|
||||
proxyOnly = true;
|
||||
serverCommand = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
|
||||
if (args.length < 1)
|
||||
return false;
|
||||
|
||||
String serverName = args[0];
|
||||
args = Arrays.copyOfRange(args, 1, args.length);
|
||||
|
||||
if (args.length == 0) {
|
||||
|
||||
GeneralBlacklist blacklist = Storage.Blacklist.getServerBlacklist(serverName);
|
||||
|
||||
String commandsListMessage = StringUtils.getStringList(
|
||||
blacklist.getCommands(),
|
||||
Storage.ConfigSections.Messages.BLACKLIST.LIST_SERVER_SPLITTER
|
||||
);
|
||||
|
||||
String message = Storage.ConfigSections.Messages.BLACKLIST.LIST_SERVER_MESSAGE;
|
||||
message = StringUtils.replace(message,
|
||||
"%size%", String.valueOf(blacklist.getCommands().size()),
|
||||
"%commands%", commandsListMessage,
|
||||
"%server%", serverName
|
||||
);
|
||||
|
||||
sender.sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
String groupName = args[0];
|
||||
Group group = GroupManager.getGroupByName(groupName);
|
||||
|
||||
if (group == null) {
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.DOES_NOT_EXIST_SERVER.replace("%group%", groupName));
|
||||
return true;
|
||||
}
|
||||
|
||||
String commandsListMessage = StringUtils.getStringList(
|
||||
group.getCommands(serverName),
|
||||
Storage.ConfigSections.Messages.GROUP.LIST_SERVER_SPLITTER
|
||||
);
|
||||
|
||||
String message = Storage.ConfigSections.Messages.GROUP.LIST_SERVER_MESSAGE;
|
||||
message = StringUtils.replace(message,
|
||||
"%group%", groupName,
|
||||
"%size%", String.valueOf(group.getCommands(serverName).size()),
|
||||
"%commands%", commandsListMessage,
|
||||
"%server%", serverName
|
||||
);
|
||||
|
||||
sender.sendMessage(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
final int length = args.length;
|
||||
return length < 2 ? Storage.Blacklist.getBlacklists().stream().map(Map.Entry::getKey).toList() :
|
||||
length < 3 ? GroupManager.getGroupNames() : null;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package de.rayzs.pat.plugin.skript;
|
||||
|
||||
import ch.njol.skript.*;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import de.rayzs.pat.api.event.events.bukkit.ExecuteCommandEvent;
|
||||
import de.rayzs.pat.plugin.skript.impl.events.ExecuteCommandSkriptEvent;
|
||||
|
||||
public class PATSkriptAddon {
|
||||
|
||||
public static SkriptAddon ADDON;
|
||||
|
||||
public static void initialize(JavaPlugin javaPlugin) {
|
||||
ADDON = Skript.getAddon(javaPlugin);
|
||||
|
||||
Skript.registerEvent("PAT Command Execution", ExecuteCommandSkriptEvent.class, ExecuteCommandEvent.class, "if [command] is (blocked|cancelled|not blocked|not cancelled)");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loaded 100 of 155 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user