mirror of
https://github.com/RayzsYT/ProAntiTab.git
synced 2026-12-01 04:49:44 -05:00
Big API Update
This commit is contained in:
1 parent
1bd19b7447
commit
ca9d055a89
30 files changed
+376
-164
No files matched your search
@@ -1,10 +1,10 @@
|
||||
package de.rayzs.pat.api.brand.impl;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.BukkitLoader;
|
||||
import de.rayzs.pat.api.netty.PacketAnalyzer;
|
||||
import de.rayzs.pat.utils.PacketUtils;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.Storage;
|
||||
import de.rayzs.pat.api.brand.CustomServerBrand;
|
||||
import de.rayzs.pat.api.brand.ServerBrand;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
@@ -22,7 +22,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
public class BukkitServerBrand implements ServerBrand {
|
||||
|
||||
private static final Server SERVER = Bukkit.getServer();
|
||||
private static String BRAND = "";
|
||||
private static String BRAND = Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().get(0);
|
||||
private static int TASK = -1;
|
||||
private static boolean INITIALIZED = false;
|
||||
private static Class<?> brandPayloadClass, clientBoundCustomPacketPayloadPacketClass, customPacketPayloadPacketClass;
|
||||
@@ -57,19 +57,19 @@ public class BukkitServerBrand implements ServerBrand {
|
||||
TASK = -1;
|
||||
}
|
||||
|
||||
if(!Storage.USE_CUSTOM_BRAND || Storage.CUSTOM_SERVER_BRAND_REPEAT_DELAY == -1) return;
|
||||
if(!Storage.ConfigSections.Settings.CUSTOM_BRAND.ENABLED || Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY == -1) 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()) + "§r";
|
||||
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.CUSTOM_SERVER_BRAND_REPEAT_DELAY);
|
||||
}, 1, Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preparePlayer(Object playerObj) {
|
||||
if(!(playerObj instanceof Player) || !Storage.USE_CUSTOM_BRAND) return;
|
||||
if(!(playerObj instanceof Player) || !Storage.ConfigSections.Settings.CUSTOM_BRAND.ENABLED) return;
|
||||
Player player = (Player) playerObj;
|
||||
|
||||
try {
|
||||
@@ -85,7 +85,7 @@ public class BukkitServerBrand implements ServerBrand {
|
||||
|
||||
@Override
|
||||
public void send(Object playerObj) {
|
||||
if(!(playerObj instanceof Player) || !Storage.USE_CUSTOM_BRAND) return;
|
||||
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);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package de.rayzs.pat.api.brand.impl;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.BungeeLoader;
|
||||
import de.rayzs.pat.utils.PacketUtils;
|
||||
import de.rayzs.pat.utils.Storage;
|
||||
import de.rayzs.pat.api.brand.ServerBrand;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
@@ -18,23 +18,21 @@ public class BungeeServerBrand implements ServerBrand {
|
||||
|
||||
private static final ProxyServer SERVER = BungeeLoader.getPlugin().getProxy();
|
||||
private static ScheduledTask TASK;
|
||||
private static String BRAND;
|
||||
private static String BRAND = Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().get(0);
|
||||
|
||||
public BungeeServerBrand() {
|
||||
if (!Storage.USE_CUSTOM_BRAND) return;
|
||||
}
|
||||
public BungeeServerBrand() { }
|
||||
|
||||
@Override
|
||||
public void initializeTask() {
|
||||
if(TASK != null) TASK.cancel();
|
||||
if(!Storage.USE_CUSTOM_BRAND || Storage.CUSTOM_SERVER_BRAND_REPEAT_DELAY == -1) return;
|
||||
if(!Storage.ConfigSections.Settings.CUSTOM_BRAND.ENABLED || Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY == -1) 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 = MessageTranslator.replaceMessage(Storage.CUSTOM_SERVER_BRANDS.get(animationState.get())) + "§r";
|
||||
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.CUSTOM_SERVER_BRAND_REPEAT_DELAY, TimeUnit.MILLISECONDS);
|
||||
}, 1, Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -42,7 +40,7 @@ public class BungeeServerBrand implements ServerBrand {
|
||||
|
||||
@Override
|
||||
public void send(Object playerObj) {
|
||||
if (!(playerObj instanceof ProxiedPlayer) || !Storage.USE_CUSTOM_BRAND) return;
|
||||
if (!(playerObj instanceof ProxiedPlayer) || !Storage.ConfigSections.Settings.CUSTOM_BRAND.ENABLED) return;
|
||||
ProxiedPlayer player = (ProxiedPlayer) playerObj;
|
||||
|
||||
String serverName = "", playerName = player.getName(), customBrand;
|
||||
|
||||
@@ -4,15 +4,14 @@ import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.scheduler.ScheduledTask;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
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.api.brand.ServerBrand;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@@ -22,12 +21,12 @@ 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);
|
||||
private static String BRAND = Storage.ConfigSections.Settings.CUSTOM_BRAND.BRANDS.getLines().get(0);
|
||||
|
||||
@Override
|
||||
public void initializeTask() {
|
||||
if(TASK != null) TASK.cancel();
|
||||
if(!Storage.USE_CUSTOM_BRAND || Storage.CUSTOM_SERVER_BRAND_REPEAT_DELAY == -1) return;
|
||||
if(!Storage.ConfigSections.Settings.CUSTOM_BRAND.ENABLED || Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY == -1) return;
|
||||
|
||||
if(pluginMessagePacketClass == null)
|
||||
pluginMessagePacketClass = Reflection.getClass("com.velocitypowered.proxy.protocol.packet.PluginMessagePacket");
|
||||
@@ -40,10 +39,10 @@ public class VelocityServerBrand implements ServerBrand {
|
||||
|
||||
AtomicInteger animationState = new AtomicInteger(0);
|
||||
TASK = SERVER.getScheduler().buildTask(VelocityLoader.getInstance(), () -> {
|
||||
if(animationState.getAndIncrement() >= Storage.CUSTOM_SERVER_BRANDS.size() - 1) animationState.set(0);
|
||||
BRAND = MessageTranslator.replaceMessage(Storage.CUSTOM_SERVER_BRANDS.get(animationState.get())) + "§r";
|
||||
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.CUSTOM_SERVER_BRAND_REPEAT_DELAY, TimeUnit.MILLISECONDS).schedule();
|
||||
}).repeat(Storage.ConfigSections.Settings.CUSTOM_BRAND.REPEAT_DELAY, TimeUnit.MILLISECONDS).schedule();
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +51,7 @@ public class VelocityServerBrand implements ServerBrand {
|
||||
|
||||
@Override
|
||||
public void send(Object playerObj) {
|
||||
if (!(playerObj instanceof Player) || !Storage.USE_CUSTOM_BRAND) return;
|
||||
if (!(playerObj instanceof Player) || !Storage.ConfigSections.Settings.CUSTOM_BRAND.ENABLED) return;
|
||||
|
||||
try {
|
||||
Player player = (Player) playerObj;
|
||||
|
||||
@@ -35,7 +35,7 @@ public class ClientCommunication {
|
||||
|
||||
ClientInfo client = getClientById(requestPacket.getServerId());
|
||||
if (client == null) {
|
||||
client = new ClientInfo(requestPacket.getServerId(), serverName);
|
||||
client = new ClientInfo(serverObj, requestPacket.getServerId(), serverName);
|
||||
QUEUE_CLIENTS.put(requestPacket.getServerId(), client);
|
||||
} else if (!client.getName().equals(serverName)) client.setName(serverName);
|
||||
|
||||
@@ -76,10 +76,16 @@ public class ClientCommunication {
|
||||
if(packet instanceof DataConverter.PacketBundle) {
|
||||
DataConverter.BackendDataPacket backendDataPacket = (DataConverter.BackendDataPacket) packet;
|
||||
if(!backendDataPacket.isToken(Storage.TOKEN)) return;
|
||||
|
||||
DataConverter.PacketBundle packetBundle = (DataConverter.PacketBundle) packet;
|
||||
DataConverter.CommandsPacket commandsPacket = packetBundle.getCommandsPacket();
|
||||
DataConverter.GroupsPacket groupsPacket = packetBundle.getGroupsPacket();
|
||||
BukkitLoader.synchronizeCommandData(commandsPacket);
|
||||
DataConverter.UnknownCommandPacket unknownCommandPacket = packetBundle.getUnknownCommandPacket();
|
||||
|
||||
List<String> commands = new ArrayList<>();
|
||||
|
||||
|
||||
BukkitLoader.synchronizeCommandData(commandsPacket, unknownCommandPacket);
|
||||
BukkitLoader.synchronizeGroupData(groupsPacket);
|
||||
}
|
||||
}
|
||||
@@ -103,8 +109,6 @@ public class ClientCommunication {
|
||||
DataConverter.GroupsPacket groupsPacket = new DataConverter.GroupsPacket(GroupManager.getGroups());
|
||||
DataConverter.PacketBundle bundle = new DataConverter.PacketBundle(Storage.TOKEN, serverId, commandsPacket, groupsPacket);
|
||||
|
||||
|
||||
|
||||
if(clientInfo == null) sendPacket(bundle);
|
||||
else clientInfo.sendBytes(DataConverter.convertToBytes(bundle));
|
||||
}
|
||||
|
||||
@@ -12,8 +12,10 @@ import java.util.*;
|
||||
public class Storage {
|
||||
|
||||
public static final GeneralBlacklist BLACKLIST = BlacklistCreator.createGeneralBlacklist();
|
||||
public static final List<UUID> NOTIFY_PLAYERS = new ArrayList<>();
|
||||
|
||||
public static String TOKEN, SERVER_NAME, CURRENT_VERSION, NEWER_VERSION;
|
||||
public static boolean OUTDATED = false;
|
||||
public static boolean OUTDATED = false, SEND_CONSOLE_NOTIFICATION = false;
|
||||
|
||||
public static void loadAll(boolean loadBlacklist) {
|
||||
loadConfig();
|
||||
@@ -64,6 +66,7 @@ public class Storage {
|
||||
public static CancelCommandSection CANCEL_COMMAND = new CancelCommandSection();
|
||||
public static CustomBrandSection CUSTOM_BRAND = new CustomBrandSection();
|
||||
public static CustomPluginsSection CUSTOM_PLUGIN = new CustomPluginsSection();
|
||||
public static CustomProtocolPingSection CUSTOM_PROTOCOL_PING = new CustomProtocolPingSection();
|
||||
public static CustomUnknownCommandSection CUSTOM_UNKNOWN_COMMAND = new CustomUnknownCommandSection();
|
||||
public static HandleThroughProxySection HANDLE_THROUGH_PROXY = new HandleThroughProxySection();
|
||||
public static TurnBlacklistToWhitelistSection TURN_BLACKLIST_TO_WHITELIST = new TurnBlacklistToWhitelistSection();
|
||||
|
||||
@@ -9,6 +9,7 @@ public class CustomPluginsSection extends ConfigStorage {
|
||||
|
||||
public boolean ENABLED;
|
||||
public MultipleMessagesHelper MESSAGE;
|
||||
private final String[] PLUGIN_COMMANDS = new String[] { "pl", "plugins", "bukkit:pl", "bukkit:plugins" };
|
||||
|
||||
public CustomPluginsSection() {
|
||||
super("custom-plugins");
|
||||
@@ -20,4 +21,20 @@ public class CustomPluginsSection extends ConfigStorage {
|
||||
ENABLED = new ConfigSectionHelper<Boolean>(this, "enabled", true).getOrSet();
|
||||
MESSAGE = new MultipleMessagesHelper(this, "message", Collections.singletonList("&fPlugins (0):"));
|
||||
}
|
||||
|
||||
public boolean isPluginsCommand(String command) {
|
||||
if(!ENABLED) return false;
|
||||
|
||||
if (command.contains(" ")) {
|
||||
String[] split = command.split(" ");
|
||||
if (split.length > 0)
|
||||
command = split[0];
|
||||
command = command.split(" ")[0];
|
||||
}
|
||||
for (String currentCommand : PLUGIN_COMMANDS) {
|
||||
if (currentCommand.equals(command.toLowerCase()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package de.rayzs.pat.api.storage.config.settings;
|
||||
|
||||
import de.rayzs.pat.api.storage.storages.ConfigStorage;
|
||||
import de.rayzs.pat.utils.configuration.helper.ConfigSectionHelper;
|
||||
|
||||
public class CustomProtocolPingSection extends ConfigStorage {
|
||||
|
||||
public boolean ENABLED, ALWAYS_SHOW;
|
||||
public String PROTOCOL;
|
||||
|
||||
public CustomProtocolPingSection() {
|
||||
super("custom-protocol-ping");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
ENABLED = new ConfigSectionHelper<Boolean>(this, "enabled", true).getOrSet();
|
||||
ALWAYS_SHOW = new ConfigSectionHelper<Boolean>(this, "always-show", true).getOrSet();
|
||||
PROTOCOL = new ConfigSectionHelper<String>(this, "protocol", "&f&lProAntiTab &7(&a%online%&7/&c%max%&7)").getOrSet();
|
||||
}
|
||||
}
|
||||
+3
@@ -1,5 +1,6 @@
|
||||
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.configuration.helper.ConfigSectionHelper;
|
||||
import de.rayzs.pat.utils.configuration.helper.MultipleMessagesHelper;
|
||||
@@ -17,6 +18,8 @@ public class CustomUnknownCommandSection extends ConfigStorage {
|
||||
@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!"));
|
||||
}
|
||||
|
||||
@@ -41,14 +41,14 @@ public class BlacklistStorage extends StorageTemplate {
|
||||
}
|
||||
|
||||
public boolean isBlocked(Object targetObj, String command) {
|
||||
if(/*Storage.TURN_BLACKLIST_TO_WHITELIST*/ false)
|
||||
return !isListed(command, false) && !PermissionUtil.hasBypassPermission(targetObj, command);
|
||||
else
|
||||
return isListed(command, false) && !PermissionUtil.hasBypassPermission(targetObj, command);
|
||||
return isBlocked(targetObj, command, false);
|
||||
}
|
||||
|
||||
public boolean isBlocked(Object targetObj, String command, boolean intensive) {
|
||||
return isListed(command, intensive) && !PermissionUtil.hasBypassPermission(targetObj, command);
|
||||
if(Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED)
|
||||
return !isListed(command, intensive) && !PermissionUtil.hasBypassPermission(targetObj, command);
|
||||
else
|
||||
return isListed(command, intensive) && !PermissionUtil.hasBypassPermission(targetObj, command);
|
||||
}
|
||||
|
||||
public void setList(List<String> commands) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.rayzs.pat.plugin;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.commands.BukkitCommand;
|
||||
import de.rayzs.pat.plugin.listeners.bukkit.BukkitAntiTabListener;
|
||||
import de.rayzs.pat.plugin.listeners.bukkit.BukkitBlockCommandListener;
|
||||
@@ -39,10 +40,10 @@ public class BukkitLoader extends JavaPlugin {
|
||||
logger = getLogger();
|
||||
|
||||
Reflection.initialize(getServer());
|
||||
Storage.CURRENT_VERSION_NAME = getDescription().getVersion();
|
||||
Storage.CURRENT_VERSION = getDescription().getVersion();
|
||||
|
||||
de.rayzs.pat.api.storage.Storage.loadAll(true);
|
||||
Storage.load(true);
|
||||
Storage.loadAll(true);
|
||||
|
||||
if(Bukkit.getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) MessageTranslator.enablePlaceholderSupport();
|
||||
MessageTranslator.initialize();
|
||||
@@ -51,7 +52,7 @@ public class BukkitLoader extends JavaPlugin {
|
||||
|
||||
PluginManager manager = getServer().getPluginManager();
|
||||
|
||||
if(Storage.BUNGEECORD)
|
||||
if(Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED)
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, ClientCommunication::sendRequest, 40, 20*10);
|
||||
else {
|
||||
loaded = true;
|
||||
@@ -69,7 +70,7 @@ public class BukkitLoader extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if(!Storage.BUNGEECORD) PacketAnalyzer.uninjectAll();
|
||||
if(!Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED) PacketAnalyzer.uninjectAll();
|
||||
MessageTranslator.closeAudiences();
|
||||
}
|
||||
|
||||
@@ -83,34 +84,39 @@ public class BukkitLoader extends JavaPlugin {
|
||||
}
|
||||
|
||||
public void startUpdaterTask() {
|
||||
if (!Storage.UPDATE_ENABLED || Storage.BUNGEECORD) return;
|
||||
if (!Storage.ConfigSections.Settings.UPDATE.ENABLED || Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED) return;
|
||||
updaterTaskId = Bukkit.getScheduler().scheduleAsyncRepeatingTask(this, () -> {
|
||||
String result = new ConnectionBuilder().setUrl("https://www.rayzs.de/proantitab/api/version.php")
|
||||
.setProperties("ProAntiTab", "4654").connect().getResponse();
|
||||
Storage.NEWEST_VERSION_NAME = result;
|
||||
Storage.NEWER_VERSION = result;
|
||||
|
||||
if (!Storage.NEWEST_VERSION_NAME.equals(Storage.CURRENT_VERSION_NAME)) {
|
||||
if (!Storage.NEWER_VERSION.equals(Storage.CURRENT_VERSION)) {
|
||||
Bukkit.getScheduler().cancelTask(updaterTaskId);
|
||||
if (result.equals("unknown")) {
|
||||
Logger.warning("Failed reaching web host! (firewall enabled? website down?)");
|
||||
} else if (result.equals("exception")) {
|
||||
Logger.warning("Failed creating web instance! (outdated java version?)");
|
||||
} else {
|
||||
Storage.OUTDATED_VERSION = true;
|
||||
Storage.UPDATE_NOTIFICATION.forEach(message -> Logger.warning(message.replace("&", "§")));
|
||||
Storage.OUTDATED = true;
|
||||
Storage.ConfigSections.Settings.UPDATE.OUTDATED.getLines().forEach(Logger::warning);
|
||||
}
|
||||
}
|
||||
}, 20L, 20L * Storage.UPDATE_PERIOD);
|
||||
}, 20L, 20L * Storage.ConfigSections.Settings.UPDATE.PERIOD);
|
||||
}
|
||||
|
||||
public static void synchronizeCommandData(DataConverter.CommandsPacket packet) {
|
||||
public static void synchronizeCommandData(DataConverter.CommandsPacket packet, DataConverter.UnknownCommandPacket unknownCommandPacket) {
|
||||
ClientCommunication.sendFeedback();
|
||||
|
||||
if (!Storage.BLOCKED_COMMANDS_LIST.containsAll(packet.getCommands()) || !packet.getCommands().containsAll(Storage.BLOCKED_COMMANDS_LIST))
|
||||
Storage.BLOCKED_COMMANDS_LIST = packet.getCommands();
|
||||
if (!Storage.BLACKLIST.getCommands().containsAll(packet.getCommands()) || !packet.getCommands().containsAll(Storage.BLACKLIST.getCommands()))
|
||||
Storage.BLACKLIST.setList(packet.getCommands());
|
||||
|
||||
if (Storage.TURN_BLACKLIST_TO_WHITELIST != packet.turnBlacklistToWhitelistEnabled())
|
||||
Storage.TURN_BLACKLIST_TO_WHITELIST = packet.turnBlacklistToWhitelistEnabled();
|
||||
if (Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED != packet.turnBlacklistToWhitelistEnabled())
|
||||
Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED = packet.turnBlacklistToWhitelistEnabled();
|
||||
|
||||
if(Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.ENABLED != unknownCommandPacket.isEnabled())
|
||||
Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.ENABLED = unknownCommandPacket.isEnabled();
|
||||
|
||||
Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.MESSAGE = unknownCommandPacket.getMessage();
|
||||
|
||||
if(Reflection.getMinor() >= 18) BukkitAntiTabListener.handleTabCompletion(packet.getCommands());
|
||||
if(!loaded) {
|
||||
@@ -127,7 +133,7 @@ public class BukkitLoader extends JavaPlugin {
|
||||
public static List<String> getNotBlockedCommands() {
|
||||
List<String> commands = new ArrayList<>();
|
||||
Bukkit.getHelpMap().getHelpTopics().stream()
|
||||
.filter(topic -> !topic.getName().contains(":") && topic.getName().startsWith("/") && !Storage.isBlocked(topic.getName().replaceFirst("/", ""), false))
|
||||
.filter(topic -> !topic.getName().contains(":") && topic.getName().startsWith("/") && !Storage.BLACKLIST.isListed(topic.getName().replaceFirst("/", "")))
|
||||
.forEach(topic -> commands.add(topic.getName().replaceFirst("/", "")));
|
||||
return commands;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package de.rayzs.pat.plugin.listeners.bukkit;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.BukkitLoader;
|
||||
import org.bukkit.event.player.PlayerCommandSendEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import org.bukkit.event.*;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class BukkitAntiTabListener implements Listener {
|
||||
@@ -17,7 +17,7 @@ public class BukkitAntiTabListener implements Listener {
|
||||
if (PermissionUtil.hasBypassPermission(player)) return;
|
||||
|
||||
if(!BukkitLoader.isLoaded()) event.getCommands().clear();
|
||||
else event.getCommands().removeIf(command -> Storage.hasNoAccess(player, command));
|
||||
else event.getCommands().removeIf(command -> Storage.BLACKLIST.isBlocked(player, command));
|
||||
}
|
||||
|
||||
public static void updateCommands() {
|
||||
|
||||
+21
-19
@@ -1,5 +1,6 @@
|
||||
package de.rayzs.pat.plugin.listeners.bukkit;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
@@ -10,57 +11,58 @@ import org.bukkit.event.*;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.help.HelpTopic;
|
||||
|
||||
public class BukkitBlockCommandListener implements Listener {
|
||||
import java.util.List;
|
||||
|
||||
public class BukkitBlockCommandListener implements Listener {
|
||||
|
||||
@EventHandler (priority = EventPriority.LOWEST)
|
||||
public void onPlayerCommandProcess(PlayerCommandPreprocessEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
World world = player.getWorld();
|
||||
String rawCommand = event.getMessage(), command = rawCommand.replaceFirst("/", ""), commandLowerCased = command.toLowerCase(),
|
||||
worldName = world.getName(), alertMessage = Storage.NOTIFY_ALERT.replace("%player%", player.getName()).replace("%command%", command).replace("%world%", worldName);
|
||||
String rawCommand = event.getMessage(), command = rawCommand.replaceFirst("/", ""), worldName = world.getName();
|
||||
List<String> notificationMessage = MessageTranslator.replaceMessageList(Storage.ConfigSections.Messages.NOTIFICATION.ALERT, "%player%", player.getName(), "%command%", command, "%world%", worldName);
|
||||
|
||||
|
||||
if(Storage.USE_UNKNOWN_COMMAND) {
|
||||
if(Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.ENABLED) {
|
||||
String targetCommand = rawCommand.contains(" ") ? rawCommand.split(" ")[0] : rawCommand;
|
||||
HelpTopic helpTopic = Bukkit.getHelpMap().getHelpTopic(targetCommand);
|
||||
if(helpTopic == null) {
|
||||
for (String line : Storage.UNKNOWN_COMMAND) MessageTranslator.send(player, line.replace("&", "§"));
|
||||
MessageTranslator.send(player, Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.MESSAGE);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(Storage.isPluginsCommand(command) && Storage.USE_CUSTOM_PLUGINS && !PermissionUtil.hasBypassPermission(player, command)) {
|
||||
for (String line : Storage.CUSTOM_PLUGINS) MessageTranslator.send(player, line.replace("%command%", rawCommand.replaceFirst("/", "")));
|
||||
if(Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isPluginsCommand(command) && !PermissionUtil.hasBypassPermission(player, command)) {
|
||||
MessageTranslator.send(player, Storage.ConfigSections.Settings.CUSTOM_PLUGIN.MESSAGE, "%command%", rawCommand.replaceFirst("/", ""));
|
||||
|
||||
if(Storage.CONSOLE_NOTIFICATION_ENABLED) Logger.info(alertMessage);
|
||||
if(Storage.SEND_CONSOLE_NOTIFICATION) Logger.info(notificationMessage);
|
||||
Storage.NOTIFY_PLAYERS.stream().filter(uuid -> Bukkit.getServer().getPlayer(uuid) != null).forEach(uuid -> {
|
||||
Player target = Bukkit.getServer().getPlayer(uuid);
|
||||
MessageTranslator.send(target, alertMessage);
|
||||
MessageTranslator.send(target, notificationMessage);
|
||||
});
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!Storage.CANCEL_COMMANDS || Storage.BUNGEECORD || rawCommand.equals("/")) return;
|
||||
if(!Storage.ConfigSections.Settings.CANCEL_COMMAND.ENABLED || Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED || rawCommand.equals("/")) return;
|
||||
List<String> cancelCommandMessage = MessageTranslator.replaceMessageList(Storage.ConfigSections.Settings.CANCEL_COMMAND.MESSAGE, "%command%", rawCommand.replaceFirst("/", ""));
|
||||
|
||||
if(Storage.TURN_BLACKLIST_TO_WHITELIST) {
|
||||
if(Storage.isBlocked(command, true)) return;
|
||||
if(Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED) {
|
||||
if(Storage.BLACKLIST.isListed(command, true)) return;
|
||||
if(PermissionUtil.hasBypassPermission(player, command)) return;
|
||||
for (String line : Storage.CANCEL_COMMANDS_MESSAGE) MessageTranslator.send(player, line.replace("%command%", rawCommand.replaceFirst("/", "")));
|
||||
MessageTranslator.send(player, cancelCommandMessage);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Storage.isBlocked(commandLowerCased, false)) return;
|
||||
if (!Storage.BLACKLIST.isBlocked(player, command)) return;
|
||||
if (PermissionUtil.hasBypassPermission(player, command)) return;
|
||||
MessageTranslator.send(player, cancelCommandMessage);
|
||||
|
||||
for (String line : Storage.CANCEL_COMMANDS_MESSAGE) MessageTranslator.send(player, line.replace("%command%", rawCommand.replaceFirst("/", "")));
|
||||
|
||||
if(Storage.CONSOLE_NOTIFICATION_ENABLED) Logger.info(alertMessage);
|
||||
if(Storage.SEND_CONSOLE_NOTIFICATION) Logger.info(notificationMessage);
|
||||
Storage.NOTIFY_PLAYERS.stream().filter(uuid -> Bukkit.getServer().getPlayer(uuid) != null).forEach(uuid -> {
|
||||
Player target = Bukkit.getServer().getPlayer(uuid);
|
||||
MessageTranslator.send(target, alertMessage);
|
||||
MessageTranslator.send(target, notificationMessage);
|
||||
});
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package de.rayzs.pat.plugin.listeners.bungee;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.PermissionUtil;
|
||||
import de.rayzs.pat.utils.Storage;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.TabCompleteEvent;
|
||||
import net.md_5.bungee.api.event.TabCompleteResponseEvent;
|
||||
@@ -17,7 +17,7 @@ public class BungeeAntiTabListener implements Listener {
|
||||
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
|
||||
if(PermissionUtil.hasBypassPermission(player)) return;
|
||||
|
||||
event.getSuggestions().removeIf(command -> Storage.hasNoAccess(player, command));
|
||||
event.getSuggestions().removeIf(command -> Storage.BLACKLIST.isBlocked(player, command));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@@ -27,6 +27,6 @@ public class BungeeAntiTabListener implements Listener {
|
||||
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
|
||||
if(PermissionUtil.hasBypassPermission(player)) return;
|
||||
|
||||
event.getSuggestions().removeIf(command -> Storage.hasNoAccess(player, command));
|
||||
event.getSuggestions().removeIf(command -> Storage.BLACKLIST.isBlocked(player, command));
|
||||
}
|
||||
}
|
||||
+32
-26
@@ -1,21 +1,23 @@
|
||||
package de.rayzs.pat.plugin.listeners.bungee;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.utils.PermissionUtil;
|
||||
import de.rayzs.pat.utils.Storage;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.*;
|
||||
import net.md_5.bungee.api.event.ChatEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import java.util.List;
|
||||
|
||||
public class BungeeBlockCommandListener implements Listener {
|
||||
|
||||
@EventHandler (priority = EventPriority.LOWEST)
|
||||
public void onChat(ChatEvent event) {
|
||||
if(!Storage.CANCEL_COMMANDS) return;
|
||||
if(event.isCancelled()) return;
|
||||
|
||||
Connection connection = event.getSender();
|
||||
if(!(connection instanceof ProxiedPlayer) || !event.getMessage().startsWith("/")) return;
|
||||
@@ -25,39 +27,43 @@ public class BungeeBlockCommandListener implements Listener {
|
||||
|
||||
if(rawCommand.equals("/")) return;
|
||||
ServerInfo serverInfo = player.getServer().getInfo();
|
||||
String serverName = serverInfo != null ? serverInfo.getName() : "unknown",
|
||||
alertMessage = Storage.NOTIFY_ALERT.replace("%player%", player.getName()).replace("%command%", command).replace("%server%", serverName);
|
||||
String serverName = serverInfo != null ? serverInfo.getName() : "unknown";
|
||||
List<String> notificationMessage = MessageTranslator.replaceMessageList(Storage.ConfigSections.Messages.NOTIFICATION.ALERT, "%player%", player.getName(), "%command%", command, "%server%", serverName);
|
||||
|
||||
|
||||
if(Storage.isPluginsCommand(command) && Storage.USE_CUSTOM_PLUGINS && !PermissionUtil.hasBypassPermission(player, command)) {
|
||||
for (String line : Storage.CUSTOM_PLUGINS) MessageTranslator.send(player, line.replace("%command%", rawCommand.replaceFirst("/", "")));
|
||||
event.setCancelled(true);
|
||||
if(Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isPluginsCommand(command) && !PermissionUtil.hasBypassPermission(player, command)) {
|
||||
MessageTranslator.send(player, Storage.ConfigSections.Settings.CUSTOM_PLUGIN.MESSAGE, "%command%", rawCommand.replaceFirst("/", ""));
|
||||
|
||||
if(Storage.CONSOLE_NOTIFICATION_ENABLED) Logger.info(alertMessage);
|
||||
Storage.NOTIFY_PLAYERS.stream().filter(uuid -> ProxyServer.getInstance().getPlayer(uuid) != null).forEach(uuid -> {
|
||||
ProxiedPlayer target = ProxyServer.getInstance().getPlayer(uuid);
|
||||
MessageTranslator.send(target, alertMessage);
|
||||
if(Storage.SEND_CONSOLE_NOTIFICATION) Logger.info(notificationMessage);
|
||||
Storage.NOTIFY_PLAYERS.stream().filter(uuid -> Bukkit.getServer().getPlayer(uuid) != null).forEach(uuid -> {
|
||||
Player target = Bukkit.getServer().getPlayer(uuid);
|
||||
MessageTranslator.send(target, notificationMessage);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if(Storage.TURN_BLACKLIST_TO_WHITELIST) {
|
||||
if(Storage.isBlocked(command, true)) return;
|
||||
if(PermissionUtil.hasBypassPermission(player, command)) return;
|
||||
|
||||
for (String line : Storage.CANCEL_COMMANDS_MESSAGE) MessageTranslator.send(player, line.replace("%command%", rawCommand.replaceFirst("/", "")));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!Storage.isBlocked(command, false) || PermissionUtil.hasBypassPermission(player, command)) return;
|
||||
for (String line : Storage.CANCEL_COMMANDS_MESSAGE) MessageTranslator.send(player, line.replace("%command%", rawCommand.replaceFirst("/", "")));
|
||||
if(!Storage.ConfigSections.Settings.CANCEL_COMMAND.ENABLED) return;
|
||||
|
||||
if(Storage.CONSOLE_NOTIFICATION_ENABLED) Logger.info(alertMessage);
|
||||
Storage.NOTIFY_PLAYERS.stream().filter(uuid -> ProxyServer.getInstance().getPlayer(uuid) != null).forEach(uuid -> {
|
||||
ProxiedPlayer target = ProxyServer.getInstance().getPlayer(uuid);
|
||||
MessageTranslator.send(target, alertMessage);
|
||||
List<String> cancelCommandMessage = MessageTranslator.replaceMessageList(Storage.ConfigSections.Settings.CANCEL_COMMAND.MESSAGE, "%command%", rawCommand.replaceFirst("/", ""));
|
||||
if(Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED) {
|
||||
if(Storage.BLACKLIST.isListed(command, true)) return;
|
||||
if(PermissionUtil.hasBypassPermission(player, command)) return;
|
||||
MessageTranslator.send(player, cancelCommandMessage);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Storage.BLACKLIST.isBlocked(player, command)) return;
|
||||
if (PermissionUtil.hasBypassPermission(player, command)) return;
|
||||
MessageTranslator.send(player, cancelCommandMessage);
|
||||
|
||||
if(Storage.SEND_CONSOLE_NOTIFICATION) Logger.info(notificationMessage);
|
||||
Storage.NOTIFY_PLAYERS.stream().filter(uuid -> Bukkit.getServer().getPlayer(uuid) != null).forEach(uuid -> {
|
||||
Player target = Bukkit.getServer().getPlayer(uuid);
|
||||
MessageTranslator.send(target, notificationMessage);
|
||||
});
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package de.rayzs.pat.plugin.listeners.bungee;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.BungeeLoader;
|
||||
import de.rayzs.pat.utils.Storage;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.ServerPing;
|
||||
import net.md_5.bungee.api.event.ProxyPingEvent;
|
||||
@@ -12,12 +12,12 @@ public class BungeePingListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onProxyPing(ProxyPingEvent event) {
|
||||
if(!Storage.USE_CUSTOM_PROTOCOL_PING) return;
|
||||
if(!Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.ENABLED) return;
|
||||
|
||||
ProxyServer proxyServer = BungeeLoader.getPlugin().getProxy();
|
||||
int online = proxyServer.getOnlineCount(), max = proxyServer.getConfigurationAdapter().getListeners().iterator().next().getMaxPlayers();
|
||||
ServerPing serverPing = event.getResponse();
|
||||
ServerPing.Protocol newProtocol = new ServerPing.Protocol(Storage.CUSTOM_PROTOCOL_PING.replace("%online%", String.valueOf(online)).replace("%max%", String.valueOf(max)), !Storage.USE_ALWAYS_SHOW_CUSTOM_PROTOCOL_PING ? serverPing.getVersion().getProtocol() : 0);
|
||||
ServerPing.Protocol newProtocol = new ServerPing.Protocol(Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.PROTOCOL.replace("%online%", String.valueOf(online)).replace("%max%", String.valueOf(max)), !Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.ALWAYS_SHOW ? serverPing.getVersion().getProtocol() : 0);
|
||||
serverPing.setVersion(newProtocol);
|
||||
|
||||
event.setResponse(serverPing);
|
||||
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
package de.rayzs.pat.plugin.listeners.bungee;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.BungeeLoader;
|
||||
import de.rayzs.pat.utils.PermissionUtil;
|
||||
import de.rayzs.pat.utils.Storage;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
@@ -18,10 +18,10 @@ public class BungeePlayerConnectionListener implements Listener {
|
||||
@EventHandler (priority = EventPriority.LOWEST)
|
||||
public void onPostLogin(PostLoginEvent event) {
|
||||
ProxiedPlayer player = event.getPlayer();
|
||||
if(Storage.OUTDATED_VERSION && (PermissionUtil.hasPermission(player, "update"))) {
|
||||
if(Storage.OUTDATED && (PermissionUtil.hasPermission(player, "update"))) {
|
||||
ProxyServer.getInstance().getScheduler().schedule(BungeeLoader.getPlugin(), () -> {
|
||||
if (player.isConnected()) {
|
||||
Storage.UPDATE_NOTIFICATION.forEach(message -> MessageTranslator.send(player, message));
|
||||
MessageTranslator.send(player, Storage.ConfigSections.Settings.UPDATE.OUTDATED);
|
||||
}
|
||||
}, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package de.rayzs.pat.plugin.listeners.bungee;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.PermissionUtil;
|
||||
import de.rayzs.pat.utils.Storage;
|
||||
import io.github.waterfallmc.waterfall.event.ProxyDefineCommandsEvent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
@@ -17,6 +17,6 @@ public class WaterfallAntiTabListener implements Listener {
|
||||
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
|
||||
if(PermissionUtil.hasBypassPermission(player)) return;
|
||||
|
||||
event.getCommands().entrySet().removeIf(entry -> Storage.hasNoAccess(player, entry.getKey()));
|
||||
event.getCommands().entrySet().removeIf(entry -> Storage.BLACKLIST.isBlocked(player, entry.getKey()));
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,8 @@ import com.velocitypowered.api.event.command.PlayerAvailableCommandsEvent;
|
||||
import com.velocitypowered.api.event.player.TabCompleteEvent;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.PermissionUtil;
|
||||
import de.rayzs.pat.utils.Storage;
|
||||
|
||||
public class VelocityAntiTabListener {
|
||||
|
||||
@@ -23,7 +23,7 @@ public class VelocityAntiTabListener {
|
||||
|
||||
if(PermissionUtil.hasBypassPermission(player)) return;
|
||||
|
||||
event.getSuggestions().removeIf(command -> Storage.hasNoAccess(player, command));
|
||||
event.getSuggestions().removeIf(command -> Storage.BLACKLIST.isBlocked(player, command));
|
||||
}
|
||||
|
||||
@Subscribe (order = PostOrder.LAST)
|
||||
@@ -32,7 +32,7 @@ public class VelocityAntiTabListener {
|
||||
|
||||
if(PermissionUtil.hasBypassPermission(player)) return;
|
||||
|
||||
event.getRootNode().getChildren().removeIf(command -> Storage.hasNoAccess(player, command.getName()));
|
||||
event.getRootNode().getChildren().removeIf(command -> Storage.BLACKLIST.isBlocked(player, command.getName()));
|
||||
}
|
||||
|
||||
public static void updateCommands() {
|
||||
|
||||
+31
-24
@@ -5,10 +5,13 @@ import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.command.CommandExecuteEvent;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import de.rayzs.pat.utils.PermissionUtil;
|
||||
import de.rayzs.pat.utils.Storage;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class VelocityBlockCommandListener {
|
||||
|
||||
@@ -20,43 +23,47 @@ public class VelocityBlockCommandListener {
|
||||
|
||||
@Subscribe
|
||||
public void onPlayerChat(CommandExecuteEvent event) {
|
||||
if(!Storage.CANCEL_COMMANDS || !event.getResult().isAllowed()) return;
|
||||
|
||||
if(!event.getResult().isAllowed()) return;
|
||||
CommandSource commandSource = event.getCommandSource();
|
||||
|
||||
if(!(commandSource instanceof Player)) return;
|
||||
|
||||
Player player = (Player) commandSource;
|
||||
String command = event.getCommand(),
|
||||
serverName = player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "unknown",
|
||||
alertMessage = Storage.NOTIFY_ALERT.replace("%player%", player.getUsername()).replace("%command%", command).replace("%server%", serverName);
|
||||
serverName = player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "unknown";
|
||||
List<String> notificationMessage = MessageTranslator.replaceMessageList(Storage.ConfigSections.Messages.NOTIFICATION.ALERT, "%player%", player.getUsername(), "%command%", command, "%server%", serverName);
|
||||
|
||||
if(Storage.isPluginsCommand(command) && Storage.USE_CUSTOM_PLUGINS && !PermissionUtil.hasBypassPermission(player, command)) {
|
||||
for (String line : Storage.CUSTOM_PLUGINS) MessageTranslator.send(player, line.replace("%command%", command.replaceFirst("/", "")));
|
||||
event.setResult(CommandExecuteEvent.CommandResult.denied());
|
||||
if(Storage.ConfigSections.Settings.CUSTOM_PLUGIN.isPluginsCommand(command) && !PermissionUtil.hasBypassPermission(player, command)) {
|
||||
MessageTranslator.send(player, Storage.ConfigSections.Settings.CUSTOM_PLUGIN.MESSAGE, "%command%", command.replaceFirst("/", ""));
|
||||
|
||||
if(Storage.CONSOLE_NOTIFICATION_ENABLED) Logger.info(alertMessage);
|
||||
Storage.NOTIFY_PLAYERS.stream().filter(uuid -> server.getPlayer(uuid).isPresent() && server.getPlayer(uuid).get().isActive()).forEach(uuid -> {
|
||||
MessageTranslator.send(server.getPlayer(uuid).get(), alertMessage);
|
||||
if(Storage.SEND_CONSOLE_NOTIFICATION) Logger.info(notificationMessage);
|
||||
Storage.NOTIFY_PLAYERS.stream().filter(uuid -> Bukkit.getServer().getPlayer(uuid) != null).forEach(uuid -> {
|
||||
org.bukkit.entity.Player target = Bukkit.getServer().getPlayer(uuid);
|
||||
MessageTranslator.send(target, notificationMessage);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if(Storage.TURN_BLACKLIST_TO_WHITELIST) {
|
||||
if(Storage.isBlocked(command, true)) return;
|
||||
if(PermissionUtil.hasBypassPermission(player, command)) return;
|
||||
|
||||
for (String line : Storage.CANCEL_COMMANDS_MESSAGE) MessageTranslator.send(player, line.replace("%command%", command.replaceFirst("/", "")));
|
||||
event.setResult(CommandExecuteEvent.CommandResult.denied());
|
||||
return;
|
||||
}
|
||||
|
||||
if(!Storage.isBlocked(command, false) || PermissionUtil.hasBypassPermission(player, command)) return;
|
||||
for (String line : Storage.CANCEL_COMMANDS_MESSAGE) MessageTranslator.send(player, line.replace("%command%", command.replaceFirst("/", "")));
|
||||
if(!Storage.ConfigSections.Settings.CANCEL_COMMAND.ENABLED) return;
|
||||
List<String> cancelCommandMessage = MessageTranslator.replaceMessageList(Storage.ConfigSections.Settings.CANCEL_COMMAND.MESSAGE, "%command%", command.replaceFirst("/", ""));
|
||||
|
||||
if(Storage.CONSOLE_NOTIFICATION_ENABLED) MessageTranslator.send(server.getConsoleCommandSource(), alertMessage);
|
||||
Storage.NOTIFY_PLAYERS.stream().filter(uuid -> server.getPlayer(uuid).isPresent() && server.getPlayer(uuid).get().isActive()).forEach(uuid -> {
|
||||
MessageTranslator.send(server.getPlayer(uuid).get(), alertMessage);
|
||||
if(Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED) {
|
||||
if(Storage.BLACKLIST.isListed(command, true)) return;
|
||||
if(PermissionUtil.hasBypassPermission(player, command)) return;
|
||||
MessageTranslator.send(player, cancelCommandMessage);
|
||||
event.setResult(CommandExecuteEvent.CommandResult.denied());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Storage.BLACKLIST.isBlocked(player, command)) return;
|
||||
if (PermissionUtil.hasBypassPermission(player, command)) return;
|
||||
MessageTranslator.send(player, cancelCommandMessage);
|
||||
|
||||
if(Storage.SEND_CONSOLE_NOTIFICATION) Logger.info(notificationMessage);
|
||||
Storage.NOTIFY_PLAYERS.stream().filter(uuid -> Bukkit.getServer().getPlayer(uuid) != null).forEach(uuid -> {
|
||||
org.bukkit.entity.Player target = Bukkit.getServer().getPlayer(uuid);
|
||||
MessageTranslator.send(target, notificationMessage);
|
||||
});
|
||||
|
||||
event.setResult(CommandExecuteEvent.CommandResult.denied());
|
||||
|
||||
+4
-6
@@ -4,11 +4,10 @@ import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.player.ServerPreConnectEvent;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.plugin.VelocityLoader;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import de.rayzs.pat.utils.PermissionUtil;
|
||||
import de.rayzs.pat.utils.Storage;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class VelocityConnectionListener {
|
||||
@@ -24,11 +23,10 @@ public class VelocityConnectionListener {
|
||||
@Subscribe
|
||||
public void onServerPreConnect(ServerPreConnectEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if(Storage.OUTDATED_VERSION && (PermissionUtil.hasPermission(player, "update"))) {
|
||||
if(Storage.OUTDATED && (PermissionUtil.hasPermission(player, "update"))) {
|
||||
server.getScheduler().buildTask(loader, () -> {
|
||||
if (player.isActive()) {
|
||||
Storage.UPDATE_NOTIFICATION.forEach(message -> MessageTranslator.send(player, message));
|
||||
}
|
||||
if (player.isActive())
|
||||
MessageTranslator.send(player, Storage.ConfigSections.Settings.UPDATE.OUTDATED);
|
||||
}).delay(1, TimeUnit.SECONDS).schedule();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyPingEvent;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.server.ServerPing;
|
||||
import de.rayzs.pat.utils.Storage;
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
|
||||
public class VelocityPingListener {
|
||||
|
||||
@@ -16,11 +16,11 @@ public class VelocityPingListener {
|
||||
|
||||
@Subscribe
|
||||
public void onProxyPing(ProxyPingEvent event) {
|
||||
if(!Storage.USE_CUSTOM_PROTOCOL_PING) return;
|
||||
if(!Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.ENABLED) return;
|
||||
|
||||
int online = server.getPlayerCount(), max = server.getConfiguration().getShowMaxPlayers();
|
||||
ServerPing oldServerPing = event.getPing(), newServerPing;
|
||||
ServerPing.Version newVersion = new ServerPing.Version(!Storage.USE_ALWAYS_SHOW_CUSTOM_PROTOCOL_PING ? oldServerPing.getVersion().getProtocol() : -1, Storage.CUSTOM_PROTOCOL_PING.replace("%online%", String.valueOf(online)).replace("%max%", String.valueOf(max)));
|
||||
ServerPing.Version newVersion = new ServerPing.Version(!Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.ALWAYS_SHOW ? oldServerPing.getVersion().getProtocol() : -1, Storage.ConfigSections.Settings.CUSTOM_PROTOCOL_PING.PROTOCOL.replace("%online%", String.valueOf(online)).replace("%max%", String.valueOf(max)));
|
||||
newServerPing = oldServerPing.asBuilder().version(newVersion).build();
|
||||
|
||||
event.setPing(newServerPing);
|
||||
|
||||
@@ -4,6 +4,8 @@ import de.rayzs.pat.plugin.*;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.message.MessageTranslator;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
@@ -15,6 +17,9 @@ public class Logger {
|
||||
? BungeeLoader.getPluginLogger()
|
||||
: BukkitLoader.getPluginLogger();
|
||||
|
||||
|
||||
public static void info(List<String> texts) { texts.forEach(text -> send(Priority.INFO, text)); }
|
||||
public static void warning(List<String> texts) { texts.forEach(text -> send(Priority.WARNING, text)); }
|
||||
public static void info(String text) { send(Priority.INFO, text); }
|
||||
public static void warning(String text) { send(Priority.WARNING, text); }
|
||||
|
||||
|
||||
@@ -326,8 +326,8 @@ public class CommandProcess {
|
||||
if(!backend && Arrays.asList("remove", "rem", "rm").contains(args[0].toLowerCase()) && PermissionUtil.hasPermission(sender, "remove")) suggestions.addAll(Storage.BLOCKED_COMMANDS_LIST);
|
||||
break;
|
||||
case 3:
|
||||
if(!backend && args[0].equals("add") && PermissionUtil.hasPermission(sender, "add") && !Reflection.isProxyServer()) suggestions.addAll(GroupManager.getGroupByNameNotIncludingCommand(args[1]));
|
||||
if(!backend && Arrays.asList("remove", "rem", "rm").contains(args[0].toLowerCase()) && PermissionUtil.hasPermission(sender, "remove")) suggestions.addAll(GroupManager.getGroupByNameOnlyIncludingCommand(args[1]));
|
||||
if(!backend && args[0].equals("add") && PermissionUtil.hasPermission(sender, "add") && !Reflection.isProxyServer()) suggestions.addAll(GroupManager.getGroupsByNameNotIncludingCommand(args[1]));
|
||||
if(!backend && Arrays.asList("remove", "rem", "rm").contains(args[0].toLowerCase()) && PermissionUtil.hasPermission(sender, "remove")) suggestions.addAll(GroupManager.getGroupsByNameOnlyIncludingCommand(args[1]));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package de.rayzs.pat.utils;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.configuration.helper.MultipleMessagesHelper;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
import oracle.jrockit.jfr.jdkevents.ThrowableTracer;
|
||||
@@ -104,6 +106,7 @@ public class DataConverter {
|
||||
|
||||
private final CommandsPacket commandsPacket;
|
||||
private final GroupsPacket groupsPacket;
|
||||
private final UnknownCommandPacket unknownCommandPacket;
|
||||
private final String proxyToken, serverId;
|
||||
|
||||
public PacketBundle(String proxyToken, String serverId, CommandsPacket commandsPacket, GroupsPacket groupsPacket) {
|
||||
@@ -111,6 +114,7 @@ public class DataConverter {
|
||||
this.serverId = serverId;
|
||||
this.commandsPacket = commandsPacket;
|
||||
this.groupsPacket = groupsPacket;
|
||||
this.unknownCommandPacket = new UnknownCommandPacket();
|
||||
}
|
||||
|
||||
public boolean isToken(String token) {
|
||||
@@ -132,6 +136,27 @@ public class DataConverter {
|
||||
public GroupsPacket getGroupsPacket() {
|
||||
return groupsPacket;
|
||||
}
|
||||
|
||||
public UnknownCommandPacket getUnknownCommandPacket() { return unknownCommandPacket; }
|
||||
}
|
||||
|
||||
public static class UnknownCommandPacket {
|
||||
|
||||
private final MultipleMessagesHelper message;
|
||||
private final boolean enabled;
|
||||
|
||||
public UnknownCommandPacket() {
|
||||
enabled = Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.ENABLED;
|
||||
message = Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.MESSAGE;
|
||||
}
|
||||
|
||||
public MultipleMessagesHelper getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CommandsPacket {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.rayzs.pat.utils;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
|
||||
public class PermissionUtil {
|
||||
@@ -24,6 +25,13 @@ public class PermissionUtil {
|
||||
|| GroupManager.canAccessCommand(targetObj, command);
|
||||
}
|
||||
|
||||
public static boolean hasBypassPermission(Object targetObj, String command, String server) {
|
||||
return hasBypassPermission(targetObj)
|
||||
|| hasPermission(targetObj, "bypass." + command.toLowerCase())
|
||||
|| hasServerPermission(targetObj, "bypass." + command.toLowerCase())
|
||||
|| GroupManager.canAccessCommand(targetObj, command, server);
|
||||
}
|
||||
|
||||
public static boolean hasServerPermission(Object targetObj, String permission) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
CommandSender sender = new CommandSender(targetObj);
|
||||
@@ -51,7 +59,7 @@ public class PermissionUtil {
|
||||
boolean permitted = hasPermission(targetObj, command);
|
||||
if(!permitted) {
|
||||
if(targetObj instanceof CommandSender)
|
||||
((CommandSender) targetObj).sendMessage(Storage.NO_PERMISSIONS.replace("%permission%", "proantitab." + command));
|
||||
((CommandSender) targetObj).sendMessage(Storage.ConfigSections.Messages.NO_PERMISSION.MESSAGE.replace("%permission%", "proantitab." + command));
|
||||
}
|
||||
return permitted;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,10 @@ public class Group {
|
||||
generalGroupBlacklist.clear().save();
|
||||
}
|
||||
|
||||
public Set<String> getServerNames() {
|
||||
return serverGroupBlacklist.keySet();
|
||||
}
|
||||
|
||||
public void clear(String server) {
|
||||
GroupBlacklist serverGroupBlacklist = BlacklistCreator.createGroupBlacklist(groupName, server);
|
||||
serverGroupBlacklist.clear().save();
|
||||
|
||||
@@ -24,6 +24,11 @@ public class GroupManager {
|
||||
).findFirst().orElse(null) != null;
|
||||
}
|
||||
|
||||
public static boolean canAccessCommand(Object targetObj, String command, String server) {
|
||||
return GROUPS.stream().filter(group -> group.contains(command) && group.hasPermission(targetObj)
|
||||
).findFirst().orElse(null) != null;
|
||||
}
|
||||
|
||||
public static void setGroup(String groupName, List<String> commands) {
|
||||
if(groupName.length() < 1) return;
|
||||
Group group = registerAndGetGroup(groupName);
|
||||
@@ -93,18 +98,36 @@ public class GroupManager {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<String> getGroupByNameOnlyIncludingCommand(String command) {
|
||||
public static List<String> getGroupsByServer(String command) {
|
||||
List<String> result = new ArrayList<>();
|
||||
GROUPS.stream().filter(group -> group.contains(command)).forEach(group -> result.add(group.getGroupName()));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<String> getGroupByNameNotIncludingCommand(String command) {
|
||||
public static List<String> getGroupsByNameOnlyIncludingCommand(String command) {
|
||||
List<String> result = new ArrayList<>();
|
||||
GROUPS.stream().filter(group -> group.contains(command)).forEach(group -> result.add(group.getGroupName()));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<String> getGroupsByNameOnlyIncludingCommand(String command, String server) {
|
||||
List<String> result = new ArrayList<>();
|
||||
GROUPS.stream().filter(group -> group.contains(command, server)).forEach(group -> result.add(group.getGroupName()));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<String> getGroupsByNameNotIncludingCommand(String command) {
|
||||
List<String> result = new ArrayList<>();
|
||||
GROUPS.stream().filter(group -> !group.contains(command)).forEach(group -> result.add(group.getGroupName()));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<String> getGroupsByNameNotIncludingCommand(String command, String server) {
|
||||
List<String> result = new ArrayList<>();
|
||||
GROUPS.stream().filter(group -> !group.contains(command, server)).forEach(group -> result.add(group.getGroupName()));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void clearAllGroups() {
|
||||
GROUPS.clear();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package de.rayzs.pat.utils.message;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import de.rayzs.pat.utils.configuration.helper.MultipleMessagesHelper;
|
||||
import de.rayzs.pat.utils.message.replacer.PlaceholderReplacer;
|
||||
import de.rayzs.pat.utils.message.translators.*;
|
||||
import java.util.*;
|
||||
@@ -48,15 +49,6 @@ public class MessageTranslator {
|
||||
placeholderSupport = true;
|
||||
}
|
||||
|
||||
public static String replaceMessage(String text) {
|
||||
return replaceMessage(null, text);
|
||||
}
|
||||
|
||||
public static String replaceMessage(Object playerObj, String text) {
|
||||
text = text.replace("&", "§").replace("%current_version%", Storage.CURRENT_VERSION).replace("%newest_version%", Storage.NEWER_VERSION).replace("\\n", "\n");
|
||||
return !placeholderSupport || playerObj == null || Reflection.isProxyServer() ? text : PlaceholderReplacer.replace(playerObj, text);
|
||||
}
|
||||
|
||||
public static String translateLegacy(String text) {
|
||||
text = replaceMessage(text);
|
||||
if(!text.contains("§")) return text;
|
||||
@@ -77,12 +69,25 @@ public class MessageTranslator {
|
||||
return text;
|
||||
}
|
||||
|
||||
public static void send(Object target, MultipleMessagesHelper texts) {
|
||||
texts.getLines().forEach(text -> send(target, text));
|
||||
}
|
||||
|
||||
public static void send(Object target, MultipleMessagesHelper texts, String... replacements) {
|
||||
texts.getLines().forEach(text -> send(target, text, replacements));
|
||||
}
|
||||
|
||||
public static void send(Object target, List<String> texts) {
|
||||
texts.forEach(text -> send(target, text));
|
||||
}
|
||||
|
||||
public static void send(Object target, String text) {
|
||||
text = replaceMessage(target, text);
|
||||
public static void send(Object target, List<String> texts, String... replacements) {
|
||||
texts = replaceMessageList(texts, replacements);
|
||||
texts.forEach(text -> send(target, text));
|
||||
}
|
||||
|
||||
public static void send(Object target, String text, String... replacements) {
|
||||
text = replaceMessageString(text, replacements);
|
||||
if(translator == null) {
|
||||
CommandSender sender = target instanceof CommandSender ? (CommandSender) target : new CommandSender(target);
|
||||
sender.sendMessage(text);
|
||||
@@ -92,6 +97,67 @@ public class MessageTranslator {
|
||||
translator.send(target, text);
|
||||
}
|
||||
|
||||
public static String replaceMessage(String text) {
|
||||
return replaceMessage(null, text);
|
||||
}
|
||||
|
||||
public static String replaceMessage(Object playerObj, String text) {
|
||||
text = text.replace("&", "§").replace("%current_version%", Storage.CURRENT_VERSION).replace("%newest_version%", Storage.NEWER_VERSION).replace("\\n", "\n");
|
||||
return !placeholderSupport || playerObj == null || Reflection.isProxyServer() ? text : PlaceholderReplacer.replace(playerObj, text);
|
||||
}
|
||||
|
||||
public static String replaceMessageString(String rawText, String... replacements) {
|
||||
final HashMap<String, String> REPLACEMENTS = new HashMap<>();
|
||||
|
||||
String firstReplacementInput = null, secondReplacementInput = null;
|
||||
for (String replacement : replacements) {
|
||||
if (firstReplacementInput == null) firstReplacementInput = replacement;
|
||||
else secondReplacementInput = replacement;
|
||||
|
||||
if (firstReplacementInput != null && secondReplacementInput != null) {
|
||||
REPLACEMENTS.put(firstReplacementInput, secondReplacementInput);
|
||||
firstReplacementInput = null;
|
||||
secondReplacementInput = null;
|
||||
}
|
||||
}
|
||||
|
||||
String text = rawText;
|
||||
for (Map.Entry<String, String> entry : REPLACEMENTS.entrySet())
|
||||
text = text.replace(entry.getKey(), entry.getValue());
|
||||
|
||||
return replaceMessage(rawText);
|
||||
}
|
||||
|
||||
public static List<String> replaceMessageList(MultipleMessagesHelper rawText, String... replacements) {
|
||||
return replaceMessageList(rawText.getLines(), replacements);
|
||||
}
|
||||
|
||||
public static List<String> replaceMessageList(List<String> rawText, String... replacements) {
|
||||
final HashMap<String, String> REPLACEMENTS = new HashMap<>();
|
||||
List<String> result = new ArrayList<>();
|
||||
|
||||
String firstReplacementInput = null, secondReplacementInput = null;
|
||||
for (String replacement : replacements) {
|
||||
if (firstReplacementInput == null) firstReplacementInput = replacement;
|
||||
else secondReplacementInput = replacement;
|
||||
|
||||
if(firstReplacementInput != null && secondReplacementInput != null) {
|
||||
REPLACEMENTS.put(firstReplacementInput, secondReplacementInput);
|
||||
firstReplacementInput = null;
|
||||
secondReplacementInput = null;
|
||||
}
|
||||
}
|
||||
|
||||
rawText.forEach(text -> {
|
||||
for (Map.Entry<String, String> entry : REPLACEMENTS.entrySet())
|
||||
text = text.replace(entry.getKey(), entry.getValue());
|
||||
String resultText = replaceMessage(text);
|
||||
result.add(resultText);
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String translateIntoMiniMessage(String text) {
|
||||
return translator.translate(replaceMessage(text));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user