mirror of
https://github.com/RayzsYT/ProAntiTab.git
synced 2026-12-02 05:19:52 -05:00
Fix Groups
This commit is contained in:
1 parent
851dcee347
commit
c2aad22808
9 files changed
+79
-72
No files matched your search
@@ -3,8 +3,6 @@ package de.rayzs.pat.api.communication;
|
||||
import de.rayzs.pat.api.communication.client.ClientInfo;
|
||||
import de.rayzs.pat.api.communication.client.impl.BungeeClientInfo;
|
||||
import de.rayzs.pat.api.communication.client.impl.VelocityClientInfo;
|
||||
import de.rayzs.pat.api.storage.StorageTemplate;
|
||||
import de.rayzs.pat.api.storage.blacklist.BlacklistCreator;
|
||||
import de.rayzs.pat.api.storage.blacklist.impl.GeneralBlacklist;
|
||||
import de.rayzs.pat.plugin.BukkitLoader;
|
||||
import de.rayzs.pat.api.communication.impl.*;
|
||||
@@ -12,7 +10,7 @@ import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.utils.DataConverter;
|
||||
import de.rayzs.pat.utils.ExpireCache;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.TinyGroup;
|
||||
import de.rayzs.pat.utils.group.TinyGroup;
|
||||
import de.rayzs.pat.utils.group.Group;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
|
||||
@@ -25,7 +23,7 @@ public class ClientCommunication {
|
||||
private static final UUID SERVER_ID = UUID.randomUUID();
|
||||
public static final List<ClientInfo> CLIENTS = new ArrayList<>();
|
||||
private static final ExpireCache<String, ClientInfo> QUEUE_CLIENTS = new ExpireCache<>(15, TimeUnit.SECONDS);
|
||||
public static long LAST_DATA_UPDATE = System.currentTimeMillis(), LAST_SENT_REQUEST = 0;
|
||||
public static long LAST_DATA_UPDATE = System.currentTimeMillis(), LAST_SENT_REQUEST = 0, LAST_BUKKIT_SYNC = System.currentTimeMillis();
|
||||
public static int SERVER_DATA_SYNC_COUNT = 0;
|
||||
|
||||
public static void sendPacket(Object packet) {
|
||||
@@ -91,6 +89,7 @@ public class ClientCommunication {
|
||||
DataConverter.GroupsPacket groupsPacket = packetBundle.getGroupsPacket();
|
||||
DataConverter.UnknownCommandPacket unknownCommandPacket = packetBundle.getUnknownCommandPacket();
|
||||
|
||||
LAST_BUKKIT_SYNC = System.currentTimeMillis();
|
||||
BukkitLoader.synchronizeCommandData(commandsPacket, unknownCommandPacket);
|
||||
BukkitLoader.synchronizeGroupData(groupsPacket);
|
||||
}
|
||||
@@ -142,7 +141,6 @@ public class ClientCommunication {
|
||||
|
||||
public static void sendRequest() {
|
||||
if(System.currentTimeMillis() - LAST_SENT_REQUEST >= 5000) {
|
||||
System.out.println("SEND REQUEST");
|
||||
LAST_SENT_REQUEST = System.currentTimeMillis();
|
||||
sendPacket(new DataConverter.RequestPacket(Storage.TOKEN, SERVER_ID.toString()));
|
||||
}
|
||||
|
||||
@@ -57,7 +57,6 @@ public class BlacklistStorage extends StorageTemplate implements Serializable {
|
||||
}
|
||||
|
||||
public BlacklistStorage add(String command) {
|
||||
//getConfig().reload();
|
||||
command = command.toLowerCase();
|
||||
if(!commands.contains(command))
|
||||
commands.add(command);
|
||||
@@ -65,14 +64,12 @@ public class BlacklistStorage extends StorageTemplate implements Serializable {
|
||||
}
|
||||
|
||||
public BlacklistStorage remove(String command) {
|
||||
//getConfig().reload();
|
||||
command = command.toLowerCase();
|
||||
commands.remove(command);
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlacklistStorage clear() {
|
||||
//getConfig().reload();
|
||||
commands.clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,11 @@ public class BukkitLoader extends JavaPlugin {
|
||||
|
||||
if(Storage.ConfigSections.Settings.HANDLE_THROUGH_PROXY.ENABLED)
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> {
|
||||
if(Bukkit.getOnlinePlayers().size() >= 1 || loaded) ClientCommunication.sendRequest();
|
||||
if(Bukkit.getOnlinePlayers().size() >= 1 || loaded) {
|
||||
if(System.currentTimeMillis() - ClientCommunication.LAST_BUKKIT_SYNC >= 500)
|
||||
loaded = false;
|
||||
ClientCommunication.sendRequest();
|
||||
}
|
||||
}, Bukkit.getOnlinePlayers().size() >= 1 ? 20 : 40, 20 * 10);
|
||||
|
||||
else {
|
||||
|
||||
@@ -199,14 +199,14 @@ public class CommandProcess {
|
||||
}
|
||||
|
||||
StringBuilder groupsBuilder = new StringBuilder();
|
||||
for (int i = 0; i < GroupManager.getGroupNames(sub.toLowerCase()).size(); i++) {
|
||||
bool = (i >= GroupManager.getGroupNames(sub.toLowerCase()).size() - 1);
|
||||
groupsBuilder.append(Storage.ConfigSections.Messages.GROUP.LIST_GROUP_SERVER_GROUPS.replace("%group%",GroupManager.getGroupNames(sub.toLowerCase()).get(i)));
|
||||
for (int i = 0; i < GroupManager.getGroupNamesByServer(sub.toLowerCase()).size(); i++) {
|
||||
bool = (i >= GroupManager.getGroupNamesByServer(sub.toLowerCase()).size() - 1);
|
||||
groupsBuilder.append(Storage.ConfigSections.Messages.GROUP.LIST_GROUP_SERVER_GROUPS.replace("%group%",GroupManager.getGroupNamesByServer(sub.toLowerCase()).get(i)));
|
||||
if (!bool)
|
||||
groupsBuilder.append(Storage.ConfigSections.Messages.GROUP.LIST_GROUP_SERVER_SPLITTER);
|
||||
}
|
||||
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.LIST_GROUP_SERVER_MESSAGE.replace("%server%", sub.toLowerCase()).replace("%size%", String.valueOf(GroupManager.getGroupNames(sub.toLowerCase()).size())).replace("%groups%", groupsBuilder.toString()));
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.LIST_GROUP_SERVER_MESSAGE.replace("%server%", sub.toLowerCase()).replace("%size%", String.valueOf(GroupManager.getGroupNamesByServer(sub.toLowerCase()).size())).replace("%groups%", groupsBuilder.toString()));
|
||||
return;
|
||||
|
||||
case "creategroup":
|
||||
@@ -437,7 +437,7 @@ public class CommandProcess {
|
||||
return;
|
||||
}
|
||||
|
||||
bool = group.contains(extra, sub);
|
||||
bool = group.containsOnServer(extra, sub);
|
||||
if (!bool) {
|
||||
group.add(extra, sub);
|
||||
handleChange();
|
||||
@@ -455,7 +455,7 @@ public class CommandProcess {
|
||||
return;
|
||||
}
|
||||
|
||||
bool = !group.contains(extra, sub);
|
||||
bool = !group.containsOnServer(extra, sub);
|
||||
if (!bool) {
|
||||
group.remove(extra, sub);
|
||||
handleChange();
|
||||
@@ -544,21 +544,21 @@ public class CommandProcess {
|
||||
suggestions.addAll(Storage.Blacklist.getBlacklist(args[2]).getCommands());
|
||||
}
|
||||
if (args[1].equals("clear") && PermissionUtil.hasPermission(sender, "clear"))
|
||||
suggestions.addAll(GroupManager.getGroupNames(args[2]));
|
||||
suggestions.addAll(GroupManager.getGroupNamesByServer(args[2]));
|
||||
}
|
||||
break;
|
||||
|
||||
case 5:
|
||||
if (Reflection.isProxyServer() && Arrays.asList("serv", "server").contains(args[0].toLowerCase())) {
|
||||
if (args[1].equals("clear") && PermissionUtil.hasPermission(sender, "clear"))
|
||||
suggestions.addAll(GroupManager.getGroupNames(args[2]));
|
||||
suggestions.addAll(GroupManager.getGroupNamesByServer(args[2]));
|
||||
}
|
||||
break;
|
||||
|
||||
case 6:
|
||||
if (Reflection.isProxyServer() && Arrays.asList("serv", "server").contains(args[0].toLowerCase())) {
|
||||
if (args[1].equals("add") && PermissionUtil.hasPermission(sender, "add")) suggestions.addAll(GroupManager.getGroupNames());
|
||||
if (Arrays.asList("remove", "rem", "rm").contains(args[1].toLowerCase()) && PermissionUtil.hasPermission(sender, "remove")) suggestions.addAll(GroupManager.getGroupNames(args[2]));
|
||||
if (Arrays.asList("remove", "rem", "rm").contains(args[1].toLowerCase()) && PermissionUtil.hasPermission(sender, "remove")) suggestions.addAll(GroupManager.getGroupNamesByServer(args[2]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,9 @@ 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;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import de.rayzs.pat.utils.group.TinyGroup;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class DataConverter {
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.*;
|
||||
|
||||
public class Group implements Serializable {
|
||||
|
||||
|
||||
private final HashMap<String, GroupBlacklist> groupServerBlacklist = new HashMap<>();
|
||||
private final GroupBlacklist generalGroupBlacklist;
|
||||
private final String groupName;
|
||||
|
||||
@@ -37,6 +37,7 @@ public class Group implements Serializable {
|
||||
|
||||
public void add(String command, String server) {
|
||||
GroupBlacklist serverGroupBlacklist = BlacklistCreator.createGroupBlacklist(groupName, server);
|
||||
serverGroupBlacklist.load();
|
||||
serverGroupBlacklist.add(command).save();
|
||||
}
|
||||
|
||||
@@ -46,6 +47,7 @@ public class Group implements Serializable {
|
||||
|
||||
public void remove(String command, String server) {
|
||||
GroupBlacklist serverGroupBlacklist = BlacklistCreator.createGroupBlacklist(groupName, server);
|
||||
serverGroupBlacklist.load();
|
||||
serverGroupBlacklist.remove(command).save();
|
||||
}
|
||||
|
||||
@@ -56,6 +58,8 @@ public class Group implements Serializable {
|
||||
public void clear(String server) {
|
||||
GroupBlacklist serverGroupBlacklist = BlacklistCreator.createGroupBlacklist(groupName, server);
|
||||
serverGroupBlacklist.clear().save();
|
||||
serverGroupBlacklist.load();
|
||||
Storage.Files.STORAGE.reload();
|
||||
}
|
||||
|
||||
public void setCommands(List<String> commands) {
|
||||
@@ -71,26 +75,70 @@ public class Group implements Serializable {
|
||||
}
|
||||
|
||||
public boolean contains(String command, String server) {
|
||||
return generalGroupBlacklist.isListed(command) || GroupManager.getOrCreateGroupList(groupName, server).getOrCreateGroupBlacklist(server).isListed(command);
|
||||
return generalGroupBlacklist.isListed(command) || getOrCreateGroupBlacklist(server).isListed(command);
|
||||
}
|
||||
|
||||
public boolean containsOnServer(String command, String server) {
|
||||
return getOrCreateGroupBlacklist(server).isListed(command);
|
||||
}
|
||||
|
||||
public GroupBlacklist getOrCreateGroupBlacklist(String server) {
|
||||
GroupBlacklist groupBlacklist;
|
||||
if(!groupServerBlacklist.containsKey(server)) {
|
||||
groupBlacklist = BlacklistCreator.createGroupBlacklist(groupName, server);
|
||||
groupServerBlacklist.put(server, groupBlacklist);
|
||||
System.out.println("NEW: " + server + " | " + groupBlacklist.getNavigatePath());
|
||||
} else {
|
||||
groupBlacklist = groupServerBlacklist.get(server);
|
||||
System.out.println("EXIST: " + server + " | " + groupBlacklist.getNavigatePath());
|
||||
}
|
||||
|
||||
groupBlacklist.load();
|
||||
|
||||
System.out.println("#A " + groupBlacklist.getCommands().size());
|
||||
return groupBlacklist;
|
||||
}
|
||||
|
||||
public List<String> getCommands() {
|
||||
return generalGroupBlacklist.getCommands();
|
||||
}
|
||||
|
||||
public List<String> getCommands(String server) {
|
||||
List<String> commands = new ArrayList<>(generalGroupBlacklist.getCommands());
|
||||
commands.addAll(getOrCreateGroupBlacklist(server).getCommands());
|
||||
return commands;
|
||||
}
|
||||
|
||||
/*
|
||||
public boolean contains(String command, String server) {
|
||||
return generalGroupBlacklist.isListed(command) || GroupManager.getOrCreateGroupList(groupName, server).getOrCreateGroupBlacklist(server).isListed(command);
|
||||
}
|
||||
|
||||
|
||||
public boolean containsOnServer(String command, String server) {
|
||||
GroupBlacklist groupBlacklist = GroupManager.getOrCreateGroupList(groupName, server).getOrCreateGroupBlacklist(server);
|
||||
System.out.println("Watching group: " + groupName + " (" + command + ":" + server + ")");
|
||||
groupBlacklist.getCommands().forEach(a -> System.out.println("ROFL: " + a));
|
||||
return GroupManager.getOrCreateGroupList(groupName, server).getOrCreateGroupBlacklist(server).isListed(command);
|
||||
}
|
||||
|
||||
public List<String> getCommands(String server) {
|
||||
List<String> commands = new ArrayList<>(generalGroupBlacklist.getCommands());
|
||||
GroupServer groupServer = GroupManager.getOrCreateGroupList(getGroupName(), server);
|
||||
commands.addAll(groupServer.getOrCreateGroupBlacklist(server).getCommands());
|
||||
return commands;
|
||||
}
|
||||
*/
|
||||
|
||||
public void deleteGroup() {
|
||||
deleteGroup(null);
|
||||
}
|
||||
|
||||
public void deleteGroup(String server) {
|
||||
Storage.Files.STORAGE.setAndSave("groups." + groupName + (server != null ? "." + server : ""), null);
|
||||
final String path = "groups." + groupName + (server != null ? "." + server : "");
|
||||
Storage.Files.STORAGE.setAndSave(path + ".commands", null);
|
||||
Storage.Files.STORAGE.setAndSave(path, null);
|
||||
Storage.Files.STORAGE.reload();
|
||||
}
|
||||
|
||||
public ConfigurationBuilder getConfig() {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package de.rayzs.pat.utils.group;
|
||||
|
||||
import de.rayzs.pat.api.storage.Storage;
|
||||
import de.rayzs.pat.api.storage.blacklist.BlacklistCreator;
|
||||
import de.rayzs.pat.api.storage.blacklist.impl.GroupBlacklist;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import java.util.*;
|
||||
@@ -9,7 +8,7 @@ import java.util.*;
|
||||
public class GroupManager {
|
||||
|
||||
private static final List<Group> GROUPS = new ArrayList<>();
|
||||
private static final HashMap<String, GroupServer> SERVER_GROUP_BLACKLIST = new HashMap<>();
|
||||
//private static final HashMap<String, GroupServer> SERVER_GROUP_BLACKLIST = new HashMap<>();
|
||||
|
||||
public static void initialize() {
|
||||
if(Reflection.isProxyServer()) Storage.Files.STORAGE.getKeys("groups", true).forEach(GroupManager::registerGroup);
|
||||
@@ -101,7 +100,8 @@ public class GroupManager {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<String> getGroupNames(String server) {
|
||||
|
||||
public static List<String> getGroupNamesByServer(String server) {
|
||||
List<String> result = new ArrayList<>();
|
||||
getGroupsByServer(server).forEach(group -> result.add(group.getGroupName()));
|
||||
return result;
|
||||
@@ -109,10 +109,10 @@ public class GroupManager {
|
||||
|
||||
public static List<Group> getGroupsByServer(String server) {
|
||||
List<Group> result = new ArrayList<>();
|
||||
GROUPS.stream().filter(group -> SERVER_GROUP_BLACKLIST.containsKey(group.getGroupName())).forEach(group -> {
|
||||
GroupServer groupServer = SERVER_GROUP_BLACKLIST.get(group.getGroupName());
|
||||
groupServer.getAllServers().stream().filter(currentServer -> Storage.isServer(server, currentServer)).forEach(currentServer -> result.add(getGroupByName(groupServer.getGroupName())));
|
||||
});
|
||||
GROUPS.stream().filter(group -> {
|
||||
GroupBlacklist groupBlacklist = group.getOrCreateGroupBlacklist(server);
|
||||
return groupBlacklist != null && !groupBlacklist.getCommands().isEmpty() && groupBlacklist.getCommands().size() >= 1;
|
||||
}).forEach(result::add);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -140,6 +140,7 @@ public class GroupManager {
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
public static GroupServer getOrCreateGroupList(String groupName, String server) {
|
||||
GroupServer groupServer = null;
|
||||
if(!SERVER_GROUP_BLACKLIST.containsKey(server)) {
|
||||
@@ -150,6 +151,7 @@ public class GroupManager {
|
||||
|
||||
return SERVER_GROUP_BLACKLIST.getOrDefault(server, groupServer);
|
||||
}
|
||||
*/
|
||||
|
||||
public static TinyGroup convertToTinyGroup(String groupName, List<String> commands) {
|
||||
return new TinyGroup(groupName, commands);
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
package de.rayzs.pat.utils.group;
|
||||
|
||||
import de.rayzs.pat.api.storage.blacklist.BlacklistCreator;
|
||||
import de.rayzs.pat.api.storage.blacklist.impl.GroupBlacklist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class GroupServer {
|
||||
|
||||
private final HashMap<String, GroupBlacklist> groupServerBlacklist = new HashMap<>();
|
||||
private final String groupName;
|
||||
|
||||
public GroupServer(String groupName) {
|
||||
this.groupName = groupName;
|
||||
}
|
||||
|
||||
public String getGroupName() {
|
||||
return groupName;
|
||||
}
|
||||
|
||||
public List<String> getAllServers() {
|
||||
return new ArrayList<>(groupServerBlacklist.keySet());
|
||||
}
|
||||
|
||||
public GroupBlacklist getOrCreateGroupBlacklist(String server) {
|
||||
GroupBlacklist groupBlacklist = null;
|
||||
if(!groupServerBlacklist.containsKey(server)) {
|
||||
System.out.println("New group: " + groupName);
|
||||
groupBlacklist = BlacklistCreator.createGroupBlacklist(groupName, server);
|
||||
groupBlacklist.load();
|
||||
groupServerBlacklist.put(server, groupBlacklist);
|
||||
} else System.out.println("Already existing group: " + groupName);
|
||||
|
||||
return groupServerBlacklist.getOrDefault(server, groupBlacklist);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package de.rayzs.pat.utils;
|
||||
package de.rayzs.pat.utils.group;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
Reference in new issue
Block a user