mirror of
https://github.com/RayzsYT/ProAntiTab.git
synced 2026-12-02 13:29:42 -05:00
Add Custom ServerBrand
This commit is contained in:
1 parent
0ee44ebf8b
commit
481c16b3e9
14 files changed
+479
-9
No files matched your search
@@ -7,6 +7,7 @@ import de.rayzs.pat.plugin.listeners.bukkit.BukkitPlayerConnectionListener;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.plugin.metrics.bStats;
|
||||
import de.rayzs.pat.plugin.netty.PacketAnalyzer;
|
||||
import de.rayzs.pat.utils.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.utils.communication.ClientCommunication;
|
||||
import de.rayzs.pat.utils.configuration.Configurator;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
@@ -41,6 +42,7 @@ public class BukkitLoader extends JavaPlugin {
|
||||
|
||||
Storage.load();
|
||||
MessageTranslator.initialize();
|
||||
CustomServerBrand.initialize();
|
||||
bStats.initialize(this);
|
||||
|
||||
PluginManager manager = getServer().getPluginManager();
|
||||
|
||||
@@ -9,6 +9,7 @@ import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.plugin.metrics.bStats;
|
||||
import de.rayzs.pat.utils.ConnectionBuilder;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.utils.communication.ClientCommunication;
|
||||
import de.rayzs.pat.utils.configuration.Configurator;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
@@ -42,6 +43,7 @@ public class BungeeLoader extends Plugin {
|
||||
|
||||
Storage.load();
|
||||
MessageTranslator.initialize();
|
||||
CustomServerBrand.initialize();
|
||||
GroupManager.initialize();
|
||||
bStats.initialize(this);
|
||||
PluginManager manager = ProxyServer.getInstance().getPluginManager();
|
||||
|
||||
@@ -15,6 +15,7 @@ import de.rayzs.pat.plugin.listeners.velocity.VelocityConnectionListener;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.plugin.metrics.impl.VelocityMetrics;
|
||||
import de.rayzs.pat.utils.ConnectionBuilder;
|
||||
import de.rayzs.pat.utils.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.utils.communication.ClientCommunication;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
@@ -57,6 +58,7 @@ public class VelocityLoader {
|
||||
|
||||
Storage.load();
|
||||
MessageTranslator.initialize();
|
||||
CustomServerBrand.initialize();
|
||||
GroupManager.initialize();
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import de.rayzs.pat.plugin.BukkitLoader;
|
||||
import de.rayzs.pat.plugin.netty.PacketAnalyzer;
|
||||
import de.rayzs.pat.utils.PermissionUtil;
|
||||
import de.rayzs.pat.utils.Storage;
|
||||
import de.rayzs.pat.utils.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.player.*;
|
||||
@@ -16,6 +17,9 @@ public class BukkitPlayerConnectionListener implements Listener {
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
CustomServerBrand.preparePlayer(player);
|
||||
CustomServerBrand.sendBrandToPlayer(player);
|
||||
|
||||
if(!PacketAnalyzer.inject(player)) player.kickPlayer("Failed to inject player!");
|
||||
|
||||
if(!Storage.BUNGEECORD && Storage.OUTDATED_VERSION && (PermissionUtil.hasPermission(player, "update"))) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import de.rayzs.pat.plugin.BukkitLoader;
|
||||
import de.rayzs.pat.plugin.listeners.bukkit.BukkitAntiTabListener;
|
||||
import de.rayzs.pat.plugin.listeners.velocity.VelocityAntiTabListener;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import de.rayzs.pat.utils.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.utils.communication.ClientCommunication;
|
||||
import de.rayzs.pat.utils.communication.ClientInfo;
|
||||
import de.rayzs.pat.utils.group.*;
|
||||
@@ -67,6 +68,7 @@ public class CommandProcess {
|
||||
if(!PermissionUtil.hasPermissionWithResponse(sender, "reload")) return;
|
||||
sender.sendMessage(Storage.RELOAD_LOADING);
|
||||
Storage.load();
|
||||
CustomServerBrand.initialize();
|
||||
handleChange();
|
||||
sender.sendMessage(Storage.RELOAD_DONE);
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
package de.rayzs.pat.utils;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class PacketUtils {
|
||||
|
||||
/*
|
||||
Original code from Bungeecord source:
|
||||
https://github.com/SpigotMC/BungeeCord/blob/master/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java#L72-L94
|
||||
*/
|
||||
|
||||
public static String readString(ByteBuf buf) throws Exception {
|
||||
return readString( buf, Short.MAX_VALUE );
|
||||
}
|
||||
|
||||
public static String readString(ByteBuf byteBuf, int maxLength) throws Exception {
|
||||
int len = readVarInt(byteBuf);
|
||||
if ( len > maxLength * 3 )
|
||||
throw new Exception("Cannot receive string longer than " + maxLength * 3 + " (got " + len + " bytes)" );
|
||||
|
||||
String string = byteBuf.toString(byteBuf.readerIndex(), len, StandardCharsets.UTF_8);
|
||||
byteBuf.readerIndex(byteBuf.readerIndex() + len );
|
||||
|
||||
if (string.length() > maxLength)
|
||||
throw new Exception( "Cannot receive string longer than " + maxLength + " (got " + string.length() + " characters)" );
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
/*
|
||||
Original code from Bungeecord source:
|
||||
https://github.com/SpigotMC/BungeeCord/blob/master/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java#L233-L261
|
||||
*/
|
||||
|
||||
public static int readVarInt(ByteBuf input) throws Exception {
|
||||
return readVarInt(input, 5);
|
||||
}
|
||||
|
||||
public static int readVarInt(ByteBuf input, int maxBytes) throws Exception {
|
||||
int out = 0, bytes = 0;
|
||||
byte in;
|
||||
|
||||
while (true) {
|
||||
in = input.readByte();
|
||||
out |= (in & 0x7F) << (bytes++ * 7);
|
||||
if (bytes > maxBytes) throw new Exception( "VarInt too big (max " + maxBytes + ")" );
|
||||
if ((in & 0x80) != 0x80) break;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/*
|
||||
Original code from Bungeecord source:
|
||||
https://github.com/SpigotMC/BungeeCord/blob/master/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java#L263C1-L283C6
|
||||
*/
|
||||
|
||||
public static void writeVarInt(int value, ByteBuf output) {
|
||||
int part;
|
||||
while (true) {
|
||||
part = value & 0x7F;
|
||||
value >>>= 7;
|
||||
|
||||
if ( value != 0 ) part |= 0x80;
|
||||
output.writeByte(part);
|
||||
|
||||
if ( value == 0 ) break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Original code from Bungeecord source:
|
||||
https://github.com/SpigotMC/BungeeCord/blob/master/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java#L50C4-L71C1
|
||||
*/
|
||||
|
||||
public static void writeString(String string, ByteBuf byteBuf) throws Exception {
|
||||
writeString(string, byteBuf, Short.MAX_VALUE );
|
||||
}
|
||||
|
||||
public static void writeString(String string, ByteBuf byteBuf, int maxLength) throws Exception {
|
||||
if (string.length() > maxLength )
|
||||
throw new Exception( "Cannot send string longer than " + maxLength + " (got " + string.length() + " characters)");
|
||||
|
||||
byte[] bytes = string.getBytes( StandardCharsets.UTF_8 );
|
||||
if (bytes.length > maxLength * 3)
|
||||
throw new Exception( "Cannot send string longer than " + ( maxLength * 3 ) + " (got " + bytes.length + " bytes)");
|
||||
|
||||
writeVarInt(bytes.length, byteBuf);
|
||||
byteBuf.writeBytes(bytes);
|
||||
}
|
||||
|
||||
public static class BrandManipulate {
|
||||
|
||||
private final int capacity;
|
||||
private final String brand;
|
||||
private final byte[] bytes;
|
||||
private ByteBuf byteBuf;
|
||||
|
||||
public BrandManipulate(String brand) {
|
||||
this.brand = brand;
|
||||
this.capacity = brand.getBytes(StandardCharsets.UTF_8).length + 1;
|
||||
bytes = buildBytes(true);
|
||||
}
|
||||
|
||||
public BrandManipulate(String brand, boolean releases) {
|
||||
this.brand = brand;
|
||||
this.capacity = brand.getBytes(StandardCharsets.UTF_8).length + 1;
|
||||
bytes = buildBytes(releases);
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
private byte[] buildBytes(boolean release) {
|
||||
byteBuf = Unpooled.buffer(this.capacity);
|
||||
|
||||
try {
|
||||
writeString(brand, byteBuf);
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
byte[] bytes = byteBuf.array();
|
||||
if(release) byteBuf.release();
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public ByteBuf getByteBuf() {
|
||||
return byteBuf;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,9 +49,18 @@ public class Reflection {
|
||||
return velocity;
|
||||
}
|
||||
|
||||
public static Class<?> getClass(String path, String name) throws ClassNotFoundException {
|
||||
String classPath = path + "." + name;
|
||||
return Class.forName(classPath);
|
||||
public static Class<?> getClass(String clazzPath) {
|
||||
Class<?> clazz = null;
|
||||
try {
|
||||
clazz = Class.forName(clazzPath);
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public static Class<?> getClass(String path, String name) {
|
||||
return getClass(path + "." + name);
|
||||
}
|
||||
|
||||
public static Class<?> getPacketClass() throws ClassNotFoundException {
|
||||
@@ -115,6 +124,41 @@ public class Reflection {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<Method> getMethodsByName(Object obj, String name) {
|
||||
return getMethodsByName(obj.getClass(), name);
|
||||
}
|
||||
|
||||
public static List<Method> getMethodsByName(Class<?> clazz, String name) {
|
||||
List<Method> result = new ArrayList<>();
|
||||
getMethods(clazz).stream().filter(method -> method.getName().equals(name)).forEach(result::add);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<Method> getMethodsByParameterAndName(Object obj, String name, Class<?>... parameterTypes) {
|
||||
return getMethodsByParameterAndName(obj.getClass(), name, parameterTypes);
|
||||
}
|
||||
|
||||
public static List<Method> getMethodsByParameterAndName(Class<?> clazz, String name, Class<?>... parameterTypes) {
|
||||
List<Method> result = new ArrayList<>();
|
||||
getMethodsByName(clazz, name).stream().filter(method -> Arrays.equals(method.getParameterTypes(), parameterTypes)).forEach(result::add);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Object invokeMethode(Method method, Object obj, Object... parameters) throws Exception {
|
||||
method.setAccessible(true);
|
||||
return method.invoke(obj, parameters);
|
||||
}
|
||||
|
||||
public static List<Method> getMethodsByParameter(Object obj, Class<?>... parameterTypes) {
|
||||
return getMethodsByParameter(obj.getClass(), parameterTypes);
|
||||
}
|
||||
|
||||
public static List<Method> getMethodsByParameter(Class<?> clazz, Class<?>... parameterTypes) {
|
||||
List<Method> result = new ArrayList<>();
|
||||
getMethods(clazz).stream().filter(method -> Arrays.equals(method.getParameterTypes(), parameterTypes)).forEach(result::add);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<Field> getFieldsByType(Class<?> clazz, String target, SearchOption type) {
|
||||
List<Field> result = new ArrayList<>(), fieldLists = getFields(clazz);
|
||||
|
||||
@@ -154,6 +198,18 @@ public class Reflection {
|
||||
return getMethodsByReturnType(clazz, target, type).get(0);
|
||||
}
|
||||
|
||||
public static List<Method> getMethodsByReturnTypeAndParameter(Class<?> clazz, String returnType, SearchOption type, Class<?>... parameters) {
|
||||
List<Method> result = new ArrayList<>();
|
||||
getMethodsByReturnType(clazz, returnType, type).stream().filter(method -> Arrays.equals(method.getParameterTypes(), parameters)).forEach(result::add);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<Method> getMethodsByReturnTypeAndName(Class<?> clazz, String returnType, SearchOption type, String methodName) {
|
||||
List<Method> result = new ArrayList<>();
|
||||
getMethodsByReturnType(clazz, returnType, type).stream().filter(method -> method.getName().equals(methodName)).forEach(result::add);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Object getPlayerConnection(Player player) throws Exception {
|
||||
Object entityPlayer = player.getClass().getMethod("getHandle").invoke(player);
|
||||
return getFieldsByType(entityPlayer.getClass(), "PlayerConnection", SearchOption.ENDS).get(0).get(entityPlayer);
|
||||
@@ -179,6 +235,22 @@ public class Reflection {
|
||||
if(closeAccessibility) field.setAccessible(false);
|
||||
}
|
||||
|
||||
public static Constructor<?> getConstructor(Object obj) throws NoSuchMethodException {
|
||||
return getConstructor(obj.getClass());
|
||||
}
|
||||
|
||||
public static Constructor<?> getConstructor(Class<?> clazz) throws NoSuchMethodException {
|
||||
return clazz.getDeclaredConstructor(new Class[] { null });
|
||||
}
|
||||
|
||||
public static Constructor<?> getConstructor(Object obj, Class<?>... parameters) throws NoSuchMethodException {
|
||||
return getConstructor(obj.getClass(), parameters);
|
||||
}
|
||||
|
||||
public static Constructor<?> getConstructor(Class<?> clazz, Class<?>... parameters) throws NoSuchMethodException {
|
||||
return clazz.getDeclaredConstructor(parameters);
|
||||
}
|
||||
|
||||
public static void getAndSetField(String fieldName, Class<?> clazz, Object clazzObj, Object value, boolean closeAccessibility) throws Exception {
|
||||
Field field = getFieldByName(clazz, fieldName);
|
||||
setFieldValue(field, clazzObj, value, closeAccessibility);
|
||||
|
||||
@@ -7,15 +7,15 @@ public class Storage {
|
||||
|
||||
public static String CURRENT_VERSION_NAME = "", NEWEST_VERSION_NAME = "";
|
||||
public static ConfigurationBuilder CONFIGURATION = Configurator.get("config"), STORAGE = Configurator.get("storage"), TOKEN = Configurator.get("token");
|
||||
public static List<String> UNKNOWN_COMMAND, STATS, BLOCKED_COMMANDS_LIST, COMMAND_HELP = new ArrayList<>(), UPDATE_NOTIFICATION = new ArrayList<>();
|
||||
public static List<String> UNKNOWN_COMMAND, STATS, BLOCKED_COMMANDS_LIST, COMMAND_HELP = new ArrayList<>(), CUSTOM_SERVER_BRANDS = new ArrayList<>(), UPDATE_NOTIFICATION = new ArrayList<>();
|
||||
public static List<UUID> NOTIFY_PLAYERS = new ArrayList<>();
|
||||
public static String TOKEN_KEY = UUID.randomUUID().toString(), BUNGEECORD_MESSAGE, NOTIFY_ALERT, NOTIFY_ENABLED, NOTIFY_DISABLED, CANCEL_COMMANDS_MESSAGE, COMMAND_UNKNOWN, NO_PERMISSIONS, RELOAD_LOADING, RELOAD_DONE,
|
||||
BLACKLIST_CLEAR_CONFIRM_MESSAGE, BLACKLIST_CLEAR_MESSAGE, BLACKLIST_LIST_COMMAND_MESSAGE, BLACKLIST_ADD_MESSAGE, BLACKLIST_ADD_FAIL_MESSAGE, BLACKLIST_REMOVE_MESSAGE, BLACKLIST_REMOVE_FAIL_MESSAGE, BLACKLIST_LIST_MESSAGE, BLACKLIST_LIST_SPLITTER_MESSAGE,
|
||||
GROUP_DELETE_CONFIRM_MESSAGE, GROUP_CREATE_MESSAGE, GROUP_DELETE_MESSAGE, GROUP_ALREADY_CREATED_MESSAGE, GROUP_NOT_EXIST_MESSAGE, GROUP_CLEAR_MESSAGE, GROUP_LIST_COMMAND_MESSAGE, GROUP_ADD_MESSAGE, GROUP_ADD_FAIL_MESSAGE, GROUP_REMOVE_MESSAGE, GROUP_REMOVE_FAIL_MESSAGE, GROUP_LIST_MESSAGE, GROUP_LIST_SPLITTER_MESSAGE, GROUPS_LIST_MESSAGE, GROUPS_LIST_SPLITTER_MESSAGE, GROUPS_LIST_GROUPS_MESSAGE,
|
||||
GROUP_CLEAR_CONFIRM_MESSAGE,
|
||||
STATS_FAIL_MESSAGE, STATS_SERVERS_SPLITTER_MESSAGE, STATS_SERVERS_MESSAGE, STATS_SERVERS_NO_SERVER_MESSAGE;
|
||||
public static boolean BUNGEECORD = false, USE_UNKNOWN_COMMAND, TURN_BLACKLIST_TO_WHITELIST, CANCEL_COMMANDS, UPDATE_ENABLED, OUTDATED_VERSION = false, CONSOLE_NOTIFICATION_ENABLED = true;
|
||||
public static int UPDATE_PERIOD, SERVER_DATA_SYNC_COUNT = 0;
|
||||
public static boolean BUNGEECORD = false, USE_CUSTOM_BRAND, USE_UNKNOWN_COMMAND, TURN_BLACKLIST_TO_WHITELIST, CANCEL_COMMANDS, UPDATE_ENABLED, OUTDATED_VERSION = false, CONSOLE_NOTIFICATION_ENABLED = true;
|
||||
public static int UPDATE_PERIOD, SERVER_DATA_SYNC_COUNT = 0, CUSTOM_SERVER_BRAND_REPEAT_DELAY;
|
||||
public static long LAST_DATA_UPDATE = System.currentTimeMillis();
|
||||
|
||||
public static void
|
||||
@@ -27,7 +27,8 @@ public class Storage {
|
||||
defaultHelpArray = new ArrayList<>(),
|
||||
defaultUnknownCommandArray = new ArrayList<>(),
|
||||
defaultNotificationArray = new ArrayList<>(),
|
||||
statsMessageArray = new ArrayList<>();
|
||||
statsMessageArray = new ArrayList<>(),
|
||||
customServerBrandsArray = new ArrayList<>();
|
||||
|
||||
defaultBlockedCommandArray.addAll(Arrays.asList("help", "?", "about", "ver", "version", "icanhasbukkit", "pl", "plugins"));
|
||||
defaultHelpArray.add("&7Available commands are: &f/%label%&7...");
|
||||
@@ -50,12 +51,28 @@ public class Storage {
|
||||
statsMessageArray.add("&7Last sync sent to &f%server_count% &7servers. &8&o(%last_sync_time% ago)");
|
||||
statsMessageArray.add("&7Sent to servers: &f%servers%");
|
||||
|
||||
customServerBrandsArray.add("&f&lP&froAntiTab |");
|
||||
customServerBrandsArray.add("&fP&lr&foAntiTab /");
|
||||
customServerBrandsArray.add("&fPr&lo&fAntiTab -");
|
||||
customServerBrandsArray.add("&fPro&lA&fntiTab |");
|
||||
customServerBrandsArray.add("&fProA&ln&ftiTab \\");
|
||||
customServerBrandsArray.add("&fProAn<&fiTab |");
|
||||
customServerBrandsArray.add("&fProAnt&li&fTab /");
|
||||
customServerBrandsArray.add("&fProAnti&lT&fab -");
|
||||
customServerBrandsArray.add("&fProAnti&lT&fab \\");
|
||||
customServerBrandsArray.add("&fProAntiT&la&fb |");
|
||||
customServerBrandsArray.add("&fProAntiTa&lb&f /");
|
||||
customServerBrandsArray.add("&fProAntiTab -");
|
||||
customServerBrandsArray.add("&fProAntiTab \\");
|
||||
|
||||
UPDATE_ENABLED = (boolean) CONFIGURATION.getOrSet("updater.enabled", true);
|
||||
UPDATE_PERIOD = (int) CONFIGURATION.getOrSet("updater.period", 18000);
|
||||
|
||||
UPDATE_NOTIFICATION = (ArrayList<String>) CONFIGURATION.getOrSet("updater.notification", defaultNotificationArray);
|
||||
STATS = (ArrayList<String>) CONFIGURATION.getOrSet("stats.message.statistic", statsMessageArray);
|
||||
|
||||
CUSTOM_SERVER_BRANDS = (ArrayList<String>) CONFIGURATION.getOrSet("custom-server-brand.brands", customServerBrandsArray);
|
||||
|
||||
COMMAND_HELP = (ArrayList<String>) CONFIGURATION.getOrSet("help", defaultHelpArray);
|
||||
BLOCKED_COMMANDS_LIST = (ArrayList<String>) STORAGE.getOrSet("commands", defaultBlockedCommandArray);
|
||||
NO_PERMISSIONS = (String) CONFIGURATION.getOrSet("no-permissions", "&cYou are not allowed to execute this command! Missing permission: &4proantitab.%permission%");
|
||||
@@ -83,6 +100,9 @@ public class Storage {
|
||||
STATS_SERVERS_SPLITTER_MESSAGE = (String) CONFIGURATION.getOrSet("stats.message.splitter", "&7, ");
|
||||
STATS_SERVERS_MESSAGE = (String) CONFIGURATION.getOrSet("stats.message.server", "&f%servername% &8(%updated%)");
|
||||
|
||||
USE_CUSTOM_BRAND = (boolean) CONFIGURATION.getOrSet("custom-server-brand.enabled", false);
|
||||
CUSTOM_SERVER_BRAND_REPEAT_DELAY = (int) CONFIGURATION.getOrSet("custom-server-brand.repeat-delay", Reflection.isProxyServer() ? 150 : 3);
|
||||
|
||||
CANCEL_COMMANDS = (boolean) CONFIGURATION.getOrSet("cancel-blocked-commands.enabled", true);
|
||||
CANCEL_COMMANDS_MESSAGE = (String) CONFIGURATION.getOrSet("cancel-blocked-commands.message", "&cThe command '%command%' is blocked!");
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package de.rayzs.pat.utils.brand;
|
||||
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.brand.impl.BukkitServerBrand;
|
||||
import de.rayzs.pat.utils.brand.impl.BungeeServerBrand;
|
||||
import de.rayzs.pat.utils.brand.impl.VelocityServerBrand;
|
||||
|
||||
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); }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package de.rayzs.pat.utils.brand;
|
||||
|
||||
public interface ServerBrand {
|
||||
void preparePlayer(Object playerObj);
|
||||
void send(Object playerObj);
|
||||
void initializeTask();
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package de.rayzs.pat.utils.brand.impl;
|
||||
|
||||
import de.rayzs.pat.plugin.BukkitLoader;
|
||||
import de.rayzs.pat.utils.PacketUtils;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.Storage;
|
||||
import de.rayzs.pat.utils.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.utils.brand.ServerBrand;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class BukkitServerBrand implements ServerBrand {
|
||||
|
||||
private static final Server SERVER = Bukkit.getServer();
|
||||
private static String BRAND = "";
|
||||
private static int TASK = -1;
|
||||
private static boolean INITIALIZED = false;
|
||||
|
||||
@Override
|
||||
public void initializeTask() {
|
||||
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 != -1) {
|
||||
Bukkit.getScheduler().cancelTask(TASK);
|
||||
TASK = -1;
|
||||
}
|
||||
if(!Storage.USE_CUSTOM_BRAND) return;
|
||||
|
||||
AtomicInteger animationState = new AtomicInteger(0);
|
||||
TASK = Bukkit.getScheduler().scheduleSyncRepeatingTask(BukkitLoader.getPlugin(), () -> {
|
||||
if(animationState.getAndIncrement() >= Storage.CUSTOM_SERVER_BRANDS.size() - 1) animationState.set(0);
|
||||
BRAND = Storage.CUSTOM_SERVER_BRANDS.get(animationState.get());
|
||||
Bukkit.getOnlinePlayers().forEach(this::send);
|
||||
}, Storage.CUSTOM_SERVER_BRAND_REPEAT_DELAY, Storage.CUSTOM_SERVER_BRAND_REPEAT_DELAY);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preparePlayer(Object playerObj) {
|
||||
if(!(playerObj instanceof Player) || !Storage.USE_CUSTOM_BRAND) return;
|
||||
Player player = (Player) playerObj;
|
||||
|
||||
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.USE_CUSTOM_BRAND) return;
|
||||
Player player = (Player) playerObj;
|
||||
|
||||
PacketUtils.BrandManipulate serverBrand = new PacketUtils.BrandManipulate(BRAND.replace("&", "§") + "§r");
|
||||
player.sendPluginMessage(BukkitLoader.getPlugin(), CustomServerBrand.CHANNEL_NAME, serverBrand.getBytes());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package de.rayzs.pat.utils.brand.impl;
|
||||
|
||||
import de.rayzs.pat.plugin.BungeeLoader;
|
||||
import de.rayzs.pat.utils.PacketUtils;
|
||||
import de.rayzs.pat.utils.Storage;
|
||||
import de.rayzs.pat.utils.brand.ServerBrand;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.scheduler.ScheduledTask;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class BungeeServerBrand implements ServerBrand {
|
||||
|
||||
private static final ProxyServer SERVER = BungeeLoader.getPlugin().getProxy();
|
||||
private static ScheduledTask TASK;
|
||||
private static String BRAND;
|
||||
|
||||
public BungeeServerBrand() {
|
||||
if (!Storage.USE_CUSTOM_BRAND) return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeTask() {
|
||||
if(TASK != null) TASK.cancel();
|
||||
if(!Storage.USE_CUSTOM_BRAND) return;
|
||||
|
||||
AtomicInteger animationState = new AtomicInteger(0);
|
||||
TASK = SERVER.getScheduler().schedule(BungeeLoader.getPlugin(), () -> {
|
||||
if(animationState.getAndIncrement() >= Storage.CUSTOM_SERVER_BRANDS.size() - 1) animationState.set(0);
|
||||
BRAND = Storage.CUSTOM_SERVER_BRANDS.get(animationState.get());
|
||||
SERVER.getPlayers().forEach(this::send);
|
||||
}, Storage.CUSTOM_SERVER_BRAND_REPEAT_DELAY, Storage.CUSTOM_SERVER_BRAND_REPEAT_DELAY, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preparePlayer(Object playerObj) { }
|
||||
|
||||
@Override
|
||||
public void send(Object playerObj) {
|
||||
if (!(playerObj instanceof ProxiedPlayer) || !Storage.USE_CUSTOM_BRAND) return;
|
||||
ProxiedPlayer player = (ProxiedPlayer) playerObj;
|
||||
|
||||
PacketUtils.BrandManipulate serverBrand = new PacketUtils.BrandManipulate(BRAND.replace("&", "§") + "§r");
|
||||
String brand = player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_13 ? "minecraft:brand" : "MC|Brand";
|
||||
player.sendData(brand, serverBrand.getBytes());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package de.rayzs.pat.utils.brand.impl;
|
||||
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||
import com.velocitypowered.api.scheduler.ScheduledTask;
|
||||
import de.rayzs.pat.plugin.VelocityLoader;
|
||||
import de.rayzs.pat.utils.PacketUtils;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.Storage;
|
||||
import de.rayzs.pat.utils.brand.ServerBrand;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class VelocityServerBrand implements ServerBrand {
|
||||
|
||||
private static final ProxyServer SERVER = VelocityLoader.getServer();
|
||||
private static Class<?> pluginMessagePacketClass, minecraftConnectionClass, connectedPlayerConnectionClass;
|
||||
private static ScheduledTask TASK;
|
||||
private static String BRAND = Storage.CUSTOM_SERVER_BRANDS.get(0);
|
||||
|
||||
@Override
|
||||
public void initializeTask() {
|
||||
if(TASK != null) TASK.cancel();
|
||||
if(!Storage.USE_CUSTOM_BRAND) 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");
|
||||
|
||||
AtomicInteger animationState = new AtomicInteger(0);
|
||||
TASK = SERVER.getScheduler().buildTask(VelocityLoader.getInstance(), () -> {
|
||||
if(animationState.getAndIncrement() >= Storage.CUSTOM_SERVER_BRANDS.size() - 1) animationState.set(0);
|
||||
BRAND = Storage.CUSTOM_SERVER_BRANDS.get(animationState.get());
|
||||
SERVER.getAllPlayers().forEach(this::send);
|
||||
}).repeat(Storage.CUSTOM_SERVER_BRAND_REPEAT_DELAY, TimeUnit.MILLISECONDS).schedule();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void preparePlayer(Object playerObj) { }
|
||||
|
||||
@Override
|
||||
public void send(Object playerObj) {
|
||||
if (!(playerObj instanceof Player) || !Storage.USE_CUSTOM_BRAND) return;
|
||||
|
||||
try {
|
||||
Player player = (Player) playerObj;
|
||||
Object connectedPlayerObj = connectedPlayerConnectionClass.cast(player),
|
||||
minecraftConnectionObj = Reflection.getMethodsByName(connectedPlayerObj, "getConnection").get(0).invoke(connectedPlayerObj);
|
||||
|
||||
PacketUtils.BrandManipulate serverBrand = new PacketUtils.BrandManipulate(BRAND.replace("&", "§") + "§r", 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||
import de.rayzs.pat.plugin.VelocityLoader;
|
||||
import de.rayzs.pat.utils.communication.Client;
|
||||
import de.rayzs.pat.utils.communication.ClientCommunication;
|
||||
@@ -40,11 +39,14 @@ public class VelocityClient implements Client {
|
||||
@Subscribe
|
||||
public void onQueryReceive(PluginMessageEvent event) {
|
||||
if (event.getIdentifier() != IDENTIFIER) return;
|
||||
|
||||
try {
|
||||
DataInputStream input = new DataInputStream(new ByteArrayInputStream(event.getData()));
|
||||
String information = input.readUTF();
|
||||
ServerConnection server = (ServerConnection) event.getSource();
|
||||
ClientCommunication.receiveInformation(server.getServerInfo().getName(), information);
|
||||
} catch (Throwable throwable) { throwable.printStackTrace(); }
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user