Compare commits

..
39 Commits
Author SHA1 Message Date
RayzsYT 53b1949bd8 Add multiple triggers per stack 2024-11-03 04:31:28 +01:00
RayzsYT cca27ebc8c Enabled Folia support 2024-11-03 03:39:45 +01:00
RayzsYT 670f2003fc Added multiple customizable response messages 2024-11-03 03:36:00 +01:00
RayzsYT b65e4a0271 Removed unused variable 2024-11-03 03:17:05 +01:00
RayzsYT d3eae2512a Changed plugin description 2024-11-03 03:16:13 +01:00
RayzsYT 2d32d09c1b Changed plugin description 2024-11-03 03:16:00 +01:00
RayzsYT 95f2436459 Imports cleanup 2024-11-03 03:14:53 +01:00
RayzsYT fbf4a553ce Remove debug messages 2024-11-03 03:09:17 +01:00
RayzsYT 032fb229cf Add Debug Messages 2024-10-24 22:59:01 +02:00
RayzsYT 4e4bcdf2b1 Removed debug message 2024-10-20 03:33:00 +02:00
RayzsYT b31653c30f Improved Subcommand functions 2024-10-20 03:30:56 +02:00
RayzsYT 2abfa75987 Improved Subcommand functions 2024-10-20 02:48:04 +02:00
RayzsYT 6c0188e38f Improved Subcommand functions & added %online_players% placeholder 2024-10-20 00:14:29 +02:00
RayzsYT 8091ebbea4 Updated PAT API version 2024-10-19 21:06:25 +02:00
RayzsYT 92c84ff2ea Add ServerPlayersChange event 2024-10-19 21:06:07 +02:00
RayzsYT 2408bf2267 Add PlayerNames methods 2024-10-19 21:05:51 +02:00
RayzsYT fe1e7338cf Added getPlayerNames method 2024-10-19 19:37:43 +02:00
RayzsYT efeb5c5d2e Improve 2024-09-29 17:17:39 +02:00
RayzsYT 85ea7d8672 Change 2024-09-29 15:37:51 +02:00
RayzsYT ca2f139542 Add Method 2024-09-29 14:45:59 +02:00
RayzsYT c1744cd4c9 Shorten Code 2024-09-29 02:03:28 +02:00
RayzsYT 1ba61f2cf9 Improve 2024-09-29 02:01:44 +02:00
RayzsYT c3c5dcf473 Merge remote-tracking branch 'origin/addons' into addons 2024-09-04 18:25:03 +02:00
RayzsYT 268ccd5938 Experimental 2024-09-04 18:24:38 +02:00
Alihan 81f58966b0 Delete subarguments/target/classes/de/rayzs/pat/addon directory 2024-08-23 13:53:48 +02:00
RayzsYT 739527af74 Improve Check 2024-08-23 13:25:58 +02:00
RayzsYT 918da7f49e Minor Improvements 2024-08-23 04:23:41 +02:00
RayzsYT 3b786a71fd Minor Improvements 2024-08-23 03:50:14 +02:00
RayzsYT 3ca164e320 Minor Change 2024-08-23 03:44:11 +02:00
RayzsYT d417ee4132 Minor Improvement 2024-08-23 03:34:20 +02:00
RayzsYT d30c40a7c3 Improve Code Structure 2024-08-23 03:18:06 +02:00
RayzsYT 596476c7a8 Sort Code 2024-08-23 03:08:13 +02:00
RayzsYT d236baae0d Improve 2024-08-23 02:12:01 +02:00
RayzsYT 812146a669 Improve 2024-08-23 01:54:21 +02:00
RayzsYT 314c5237a1 Init 2024-08-23 01:06:20 +02:00
Alihan bc8b03a8bc Delete subarguments/target directory 2024-08-22 21:04:25 +02:00
Alihan 1500c5e93c init 2024-08-22 20:52:33 +02:00
Alihan 08685ff098 Delete pom.xml 2024-08-22 20:48:10 +02:00
Alihan 057e3826e8 Delete src/main directory 2024-08-22 20:47:32 +02:00
250 changed files with 563 additions and 21527 deletions

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2025 Alihan
Copyright (c) 2024 Alihan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
+10 -317
View File
@@ -4,325 +4,18 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.rayzs.pat</groupId>
<artifactId>ProAntiTab</artifactId>
<version>2.1.2</version>
<groupId>de.rayzs.controlplayer</groupId>
<artifactId>ProAntiTab-Addons</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>subarguments</module>
</modules>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>bungeecord-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>velocity</id>
<url>https://repo.velocitypowered.com/snapshots/</url>
</repository>
<repository>
<id>minecraft-libraries</id>
<name>Minecraft Libraries</name>
<url>https://libraries.minecraft.net/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<id>viaversion-repo</id>
<url>https://repo.viaversion.com</url>
</repository>
<repository>
<id>william278-velocity</id>
<name>William278</name>
<url>https://repo.william278.net/velocity</url>
</repository>
<repository>
<id>william278-papiproxybridge</id>
<name>William278</name>
<url>https://repo.william278.net/papiproxybridge</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>dev.folia</groupId>
<artifactId>folia-api</artifactId>
<version>1.20.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.19-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.2.0.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.20-R0.3-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-protocol</artifactId>
<version>1.16-R0.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>authlib</artifactId>
<version>4.0.43</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.ElgarL</groupId>
<artifactId>groupmanager</artifactId>
<version>3.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>brigadier</artifactId>
<version>1.1.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>datafixerupper</artifactId>
<version>6.0.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>logging</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-resolver-provider</artifactId>
<version>3.8.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-connector-basic</artifactId>
<version>1.7.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-http</artifactId>
<version>1.7.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.18.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.github.waterfallmc</groupId>
<artifactId>waterfall-api</artifactId>
<version>1.20-R0.3-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.william278</groupId>
<artifactId>papiproxybridge</artifactId>
<version>1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>3.1.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-proxy</artifactId>
<version>3.3.0-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-proxy-log4j2-plugin</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.sonatype.sisu</groupId>
<artifactId>sisu-guice</artifactId>
<version>2.1.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spongepowered</groupId>
<artifactId>configurate-hocon</artifactId>
<version>4.1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.25.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-api</artifactId>
<version>4.25.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-api</artifactId>
<version>4.3.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-bungeecord</artifactId>
<version>4.3.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-bukkit</artifactId>
<version>4.3.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.luckperms</groupId>
<artifactId>api</artifactId>
<version>5.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.viaversion</groupId>
<artifactId>viaversion-api</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>IgnoreThisJar</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>ProAntiTab</finalName>
<shadedArtifactAttached>false</shadedArtifactAttached>
<shadedClassifierName>shaded</shadedClassifierName>
<artifactSet>
<excludes/>
</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>
</project>
@@ -1,24 +0,0 @@
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;
public class CustomServerBrand {
public static final String CHANNEL_NAME = Reflection.getMinor() < 13 ? "MC|Brand" : "minecraft:brand";
private static final ServerBrand SERVER_BRAND = Reflection.isVelocityServer() ? new VelocityServerBrand() : Reflection.isProxyServer() ? new BungeeServerBrand() : new BukkitServerBrand();
public static void initialize() { refreshTask(); }
public static void refreshTask() { SERVER_BRAND.initializeTask(); }
public static void preparePlayer(Object playerObj) { SERVER_BRAND.preparePlayer(playerObj); }
public static void sendBrandToPlayer(Object playerObj) { SERVER_BRAND.send(playerObj); }
public static PacketUtils.BrandManipulate createBrandPacket(Object playerObj) { return SERVER_BRAND.createPacket(playerObj); }
public static boolean isEnabled() { return Storage.ConfigSections.Settings.CUSTOM_BRAND.ENABLED; }
public static boolean isBrandTag(String tag) {
return tag.equals("MC|Brand") || tag.equals("minecraft:brand");
}
}
@@ -1,10 +0,0 @@
package de.rayzs.pat.api.brand;
import de.rayzs.pat.utils.PacketUtils;
public interface ServerBrand {
void preparePlayer(Object playerObj);
void send(Object playerObj);
PacketUtils.BrandManipulate createPacket(Object playerObj);
void initializeTask();
}
@@ -1,133 +0,0 @@
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;
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 org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import de.rayzs.pat.utils.*;
import java.lang.reflect.*;
import org.bukkit.*;
import java.util.*;
public class BukkitServerBrand implements ServerBrand {
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, NO_PREP_CHANNELS = false;
private static Class<?> brandPayloadClass, clientBoundCustomPacketPayloadPacketClass, customPacketPayloadPacketClass;
@Override
public void initializeTask() {
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");
if (clientBoundCustomPacketPayloadPacketClass == null)
clientBoundCustomPacketPayloadPacketClass = Reflection.getClass("net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket");
if (customPacketPayloadPacketClass == null)
customPacketPayloadPacketClass = Reflection.getClass("net.minecraft.network.protocol.common.custom.CustomPacketPayload");
}
Bukkit.getOnlinePlayers().forEach(this::preparePlayer);
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);
SERVER.getMessenger().registerOutgoingPluginChannel(BukkitLoader.getPlugin(), CustomServerBrand.CHANNEL_NAME);
INITIALIZED = true;
} catch (Exception exception) {
exception.printStackTrace();
}
if(TASK != null && TASK.isActive()) {
TASK.cancelTask();
TASK = null;
}
if(!Storage.ConfigSections.Settings.CUSTOM_BRAND.ENABLED) return;
if(Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY == -1) {
BRAND = Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().get(0) + "§r";
PATScheduler.createAsyncScheduler(() -> {
Bukkit.getOnlinePlayers().forEach(this::send);
}, 1, 1);
} else {
AtomicInteger animationState = new AtomicInteger(0);
TASK = PATScheduler.createAsyncScheduler(() -> {
if (animationState.getAndIncrement() >= Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().size() - 1)
animationState.set(0);
BRAND = Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().get(animationState.get()) + "§r";
Bukkit.getOnlinePlayers().forEach(this::send);
}, 1, Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY);
}
}
@Override
public void preparePlayer(Object playerObj) {
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);
} catch (Exception exception) {
exception.printStackTrace();
}
}
@Override
public void send(Object playerObj) {
if(!(playerObj instanceof Player) || !Storage.ConfigSections.Settings.CUSTOM_BRAND.ENABLED) return;
Player player = (Player) playerObj;
String playerName = player.getName(), displayName = player.getDisplayName(), worldName = player.getWorld().getName(),
customBrand = BRAND.replace("%player%", playerName).replace("%displayname%", displayName).replace("%world%", worldName);
if(!Reflection.isWeird()) {
PacketUtils.BrandManipulate serverBrand = new PacketUtils.BrandManipulate(MessageTranslator.replaceMessage(player, customBrand));
player.sendPluginMessage(BukkitLoader.getPlugin(), CustomServerBrand.CHANNEL_NAME, serverBrand.getBytes());
return;
}
try {
Channel channel = BukkitPacketAnalyzer.INJECTED_PLAYERS.get(player.getUniqueId());
if(channel == null) return;
Object brandPayloadObj = brandPayloadClass.getDeclaredConstructor(String.class).newInstance(MessageTranslator.replaceMessage(player, customBrand)),
customPacketPayloadPacket = clientBoundCustomPacketPayloadPacketClass.getDeclaredConstructor(customPacketPayloadPacketClass).newInstance(brandPayloadObj);
channel.pipeline().writeAndFlush(customPacketPayloadPacket);
} catch (Exception exception) {
exception.printStackTrace();
}
}
@Override
public PacketUtils.BrandManipulate createPacket(Object playerObj) {
return null;
}
}
@@ -1,73 +0,0 @@
package de.rayzs.pat.api.brand.impl;
import de.rayzs.pat.utils.message.MessageTranslator;
import net.md_5.bungee.api.scheduler.ScheduledTask;
import net.md_5.bungee.protocol.ProtocolConstants;
import java.util.concurrent.atomic.AtomicInteger;
import de.rayzs.pat.api.brand.ServerBrand;
import net.md_5.bungee.api.connection.*;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.plugin.BungeeLoader;
import net.md_5.bungee.api.ProxyServer;
import de.rayzs.pat.utils.PacketUtils;
import java.util.concurrent.TimeUnit;
public class BungeeServerBrand implements ServerBrand {
private static final ProxyServer SERVER = BungeeLoader.getPlugin().getProxy();
private static ScheduledTask TASK;
private static String BRAND = Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().get(0);
public BungeeServerBrand() { }
@Override
public void initializeTask() {
if(TASK != null) TASK.cancel();
if(!Storage.ConfigSections.Settings.CUSTOM_BRAND.ENABLED) return;
if(Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY == -1) {
BRAND = MessageTranslator.replaceMessage(Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().get(0)) + "§r";
SERVER.getPlayers().forEach(this::send);
} else {
AtomicInteger animationState = new AtomicInteger(0);
TASK = SERVER.getScheduler().schedule(BungeeLoader.getPlugin(), () -> {
if (animationState.getAndIncrement() >= Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().size() - 1)
animationState.set(0);
BRAND = MessageTranslator.replaceMessage(Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().get(animationState.get())) + "§r";
SERVER.getPlayers().forEach(this::send);
}, 1, Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY, TimeUnit.MILLISECONDS);
}
}
@Override
public void preparePlayer(Object playerObj) { }
@Override
public void send(Object playerObj) {
if (!(playerObj instanceof ProxiedPlayer) || !Storage.ConfigSections.Settings.CUSTOM_BRAND.ENABLED) return;
ProxiedPlayer player = (ProxiedPlayer) playerObj;
String serverName = "", playerName = player.getName(), customBrand;
Server server = player.getServer();
if(server != null) serverName = server.getInfo().getName();
customBrand = BRAND.replace("%player%", playerName).replace("%server%", serverName);
PacketUtils.BrandManipulate serverBrand = new PacketUtils.BrandManipulate(customBrand);
String brand = player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_13 ? "minecraft:brand" : "MC|Brand";
player.sendData(brand, serverBrand.getBytes());
}
@Override
public PacketUtils.BrandManipulate createPacket(Object playerObj) {
if (!(playerObj instanceof ProxiedPlayer) || !Storage.ConfigSections.Settings.CUSTOM_BRAND.ENABLED) return null;
ProxiedPlayer player = (ProxiedPlayer) playerObj;
String serverName = "", playerName = player.getName(), customBrand;
Server server = player.getServer();
if(server != null) serverName = server.getInfo().getName();
customBrand = BRAND.replace("%player%", playerName).replace("%server%", serverName);
return new PacketUtils.BrandManipulate(customBrand);
}
}
@@ -1,104 +0,0 @@
package de.rayzs.pat.api.brand.impl;
import com.velocitypowered.api.scheduler.ScheduledTask;
import de.rayzs.pat.utils.message.MessageTranslator;
import net.md_5.bungee.protocol.ProtocolConstants;
import java.util.concurrent.atomic.AtomicInteger;
import de.rayzs.pat.api.brand.ServerBrand;
import de.rayzs.pat.plugin.VelocityLoader;
import de.rayzs.pat.api.storage.Storage;
import com.velocitypowered.api.proxy.*;
import java.util.concurrent.TimeUnit;
import java.lang.reflect.Method;
import io.netty.buffer.ByteBuf;
import de.rayzs.pat.utils.*;
import java.util.Optional;
public class VelocityServerBrand implements ServerBrand {
private static final ProxyServer SERVER = VelocityLoader.getServer();
private static Class<?> pluginMessagePacketClass, minecraftConnectionClass, connectedPlayerConnectionClass;
private static Method connectionMethod;
private static ScheduledTask TASK;
private static String BRAND = Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().get(0);
@Override
public void initializeTask() {
if(TASK != null) TASK.cancel();
if(!Storage.ConfigSections.Settings.CUSTOM_BRAND.ENABLED) return;
if(pluginMessagePacketClass == null)
pluginMessagePacketClass = Reflection.getClass("com.velocitypowered.proxy.protocol.packet.PluginMessagePacket");
if(minecraftConnectionClass == null)
minecraftConnectionClass = Reflection.getClass("com.velocitypowered.proxy.connection.MinecraftConnection");
if(connectedPlayerConnectionClass == null)
connectedPlayerConnectionClass = Reflection.getClass("com.velocitypowered.proxy.connection.client.ConnectedPlayer");
if(connectionMethod == null)
connectionMethod = Reflection.getMethodByName(connectedPlayerConnectionClass, "getConnection");
if(Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY == -1) {
BRAND = MessageTranslator.replaceMessage(Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().get(0)) + "§r";
SERVER.getAllPlayers().forEach(this::send);
} else {
AtomicInteger animationState = new AtomicInteger(0);
TASK = SERVER.getScheduler().buildTask(VelocityLoader.getInstance(), () -> {
if (animationState.getAndIncrement() >= Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().size() - 1)
animationState.set(0);
BRAND = MessageTranslator.replaceMessage(Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().get(animationState.get())) + "§r";
SERVER.getAllPlayers().forEach(this::send);
}).repeat(Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY, TimeUnit.MILLISECONDS).schedule();
}
}
@Override
public void preparePlayer(Object playerObj) { }
@Override
public void send(Object playerObj) {
if (!(playerObj instanceof Player) || !Storage.ConfigSections.Settings.CUSTOM_BRAND.ENABLED) return;
try {
Player player = (Player) playerObj;
Object connectedPlayerObj = connectedPlayerConnectionClass.cast(player),
minecraftConnectionObj = connectionMethod.invoke(connectedPlayerObj);
String serverName = "", playerName = player.getUsername(), customBrand;
Optional<ServerConnection> serverConnection = player.getCurrentServer();
if(serverConnection.isPresent()) serverName = serverConnection.get().getServerInfo().getName();
customBrand = BRAND.replace("%player%", playerName).replace("%server%", serverName).replace("%ping%", String.valueOf(player.getPing()));
PacketUtils.BrandManipulate serverBrand = new PacketUtils.BrandManipulate(customBrand, false);
String brand = player.getProtocolVersion().getProtocol() >= ProtocolConstants.MINECRAFT_1_13 ? "minecraft:brand" : "MC|Brand";
Object pluginMessagePacket = pluginMessagePacketClass.getConstructor(String.class, ByteBuf.class).newInstance(brand, serverBrand.getByteBuf());
Reflection.getMethodsByParameterAndName(minecraftConnectionObj, "write", Object.class).get(0).invoke(minecraftConnectionObj, pluginMessagePacket);
} catch (Exception exception) {
exception.printStackTrace();
}
}
@Override
public PacketUtils.BrandManipulate createPacket(Object playerObj) {
if (!(playerObj instanceof Player) || !Storage.ConfigSections.Settings.CUSTOM_BRAND.ENABLED) return null;
try {
Player player = (Player) playerObj;
String serverName = "", playerName = player.getUsername(), customBrand;
Optional<ServerConnection> serverConnection = player.getCurrentServer();
if(serverConnection.isPresent()) serverName = serverConnection.get().getServerInfo().getName();
customBrand = BRAND.replace("%player%", playerName).replace("%server%", serverName).replace("%ping%", String.valueOf(player.getPing()));
return new PacketUtils.BrandManipulate(customBrand, false);
} catch (Exception exception) {
exception.printStackTrace();
}
return null;
}
}
@@ -1,47 +0,0 @@
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);
}
@@ -1,41 +0,0 @@
package de.rayzs.pat.api.communication;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.utils.scheduler.*;
import org.bukkit.Bukkit;
public class BackendUpdater {
private static PATSchedulerTask TASK;
public static void handle() {
if(isRunning() || !shouldRun() || !Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED) return;
start();
}
public static boolean isRunning() {
return TASK != null && TASK.isActive();
}
public static void start() {
if(isRunning()) return;
TASK = PATScheduler.createScheduler(() -> {
if (shouldRun())
Communicator.sendRequest();
else
stop();
}, 5, 20);
}
public static void stop() {
if(TASK == null || !TASK.isActive()) return;
TASK.cancelTask();
TASK = null;
}
private static boolean shouldRun() {
int onlinePlayerSize = Bukkit.getOnlinePlayers().size();
return onlinePlayerSize >= 1;
}
}
@@ -1,6 +0,0 @@
package de.rayzs.pat.api.communication;
public interface Client {
String CHANNEL_NAME = "pat:channel";
void send(Object packet);
}
@@ -1,253 +0,0 @@
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.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.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.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 UUID SERVER_ID = UUID.randomUUID();
public static final List<ClientInfo> CLIENTS = new ArrayList<>();
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);
}
public static void sendPacket(ClientInfo clientInfo, Object packet) {
clientInfo.sendBytes(CommunicationPackets.convertToBytes(packet));
}
public static void receiveInformation(String serverName, Object packet) {
ClientInfo client = getClientByName(serverName);
if (packet instanceof CommunicationPackets.RequestPacket) {
CommunicationPackets.RequestPacket requestPacket = (CommunicationPackets.RequestPacket) packet;
if (!requestPacket.isToken(Storage.TOKEN))
return;
if (client == null) {
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());
syncData(client.getId());
return;
}
if (packet instanceof CommunicationPackets.UpdateCommandsPacket) {
if (Reflection.isProxyServer())
return;
CommunicationPackets.UpdateCommandsPacket updateCommandsPacket = (CommunicationPackets.UpdateCommandsPacket) packet;
BukkitLoader.handleUpdateCommandsPacket(updateCommandsPacket);
}
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();
return;
}
if (packet instanceof CommunicationPackets.BackendDataPacket) {
CommunicationPackets.BackendDataPacket backendDataPacket = (CommunicationPackets.BackendDataPacket) packet;
if (!backendDataPacket.isToken(Storage.TOKEN))
return;
Storage.SERVER_NAME = backendDataPacket.getServerName();
return;
}
if (packet instanceof CommunicationPackets.FeedbackPacket) {
CommunicationPackets.FeedbackPacket feedbackPacket = (CommunicationPackets.FeedbackPacket) packet;
if (!feedbackPacket.isToken(Storage.TOKEN))
return;
String serverId = feedbackPacket.getServerId();
if (client == null) {
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;
client.setFeedback(true);
client.syncTime();
SERVER_DATA_SYNC_COUNT++;
CommunicationPackets.BackendDataPacket backendDataPacket = new CommunicationPackets.BackendDataPacket(Storage.TOKEN, serverId, serverName);
sendPacket(client, backendDataPacket);
return;
}
if (packet instanceof CommunicationPackets.PacketBundle) {
CommunicationPackets.PacketBundle packetBundle = (CommunicationPackets.PacketBundle) packet;
if (!packetBundle.isToken(Storage.TOKEN) || !packetBundle.isId(SERVER_ID.toString()))
return;
Storage.USE_VELOCITY = packetBundle.isVelocity();
LAST_BUKKIT_SYNC = System.currentTimeMillis();
BukkitLoader.synchronize(packetBundle);
}
}
public static void syncData() {
syncData(null);
}
public static void syncData(String serverId) {
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 = Math.max(0, SERVER_DATA_SYNC_COUNT -1);
}
CommunicationPackets.CommandsPacket commandsPacket = new CommunicationPackets.CommandsPacket();
CommunicationPackets.GroupsPacket groupsPacket;
CommunicationPackets.PacketBundle bundle;
List<String> commands = new ArrayList<>();
String 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.getServerBlacklists(clientInfo.getName());
serverBlacklists.stream().filter(serverBlacklist ->
serverBlacklist != null && serverBlacklist.getCommands() != null
).forEach(serverBlacklist ->
commands.addAll(serverBlacklist.getCommands())
);
}
final String serverName = tempServerName;
List<TinyGroup> groups = new ArrayList<>();
TinyGroup tinyGroup;
for (Group group : GroupManager.getGroups()) {
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))
tinyGroup.addAll(groupBlacklist.getCommands());
groups.add(tinyGroup);
}
groupsPacket = new CommunicationPackets.GroupsPacket(groups);
commandsPacket.setTurnBlacklistToWhitelist(Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED);
commandsPacket.setCommands(commands);
bundle = new CommunicationPackets.PacketBundle(Storage.TOKEN, serverId, commandsPacket, groupsPacket);
clientInfo.sendBytes(CommunicationPackets.convertToBytes(bundle));
PATEventHandler.callSentSyncEvents(bundle, serverName);
}
public static void sendRequest() {
if(System.currentTimeMillis() - LAST_SENT_REQUEST >= 5000) {
LAST_SENT_REQUEST = System.currentTimeMillis();
sendPacket(new CommunicationPackets.RequestPacket(Storage.TOKEN, SERVER_ID.toString()));
}
}
public static void sendPermissionReset() {
if(Reflection.isProxyServer())
sendPacket(new CommunicationPackets.ForcePermissionResetPacket(Storage.TOKEN));
}
public static void sendUpdateCommand() {
sendPacket(new CommunicationPackets.UpdateCommandsPacket(Storage.TOKEN));
}
public static void sendUpdateCommand(UUID targetUUID) {
sendPacket(new CommunicationPackets.UpdateCommandsPacket(Storage.TOKEN, targetUUID));
}
public static void sendFeedback() {
sendPacket(new CommunicationPackets.FeedbackPacket(Storage.TOKEN, SERVER_ID.toString()));
}
public static Client getClient() {
return CLIENT;
}
public static ClientInfo getClientById(String id) {
return CLIENTS.isEmpty() ? null : CLIENTS.stream().filter(client -> client != null && client.compareId(id)).findFirst().orElse(null);
}
public static ClientInfo getClientByName(String name) {
return CLIENTS.isEmpty() ? null : CLIENTS.stream().filter(client -> client != null && client.getName().equalsIgnoreCase(name)).findFirst().orElse(null);
}
}
@@ -1,58 +0,0 @@
package de.rayzs.pat.api.communication.client;
import de.rayzs.pat.utils.TimeConverter;
public abstract class ClientInfo {
private String id, name;
private boolean sentFeedback = false;
private long syncTime = System.currentTimeMillis();
public ClientInfo(String serverId) {
this.id = serverId;
}
public ClientInfo(String serverId, String name) {
this.id = serverId;
this.name = name;
}
public abstract void sendBytes(byte[] bytes);
public void setName(String name) {
this.name = name;
}
public void setId(String serverId) {
this.id = serverId;
}
public String getName() {
return name;
}
public boolean compareId(String id) {
return this.id.equals(id);
}
public void syncTime() {
syncTime = System.currentTimeMillis();
}
public String getSyncTime() {
return TimeConverter.calcAndGetTime(syncTime);
}
public void setFeedback(boolean state) {
this.sentFeedback = state;
}
public boolean hasSentFeedback() {
return sentFeedback;
}
public String getId() {
return id;
}
}
@@ -1,26 +0,0 @@
package de.rayzs.pat.api.communication.client.impl;
import de.rayzs.pat.api.communication.client.ClientInfo;
import de.rayzs.pat.api.communication.Client;
import net.md_5.bungee.api.ProxyServer;
public class BungeeClientInfo extends ClientInfo {
public BungeeClientInfo(String serverId) {
super(serverId);
}
public BungeeClientInfo(String serverId, String name) {
super(serverId, name);
}
@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)
);
}
}
@@ -1,25 +0,0 @@
package de.rayzs.pat.api.communication.client.impl;
import de.rayzs.pat.api.communication.impl.VelocityClient;
import de.rayzs.pat.api.communication.client.ClientInfo;
import de.rayzs.pat.plugin.VelocityLoader;
public class VelocityClientInfo extends ClientInfo {
public VelocityClientInfo(String serverId) {
super(serverId);
}
public VelocityClientInfo(String serverId, String name) {
super(serverId, name);
}
@Override
public void sendBytes(byte[] bytes) {
VelocityLoader.getServer().getAllServers().stream().filter(server ->
server.getServerInfo().getName().equalsIgnoreCase(getName())
).forEach(server ->
server.sendPluginMessage(VelocityClient.getIdentifier(), bytes)
);
}
}
@@ -1,49 +0,0 @@
package de.rayzs.pat.api.communication.impl;
import de.rayzs.pat.utils.scheduler.PATScheduler;
import org.bukkit.plugin.messaging.PluginMessageListener;
import de.rayzs.pat.utils.CommunicationPackets;
import de.rayzs.pat.plugin.BukkitLoader;
import de.rayzs.pat.api.communication.*;
import org.bukkit.entity.Player;
import org.bukkit.*;
public class BukkitClient implements Client, PluginMessageListener {
private static final Server SERVER = Bukkit.getServer();
public BukkitClient() {
SERVER.getMessenger().registerIncomingPluginChannel(BukkitLoader.getPlugin(), CHANNEL_NAME, this);
SERVER.getMessenger().registerOutgoingPluginChannel(BukkitLoader.getPlugin(), CHANNEL_NAME);
}
@Override
public void send(Object packet) {
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;
try {
Object packetObj = CommunicationPackets.buildFromBytes(bytes);
if (!CommunicationPackets.isPacket(packetObj))
return;
PATScheduler.createScheduler(() -> Communicator.receiveInformation("proxy", packetObj));
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
}
@@ -1,57 +0,0 @@
package de.rayzs.pat.api.communication.impl;
import net.md_5.bungee.api.event.PluginMessageEvent;
import de.rayzs.pat.utils.CommunicationPackets;
import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
import de.rayzs.pat.plugin.BungeeLoader;
import de.rayzs.pat.api.communication.*;
import net.md_5.bungee.api.ProxyServer;
public class BungeeClient implements Client, Listener {
private static final ProxyServer SERVER = ProxyServer.getInstance();
public BungeeClient() {
SERVER.registerChannel(CHANNEL_NAME);
SERVER.getPluginManager().registerListener(BungeeLoader.getPlugin(), this);
}
@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();
}
}
}
@EventHandler
public void onQueryReceive(PluginMessageEvent event) {
if (!event.getTag().equalsIgnoreCase(CHANNEL_NAME))
return;
try {
Object packetObj = CommunicationPackets.buildFromBytes(event.getData());
if (!CommunicationPackets.isPacket(packetObj))
return;
Server server = (Server) event.getSender();
Communicator.receiveInformation(server.getInfo().getName(), packetObj);
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
}
@@ -1,54 +0,0 @@
package de.rayzs.pat.api.communication.impl;
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
import com.velocitypowered.api.event.connection.PluginMessageEvent;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import de.rayzs.pat.utils.CommunicationPackets;
import com.velocitypowered.api.event.Subscribe;
import de.rayzs.pat.plugin.VelocityLoader;
import de.rayzs.pat.api.communication.*;
import com.velocitypowered.api.proxy.*;
public class VelocityClient implements Client {
private static final ProxyServer SERVER = VelocityLoader.getServer();
private static final MinecraftChannelIdentifier IDENTIFIER = MinecraftChannelIdentifier.from(CHANNEL_NAME);
public VelocityClient() {
SERVER.getChannelRegistrar().register(IDENTIFIER);
SERVER.getEventManager().register(VelocityLoader.getInstance(), this);
}
@Override
public void send(Object packet) {
for (RegisteredServer registeredServer : SERVER.getAllServers()) {
try {
registeredServer.sendPluginMessage(IDENTIFIER, CommunicationPackets.convertToBytes(packet));
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
}
@Subscribe
public void onQueryReceive(PluginMessageEvent event) {
if (event.getIdentifier() != IDENTIFIER)
return;
Object packetObj = CommunicationPackets.buildFromBytes(event.getData());
if (!CommunicationPackets.isPacket(packetObj))
return;
ServerConnection server = (ServerConnection) event.getSource();
Communicator.receiveInformation(server.getServerInfo().getName(), packetObj);
}
public static MinecraftChannelIdentifier getIdentifier() {
return IDENTIFIER;
}
}
@@ -1,24 +0,0 @@
package de.rayzs.pat.api.event;
public abstract class PATEvent<T> {
private final Object senderObj;
private boolean cancelled = false;
public PATEvent(Object senderObj) {
this.senderObj = senderObj;
}
public abstract void handle(T t);
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
public Object getSenderObj() {
return senderObj;
}
public boolean isCancelled() {
return cancelled;
}
}
@@ -1,200 +0,0 @@
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.*;
public class PATEventHandler {
private static List<PATEvent> EVENTS = new ArrayList<>();
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) {
ExecuteCommandEvent executeCommandEvent = (ExecuteCommandEvent) patEvent;
executeCommandEvent.handle(event);
}
}
return event;
}
public static FilteredSuggestionEvent callFilteredSuggestionEvents(Object senderObj, List<String> suggestions) {
FilteredSuggestionEvent event = EmptyEvent.createEmptyFilteredSuggestionEvent(senderObj, suggestions);
for (PATEvent patEvent : EVENTS) {
if(patEvent instanceof FilteredSuggestionEvent) {
FilteredSuggestionEvent filteredSuggestion = (FilteredSuggestionEvent) patEvent;
filteredSuggestion.handle(event);
}
}
return event;
}
public static FilteredTabCompletionEvent callFilteredTabCompletionEvents(Object senderObj, String cursor, List<String> completion) {
FilteredTabCompletionEvent event = EmptyEvent.createEmptyFilteredTabCompletion(senderObj, cursor, completion);
for (PATEvent patEvent : EVENTS) {
if(patEvent instanceof FilteredTabCompletionEvent) {
FilteredTabCompletionEvent filteredTabCompletion = (FilteredTabCompletionEvent) patEvent;
filteredTabCompletion.handle(event);
}
}
return event;
}
public static ServerPlayersChangeEvent callServerPlayersChangeEvents(Object senderObj, ServerPlayersChangeEvent.Type type) {
ServerPlayersChangeEvent event = EmptyEvent.createEmptyServerPlayersChangeEvent(senderObj, type);
for (PATEvent patEvent : EVENTS) {
if(patEvent instanceof ServerPlayersChangeEvent) {
ServerPlayersChangeEvent serverPlayersChangeEvent = (ServerPlayersChangeEvent) patEvent;
serverPlayersChangeEvent.handle(event);
}
}
return event;
}
public static UpdatePluginEvent callUpdatePluginEvents() {
UpdatePluginEvent event = EmptyEvent.createEmptyUpdatePluginEvent();
for (PATEvent patEvent : EVENTS) {
if(patEvent instanceof UpdatePluginEvent) {
UpdatePluginEvent updatePluginEvent = (UpdatePluginEvent) patEvent;
updatePluginEvent.handle(event);
}
}
return event;
}
public static UpdatePlayerCommandsEvent callUpdatePlayerCommandsEvents(Object playerObj, List<String> commands, boolean serverBased) {
UpdatePlayerCommandsEvent event = EmptyEvent.createEmptyUpdatePlayerCommandsEvent(playerObj, commands, serverBased);
for (PATEvent patEvent : EVENTS) {
if(patEvent instanceof UpdatePlayerCommandsEvent) {
UpdatePlayerCommandsEvent updatePlayerCommandsEvent = (UpdatePlayerCommandsEvent) patEvent;
updatePlayerCommandsEvent.handle(event);
}
}
return event;
}
public static SentSyncEvent callSentSyncEvents(CommunicationPackets.PacketBundle packetBundle, String serverName) {
SentSyncEvent event = EmptyEvent.createEmptySentSyncEvent(packetBundle, serverName);
for (PATEvent patEvent : EVENTS) {
if(patEvent instanceof SentSyncEvent) {
SentSyncEvent sentSyncEvent = (SentSyncEvent) patEvent;
sentSyncEvent.handle(event);
}
}
return event;
}
public static ReceiveSyncEvent callReceiveSyncEvents(CommunicationPackets.PacketBundle packetBundle) {
ReceiveSyncEvent event = EmptyEvent.createEmptyReceiveSyncEvent(packetBundle);
for (PATEvent patEvent : EVENTS) {
if(patEvent instanceof ReceiveSyncEvent) {
ReceiveSyncEvent proxySyncEvent = (ReceiveSyncEvent) patEvent;
proxySyncEvent.handle(event);
}
}
return event;
}
public static void register(PATEvent event) {
EVENTS.add(event);
}
public static void unregister(PATEvent event) {
EVENTS.remove(event);
}
public static class EmptyEvent {
public static ServerPlayersChangeEvent createEmptyServerPlayersChangeEvent(Object senderObj, ServerPlayersChangeEvent.Type type) {
return new ServerPlayersChangeEvent(senderObj, type) {
@Override
public void handle(ServerPlayersChangeEvent event) {
}
};
}
public static SentSyncEvent createEmptySentSyncEvent(CommunicationPackets.PacketBundle packetBundle, String serverName) {
return new SentSyncEvent(null, packetBundle, serverName) {
@Override
public void handle(SentSyncEvent event) {
}
};
}
public static ReceiveSyncEvent createEmptyReceiveSyncEvent(CommunicationPackets.PacketBundle packetBundle) {
return new ReceiveSyncEvent(null, packetBundle) {
@Override
public void handle(ReceiveSyncEvent event) {
}
};
}
public static UpdatePlayerCommandsEvent createEmptyUpdatePlayerCommandsEvent(Object playerObj, List<String> commands, boolean serverBased) {
return new UpdatePlayerCommandsEvent(playerObj, commands, serverBased) {
@Override
public void handle(UpdatePlayerCommandsEvent event) {
}
};
}
public static UpdatePluginEvent createEmptyUpdatePluginEvent() {
return new UpdatePluginEvent(null) {
@Override
public void handle(UpdatePluginEvent event) {
}
};
}
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) {
}
};
}
public static FilteredSuggestionEvent createEmptyFilteredSuggestionEvent(Object senderObj, List<String> suggestions) {
return new FilteredSuggestionEvent(senderObj, suggestions) {
@Override
public void handle(FilteredSuggestionEvent event) {
}
};
}
public static FilteredTabCompletionEvent createEmptyFilteredTabCompletion(Object senderObj, String cursor, List<String> completion) {
return new FilteredTabCompletionEvent(senderObj, cursor, completion) {
@Override
public void handle(FilteredTabCompletionEvent event) {
}
};
}
}
}
@@ -1,43 +0,0 @@
package de.rayzs.pat.api.event.events;
import de.rayzs.pat.api.event.PATEvent;
public abstract class ExecuteCommandEvent extends PATEvent<ExecuteCommandEvent> {
private final String command;
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, boolean notify) {
super(senderObj);
this.blocked = blocked;
this.command = command;
this.notify = notify;
}
public void setDoesNotify(boolean notify) {
this.notify = notify;
}
public String getCommand() {
return command;
}
public boolean isBlocked() {
return blocked;
}
public boolean doesNotify() {
return notify;
}
public void setBlocked(boolean blocked) {
this.blocked = blocked;
}
}
@@ -1,27 +0,0 @@
package de.rayzs.pat.api.event.events;
import de.rayzs.pat.api.event.PATEvent;
import java.util.*;
public abstract class FilteredSuggestionEvent extends PATEvent<FilteredSuggestionEvent> {
private List<String> suggestions;
public FilteredSuggestionEvent() {
super(null);
this.suggestions = null;
}
public FilteredSuggestionEvent(Object senderObj, List<String> suggestions) {
super(senderObj);
this.suggestions = suggestions;
}
public List<String> getSuggestions() {
return suggestions;
}
public void setSuggestions(List<String> suggestions) {
this.suggestions = suggestions;
}
}
@@ -1,36 +0,0 @@
package de.rayzs.pat.api.event.events;
import de.rayzs.pat.api.event.PATEvent;
import java.util.*;
public abstract class FilteredTabCompletionEvent extends PATEvent<FilteredTabCompletionEvent> {
private String cursor;
private List<String> completion;
public FilteredTabCompletionEvent() {
super(null);
this.cursor = null;
this.completion = null;
}
public FilteredTabCompletionEvent(Object senderObj, String cursor, List<String> completion) {
super(senderObj);
this.cursor = cursor;
this.completion = completion;
}
public abstract void handle(FilteredTabCompletionEvent event);
public String getCursor() {
return cursor;
}
public List<String> getCompletion() {
return completion;
}
public void setCompletion(List<String> completion) {
this.completion = completion;
}
}
@@ -1,23 +0,0 @@
package de.rayzs.pat.api.event.events;
import de.rayzs.pat.utils.CommunicationPackets;
import de.rayzs.pat.api.event.PATEvent;
public abstract class ReceiveSyncEvent extends PATEvent<ReceiveSyncEvent> {
private final CommunicationPackets.PacketBundle packetBundle;
public ReceiveSyncEvent() {
super(null);
this.packetBundle = null;
}
public ReceiveSyncEvent(Object senderObj, CommunicationPackets.PacketBundle packetBundle) {
super(senderObj);
this.packetBundle = packetBundle;
}
public CommunicationPackets.PacketBundle getPacketBundle() {
return packetBundle;
}
}
@@ -1,30 +0,0 @@
package de.rayzs.pat.api.event.events;
import de.rayzs.pat.utils.CommunicationPackets;
import de.rayzs.pat.api.event.PATEvent;
public abstract class SentSyncEvent extends PATEvent<SentSyncEvent> {
private final CommunicationPackets.PacketBundle packetBundle;
private final String serverName;
public SentSyncEvent() {
super(null);
this.packetBundle = null;
this.serverName = null;
}
public SentSyncEvent(Object senderObj, CommunicationPackets.PacketBundle packetBundle, String serverName) {
super(senderObj);
this.packetBundle = packetBundle;
this.serverName = serverName;
}
public String getServerName() {
return serverName;
}
public CommunicationPackets.PacketBundle getPacketBundle() {
return packetBundle;
}
}
@@ -1,20 +0,0 @@
package de.rayzs.pat.api.event.events;
import de.rayzs.pat.api.event.PATEvent;
public abstract class ServerPlayersChangeEvent extends PATEvent<ServerPlayersChangeEvent> {
private final Type type;
public ServerPlayersChangeEvent(Object senderObj, Type type) {
super(senderObj);
this.type = type;
}
public ServerPlayersChangeEvent() {
super(null);
this.type = Type.UNKNOWN;
}
public enum Type { JOINED, LEFT, UNKNOWN }
}
@@ -1,28 +0,0 @@
package de.rayzs.pat.api.event.events;
import de.rayzs.pat.api.event.PATEvent;
import java.util.List;
public abstract class UpdatePlayerCommandsEvent extends PATEvent<UpdatePlayerCommandsEvent> {
private List<String> commands;
private boolean serverBased;
public UpdatePlayerCommandsEvent() {
super(null);;
}
public UpdatePlayerCommandsEvent(Object senderObj, List<String> commands, boolean serverBased) {
super(senderObj);
this.commands = commands;
this.serverBased = serverBased;
}
public List<String> getCommands() {
return commands;
}
public boolean isServerBased() {
return serverBased;
}
}
@@ -1,14 +0,0 @@
package de.rayzs.pat.api.event.events;
import de.rayzs.pat.api.event.PATEvent;
public abstract class UpdatePluginEvent extends PATEvent<UpdatePluginEvent> {
public UpdatePluginEvent() {
super(null);;
}
public UpdatePluginEvent(Object senderObj) {
super(senderObj);
}
}
@@ -1,43 +0,0 @@
package de.rayzs.pat.api.event.events.bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
public abstract class ExecuteCommandEvent extends Event implements Cancellable {
private final String command;
private boolean blocked;
public ExecuteCommandEvent() {
this.blocked = false;
this.command = null;
}
public ExecuteCommandEvent(Player player, String command, boolean blocked) {
this.blocked = blocked;
this.command = command;
}
public String getCommand() {
return command;
}
public boolean isBlocked() {
return blocked;
}
public void setBlocked(boolean blocked) {
this.blocked = blocked;
}
@Override
public boolean isCancelled() {
return blocked;
}
@Override
public void setCancelled(boolean cancel) {
this.blocked = cancel;
}
}
@@ -1,26 +0,0 @@
package de.rayzs.pat.api.event.events.bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import java.util.List;
public abstract class FilteredSuggestionEvent extends Event {
private List<String> suggestions;
public FilteredSuggestionEvent() {
this.suggestions = null;
}
public FilteredSuggestionEvent(Player player, List<String> suggestions) {
this.suggestions = suggestions;
}
public List<String> getSuggestions() {
return suggestions;
}
public void setSuggestions(List<String> suggestions) {
this.suggestions = suggestions;
}
}
@@ -1,35 +0,0 @@
package de.rayzs.pat.api.event.events.bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import java.util.List;
public abstract class FilteredTabCompletionEvent extends Event {
private String cursor;
private List<String> completion;
public FilteredTabCompletionEvent() {
this.cursor = null;
this.completion = null;
}
public FilteredTabCompletionEvent(Player player, String cursor, List<String> completion) {
this.cursor = cursor;
this.completion = completion;
}
public abstract void handle(FilteredTabCompletionEvent event);
public String getCursor() {
return cursor;
}
public List<String> getCompletion() {
return completion;
}
public void setCompletion(List<String> completion) {
this.completion = completion;
}
}
@@ -1,184 +0,0 @@
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;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.utils.ExpireCache;
import de.rayzs.pat.utils.Reflection;
import java.util.concurrent.TimeUnit;
import org.bukkit.entity.Player;
import io.netty.channel.*;
import org.bukkit.Bukkit;
import java.util.*;
public class BukkitPacketAnalyzer {
public static final ConcurrentHashMap<UUID, Channel> INJECTED_PLAYERS = new ConcurrentHashMap<>();
private static final ExpireCache<UUID, Object> SENT_PACKET = new ExpireCache<>(2, TimeUnit.SECONDS);
private static final String HANDLER_NAME = "pat-bukkit-handler", PIPELINE_NAME = "packet_handler";
private static final BukkitPacketHandler PACKET_HANDLER = Reflection.getMinor() >= 16 ? new ModernPacketHandler() : new LegacyPacketHandler();
private static final HashMap<Player, String> PLAYER_INPUT_CACHE = new HashMap<>();
public static void injectAll() {
Bukkit.getOnlinePlayers().forEach(BukkitPacketAnalyzer::inject);
}
public static void uninjectAll() {
BukkitPacketAnalyzer.INJECTED_PLAYERS.keySet().forEach(BukkitPacketAnalyzer::uninject);
BukkitPacketAnalyzer.INJECTED_PLAYERS.clear();
}
public static void sendPacket(UUID uuid, Object object) {
Channel channel = INJECTED_PLAYERS.get(uuid);
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;
try {
Channel channel = Reflection.getPlayerChannel(player);
if (channel == null) {
return false;
}
if (channel.pipeline().names().contains(BukkitPacketAnalyzer.HANDLER_NAME))
uninject(channel);
channel.pipeline().addBefore(BukkitPacketAnalyzer.PIPELINE_NAME, BukkitPacketAnalyzer.HANDLER_NAME, new PacketDecoder(player));
BukkitPacketAnalyzer.INJECTED_PLAYERS.put(player.getUniqueId(), channel);
} catch (IndexOutOfBoundsException indexOutOfBoundsException) {
Reflection.toggleInjectionMethod();
Logger.info("Injection failed. Switching to secondary injection method.");
boolean success = inject(player);
if (success) {
Logger.info("Secondary injection method was successful.");
} else {
Logger.warning("Secondary injection method failed!");
}
return success;
} catch (Exception exception) {
exception.printStackTrace();
return false;
}
return true;
}
public static void uninject(UUID uuid) {
if (Storage.USE_VELOCITY)
return;
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 (channel != null) {
channel.eventLoop().submit(() -> {
ChannelPipeline pipeline = channel.pipeline();
if (pipeline.names().contains(BukkitPacketAnalyzer.HANDLER_NAME))
pipeline.remove(BukkitPacketAnalyzer.HANDLER_NAME);
});
}
}
public static String getPlayerInput(Player player) {
String input = PLAYER_INPUT_CACHE.get(player);
PLAYER_INPUT_CACHE.remove(player);
return input;
}
public static void insertPlayerInput(Player player, String text) {
PLAYER_INPUT_CACHE.put(player, text);
}
private static class PacketDecoder extends ChannelDuplexHandler {
private final Player player;
private PacketDecoder(Player player) {
this.player = player;
}
@Override
public void channelRead(ChannelHandlerContext channel, Object packetObj) {
try {
if (packetObj.getClass() != null) {
String packetName = packetObj.getClass().getSimpleName();
if (!packetName.equals("PacketPlayInTabComplete") && !packetName.equals("ServerboundCommandSuggestionPacket")) {
super.channelRead(channel, packetObj);
return;
}
if (!PermissionUtil.hasBypassPermission(player)) {
if (!PACKET_HANDLER.handleIncomingPacket(player, packetObj))
return;
}
}
super.channelRead(channel, packetObj);
} catch (Throwable exception) { exception.printStackTrace(); }
}
@Override
public void write(ChannelHandlerContext channel, Object packetObj, ChannelPromise promise) {
try {
if(packetObj.getClass() != null) {
String packetName = packetObj.getClass().getSimpleName();
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();
}
}
}
}
@@ -1,8 +0,0 @@
package de.rayzs.pat.api.netty.bukkit;
import org.bukkit.entity.Player;
public interface BukkitPacketHandler {
boolean handleIncomingPacket(Player player, Object packetObj) throws Exception;
boolean handleOutgoingPacket(Player player, Object packetObj) throws Exception;
}
@@ -1,112 +0,0 @@
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 de.rayzs.pat.utils.StringUtils;
import org.bukkit.entity.Player;
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.logger.Logger;
import de.rayzs.pat.utils.Reflection;
public class LegacyPacketHandler implements BukkitPacketHandler {
@Override
public boolean handleIncomingPacket(Player player, Object packetObj) throws Exception {
Field stringField = Reflection.getFirstFieldByType(packetObj.getClass(), "String", Reflection.SearchOption.ENDS);
if(stringField == null) {
Logger.warning("Failed PacketAnalyze process! (#1)");
return false;
}
String text = (String) stringField.get(packetObj);
BukkitPacketAnalyzer.insertPlayerInput(player, text);
return true;
}
@Override
public boolean handleOutgoingPacket(Player player, Object packetObj) throws Exception {
final String rawInput = BukkitPacketAnalyzer.getPlayerInput(player);
if(rawInput == null)
return false;
String input = rawInput;
boolean cancelsBeforeHand = false;
if (!input.startsWith("/")) {
return true;
}
input = input.substring(1);
final boolean doesBypassNamespace = Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.doesBypass(player);
final boolean spaces = input.contains(" ");
if (Storage.ConfigSections.Settings.BLOCK_NAMESPACE_COMMANDS.isCommand(input) && !doesBypassNamespace) {
cancelsBeforeHand = true;
}
if (!cancelsBeforeHand && !input.isEmpty()) {
cancelsBeforeHand = !Storage.Blacklist.canPlayerAccessTab(player, StringUtils.getFirstArg(input));
}
if (!cancelsBeforeHand) {
cancelsBeforeHand = Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isCommand(input) || Storage.ConfigSections.Settings.CUSTOM_VERSION.isCommand(input);
}
for (Field field : Reflection.getFields(packetObj)) {
field.setAccessible(true);
Object result = field.get(packetObj);
if (!(result instanceof String[])) {
continue;
}
String[] tR = (String[]) result;
List<String> suggestions = new ArrayList<>(Arrays.asList(tR));
if (spaces) {
if (cancelsBeforeHand) {
suggestions.clear();
field.set(packetObj, suggestions.toArray(new String[0]));
return true;
}
FilteredTabCompletionEvent filteredTabCompletionEvent = PATEventHandler.callFilteredTabCompletionEvents(player.getUniqueId(), rawInput, new ArrayList<>(suggestions));
if (filteredTabCompletionEvent.isCancelled()) {
suggestions.clear();
} else {
suggestions.removeIf(s -> !filteredTabCompletionEvent.getCompletion().contains(s));
}
} else {
suggestions.removeIf(s -> {
String cpy = s;
if (cpy.startsWith("/")) {
cpy = cpy.substring(1);
}
if (Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isTabCompletable(cpy) || Storage.ConfigSections.Settings.CUSTOM_VERSION.isTabCompletable(cpy)) {
return false;
}
return !Storage.Blacklist.canPlayerAccessTab(player, cpy);
});
}
field.set(packetObj, suggestions.toArray(new String[0]));
}
return true;
}
}
@@ -1,267 +0,0 @@
package de.rayzs.pat.api.netty.bukkit.handlers;
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);
if(stringField == null) {
Logger.warning("Failed PacketAnalyze process! (#1)");
return false;
}
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(
StringUtils.replace(Storage.ConfigSections.Settings.PATCH_EXPLOITS.KICK_MESSAGE.get(), "&", "§")
)
);
return false;
}
BukkitPacketAnalyzer.insertPlayerInput(player, text);
return true;
}
@Override
public boolean handleOutgoingPacket(Player player, Object packetObj) throws Exception {
Object suggestionObj;
String rawInput = BukkitPacketAnalyzer.getPlayerInput(player), input = rawInput;
if(input == null)
return false;
boolean is121Packet = packetObj.getClass().getSimpleName().equals("ClientboundCommandSuggestionsPacket"),
cancelsBeforeHand = false;
int spaces = 0;
if(input.startsWith("/") || is121Packet) {
input = input.replace("/", "");
if(input.contains(" ")) {
String[] split = input.split(" ");
spaces = split.length;
if(spaces > 0) input = split[0];
}
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")) {
try {
Field suggestionsField = Reflection.getFieldsByTypeNormal(packetObj.getClass(), "List", Reflection.SearchOption.ENDS).get(0);
List<?> suggestionsTmp = (List<?>) suggestionsField.get(packetObj),
suggestions = new ArrayList<>(suggestionsTmp);
List<Field> intFields = Reflection.getFieldsByTypeNormal(packetObj.getClass(), "int", Reflection.SearchOption.ENDS);
int id = (int) intFields.get(0).get(packetObj),
start = (int) intFields.get(1).get(packetObj),
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 (spaces >= 1 && cancelsBeforeHand || !BukkitLoader.isLoaded()) {
suggestions.clear();
return true;
}
if (spaces == 0) {
suggestions.removeIf(suggestion -> {
String command = getSuggestionFromEntry(suggestion);
return !Storage.Blacklist.canPlayerAccessTab(player, command);
});
return true;
} else {
List<String> suggestionsAsString = new ArrayList<>();
for (Object suggestion : suggestions)
suggestionsAsString.add(getSuggestionFromEntry(suggestion));
FilteredTabCompletionEvent filteredTabCompletionEvent = PATEventHandler.callFilteredTabCompletionEvents(player.getUniqueId(), rawInput, suggestionsAsString);
if (filteredTabCompletionEvent.isCancelled()) suggestions.clear();
for (int i = 0; i < suggestions.size(); i++) {
Object csO = suggestions.get(i);
String suggestionAsString = getSuggestionFromEntry(csO);
if (!filteredTabCompletionEvent.getCompletion().contains(suggestionAsString))
suggestions.remove(csO);
}
suggestions.removeIf(suggestion -> !filteredTabCompletionEvent.getCompletion().contains(getSuggestionFromEntry(suggestion)));
}
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();
}
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 {
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(spaces >= 1 && cancelsBeforeHand || !BukkitLoader.isLoaded()) {
suggestions.getList().clear();
return true;
}
if(spaces == 0) {
suggestions.getList().removeIf(suggestion -> {
String command = suggestion.getText();
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 (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);
if(fields.isEmpty()) return "";
Field field = fields.get(0);
String result = (String) field.get(suggestionObj);
field.setAccessible(false);
return result;
} catch (Throwable throwable) {
throwable.printStackTrace();
}
return "";
}
}
@@ -1,327 +0,0 @@
package de.rayzs.pat.api.netty.proxy;
import java.lang.reflect.Field;
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 com.mojang.brigadier.tree.RootCommandNode;
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.plugin.modules.SubArgsModule;
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 {
public static final ConcurrentHashMap<ProxiedPlayer, Channel> INJECTED_PLAYERS = new ConcurrentHashMap<>();
private static final String HANDLER_NAME = "pat-bungee-handler", PIPELINE_NAME = "packet-decoder";
private static final HashMap<ProxiedPlayer, Boolean> PLAYER_MODIFIED = new HashMap<>();
private static final HashMap<ProxiedPlayer, String> PLAYER_INPUT_CACHE = new HashMap<>();
private static final List<String> PLUGIN_COMMANDS = new ArrayList<>();
private static Class<?> channelWrapperClass, serverConnectionClass;
private static List<String> PROXY_COMMANDS;
static {
CommandNodeHelper.setDefaultSuggestionProvider(Commands.SuggestionRegistry.ASK_SERVER);
loadProxyCommands();
}
public static void loadProxyCommands() {
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);
}
public static void uninjectAll() {
BungeePacketAnalyzer.INJECTED_PLAYERS.keySet().forEach(BungeePacketAnalyzer::uninject);
BungeePacketAnalyzer.INJECTED_PLAYERS.clear();
}
public static void setPluginCommands() {
if(!PLUGIN_COMMANDS.isEmpty()) return;
ProxyServer.getInstance().getPluginManager().getCommands().stream().filter(entry -> !PLUGIN_COMMANDS.contains(entry.getKey())).forEach(entry -> PLUGIN_COMMANDS.add(entry.getKey()));
}
public static boolean inject(ProxiedPlayer player) {
if(channelWrapperClass == null)
channelWrapperClass = Reflection.getClass("net.md_5.bungee.netty.ChannelWrapper");
if(serverConnectionClass == null)
serverConnectionClass = Reflection.getClass("net.md_5.bungee.ServerConnection");
Object channelWrapperObj;
Field channelField;
Channel channel;
try {
channelField = Reflection.getFieldByName(serverConnectionClass, "ch");
channelWrapperObj = channelField.get(player.getServer());
channel = (Channel) Reflection.getFieldsByType(channelWrapperClass, "Channel", Reflection.SearchOption.ENDS).get(0).get(channelWrapperObj);
if(channel == null) {
Logger.warning("Failed to inject " + player.getName() + "! Channel is null.");
return false;
}
channelField.setAccessible(false);
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;
}
public static void uninject(ProxiedPlayer player) {
BungeePacketAnalyzer.PLAYER_INPUT_CACHE.remove(player);
BungeePacketAnalyzer.PLAYER_MODIFIED.remove(player);
if(BungeePacketAnalyzer.INJECTED_PLAYERS.containsKey(player)) {
Channel channel = BungeePacketAnalyzer.INJECTED_PLAYERS.get(player);
if(channel != null) {
BungeePacketAnalyzer.INJECTED_PLAYERS.remove(player);
channel.eventLoop().submit(() -> {
ChannelPipeline pipeline = channel.pipeline();
if (pipeline.names().contains(BungeePacketAnalyzer.HANDLER_NAME))
pipeline.remove(BungeePacketAnalyzer.HANDLER_NAME);
});
}
}
}
public static String getPlayerInput(ProxiedPlayer player) {
String input = PLAYER_INPUT_CACHE.get(player);
PLAYER_INPUT_CACHE.remove(player);
return input;
}
private static void modifyCommands(ProxiedPlayer player, Commands commands) {
if (PermissionUtil.hasBypassPermission(player))
return;
ServerInfo serverInfo = player.getServer().getInfo();
String serverName = serverInfo.getName();
if (Storage.Blacklist.isDisabledServer(serverName))
return;
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<>(PROXY_COMMANDS);
commandsAsString.addAll(helper.getChildrenNames());
commandsCache.handleCommands(commandsAsString, serverName);
List<String> playerCommands = commandsCache.getPlayerCommands(commandsAsString, player, serverName);
helper.removeIf(str -> !playerCommands.contains(str));
if (Storage.ConfigSections.Settings.CUSTOM_VERSION.ALWAYS_TAB_COMPLETABLE) {
Storage.ConfigSections.Settings.CUSTOM_VERSION.COMMANDS.getLines().forEach(input -> helper.add(input, false));
}
if (Storage.ConfigSections.Settings.CUSTOM_PLUGIN.ALWAYS_TAB_COMPLETABLE) {
Storage.ConfigSections.Settings.CUSTOM_PLUGIN.COMMANDS.getLines().forEach(input -> helper.add(input, false));
}
for (Map.Entry<String, Command> command : ProxyServer.getInstance().getPluginManager().getCommands()) {
if (ProxyServer.getInstance().getDisabledCommands().contains(command.getKey()))
continue;
if (commands.getRoot().getChild(command.getKey()) != null)
continue;
if (!command.getValue().hasPermission(player)) {
continue;
}
String commandName = command.getKey();
commandName = commandName.startsWith("/") ? commandName.substring(1) : commandName;
boolean tabablePluginCommand = Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isTabCompletable(commandName);
boolean tabableVersionCommand = Storage.ConfigSections.Settings.CUSTOM_VERSION.isTabCompletable(commandName);
if (!tabablePluginCommand && !tabableVersionCommand && !playerCommands.contains(commandName)) {
continue;
}
CommandNode dummy = CommandNodeHelper.createDummyCommandNode(command.getKey());
commands.getRoot().addChild(dummy);
}
PROXY_COMMANDS.stream().filter(playerCommands::contains).forEach(input -> helper.add(input, true));
SubArgsModule.handleCommandNode(player.getUniqueId(), helper);
}
public static void sendCommandsPacket() {
for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
RootCommandNode root = new RootCommandNode();
Commands packet = new Commands(root);
modifyCommands(player, packet);
player.unsafe().sendPacket(packet);
}
}
private static class PacketDecoder extends MessageToMessageDecoder<PacketWrapper> {
private final ProxiedPlayer player;
private PacketDecoder(ProxiedPlayer player) {
this.player = player;
}
@Override
protected void decode(ChannelHandlerContext channelHandlerContext, PacketWrapper wrapper, List<Object> list) {
if (wrapper.packet == null) {
list.add(wrapper);
return;
}
if(wrapper.packet instanceof PluginMessage) {
PluginMessage pluginMessage = (PluginMessage) wrapper.packet;
if(CustomServerBrand.isEnabled() && CustomServerBrand.isBrandTag(pluginMessage.getTag()))
return;
} else if (wrapper.packet instanceof Commands) {
Commands response = (Commands) wrapper.packet;
modifyCommands(player, response);
player.unsafe().sendPacket(response);
return;
} else if (wrapper.packet instanceof TabCompleteResponse) {
TabCompleteResponse response = (TabCompleteResponse) wrapper.packet;
String serverName = player.getServer().getInfo().getName();
if (!Storage.Blacklist.isDisabledServer(serverName) && player.getPendingConnection().getVersion() < 754) {
if (!PermissionUtil.hasBypassPermission(player)) {
ClientInfo clientInfo = Communicator.getClientByName(player.getServer().getInfo().getName());
if (clientInfo == null || !PLAYER_INPUT_CACHE.containsKey(player))
return;
boolean cancelsBeforeHand = false;
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, "/", ""));
}
final String cursor = playerInput;
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.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 (Storage.Blacklist.canPlayerAccessTab(player, command, server)) {
suggestions.add("/" + command);
}
});
suggestions.stream().filter(suggestion -> suggestion.startsWith(cursor) && !response.getCommands().contains(suggestion)).forEach(command -> response.getCommands().add(command));
} 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.canPlayerAccessTab(player, command, server);
});
response.getCommands().clear();
suggestions.forEach(command -> response.getCommands().add(command));
}
if (response.getCommands().isEmpty())
return;
} else {
if (cancelsBeforeHand)
return;
}
player.unsafe().sendPacket(new TabCompleteResponse(response.getCommands()));
}
}
}
}
list.add(wrapper);
}
}
}
@@ -1,319 +0,0 @@
package de.rayzs.pat.api.netty.proxy;
import java.lang.reflect.Field;
import java.util.*;
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 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;
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 Class<?> minecraftConnectionClass, connectedPlayerConnectionClass, signedChatCommandPacketClass;
public static void injectAll() {
VelocityLoader.getServer().getAllPlayers().forEach(VelocityPacketAnalyzer::inject);
}
public static void uninjectAll() {
VelocityPacketAnalyzer.INJECTED_PLAYERS.keySet().forEach(VelocityPacketAnalyzer::uninject);
VelocityPacketAnalyzer.INJECTED_PLAYERS.clear();
}
public static boolean isInjected(Player player) {
return INJECTED_PLAYERS.containsKey(player);
}
public static boolean inject(Player player) {
if(connectedPlayerConnectionClass == null)
connectedPlayerConnectionClass = Reflection.getClass("com.velocitypowered.proxy.connection.client.ConnectedPlayer");
if(minecraftConnectionClass == null)
minecraftConnectionClass = Reflection.getClass("com.velocitypowered.proxy.connection.MinecraftConnection");
Channel channel;
try {
Object connectedPlayerObj = connectedPlayerConnectionClass.cast(player),
minecraftConnectionObj = Reflection.getMethodsByName(connectedPlayerConnectionClass, "getConnection").get(0).invoke(connectedPlayerObj);
channel = (Channel) Reflection.getMethodsByName(minecraftConnectionClass, "getChannel").get(0).invoke(minecraftConnectionObj);
if (channel == null) {
Logger.warning("Failed to inject " + player.getUsername() + "! Channel is null.");
return false;
}
if (channel.pipeline().names().contains(VelocityPacketAnalyzer.PIPELINE_NAME))
uninject(player);
channel.pipeline().addBefore(VelocityPacketAnalyzer.HANDLER_NAME, VelocityPacketAnalyzer.PIPELINE_NAME, new PacketDecoder(player));
VelocityPacketAnalyzer.INJECTED_PLAYERS.put(player, channel);
} catch (NoSuchElementException e) {
Logger.warning("Failed to find 'handler' inside player pipeline! (name=" + player.getUsername() + ", uuid=" + player.getUniqueId() + ", version=" + player.getProtocolVersion() + ", brand=" + player.getClientBrand() + " )");
return false;
} catch (Throwable throwable) {
throwable.printStackTrace();
return false;
}
return true;
}
public static void uninject(Player player) {
VelocityPacketAnalyzer.PLAYER_INPUT_CACHE.remove(player);
if(VelocityPacketAnalyzer.INJECTED_PLAYERS.containsKey(player)) {
Channel channel = VelocityPacketAnalyzer.INJECTED_PLAYERS.get(player);
if(channel != null) {
VelocityPacketAnalyzer.INJECTED_PLAYERS.remove(player);
channel.eventLoop().submit(() -> {
ChannelPipeline pipeline = channel.pipeline();
if (pipeline.names().contains(VelocityPacketAnalyzer.PIPELINE_NAME)) pipeline.remove(VelocityPacketAnalyzer.PIPELINE_NAME);
});
}
}
}
public static String getPlayerInput(Player player) {
String input = PLAYER_INPUT_CACHE.get(player);
PLAYER_INPUT_CACHE.remove(player);
return input;
}
public static void insertPlayerInput(Player player, String text) {
PLAYER_INPUT_CACHE.put(player, text.toLowerCase());
}
private static class PacketDecoder extends ChannelDuplexHandler {
private final Player player;
private PacketDecoder(Player player) {
this.player = player;
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (!(msg instanceof MinecraftPacket)) {
super.channelRead(ctx, msg);
return;
}
MinecraftPacket packet = (MinecraftPacket) msg;
if (packet.getClass().getSimpleName().equals("SignedChatCommand")) {
try {
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).getResult().isAllowed())
return;
} catch (Exception exception) {
exception.printStackTrace();
}
}
if (packet instanceof UnsignedPlayerCommandPacket) {
UnsignedPlayerCommandPacket unsignedPlayerCommandPacket = (UnsignedPlayerCommandPacket) packet;
if (!VelocityBlockCommandListener.handleCommand(player, unsignedPlayerCommandPacket.getCommand()).getResult().isAllowed())
return;
}
if (packet instanceof TabCompleteRequestPacket) {
TabCompleteRequestPacket request = (TabCompleteRequestPacket) msg;
if (request.getCommand() != null) {
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 {
insertPlayerInput(player, request.getCommand());
super.channelRead(ctx, msg);
}
}
} else super.channelRead(ctx, msg);
}
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (!(msg instanceof MinecraftPacket)) {
super.write(ctx, msg, promise);
return;
}
MinecraftPacket packet = (MinecraftPacket) msg;
if (packet instanceof PluginMessagePacket) {
PluginMessagePacket pluginMessagePacket = (PluginMessagePacket) packet;
if(CustomServerBrand.isEnabled() && CustomServerBrand.isBrandTag(pluginMessagePacket.getChannel()) && !player.getCurrentServer().isPresent()) {
PacketUtils.BrandManipulate brandManipulatePacket = CustomServerBrand.createBrandPacket(player);
super.write(ctx, new PluginMessagePacket(pluginMessagePacket.getChannel(), brandManipulatePacket.getByteBuf()), promise);
return;
}
} else if (packet instanceof TabCompleteResponsePacket) {
String serverName = player.getCurrentServer().get().getServer().getServerInfo().getName();
if (Storage.Blacklist.isDisabledServer(serverName)) {
super.write(ctx, msg, promise);
return;
}
if (!PermissionUtil.hasBypassPermission(player) && player.getCurrentServer().isPresent()) {
TabCompleteResponsePacket response = (TabCompleteResponsePacket) packet;
boolean cancelsBeforeHand = false;
String playerInput = getPlayerInput(player), rawPlayerInput = playerInput, server = player.getCurrentServer().get().getServerInfo().getName();
int spaces = 0;
if(playerInput.contains(" ")) {
String[] split = playerInput.split(" ");
spaces = split.length;
if(spaces > 0) playerInput = split[0];
}
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, "/", ""));
}
final String cursor = playerInput;
if (!cursor.startsWith("/") && spaces < 2 && player.getProtocolVersion().getProtocol() >= 754) {
return;
}
if (cursor.startsWith("/")) {
if (spaces == 0) {
response.getOffers().removeIf(offer -> {
String command = offer.getText();
if (command.startsWith("/")) command = StringUtils.replaceFirst(command, "/", "");
if (Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isTabCompletable(command) || Storage.ConfigSections.Settings.CUSTOM_VERSION.isTabCompletable(command)) {
return false;
}
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 (response.getOffers().isEmpty()) return;
}
}
}
} else if (packet instanceof AvailableCommandsPacket) {
if (!PermissionUtil.hasBypassPermission(player) && player.getCurrentServer().isPresent()) {
String serverName = player.getCurrentServer().get().getServer().getServerInfo().getName();
if (Storage.Blacklist.isDisabledServer(serverName)) {
super.write(ctx, msg, promise);
return;
}
AvailableCommandsPacket commands = (AvailableCommandsPacket) packet;
if(!commands.getRootNode().getChildren().isEmpty()) {
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<>();
commands.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, serverName);
if (commands.getRootNode().getChildren().size() == 1 && newer
&& commands.getRootNode().getChild("args") != null
&& commands.getRootNode().getChild("args").getChildren().isEmpty()) {
super.write(ctx, msg, promise);
return;
}
commands.getRootNode().getChildren().removeIf(command -> {
if (command == null || command.getName() == null)
return true;
if (command.getName().equals("args"))
return false;
if (Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isTabCompletable(command.getName()) || Storage.ConfigSections.Settings.CUSTOM_VERSION.isTabCompletable(command.getName())) {
return false;
}
return !playerCommands.contains(command.getName());
});
}
}
}
super.write(ctx, msg, promise);
}
}
}
@@ -1,705 +0,0 @@
package de.rayzs.pat.api.storage;
import java.util.*;
import java.util.concurrent.TimeUnit;
import de.rayzs.pat.api.brand.CustomServerBrand;
import de.rayzs.pat.api.communication.BackendUpdater;
import de.rayzs.pat.api.communication.Communicator;
import de.rayzs.pat.api.netty.proxy.BungeePacketAnalyzer;
import de.rayzs.pat.api.storage.config.messages.*;
import de.rayzs.pat.api.storage.config.settings.*;
import de.rayzs.pat.plugin.listeners.bukkit.BukkitAntiTabListener;
import de.rayzs.pat.plugin.logger.Logger;
import de.rayzs.pat.plugin.modules.SubArgsModule;
import de.rayzs.pat.utils.configuration.updater.ConfigUpdater;
import de.rayzs.pat.utils.permission.PermissionPlugin;
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.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 = "";
public static boolean OUTDATED = false, SEND_CONSOLE_NOTIFICATION = true;
public static Object PLUGIN_OBJECT;
public static boolean USE_PLACEHOLDERAPI = false, USE_PAPIPROXYBRIDGE = false, USE_VIAVERSION = false, USE_VELOCITY = false, USE_SIMPLECLOUD;
public static long LAST_SYNC = System.currentTimeMillis();
private static PermissionPlugin PERMISSION_PLUGIN = PermissionPlugin.NONE;
public static void initialize(PluginLoader loader, String currentVersion) {
LOADER = loader;
CURRENT_VERSION = currentVersion;
}
public static void setPermissionPlugin(PermissionPlugin permissionPlugin) {
if (PERMISSION_PLUGIN == PermissionPlugin.LUCKPERMS) {
return;
}
PERMISSION_PLUGIN = permissionPlugin;
}
public static void broadcastPermissionsPluginNotice() {
if (Storage.getPermissionPlugin() != PermissionPlugin.NONE) {
return;
}
Logger.warning("No known permissions plugin found, so some features may be disabled.");
Logger.warning("Read more about it here: http://rayzs.de/products/proantitab/nkppf");
}
public static PermissionPlugin getPermissionPlugin() {
return PERMISSION_PLUGIN;
}
public static void loadAll(boolean loadBlacklist) {
loadConfig();
loadToken();
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() {
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() {
ConfigSections.Settings.initialize();
ConfigSections.Messages.initialize();
ConfigSections.SECTIONS.forEach(ConfigStorage::load);
if (USE_PLACEHOLDERAPI)
ConfigSections.PLACEHOLDERS.forEach(PlaceholderStorage::load);
}
public static void reload() {
boolean proxy = Reflection.isProxyServer();
boolean backend = Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED && !proxy;
ConfigUpdater.initialize();
Storage.loadAll(Reflection.isProxyServer() || !backend);
CustomServerBrand.initialize();
GroupManager.clearAllGroups();
GroupManager.initialize();
if (!proxy) {
BackendUpdater.stop();
BackendUpdater.start();
}
if (!backend) {
Storage.handleChange();
}
ConfigUpdater.broadcastMissingParts();
Storage.getLoader().handleReload();
}
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 {
Storage.Blacklist.Experimental.forceCacheReset();
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();
if (!Reflection.isVelocityServer()) {
BungeePacketAnalyzer.sendCommandsPacket();
}
return;
}
getLoader().handleReload();
PermissionUtil.reloadPermissions();
if (Reflection.getMinor() < 13) {
final List<UUID> playerIds = Storage.getLoader().getPlayerIds();
final List<String> commands = new ArrayList<>(Blacklist.BLACKLIST.getCommands());
playerIds.forEach(playerId -> {
List<String> playerCommands = new ArrayList<>(commands);
playerCommands.addAll(SubArgsModule.getGroupCommands(playerId));
PATEventHandler.callUpdatePlayerCommandsEvents(playerId, playerCommands, true);
});
} else {
BukkitAntiTabListener.handleTabCompletion();
}
}
// Quickly updates all player subarguments.
public static void quickSubArgumentUpdate(UUID uuid) {
List<String> playerCommands = new ArrayList<>(SubArgsModule.getServerCommands(uuid));
playerCommands.addAll(SubArgsModule.getGroupCommands(uuid));
PATEventHandler.callUpdatePlayerCommandsEvents(uuid, playerCommands, false);
}
public static PluginLoader getLoader() {
return LOADER;
}
public static List<String> getServers() {
return getServers(false);
}
public static List<String> getServers(boolean includingServerSpecifics) {
List<String> servers = LOADER.getServerNames();
if(includingServerSpecifics) {
servers.addAll(Blacklist.getBlacklists().stream().map(Map.Entry::getKey).toList());
}
return servers;
}
public static boolean isServer(String targetServers, List<String> servers) {
for (String originServer : servers)
if(isServer(originServer, targetServers))
return true;
return false;
}
public static boolean isServer(String originServer, String targetServer) {
originServer = originServer.toLowerCase();
targetServer = targetServer.toLowerCase();
if (originServer.endsWith("*")) {
originServer = originServer.substring(0, originServer.length() - 2);
return targetServer.startsWith(originServer);
}
return originServer.equalsIgnoreCase(targetServer);
}
public static class Files {
public static final ConfigurationBuilder
CONFIGURATION = Configurator.get("config"),
STORAGE = Configurator.get("storage"),
PLACEHOLDERS = Configurator.get("placeholders"),
CUSTOM_RESPONSES = Configurator.get("custom-responses"),
TOKEN = Configurator.get("token");
public static void initialize() {}
}
public static class ConfigSections {
public static List<ConfigStorage> SECTIONS = new ArrayList<>();
public static List<PlaceholderStorage> PLACEHOLDERS = new ArrayList<>();
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();
public static CustomBrandSection CUSTOM_BRAND = new CustomBrandSection();
public static CancelCommandSection CANCEL_COMMAND = new CancelCommandSection();
public static CustomPluginsSection CUSTOM_PLUGIN = new CustomPluginsSection();
public static CustomVersionSection CUSTOM_VERSION = new CustomVersionSection();
public static DisableSyncSection DISABLE_SYNC = new DisableSyncSection();
public static CustomProtocolPingSection CUSTOM_PROTOCOL_PING = new CustomProtocolPingSection();
public static CustomUnknownCommandSection CUSTOM_UNKNOWN_COMMAND = new CustomUnknownCommandSection();
public static TurnBlacklistToWhitelistSection TURN_BLACKLIST_TO_WHITELIST = new TurnBlacklistToWhitelistSection();
public static BaseCommandCaseSensitiveSection BASE_COMMAND_CASE_SENSITIVE = new BaseCommandCaseSensitiveSection();
public static UpdateGroupsPerWorldSection UPDATE_GROUPS_PER_WORLD = new UpdateGroupsPerWorldSection();
public static UpdateGroupsPerServerSection UPDATE_GROUPS_PER_SERVER = new UpdateGroupsPerServerSection();
public static UpdateSection UPDATE = new UpdateSection();
public static void initialize() {}
}
public static class Messages {
public static PrefixSection PREFIX = new PrefixSection();
public static BlacklistSection BLACKLIST = new BlacklistSection();
public static CommandFailedSection COMMAND_FAILED = new CommandFailedSection();
public static ConvertSection CONVERT = new ConvertSection();
public static ExtractSection EXTRACT = new ExtractSection();
public static GroupSection GROUP = new GroupSection();
public static HelpSection HELP = new HelpSection();
public static InfoSection INFO = new InfoSection();
public static NoPermissionSection NO_PERMISSION = new NoPermissionSection();
public static NotificationSection NOTIFICATION = new NotificationSection();
public static PermsCheckSection PERMS_CHECK = new PermsCheckSection();
public static PostDebugSection POST_DEBUG = new PostDebugSection();
public static OnlyForProxySection NO_PROXY = new OnlyForProxySection();
public static ReloadSection RELOAD = new ReloadSection();
public static ServerListSection SERV_LIST = new ServerListSection();
public static StatsSection STATS = new StatsSection();
public static UpdatePermissionsSection UPDATE_PERMISSIONS = new UpdatePermissionsSection();
public static void initialize() {}
}
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();
public static ListSizeGroupsPlaceholder LIST_SIZE_GROUPS = new ListSizeGroupsPlaceholder();
public static ListGroupCommandsPlaceholder LIST_GROUP_COMMANDS = new ListGroupCommandsPlaceholder();
public static ListGroupReversedCommandsPlaceholder LIST_GROUP_REVERSED_COMMANDS = new ListGroupReversedCommandsPlaceholder();
public static ListGroupSortedCommandsPlaceholder LIST_GROUP_SORTED_COMMANDS = new ListGroupSortedCommandsPlaceholder();
public static ListGroupSizeCommandsPlaceholder LIST_GROUP_SIZE_GROUP = new ListGroupSizeCommandsPlaceholder();
public static ListCommandsPlaceholder LIST_COMMANDS = new ListCommandsPlaceholder();
public static ListReversedCommandsPlaceholder LIST_REVERSED_COMMANDS = new ListReversedCommandsPlaceholder();
public static ListSortedCommandsPlaceholder LIST_SORTED_COMMANDS = new ListSortedCommandsPlaceholder();
public static ListSizeCommandsPlaceholder LIST_SIZE_COMMANDS = new ListSizeCommandsPlaceholder();
public static void initialize() {}
public static String findAndReplace(Player player, String request) {
String result = null, param = "";
if(USE_PLACEHOLDERAPI) {
for (PlaceholderStorage storage : PLACEHOLDERS) {
if (!storage.getRequest().startsWith(request)) continue;
if (storage.getRequest().endsWith("group_") && request.contains("group_"))
param = request.split("group_")[1];
result = storage.onRequest(player, param);
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;
}
}
}
public static class Blacklist {
public static class Experimental {
public static void forceCacheReset() {
for (Object o : CACHED_SERVER_BLACKLIST.getCache().asMap().keySet()) {
String s = (String) o;
clearServerBlacklists(s);
loadCachedServerBlacklists(s);
}
}
}
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() {
CACHED_SERVER_BLACKLIST.clear();
SERVER_BLACKLISTS.clear();
BLACKLIST.load();
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);
});
getServers().forEach(Blacklist::loadCachedServerBlacklists);
}
private static void loadCachedServerBlacklists(String server) {
List<GeneralBlacklist> blacklists = SERVER_BLACKLISTS.entrySet().stream()
.filter(entry ->
isServer(entry.getKey(), server)
).map(Map.Entry::getValue).toList();
CACHED_SERVER_BLACKLIST.put(server, blacklists);
}
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 List<GeneralBlacklist> getServerBlacklists(String server) {
if (!CACHED_SERVER_BLACKLIST.contains(server)) {
loadCachedServerBlacklists(server);
}
return CACHED_SERVER_BLACKLIST.get(server);
}
public static void clearServerBlacklists(String server) {
CACHED_SERVER_BLACKLIST.remove(server);
}
public static boolean isDisabledServer(String server) {
return DISABLED_SERVERS.isListed(server);
}
public static boolean isIgnoredServer(String server) {
return IGNORED_SERVERS.isListed(server);
}
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;
}
if (Storage.getPermissionPlugin() != PermissionPlugin.NONE) {
if (PermissionUtil.hasBypassPermission(player, command)) {
return true;
}
}
return GroupManager.canAccessCommand(player, command, type, server);
}
public static boolean isBlockedChat(String command) {
return isBlocked(command, BlockType.CHAT, null);
}
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) {
BlockType negation = BlockType.NEGATE;
String negatedCommand = negation + command;
boolean listed = isListed(command, type, server),
negatedListed = isListed(negatedCommand, type, server),
turn = ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED;
if (!turn && negatedListed) {
listed = !listed;
}
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;
String command = type.toString() + unmodifiedCommand;
if (server == null || !isIgnoredServer(server)) {
listed = BLACKLIST.isListed(command, false/*!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, false/*turn*/);
}
if (!listed && type != BlockType.BOTH) {
return isListed(unmodifiedCommand, BlockType.BOTH, server);
}
return listed;
}
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;
}
public static String modify(String command) {
BlockType type = getType(command);
return modify(command, type);
}
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;
return command.substring(type.toString().length());
}
}
}
}
@@ -1,39 +0,0 @@
package de.rayzs.pat.api.storage;
import de.rayzs.pat.utils.configuration.*;
import java.io.Serializable;
public abstract class StorageTemplate implements Serializable {
private final String navigatePath;
private final ConfigurationBuilder configuration;
public StorageTemplate(ConfigurationBuilder configuration, String navigatePath) {
this.navigatePath = navigatePath;
this.configuration = configuration;
this.load();
}
public StorageTemplate setIfEmpty(String target, Object obj) {
configuration.getOrSet(target, obj);
return this;
}
public StorageTemplate set(String target, Object obj) {
configuration.setAndSave(target, obj);
return this;
}
public Object get(String target, Object obj) {
configuration.getOrSet(target, obj);
return this;
}
public ConfigurationBuilder getConfig() {
return configuration;
}
public String getNavigatePath() { return navigatePath; }
public abstract void save();
public abstract void load();
}
@@ -1,36 +0,0 @@
package de.rayzs.pat.api.storage.blacklist;
import de.rayzs.pat.api.storage.blacklist.impl.*;
import de.rayzs.pat.api.storage.Storage;
public class BlacklistCreator {
public static GeneralBlacklist createGeneralBlacklist() {
return new GeneralBlacklist("commands");
}
public static GeneralBlacklist createGeneralBlacklist(String server) {
return new GeneralBlacklist("servers." + server + ".commands");
}
public static GroupBlacklist createGroupBlacklist(String group) {
return new GroupBlacklist(group, "commands");
}
public static GroupBlacklist createGroupBlacklist(String group, String server, boolean ignoreExist) {
if (!exist(group, server) && !ignoreExist)
return null;
return new GroupBlacklist(group, "servers." + server + ".commands");
}
public static boolean exist(String server) {
Object obj = Storage.Blacklist.getBlacklist().getConfig().get("global.servers." + server);
return obj != null;
}
public static boolean exist(String group, String server) {
Object obj = Storage.Blacklist.getBlacklist().getConfig().get("groups." + group + ".servers." + server);
return obj != null;
}
}
@@ -1,60 +0,0 @@
package de.rayzs.pat.api.storage.blacklist.impl;
import de.rayzs.pat.api.storage.storages.BlacklistStorage;
import de.rayzs.pat.api.storage.StorageTemplate;
import java.util.List;
public class GeneralBlacklist extends BlacklistStorage {
public GeneralBlacklist(String navigatePath) { super("global." + navigatePath); }
@Override
public List<String> getCommands() {
return super.getCommands();
}
@Override
public BlacklistStorage add(String command) {
return super.add(command);
}
@Override
public BlacklistStorage remove(String command) {
return super.remove(command);
}
@Override
public BlacklistStorage clear() {
return super.clear();
}
@Override
public StorageTemplate setIfEmpty(String target, Object obj) {
return super.setIfEmpty(target, obj);
}
@Override
public StorageTemplate set(String target, Object obj) {
return super.set(target, obj);
}
@Override
public void setList(List<String> commands) {
super.setList(commands);
}
@Override
public Object get(String target, Object obj) {
return super.get(target, obj);
}
@Override
public void save() {
super.save();
}
@Override
public void load() {
super.load();
}
}
@@ -1,40 +0,0 @@
package de.rayzs.pat.api.storage.blacklist.impl;
import de.rayzs.pat.api.storage.storages.IgnoredServersStorage;
public class GeneralIgnoredServers extends IgnoredServersStorage {
public GeneralIgnoredServers() {
super("global.ignored-servers");
}
@Override
public IgnoredServersStorage add(String server) {
return super.add(server);
}
@Override
public IgnoredServersStorage remove(String server) {
return super.remove(server);
}
@Override
public boolean isListed(String server) {
return super.isListed(server);
}
@Override
public boolean isListEmpty() {
return super.isListEmpty();
}
@Override
public void load() {
super.load();
}
@Override
public void save() {
super.save();
}
}
@@ -1,58 +0,0 @@
package de.rayzs.pat.api.storage.blacklist.impl;
import de.rayzs.pat.api.storage.storages.BlacklistStorage;
import de.rayzs.pat.api.storage.StorageTemplate;
import java.util.List;
public class GroupBlacklist extends BlacklistStorage {
public GroupBlacklist(String group, String navigatePath) { super("groups." + group + "." + navigatePath); }
@Override
public List<String> getCommands() {
return super.getCommands();
}
@Override
public BlacklistStorage add(String command) {
return super.add(command);
}
@Override
public BlacklistStorage remove(String command) { return super.remove(command); }
@Override
public BlacklistStorage clear() {
return super.clear();
}
@Override
public StorageTemplate setIfEmpty(String target, Object obj) {
return super.setIfEmpty(target, obj);
}
@Override
public StorageTemplate set(String target, Object obj) {
return super.set(target, obj);
}
@Override
public void setList(List<String> commands) {
super.setList(commands);
}
@Override
public Object get(String target, Object obj) {
return super.get(target, obj);
}
@Override
public void save() {
super.save();
}
@Override
public void load() {
super.load();
}
}
@@ -1,51 +0,0 @@
package de.rayzs.pat.api.storage.config.messages;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
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_SERVER_MESSAGE, LIST_SERVER_SPLITTER;
public String ADD_SUCCESS, ADD_FAILED;
public String REMOVE_SUCCESS, REMOVE_FAILED;
public String ADD_SERVER_SUCCESS, ADD_SERVER_FAILED;
public String REMOVE_SERVER_SUCCESS, REMOVE_SERVER_FAILED;
public BlacklistSection() {
super("blacklist");
}
@Override
public void load() {
super.load();
CLEAR = new ConfigSectionHelper<String>(this, "clear", "&aList has been cleared!").getOrSet();
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, &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();
REMOVE_SUCCESS = new ConfigSectionHelper<String>(this, "remove.success", "&aSuccessfully removed %command% from the list!").getOrSet();
REMOVE_FAILED = new ConfigSectionHelper<String>(this, "remove.failed", "&c%command% is not listed!").getOrSet();
if(!Reflection.isProxyServer()) return;
CLEAR_SERVER = new ConfigSectionHelper<String>(this, "clear-server", "&aList has been cleared!").getOrSet();
CLEAR_SERVER_CONFIRM = new ConfigSectionHelper<String>(this, "clear-confirmation-server", "&4Warning! &7This command will &cclear the entire list of this server&7! &7Repeat the &esame command &7to confirm this action.").getOrSet();
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, &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();
REMOVE_SERVER_SUCCESS = new ConfigSectionHelper<String>(this, "remove.success-server", "&aSuccessfully removed %command% from the list of %server%!").getOrSet();
REMOVE_SERVER_FAILED = new ConfigSectionHelper<String>(this, "remove.failed-server", "&c%command% is not the list of %server%!").getOrSet();
}
}
@@ -1,19 +0,0 @@
package de.rayzs.pat.api.storage.config.messages;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
public class CommandFailedSection extends ConfigStorage {
public String MESSAGE;
public CommandFailedSection() {
super("command-failed");
}
@Override
public void load() {
super.load();
MESSAGE = new ConfigSectionHelper<String>(this, null, "&cFailed to execute this command! Use \"/pat\" to see all available commands.").getOrSet();
}
}
@@ -1,25 +0,0 @@
package de.rayzs.pat.api.storage.config.messages;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
import de.rayzs.pat.utils.configuration.helper.MultipleMessagesHelper;
public class ConvertSection extends ConfigStorage {
public MultipleMessagesHelper MESSAGE;
public ConvertSection() {
super("convert");
}
public String INVALID_CONVERTER, SUCCESS;
@Override
public void load() {
super.load();
INVALID_CONVERTER = new ConfigSectionHelper<String>(this, "converter-not-found", "&cConverter or necessary files could not be found!").getOrSet();
SUCCESS = new ConfigSectionHelper<String>(this, "success", "&aSuccessfully converted &e%converter% &ainto the PAT storage.yml!").getOrSet();
}
}
@@ -1,31 +0,0 @@
package de.rayzs.pat.api.storage.config.messages;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
import de.rayzs.pat.utils.Reflection;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
import de.rayzs.pat.utils.configuration.helper.MultipleMessagesHelper;
public class ExtractSection extends ConfigStorage {
public MultipleMessagesHelper MESSAGE;
public ExtractSection() {
super("extract");
}
public String USAGE, PLUGIN_NOT_FOUND, SUCCESS;
@Override
public void load() {
super.load();
if (Reflection.isProxyServer()) {
return;
}
USAGE = new ConfigSectionHelper<String>(this, "usage", "&7Usage: &f/pat extract [plugin] <use-colon> &7or &f<group> <use-colon>").getOrSet();
PLUGIN_NOT_FOUND = new ConfigSectionHelper<String>(this, "plugin-not-found", "&cPlugin %plugin% not found!").getOrSet();
SUCCESS = new ConfigSectionHelper<String>(this, "success", "&aSuccessfully extracted &e%amount% &anew commands from %plugin%!").getOrSet();
}
}
@@ -1,82 +0,0 @@
package de.rayzs.pat.api.storage.config.messages;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
import de.rayzs.pat.utils.Reflection;
public class GroupSection extends ConfigStorage {
public String CREATE, ALREADY_EXIST, DOES_NOT_EXIST, DELETE, DELETE_CONFIRM, CREATE_SERVER, ALREADY_SERVER_EXIST, DOES_NOT_EXIST_SERVER, DELETE_SERVER, DELETE_SERVER_CONFIRM;
public String CLEAR, CLEAR_CONFIRM, CLEAR_SERVER, CLEAR_SERVER_CONFIRM;
public String PRIORITY_SUCCESS, PRIORITY_FAILED;
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;
public String REMOVE_SUCCESS, REMOVE_FAILED;
public String ADD_SERVER_SUCCESS, ADD_SERVER_FAILED;
public String REMOVE_SERVER_SUCCESS, REMOVE_SERVER_FAILED;
public GroupSection() {
super("group");
}
@Override
public void load() {
super.load();
CREATE = new ConfigSectionHelper<String>(this, "create", "&aGroup %group% has been created!").getOrSet();
ALREADY_EXIST = new ConfigSectionHelper<String>(this, "already-exist", "&cGroup %group% already exist!").getOrSet();
DOES_NOT_EXIST = new ConfigSectionHelper<String>(this, "does-not-exist", "&cGroup %group% does not exist!").getOrSet();
DELETE = new ConfigSectionHelper<String>(this, "delete", "&cGroup %group% has been deleted!").getOrSet();
DELETE_CONFIRM = new ConfigSectionHelper<String>(this, "delete-confirmation", "&4Warning! &7This command will &cdelete the group with the whole list&7 of this group! &7Repeat the &esame command &7to confirm this action.").getOrSet();
CLEAR = new ConfigSectionHelper<String>(this, "clear", "&aList of group %group% has been cleared!").getOrSet();
CLEAR_CONFIRM = new ConfigSectionHelper<String>(this, "clear-confirmation", "&4Warning! &7This command will &cclear the entire list&7 of this group! &7Repeat the &esame command &7to confirm this action.").getOrSet();
PRIORITY_SUCCESS = new ConfigSectionHelper<String>(this, "priority.success", "&aSuccessfully set the priority of group &e%group% &ato &e%priority%&a!").getOrSet();
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, &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: &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, &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();
REMOVE_SUCCESS = new ConfigSectionHelper<String>(this, "remove.success", "&aSuccessfully removed %command% from the list of group %group%!").getOrSet();
REMOVE_FAILED = new ConfigSectionHelper<String>(this, "remove.failed", "&c%command% is not listed in the group %group%!").getOrSet();
if(!Reflection.isProxyServer()) return;
CREATE_SERVER = new ConfigSectionHelper<String>(this, "create-server", "&aGroup %group% for %server% has been created!").getOrSet();
ALREADY_SERVER_EXIST = new ConfigSectionHelper<String>(this, "already-exist-server", "&cGroup %group% for %server% already exist!").getOrSet();
DOES_NOT_EXIST_SERVER = new ConfigSectionHelper<String>(this, "does-not-exist-server", "&cGroup %group% of %server% does not exist!").getOrSet();
DELETE_SERVER = new ConfigSectionHelper<String>(this, "delete-server", "&cGroup %group% of %server% has been deleted!").getOrSet();
DELETE_SERVER_CONFIRM = new ConfigSectionHelper<String>(this, "delete-confirmation-server", "&4Warning! &7This command will &cdelete the group of the server %server% with the whole list&7 of this group! &7Repeat the &esame command &7to confirm this action.").getOrSet();
CLEAR_SERVER = new ConfigSectionHelper<String>(this, "clear-server", "&aList of group %group% from %server% has been cleared!").getOrSet();
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, &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, &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();
REMOVE_SERVER_SUCCESS = new ConfigSectionHelper<String>(this, "remove.success-server", "&aSuccessfully removed %command% from the list of group %group% from %server%!").getOrSet();
REMOVE_SERVER_FAILED = new ConfigSectionHelper<String>(this, "remove.failed-server", "&c%command% is not listed in the group %group% of %server%!").getOrSet();
}
}
@@ -1,65 +0,0 @@
package de.rayzs.pat.api.storage.config.messages;
import de.rayzs.pat.utils.configuration.helper.MultipleMessagesHelper;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
import de.rayzs.pat.utils.Reflection;
import java.util.Arrays;
public class HelpSection extends ConfigStorage {
public MultipleMessagesHelper MESSAGE;
public HelpSection() {
super("help");
}
@Override
public void load() {
super.load();
MESSAGE = new MultipleMessagesHelper(this, null, Reflection.isProxyServer() ?
Arrays.asList(
"&7Available commands are: &f/%label%&7..."
, "&7Format: &8<optional> (required)"
, "&f reload &7to reload the plugin"
, "&f notify &7to get alerted"
, "&f info &7to get a few information"
, "&f postdebug &7to post the PAT logs"
, "&f update <player> &7to update player(s) permissions"
, "&f perms <player> &7to check a player's permissions"
, "&f extract (plugin) &7to extract all plugin commands"
, "&f convert (plugin) &7converts into a PAT storage.yml"
, "&f creategroup (group) &7Create a group"
, "&f deletegroup (group) &7Delete a group"
, "&f setpriority (group) (priority) &7to set the priority"
, "&f list &8(optional: group) &7to see all listed commands"
, "&f listgroups &7List all groups"
, "&f listpriorities &7to list all group priorities"
, "&f add/rem (command) &8<group> &7to manage the list"
, "&f clear &8<group> &7to clear the list")
:
Arrays.asList(
"&7Available commands are: &f/%label%&7..."
, "&7Format: &8<optional> (required)"
, "&f reload &7to reload the plugin"
, "&f notify &7to get alerted"
, "&f info &7to get a few information"
, "&f postdebug &7to post the PAT logs"
, "&f update <player> &7to update player(s) permissions"
, "&f perms <player> &7to check a player's permissions"
, "&f extract (plugin) &7to extract all plugin commands"
, "&f creategroup (group) &7Create a group"
, "&f deletegroup (group) &7Delete a group"
, "&f setpriority (group) (priority) &7to set the priority"
, "&f list &8<group> &7to see all listed commands"
, "&f listgroups &8<server> &7List all groups"
, "&f listpriorities &7to list all group priorities"
, "&f add/rem (command) &8<group> &7to manage the list"
, "&f clear &8<group> &7to clear the list"
, "&7 For a specific server:"
, "&f serv list (server) &8<group>"
, "&f serv add/rem (server) (command) &8<group>"
, "&f serv clear (server) &8<group>"
));
}
}
@@ -1,36 +0,0 @@
package de.rayzs.pat.api.storage.config.messages;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
import de.rayzs.pat.utils.configuration.helper.*;
import java.util.Arrays;
public class InfoSection extends ConfigStorage {
public String VERSION_OUTDATED, VERSION_UPDATED, SYNC_TIME, SYNC_DISABLED;
public MultipleMessagesHelper MESSAGE;
public InfoSection() {
super("info");
}
@Override
public void load() {
super.load();
VERSION_UPDATED = new ConfigSectionHelper<String>(this, "version.updated", "&aLatest version").getOrSet();
VERSION_OUTDATED = new ConfigSectionHelper<String>(this, "version.outdated", "&cOutdated (%newest_version%)").getOrSet();
SYNC_TIME = new ConfigSectionHelper<String>(this, "proxy-sync.time", "&e%time%").getOrSet();
SYNC_DISABLED = new ConfigSectionHelper<String>(this, "proxy-sync.disabled", "&cDisabled").getOrSet();
MESSAGE = new MultipleMessagesHelper(this, "message",
Arrays.asList(
"&7Necessary information about &fPAT&8:"
, "&7 Version: &e%current_version%"
, "&7 Status: %version_status%"
, "&7 Last sync with proxy: &e%sync_time%"
, "&7 Proxy sync-token: &e%token%"
, "&7 Proxy-received server name: &e%sync_server_name%"
)
);
}
}
@@ -1,19 +0,0 @@
package de.rayzs.pat.api.storage.config.messages;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
public class NoPermissionSection extends ConfigStorage {
public String MESSAGE;
public NoPermissionSection() {
super("no-permissions");
}
@Override
public void load() {
super.load();
MESSAGE = new ConfigSectionHelper<String>(this, null, "&cYou are not allowed to execute this command! Missing permission: &4proantitab.%permission%").getOrSet();
}
}
@@ -1,24 +0,0 @@
package de.rayzs.pat.api.storage.config.messages;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
import de.rayzs.pat.utils.configuration.helper.*;
import de.rayzs.pat.utils.Reflection;
import java.util.Collections;
public class NotificationSection extends ConfigStorage {
public String ENABLED, DISABLED;
public MultipleMessagesHelper ALERT;
public NotificationSection() {
super("notification");
}
@Override
public void load() {
super.load();
ENABLED = new ConfigSectionHelper<String>(this, "enabled", "&aEnabled notifications").getOrSet();
DISABLED = new ConfigSectionHelper<String>(this, "disabled", "&cDisabled notifications").getOrSet();
ALERT = new MultipleMessagesHelper(this, "alert", Collections.singletonList("&8[&4ALERT&8] &c%player% &8(&7" + (Reflection.isProxyServer() ? "server: &e%server%" : "world: &e%world%") + "&8) &ctried to execute the following blocked command: &4%command%"));
}
}
@@ -1,21 +0,0 @@
package de.rayzs.pat.api.storage.config.messages;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
import de.rayzs.pat.utils.Reflection;
public class OnlyForProxySection extends ConfigStorage {
public String MESSAGE;
public OnlyForProxySection() {
super("only-for-proxy");
}
@Override
public void load() {
super.load();
if(Reflection.isProxyServer()) return;
MESSAGE = new ConfigSectionHelper<String>(this, null, "&cThis command works on Bungeecord/Velocity servers only!").getOrSet();
}
}
@@ -1,21 +0,0 @@
package de.rayzs.pat.api.storage.config.messages;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
import de.rayzs.pat.utils.configuration.helper.*;
public class PermsCheckSection extends ConfigStorage {
public String MESSAGE, PLAYER_MISSING, PLAYER_NOT_ONLINE;
public PermsCheckSection() {
super("perms-check");
}
@Override
public void load() {
super.load();
MESSAGE = new ConfigSectionHelper<String>(this, "message", "&7All of &e%player%'s &7PAT-related permission: &e%permissions%").getOrSet();
PLAYER_MISSING = new ConfigSectionHelper<String>(this, "player-is-missing", "&cPlease specify the player whose permission you want to check.").getOrSet();
PLAYER_NOT_ONLINE = new ConfigSectionHelper<String>(this, "player-not-online", "&c%player% is not online!").getOrSet();
}
}
@@ -1,20 +0,0 @@
package de.rayzs.pat.api.storage.config.messages;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
public class PostDebugSection extends ConfigStorage {
public String SUCCESS, FAILED;
public PostDebugSection() {
super("post-debug");
}
@Override
public void load() {
super.load();
SUCCESS = new ConfigSectionHelper<String>(this, "success", "&aSuccessfully uploaded debug logs: &e%link% &8(<click:open_url:%link%><gray>CLICK</click>&8)").getOrSet();
FAILED = new ConfigSectionHelper<String>(this, "failed", "&cFailed to upload debug logs!").getOrSet();
}
}
@@ -1,19 +0,0 @@
package de.rayzs.pat.api.storage.config.messages;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
public class PrefixSection extends ConfigStorage {
public String PREFIX;
public PrefixSection() {
super("prefix");
}
@Override
public void load() {
super.load();
PREFIX = new ConfigSectionHelper<String>(this, null, "&8[&4ProAntiTab&8]").getOrSet();
}
}
@@ -1,20 +0,0 @@
package de.rayzs.pat.api.storage.config.messages;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
public class ReloadSection extends ConfigStorage {
public String LOADING, DONE;
public ReloadSection() {
super("reload");
}
@Override
public void load() {
super.load();
LOADING = new ConfigSectionHelper<String>(this, "loading", "&eReloading all configuration files...").getOrSet();
DONE = new ConfigSectionHelper<String>(this, "done", "&aSuccessfully reloaded all configuration files!").getOrSet();
}
}
@@ -1,30 +0,0 @@
package de.rayzs.pat.api.storage.config.messages;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
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_GROUP_MESSAGE, LIST_GROUP_SPLITTER;
public ServerListSection() {
super("server-list");
}
@Override
public void load() {
super.load();
if(!Reflection.isProxyServer()) return;
SERVER_DOES_NOT_EXIST = new ConfigSectionHelper<String>(this, "server-not-found", "&cThe server %server% does not have any commands!").getOrSet();
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, &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, &f").getOrSet();
}
}
@@ -1,30 +0,0 @@
package de.rayzs.pat.api.storage.config.messages;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
import de.rayzs.pat.utils.configuration.helper.*;
import de.rayzs.pat.utils.Reflection;
import java.util.Arrays;
public class StatsSection extends ConfigStorage {
public String NO_SERVER, SPLITTER, SERVER;
public MultipleMessagesHelper STATISTIC;
public StatsSection() {
super("stats");
}
@Override
public void load() {
super.load();
if(!Reflection.isProxyServer()) return;
NO_SERVER = new ConfigSectionHelper<String>(this, "no-server", "&cNone!").getOrSet();
SPLITTER = new ConfigSectionHelper<String>(this, "message.splitter", "&7, ").getOrSet();
SERVER = new ConfigSectionHelper<String>(this, "message.server", "&f%servername% &8(%updated%)").getOrSet();
STATISTIC = new MultipleMessagesHelper(this, "message.statistic", Arrays.asList(
"&7Last sync sent to &f%server_count% &7servers. &8&o(%last_sync_time% ago)",
"&7Sent to servers: &f%servers%"
));
}
}
@@ -1,21 +0,0 @@
package de.rayzs.pat.api.storage.config.messages;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
public class UpdatePermissionsSection extends ConfigStorage {
public String UPDATE_ALL, UPDATE_SPECIFIC, PLAYER_NOT_ONLINE;
public UpdatePermissionsSection() {
super("update-permissions");
}
@Override
public void load() {
super.load();
UPDATE_ALL = new ConfigSectionHelper<String>(this, "all-players", "&aUpdated permissions!").getOrSet();
UPDATE_SPECIFIC = new ConfigSectionHelper<String>(this, "specific-player", "&aUpdated %target%'s permissions!").getOrSet();
PLAYER_NOT_ONLINE = new ConfigSectionHelper<String>(this, "player-not-online", "&c%target% is not online!").getOrSet();
}
}
@@ -1,36 +0,0 @@
package de.rayzs.pat.api.storage.config.settings;
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");
}
}
@@ -1,22 +0,0 @@
package de.rayzs.pat.api.storage.config.settings;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
import de.rayzs.pat.utils.configuration.helper.MultipleMessagesHelper;
import java.util.Collections;
public class BaseCommandCaseSensitiveSection extends ConfigStorage {
public boolean ENABLED;
public BaseCommandCaseSensitiveSection() {
super("base-command-case-sensitive");
}
@Override
public void load() {
super.load();
ENABLED = new ConfigSectionHelper<Boolean>(this, null, true).getOrSet();
}
}
@@ -1,32 +0,0 @@
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.StringUtils;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
import de.rayzs.pat.utils.permission.PermissionUtil;
public class BlockNamespaceCommandsSection extends ConfigStorage {
public boolean ENABLED;
public BlockNamespaceCommandsSection() {
super("block-namespace-commands");
}
@Override
public void load() {
super.load();
ENABLED = new ConfigSectionHelper<Boolean>(this, "enabled", true).getOrSet();
}
public boolean isCommand(String command) {
if(!ENABLED || Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED) return false;
return StringUtils.getFirstArg(command).contains(":");
}
public boolean doesBypass(Object targetObj) {
return !ENABLED || PermissionUtil.hasPermission(targetObj, "namespace");
}
}
@@ -1,23 +0,0 @@
package de.rayzs.pat.api.storage.config.settings;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
import de.rayzs.pat.utils.configuration.helper.*;
import java.util.Collections;
public class CancelCommandSection extends ConfigStorage {
public boolean ENABLED;
public MultipleMessagesHelper BASE_COMMAND_RESPONSE, SUB_COMMAND_RESPONSE;
public CancelCommandSection() {
super("cancel-blocked-commands");
}
@Override
public void load() {
super.load();
ENABLED = new ConfigSectionHelper<Boolean>(this, "enabled", true).getOrSet();
BASE_COMMAND_RESPONSE = new MultipleMessagesHelper(this, "base-command-message", Collections.singletonList("&cThe command %command% is blocked!"));
SUB_COMMAND_RESPONSE = new MultipleMessagesHelper(this, "sub-command-message", Collections.singletonList("&cThis sub-argument is blocked!"));
}
}
@@ -1,38 +0,0 @@
package de.rayzs.pat.api.storage.config.settings;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
import de.rayzs.pat.utils.configuration.helper.*;
import java.util.Arrays;
public class CustomBrandSection extends ConfigStorage {
public boolean ENABLED;
public int REPEAT_DELAY;
public MultipleMessagesHelper BRANDS;
public CustomBrandSection() {
super("custom-server-brand");
}
@Override
public void load() {
super.load();
ENABLED = new ConfigSectionHelper<Boolean>(this, "enabled", false).getOrSet();
REPEAT_DELAY = new ConfigSectionHelper<Integer>(this, "repeat-delay", 3).getOrSet();
BRANDS = new MultipleMessagesHelper(this, "brands", Arrays.asList(
"&f&lP&froAntiTab |",
"&fP&lr&foAntiTab /",
"&fPr&lo&fAntiTab -",
"&fPro&lA&fntiTab |",
"&fProA&ln&ftiTab \\",
"&fProAn&lt&fiTab |",
"&fProAnt&li&fTab /",
"&fProAnti&lT&fab -",
"&fProAnti&lT&fab \\",
"&fProAntiT&la&fb |",
"&fProAntiTa&lb&f /",
"&fProAntiTab -",
"&fProAntiTab \\"
));
}
}
@@ -1,43 +0,0 @@
package de.rayzs.pat.api.storage.config.settings;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
import de.rayzs.pat.utils.StringUtils;
import de.rayzs.pat.utils.configuration.helper.*;
import java.util.*;
public class CustomPluginsSection extends ConfigStorage {
public boolean ENABLED, ALWAYS_TAB_COMPLETABLE;
public MultipleMessagesHelper MESSAGE, COMMANDS;
public CustomPluginsSection() {
super("custom-plugins");
}
@Override
public void load() {
super.load();
ENABLED = new ConfigSectionHelper<Boolean>(this, "enabled", true).getOrSet();
ALWAYS_TAB_COMPLETABLE = new ConfigSectionHelper<Boolean>(this, "always-tab-completable", false).getOrSet();
COMMANDS = new MultipleMessagesHelper(this, "commands", Arrays.asList("pl", "plugins"));
MESSAGE = new MultipleMessagesHelper(this, "message", Collections.singletonList("&fPlugins (0):"));
}
public boolean isTabCompletable(String command) {
if (!isCommand(command))
return false;
return ALWAYS_TAB_COMPLETABLE;
}
public boolean isCommand(String command) {
if(!ENABLED) return false;
command = StringUtils.getFirstArg(command);
for (String currentCommand : COMMANDS.getLines()) {
if (currentCommand.equalsIgnoreCase(command))
return true;
}
return false;
}
}
@@ -1,53 +0,0 @@
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, USE_CUSTOM_PLAYERLIST;
public String PROTOCOL;
public MultipleMessagesHelper PLAYERLIST;
public int EXTEND_COUNT;
public CustomProtocolPingSection() {
super("custom-protocol-ping");
}
@Override
public void load() {
super.load();
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();
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.");
}
}
}
@@ -1,25 +0,0 @@
package de.rayzs.pat.api.storage.config.settings;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
import de.rayzs.pat.utils.configuration.helper.*;
import de.rayzs.pat.api.storage.Storage;
import java.util.Collections;
public class CustomUnknownCommandSection extends ConfigStorage {
public boolean ENABLED;
public MultipleMessagesHelper MESSAGE;
public CustomUnknownCommandSection() {
super("custom-unknown-command");
}
@Override
public void load() {
super.load();
if(Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED) return;
ENABLED = new ConfigSectionHelper<Boolean>(this, "enabled", true).getOrSet();
MESSAGE = new MultipleMessagesHelper(this, "message", Collections.singletonList("&cThis command does not exist!"));
}
}
@@ -1,43 +0,0 @@
package de.rayzs.pat.api.storage.config.settings;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
import de.rayzs.pat.utils.configuration.helper.*;
import de.rayzs.pat.utils.StringUtils;
import java.util.*;
public class CustomVersionSection extends ConfigStorage {
public boolean ENABLED, ALWAYS_TAB_COMPLETABLE;
public MultipleMessagesHelper MESSAGE, COMMANDS;
public CustomVersionSection() {
super("custom-version");
}
@Override
public void load() {
super.load();
ENABLED = new ConfigSectionHelper<Boolean>(this, "enabled", true).getOrSet();
ALWAYS_TAB_COMPLETABLE = new ConfigSectionHelper<Boolean>(this, "always-tab-completable", false).getOrSet();
COMMANDS = new MultipleMessagesHelper(this, "commands", Arrays.asList("icanhasbukkit", "about", "ver", "version"));
MESSAGE = new MultipleMessagesHelper(this, "message", Collections.singletonList("&fThis server is running CraftBukkit version git-NasaSpigot-294 (MC: X)"));
}
public boolean isTabCompletable(String command) {
if (!isCommand(command))
return false;
return ALWAYS_TAB_COMPLETABLE;
}
public boolean isCommand(String command) {
if(!ENABLED) return false;
command = StringUtils.getFirstArg(command);
for (String currentCommand : COMMANDS.getLines()) {
if (currentCommand.equalsIgnoreCase(command))
return true;
}
return false;
}
}
@@ -1,22 +0,0 @@
package de.rayzs.pat.api.storage.config.settings;
import de.rayzs.pat.utils.Reflection;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
public class DisableSyncSection extends ConfigStorage {
public boolean DISABLED;
public DisableSyncSection() {
super("disable-sync");
}
@Override
public void load() {
super.load();
if(!Reflection.isProxyServer()) return;
DISABLED = new ConfigSectionHelper<Boolean>(this, null, false).getOrSet();
}
}
@@ -1,31 +0,0 @@
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.utils.Reflection;
public class HandleThroughProxySection extends ConfigStorage {
public boolean ENABLED;
public boolean LOAD_FROM_ENV;
public String ENV_NAME;
public String TOKEN;
public HandleThroughProxySection() {
super("handle-through-proxy");
}
@Override
public void load() {
super.load();
if(Reflection.isProxyServer()) return;
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", "PAT_TOKEN").getOrSet();
}
}
@@ -1,32 +0,0 @@
package de.rayzs.pat.api.storage.config.settings;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
import de.rayzs.pat.utils.configuration.helper.*;
import de.rayzs.pat.utils.StringUtils;
import java.util.Collections;
public class PatchExploitSection extends ConfigStorage {
public boolean ENABLED;
public ConfigSectionHelper<String> ALERT_MESSAGE, KICK_MESSAGE;
public PatchExploitSection() {
super("patch-exploits");
}
@Override
public void load() {
super.load();
ENABLED = new ConfigSectionHelper<Boolean>(this, "enabled", true).getOrSet();
ALERT_MESSAGE = new ConfigSectionHelper<>(this, "alert-message", "%prefix% &4%player% &ctried to crash/lag the server.");
KICK_MESSAGE = new ConfigSectionHelper(this, "kick-message", "&cFailed to read packet! Please reconnect.");
}
public boolean isMalicious(String text) {
if(!ENABLED) return false;
return text.length() > 256
|| text.contains("nbt")
&& (StringUtils.countMatches('[', text) > 15 || StringUtils.countMatches('{', text) > 25);
}
}
@@ -1,19 +0,0 @@
package de.rayzs.pat.api.storage.config.settings;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
public class TurnBlacklistToWhitelistSection extends ConfigStorage {
public boolean ENABLED;
public TurnBlacklistToWhitelistSection() {
super("turn-blacklist-to-whitelist");
}
@Override
public void load() {
super.load();
ENABLED = new ConfigSectionHelper<Boolean>(this, null, false).getOrSet();
}
}
@@ -1,27 +0,0 @@
package de.rayzs.pat.api.storage.config.settings;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
import de.rayzs.pat.utils.Reflection;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
public class UpdateGroupsPerServerSection extends ConfigStorage {
// Disabled for now
public boolean ENABLED = false;
public UpdateGroupsPerServerSection() {
super("update-groups-per-server");
}
@Override
public void load() {
super.load();
/*
if (!Reflection.isProxyServer())
return;
ENABLED = new ConfigSectionHelper<Boolean>(this, null, false).getOrSet();
*/
}
}
@@ -1,24 +0,0 @@
package de.rayzs.pat.api.storage.config.settings;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
import de.rayzs.pat.utils.Reflection;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
public class UpdateGroupsPerWorldSection extends ConfigStorage {
public boolean ENABLED;
public UpdateGroupsPerWorldSection() {
super("update-groups-per-world");
}
@Override
public void load() {
super.load();
if (Reflection.isProxyServer())
return;
ENABLED = new ConfigSectionHelper<Boolean>(this, null, false).getOrSet();
}
}
@@ -1,30 +0,0 @@
package de.rayzs.pat.api.storage.config.settings;
import de.rayzs.pat.api.storage.storages.ConfigStorage;
import de.rayzs.pat.utils.configuration.helper.*;
import java.util.*;
public class UpdateSection extends ConfigStorage {
public boolean ENABLED, AUTO_UPDATE_CONFIG;
public int PERIOD;
public MultipleMessagesHelper OUTDATED, UPDATED;
public UpdateSection() {
super("updater");
}
@Override
public void load() {
super.load();
ENABLED = new ConfigSectionHelper<Boolean>(this, "enabled", true).getOrSet();
PERIOD = new ConfigSectionHelper<Integer>(this, "period", 10000).getOrSet();
AUTO_UPDATE_CONFIG = new ConfigSectionHelper<Boolean>(this, "auto-update-config", true).getOrSet();
UPDATED = new MultipleMessagesHelper(this, "updated", Collections.singletonList("&aYou are using the newest version! ^^"));
OUTDATED = new MultipleMessagesHelper(this, "outdated", Arrays.asList(
"&8[&4ProAntiTab&8] &cThere is a new version available! (%newest_version%)",
"&8[&4ProAntiTab&8] &cYou are still using the %current_version%.",
"&8[&4ProAntiTab&8] &cGet the newest version here:",
"&8[&4ProAntiTab&8] &ehttps://www.rayzs.de/products/proantitab/page"));
}
}
@@ -1,26 +0,0 @@
package de.rayzs.pat.api.storage.placeholders.commands.general;
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 SPLITTER;
@Override
public String onRequest(Player player, String param) {
return StringUtils.getStringList(Storage.Blacklist.getBlacklist().getCommands(), SPLITTER);
}
@Override
public void load() {
super.load();
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7, &e").getOrSet();
}
}
@@ -1,25 +0,0 @@
package de.rayzs.pat.api.storage.placeholders.commands.general;
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 org.bukkit.entity.Player;
public class ListReversedCommandsPlaceholder extends PlaceholderStorage {
public ListReversedCommandsPlaceholder() { super("list_reversed_commands"); }
public String SPLITTER;
@Override
public String onRequest(Player player, String param) {
return StringUtils.getReversedStringList(Storage.Blacklist.getBlacklist().getCommands(), SPLITTER);
}
@Override
public void load() {
super.load();
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7, &e").getOrSet();
}
}
@@ -1,20 +0,0 @@
package de.rayzs.pat.api.storage.placeholders.commands.general;
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
import de.rayzs.pat.api.storage.Storage;
import org.bukkit.entity.Player;
public class ListSizeCommandsPlaceholder extends PlaceholderStorage {
public ListSizeCommandsPlaceholder() { super("list_size_commands"); }
@Override
public String onRequest(Player player, String param) {
return String.valueOf(Storage.Blacklist.getBlacklist().getCommands().size());
}
@Override
public void load() {
super.load();
}
}
@@ -1,25 +0,0 @@
package de.rayzs.pat.api.storage.placeholders.commands.general;
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 org.bukkit.entity.Player;
public class ListSortedCommandsPlaceholder extends PlaceholderStorage {
public ListSortedCommandsPlaceholder() { super("list_sorted_commands"); }
public String SPLITTER;
@Override
public String onRequest(Player player, String param) {
return StringUtils.getSortedStringList(Storage.Blacklist.getBlacklist().getCommands(), SPLITTER);
}
@Override
public void load() {
super.load();
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7, &e").getOrSet();
}
}
@@ -1,28 +0,0 @@
package de.rayzs.pat.api.storage.placeholders.commands.group;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
import de.rayzs.pat.utils.StringUtils;
import de.rayzs.pat.utils.group.*;
import org.bukkit.entity.Player;
public class ListGroupCommandsPlaceholder extends PlaceholderStorage {
public ListGroupCommandsPlaceholder() { super("list_commands_group_"); }
public String SPLITTER;
@Override
public String onRequest(Player player, String param) {
Group group = GroupManager.getGroupByName(param);
if(group == null) return null;
return StringUtils.getStringList(group.getCommands(), SPLITTER);
}
@Override
public void load() {
super.load();
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7, &e").getOrSet();
}
}
@@ -1,28 +0,0 @@
package de.rayzs.pat.api.storage.placeholders.commands.group;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
import de.rayzs.pat.utils.StringUtils;
import de.rayzs.pat.utils.group.*;
import org.bukkit.entity.Player;
public class ListGroupReversedCommandsPlaceholder extends PlaceholderStorage {
public ListGroupReversedCommandsPlaceholder() { super("list_reversed_commands_group_"); }
public String SPLITTER;
@Override
public String onRequest(Player player, String param) {
Group group = GroupManager.getGroupByName(param);
if(group == null) return null;
return StringUtils.getReversedStringList(group.getCommands(), SPLITTER);
}
@Override
public void load() {
super.load();
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7, &e").getOrSet();
}
}
@@ -1,22 +0,0 @@
package de.rayzs.pat.api.storage.placeholders.commands.group;
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
import de.rayzs.pat.utils.group.*;
import org.bukkit.entity.Player;
public class ListGroupSizeCommandsPlaceholder extends PlaceholderStorage {
public ListGroupSizeCommandsPlaceholder() { super("list_size_commands_group_"); }
@Override
public String onRequest(Player player, String param) {
Group group = GroupManager.getGroupByName(param);
if(group == null) return null;
return String.valueOf(group.getCommands().size());
}
@Override
public void load() {
super.load();
}
}
@@ -1,28 +0,0 @@
package de.rayzs.pat.api.storage.placeholders.commands.group;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
import de.rayzs.pat.utils.StringUtils;
import de.rayzs.pat.utils.group.*;
import org.bukkit.entity.Player;
public class ListGroupSortedCommandsPlaceholder extends PlaceholderStorage {
public ListGroupSortedCommandsPlaceholder() { super("list_sorted_commands_group_"); }
public String SPLITTER;
@Override
public String onRequest(Player player, String param) {
Group group = GroupManager.getGroupByName(param);
if(group == null) return null;
return StringUtils.getSortedStringList(group.getCommands(), SPLITTER);
}
@Override
public void load() {
super.load();
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7, &e").getOrSet();
}
}
@@ -1,15 +0,0 @@
package de.rayzs.pat.api.storage.placeholders.general;
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
import de.rayzs.pat.api.storage.Storage;
import org.bukkit.entity.Player;
public class GeneralCurrentVersionPlaceholder extends PlaceholderStorage {
public GeneralCurrentVersionPlaceholder() { super("general_version_current"); }
@Override
public String onRequest(Player player, String param) {
return Storage.CURRENT_VERSION;
}
}
@@ -1,15 +0,0 @@
package de.rayzs.pat.api.storage.placeholders.general;
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
import de.rayzs.pat.api.storage.Storage;
import org.bukkit.entity.Player;
public class GeneralNewestVersionPlaceholder extends PlaceholderStorage {
public GeneralNewestVersionPlaceholder() { super("general_version_newest"); }
@Override
public String onRequest(Player player, String param) {
return Storage.NEWER_VERSION;
}
}
@@ -1,16 +0,0 @@
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;
}
}
@@ -1,23 +0,0 @@
package de.rayzs.pat.api.storage.placeholders.general;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
import org.bukkit.entity.Player;
public class GeneralUserPlaceholder extends PlaceholderStorage {
public GeneralUserPlaceholder() { super("general_user"); }
public String CONSOLE;
@Override
public String onRequest(Player player, String param) {
return player == null ? CONSOLE : player.getName();
}
@Override
public void load() {
super.load();
CONSOLE = new ConfigSectionHelper<String>(this, "console-name", "Server console").getOrSet();
}
}
@@ -1,25 +0,0 @@
package de.rayzs.pat.api.storage.placeholders.groups;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
import de.rayzs.pat.utils.StringUtils;
import de.rayzs.pat.utils.group.*;
import org.bukkit.entity.Player;
public class ListGroupsPlaceholder extends PlaceholderStorage {
public ListGroupsPlaceholder() { super("list_groups"); }
public String SPLITTER;
@Override
public String onRequest(Player player, String param) {
return StringUtils.getStringList(GroupManager.getGroupNames(), SPLITTER);
}
@Override
public void load() {
super.load();
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7, &e").getOrSet();
}
}
@@ -1,25 +0,0 @@
package de.rayzs.pat.api.storage.placeholders.groups;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
import de.rayzs.pat.utils.StringUtils;
import de.rayzs.pat.utils.group.*;
import org.bukkit.entity.Player;
public class ListGroupsReversedPlaceholder extends PlaceholderStorage {
public ListGroupsReversedPlaceholder() { super("list_reversed_groups"); }
public String SPLITTER;
@Override
public String onRequest(Player player, String param) {
return StringUtils.getReversedStringList(GroupManager.getGroupNames(), SPLITTER);
}
@Override
public void load() {
super.load();
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7, &e").getOrSet();
}
}
@@ -1,25 +0,0 @@
package de.rayzs.pat.api.storage.placeholders.groups;
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
import de.rayzs.pat.utils.StringUtils;
import de.rayzs.pat.utils.group.*;
import org.bukkit.entity.Player;
public class ListGroupsSortedPlaceholder extends PlaceholderStorage {
public ListGroupsSortedPlaceholder() { super("list_sorted_groups"); }
public String SPLITTER;
@Override
public String onRequest(Player player, String param) {
return StringUtils.getSortedStringList(GroupManager.getGroupNames(), SPLITTER);
}
@Override
public void load() {
super.load();
SPLITTER = new ConfigSectionHelper<String>(this, "splitter", "&7, &e").getOrSet();
}
}
@@ -1,20 +0,0 @@
package de.rayzs.pat.api.storage.placeholders.groups;
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
import de.rayzs.pat.utils.group.GroupManager;
import org.bukkit.entity.Player;
public class ListSizeGroupsPlaceholder extends PlaceholderStorage {
public ListSizeGroupsPlaceholder() { super("list_size_groups"); }
@Override
public String onRequest(Player player, String param) {
return String.valueOf(GroupManager.getGroups().size());
}
@Override
public void load() {
super.load();
}
}
@@ -1,17 +0,0 @@
package de.rayzs.pat.api.storage.placeholders.messages;
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.utils.StringUtils;
import org.bukkit.entity.Player;
public class BlockedBaseCommandPlaceholder extends PlaceholderStorage {
public BlockedBaseCommandPlaceholder() { super("message_base_blocked"); }
@Override
public String onRequest(Player player, String param) {
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");
}
}
@@ -1,17 +0,0 @@
package de.rayzs.pat.api.storage.placeholders.messages;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
import de.rayzs.pat.utils.StringUtils;
import org.bukkit.entity.Player;
public class BlockedSubCommandPlaceholder extends PlaceholderStorage {
public BlockedSubCommandPlaceholder() { super("message_sub_blocked"); }
@Override
public String onRequest(Player player, String param) {
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");
}
}
@@ -1,17 +0,0 @@
package de.rayzs.pat.api.storage.placeholders.messages;
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.utils.StringUtils;
import org.bukkit.entity.Player;
public class UnknownCommandPlaceholder extends PlaceholderStorage {
public UnknownCommandPlaceholder() { super("message_unknowncommand"); }
@Override
public String onRequest(Player player, String param) {
if (Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.MESSAGE == null) return null;
return StringUtils.getStringList(Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.MESSAGE.getLines(), "\n");
}
}
@@ -1,105 +0,0 @@
package de.rayzs.pat.api.storage.storages;
import de.rayzs.pat.utils.StringUtils;
import de.rayzs.pat.api.storage.*;
import java.io.Serializable;
import java.util.*;
public class BlacklistStorage extends StorageTemplate implements Serializable {
private List<String> commands = new ArrayList<>();
public BlacklistStorage(String navigatePath) {
super(Storage.Files.STORAGE, navigatePath);
}
public boolean isListed(String command) {
return isListed(command, false/*!Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED*/);
}
public boolean isListed(String command, boolean ignoreColons) {
final boolean caseSensitive = Storage.ConfigSections.Settings.BASE_COMMAND_CASE_SENSITIVE.ENABLED;
if (commands == null || command.isEmpty()) {
return false;
}
if (!isNegated(command) && commands.contains("*")) {
return true;
}
for (String listedCommand : commands) {
if (listedCommand == null)
continue;
if (ignoreColons) {
command = StringUtils.getFirstArg(command);
if (command.contains(":"))
command = command.substring(command.indexOf(':'));
}
if (caseSensitive) {
if (StringUtils.getFirstArg(listedCommand).equals(StringUtils.getFirstArg(command))) {
return true;
}
} else {
if (StringUtils.getFirstArg(listedCommand).equalsIgnoreCase(StringUtils.getFirstArg(command))) {
return true;
}
}
}
return false;
}
public void setList(List<String> commands) {
this.commands = commands;
}
public BlacklistStorage add(String command) {
if (!commands.contains(command))
commands.add(command);
return this;
}
public BlacklistStorage remove(String command) {
commands.remove(command);
return this;
}
public BlacklistStorage clear() {
commands.clear();
return this;
}
public List<String> getCommands() {
return commands;
}
@Override
public void save() {
getConfig().setAndSave(getNavigatePath(), commands);
}
@Override
public void load() {
getConfig().reload();
commands = (ArrayList<String>) getConfig().getOrSet(getNavigatePath(), commands);
}
private boolean isNegated(String command) {
if (command.isEmpty()) {
return false;
}
boolean negated = command.charAt(0) == '!';
if (!negated && command.length() > 5)
negated = command.charAt(5) == '!';
return negated;
}
}
@@ -1,17 +0,0 @@
package de.rayzs.pat.api.storage.storages;
import de.rayzs.pat.api.storage.*;
public class ConfigStorage extends StorageTemplate {
public ConfigStorage(String navigatePath) {
super(Storage.Files.CONFIGURATION, navigatePath);
Storage.ConfigSections.SECTIONS.add(this);
}
@Override
public void save() { getConfig().save(); }
@Override
public void load() { getConfig().reload(); }
}
@@ -1,59 +0,0 @@
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);
}
}
@@ -1,46 +0,0 @@
package de.rayzs.pat.api.storage.storages;
import de.rayzs.pat.utils.Reflection;
import de.rayzs.pat.api.storage.*;
import java.util.*;
public class IgnoredServersStorage extends StorageTemplate {
private List<String> servers = new ArrayList<>();
public IgnoredServersStorage(String navigatePath) {
super(Storage.Files.STORAGE, navigatePath);
}
public IgnoredServersStorage add(String server) {
server = server.toLowerCase();
if(!servers.contains(server))
servers.add(server);
return this;
}
public IgnoredServersStorage 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);
}
}
@@ -1,28 +0,0 @@
package de.rayzs.pat.api.storage.storages;
import de.rayzs.pat.api.storage.*;
import org.bukkit.entity.Player;
public abstract class PlaceholderStorage extends StorageTemplate {
private final String request;
public PlaceholderStorage(String request) {
super(Storage.Files.PLACEHOLDERS, request);
this.request = request;
Storage.ConfigSections.PLACEHOLDERS.add(this);
}
@Override
public void save() { getConfig().save(); }
@Override
public void load() { getConfig().reload(); }
public String getRequest() {
return request;
}
public abstract String onRequest(Player player, String param);
}
@@ -1,480 +0,0 @@
package de.rayzs.pat.plugin;
import de.rayzs.pat.api.brand.CustomServerBrand;
import de.rayzs.pat.plugin.converter.StorageConverter;
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.adapter.GroupManagerAdapter;
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.utils.hooks.PlaceholderHook;
import de.rayzs.pat.plugin.listeners.bukkit.*;
import de.rayzs.pat.api.event.PATEventHandler;
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 de.rayzs.pat.utils.sender.CommandSender;
import de.rayzs.pat.utils.sender.CommandSenderHandler;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.java.JavaPlugin;
import de.rayzs.pat.api.storage.Storage;
import de.rayzs.pat.utils.scheduler.*;
import org.bukkit.entity.Player;
import java.lang.reflect.Field;
import de.rayzs.pat.utils.*;
import org.bukkit.command.*;
import org.bukkit.plugin.*;
import org.bukkit.Bukkit;
import java.util.*;
import java.util.stream.Collectors;
public class BukkitLoader extends JavaPlugin implements PluginLoader {
private static List<String> commands = new ArrayList<>(),
allowedCommands = new ArrayList<>(),
disallowedCommands = new ArrayList<>();
private static Plugin plugin;
private static java.util.logging.Logger logger;
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("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
public void onEnable() {
plugin = this;
logger = getLogger();
for (OfflinePlayer offlinePlayerName : Bukkit.getOfflinePlayers()) {
offlinePlayerNames.add(offlinePlayerName.getName());
}
loadCommandMap();
CommandProcess.initialize();
Reflection.initialize(getServer());
ConfigUpdater.initialize();
Storage.initialize(this, getDescription().getVersion());
VersionComparer.get().setCurrentVersion(Storage.CURRENT_VERSION);
Storage.loadAll(true);
if (Bukkit.getServer().getPluginManager().getPlugin("PlaceholderAPI") != null)
new PlaceholderHook().register();
MessageTranslator.initialize();
CustomServerBrand.initialize();
bStats.initialize(this);
PluginManager manager = getServer().getPluginManager();
if (!Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED) {
loaded = true;
GroupManager.initialize();
BukkitPacketAnalyzer.injectAll();
} else BackendUpdater.handle();
manager.registerEvents(new BukkitPlayerListener(), this);
manager.registerEvents(new BukkitBlockCommandListener(), this);
if (Reflection.getMinor() >= 13) {
suggestions = true;
manager.registerEvents(new BukkitAntiTabListener(), this);
}
if (Reflection.isPaper() && Reflection.getMinor() >= 12)
manager.registerEvents(new PaperServerListPing(), this);
registerCommand("proantitab", "pat");
startUpdaterTask();
Storage.PLUGIN_OBJECT = this;
if (getServer().getPluginManager().getPlugin("LuckPerms") != null) {
LuckPermsAdapter.initialize();
Bukkit.getOnlinePlayers().forEach(player -> PermissionUtil.setPlayerPermissions(player.getUniqueId()));
} else {
final Plugin groupManagerPlugin = getServer().getPluginManager().getPlugin("GroupManager");
if (groupManagerPlugin != null) {
GroupManagerAdapter.initialize(groupManagerPlugin);
Bukkit.getOnlinePlayers().forEach(player -> PermissionUtil.setPlayerPermissions(player.getUniqueId()));
}
}
if (getServer().getPluginManager().getPlugin("ViaVersion") != null)
ViaVersionAdapter.initialize();
if (Storage.USE_SIMPLECLOUD) {
Logger.warning("Detected SimpleCloud. Therefore, MiniMessages are disabled!");
}
Storage.broadcastPermissionsPluginNotice();
ConfigUpdater.broadcastMissingParts();
ActionHandler.initialize();
SubArgsModule.initialize();
StorageConverter.initialize();
PATScheduler.createScheduler(this::loadAllCommands);
}
@Override
public void onDisable() {
BackendUpdater.stop();
BukkitPacketAnalyzer.uninjectAll();
MessageTranslator.closeAudiences();
}
public void registerCommand(String... commands) {
BukkitCommand command = new BukkitCommand();
for (String commandName : commands) {
PluginCommand pluginCommand = getCommand(commandName);
pluginCommand.setExecutor(command);
pluginCommand.setTabCompleter(command);
}
}
@Override
public void handleReload() {
loadAllCommands();
}
@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 isPlayerOnline(playerName) || 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 Bukkit.getOnlinePlayers().stream().map(Entity::getUniqueId).collect(Collectors.toList());
}
@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();
}
@Override
public void delayedPermissionsReload() {
PATScheduler.createScheduler(PermissionUtil::reloadPermissions, 40);
}
public void startUpdaterTask() {
if (!Storage.ConfigSections.Settings.UPDATE.ENABLED)
return;
updaterTask = PATScheduler.createAsyncScheduler(() -> {
if (VersionComparer.get().computeComparison())
updaterTask.cancelTask();
}, 20L, 20L * Storage.ConfigSections.Settings.UPDATE.PERIOD);
}
public static void handleUpdateCommandsPacket(CommunicationPackets.UpdateCommandsPacket packet) {
if (!packet.hasTargetUUID()) {
Bukkit.getOnlinePlayers().forEach(Player::updateCommands);
return;
}
Player player = Bukkit.getPlayer(packet.getTargetUUID());
if (player != null) {
player.updateCommands();
}
}
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();
boolean updatedList = false;
if (!messagePacket.getBaseBlockedMessage().getLines().isEmpty())
Storage.ConfigSections.Settings.CANCEL_COMMAND.BASE_COMMAND_RESPONSE = messagePacket.getBaseBlockedMessage();
if (!messagePacket.getSubBlockedMessage().getLines().isEmpty())
Storage.ConfigSections.Settings.CANCEL_COMMAND.SUB_COMMAND_RESPONSE = messagePacket.getSubBlockedMessage();
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;
}
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())
Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.ENABLED = unknownCommandPacket.isEnabled();
if (!loaded) {
loaded = true;
Bukkit.getOnlinePlayers().forEach(player -> {
CommandSender sender = CommandSenderHandler.from(player);
sender.updateGroups();
});
}
if (Reflection.getMinor() >= 13 && updatedList) {
BukkitAntiTabListener.updateCommands();
}
PATEventHandler.callReceiveSyncEvents(packetBundle);
}
public static List<String> getAllCommands() {
return new ArrayList<>(commands);
}
public static List<String> getAllowedCommands() {
return new ArrayList<>(allowedCommands);
}
public static List<String> getDisallowedCommands() {
return disallowedCommands;
}
@Override
public List<String> getPluginNames(String format) {
List<String> pluginNames = new ArrayList<>();
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
PluginDescriptionFile description = plugin.getDescription();
pluginNames.add(
format.replace("%n", description.getName())
.replace("%v", description.getVersion())
);
}
return pluginNames;
}
private void loadCommandMap() {
try {
if (Bukkit.getPluginManager() instanceof SimplePluginManager) {
Field commandMapField = SimplePluginManager.class.getDeclaredField("commandMap");
commandMapField.setAccessible(true);
SimpleCommandMap simpleCommandMap = (SimpleCommandMap) commandMapField.get(Bukkit.getPluginManager());
Field knownCommandsField = SimpleCommandMap.class.getDeclaredField("knownCommands");
knownCommandsField.setAccessible(true);
commandsMap = (Map<String, Command>) knownCommandsField.get(simpleCommandMap);
}
} catch (Throwable ignored) { }
if (commandsMap == null) {
Logger.warning("Failed to get server 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 -> {
boolean contains = Storage.Blacklist.getBlacklist().getCommands().contains(command);
return turn == contains;
}).toList();
lastCommandsLoad = System.currentTimeMillis();
BukkitLoader.commands = result;
BukkitLoader.allowedCommands = allowedCommands;
BukkitLoader.disallowedCommands = commands.stream().filter(command -> !allowedCommands.contains(command)).toList();
}
public static Map<String, Command> getCommandsMap() {
return commandsMap;
}
public static boolean useSuggestions() {
return suggestions;
}
public static Plugin getPlugin() {
return plugin;
}
public static java.util.logging.Logger getPluginLogger() {
return logger;
}
public static boolean isLoaded() {
return loaded;
}
}
Loaded 100 of 250 files, more files were not shown because too many files have changed in this diff. Show more