mirror of
https://github.com/RayzsYT/ProAntiTab.git
synced 2026-12-01 04:49:44 -05:00
Fix Per-Server Sync
This commit is contained in:
1 parent
53842eab4e
commit
12f080e2c9
7 files changed
+80
-40
No files matched your search
@@ -7,6 +7,7 @@ import de.rayzs.pat.api.storage.config.messages.*;
|
||||
import de.rayzs.pat.api.storage.config.settings.*;
|
||||
import de.rayzs.pat.plugin.BungeeLoader;
|
||||
import de.rayzs.pat.plugin.VelocityLoader;
|
||||
import de.rayzs.pat.plugin.logger.Logger;
|
||||
import de.rayzs.pat.utils.configuration.*;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
import de.rayzs.pat.utils.group.GroupManager;
|
||||
@@ -131,9 +132,9 @@ public class Storage {
|
||||
if(!Reflection.isProxyServer()) return;
|
||||
|
||||
BLACKLIST.getConfig().getKeys("global.servers", true).forEach(key -> {
|
||||
GeneralBlacklist blacklist = BlacklistCreator.createGeneralBlacklist(key);
|
||||
blacklist.load();
|
||||
SERVER_BLACKLISTS.put(key, blacklist);
|
||||
GeneralBlacklist blacklist = BlacklistCreator.createGeneralBlacklist(key);
|
||||
blacklist.load();
|
||||
SERVER_BLACKLISTS.put(key, blacklist);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -209,13 +210,18 @@ public class Storage {
|
||||
}
|
||||
|
||||
public static boolean isBlocked(Object targetObj, String command, boolean intensive, String server) {
|
||||
if(GroupManager.getGroupsByServer(server).stream().anyMatch(group -> isInListed(command, group.getCommands(server), intensive) && group.hasPermission(targetObj))) return false;
|
||||
if(GroupManager.getGroupsByServer(server).stream().anyMatch(group -> isInListed(command, group.getCommands(server), intensive) && group.hasPermission(targetObj)))
|
||||
return false;
|
||||
|
||||
boolean blocked = isBlocked(targetObj, command, intensive);
|
||||
if(!blocked) for (GeneralBlacklist blacklist : getBlacklists(server)) {
|
||||
blocked = blacklist.isBlocked(targetObj, command, intensive);
|
||||
if(blocked) break;
|
||||
boolean blocked = isBlocked(targetObj, command, intensive),
|
||||
allow = false;
|
||||
|
||||
for (GeneralBlacklist blacklist : getBlacklists(server)) {
|
||||
allow = !blacklist.isBlocked(targetObj, command, intensive);
|
||||
if(allow) break;
|
||||
}
|
||||
|
||||
blocked = !allow && blocked;
|
||||
return blocked;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ public class BlacklistCreator {
|
||||
}
|
||||
|
||||
public static GeneralBlacklist createGeneralBlacklist(String server) {
|
||||
//return new GeneralBlacklist((server != null ? "servers." + server + "." : "") + "commands");
|
||||
return new GeneralBlacklist("servers." + server + ".commands");
|
||||
}
|
||||
|
||||
@@ -18,19 +17,21 @@ public class BlacklistCreator {
|
||||
return new GroupBlacklist(group, "commands");
|
||||
}
|
||||
|
||||
public static GroupBlacklist createGroupBlacklist(String group, String server) {
|
||||
//return new GroupBlacklist(group, (server != null ? ".servers." + server : "") + ".commands");
|
||||
public static GroupBlacklist createGroupBlacklist(String group, String server, boolean ignoreExist) {
|
||||
server = server.toLowerCase();
|
||||
if (!exist(group, server) && !ignoreExist)
|
||||
return null;
|
||||
return new GroupBlacklist(group, "servers." + server + ".commands");
|
||||
}
|
||||
|
||||
public static boolean exist(String server) {
|
||||
//Object obj = Storage.Blacklist.getBlacklist().getConfig().get("general." + (server != null ? "servers." + server + "." : "") + "commands");
|
||||
server = server.toLowerCase();
|
||||
Object obj = Storage.Blacklist.getBlacklist().getConfig().get("global.servers." + server);
|
||||
return obj != null;
|
||||
}
|
||||
|
||||
public static boolean exist(String group, String server) {
|
||||
//Object obj = Storage.Blacklist.getBlacklist().getConfig().get("groups." + group + "." + (server != null ? "servers." + server + "." : "") + "commands");
|
||||
server = server.toLowerCase();
|
||||
Object obj = Storage.Blacklist.getBlacklist().getConfig().get("groups." + group + ".servers." + server);
|
||||
return obj != null;
|
||||
}
|
||||
|
||||
@@ -488,6 +488,7 @@ public class CommandProcess {
|
||||
|
||||
bool = group.containsOnServer(extra, sub);
|
||||
if (!bool) {
|
||||
group.getOrCreateGroupBlacklist(sub, true);
|
||||
group.add(extra, sub);
|
||||
handleChange();
|
||||
}
|
||||
@@ -506,6 +507,7 @@ public class CommandProcess {
|
||||
|
||||
bool = !group.containsOnServer(extra, sub);
|
||||
if (!bool) {
|
||||
group.getOrCreateGroupBlacklist(sub, true);
|
||||
group.remove(extra, sub);
|
||||
handleChange();
|
||||
}
|
||||
@@ -575,7 +577,7 @@ public class CommandProcess {
|
||||
break;
|
||||
|
||||
case 3:
|
||||
if (!backend && args[0].equals("add") && PermissionUtil.hasPermission(sender, "add") && !Reflection.isProxyServer())
|
||||
if (!backend && args[0].equals("add") && PermissionUtil.hasPermission(sender, "add"))
|
||||
suggestions.addAll(GroupManager.getGroupNames());
|
||||
if (!backend && Arrays.asList("remove", "rem", "rm").contains(args[0].toLowerCase()) && PermissionUtil.hasPermission(sender, "remove"))
|
||||
suggestions.addAll(GroupManager.getGroupNamesByServer(args[2]));
|
||||
|
||||
@@ -19,6 +19,13 @@ public class PermissionUtil {
|
||||
}
|
||||
|
||||
public static boolean hasBypassPermission(Object targetObj, String command) {
|
||||
if (command.contains(" ")) {
|
||||
String[] split = command.split(" ");
|
||||
if (split.length > 0)
|
||||
command = split[0];
|
||||
command = command.split(" ")[0];
|
||||
}
|
||||
|
||||
return hasBypassPermission(targetObj)
|
||||
|| hasPermission(targetObj, "bypass." + command.toLowerCase())
|
||||
|| hasServerPermission(targetObj, "bypass." + command.toLowerCase())
|
||||
@@ -26,6 +33,14 @@ public class PermissionUtil {
|
||||
}
|
||||
|
||||
public static boolean hasBypassPermission(Object targetObj, String command, String server) {
|
||||
server = server.toLowerCase();
|
||||
if (command.contains(" ")) {
|
||||
String[] split = command.split(" ");
|
||||
if (split.length > 0)
|
||||
command = split[0];
|
||||
command = command.split(" ")[0];
|
||||
}
|
||||
|
||||
return hasBypassPermission(targetObj)
|
||||
|| hasPermission(targetObj, "bypass." + command.toLowerCase())
|
||||
|| hasServerPermission(targetObj, "bypass." + command.toLowerCase())
|
||||
|
||||
@@ -32,75 +32,87 @@ public class Group implements Serializable {
|
||||
}
|
||||
|
||||
public void add(String command) {
|
||||
generalGroupBlacklist.add(command).save();
|
||||
this.generalGroupBlacklist.add(command).save();
|
||||
}
|
||||
|
||||
public void add(String command, String server) {
|
||||
GroupBlacklist serverGroupBlacklist = BlacklistCreator.createGroupBlacklist(groupName, server);
|
||||
GroupBlacklist serverGroupBlacklist = BlacklistCreator.createGroupBlacklist(this.groupName, server, true);
|
||||
serverGroupBlacklist.load();
|
||||
serverGroupBlacklist.add(command).save();
|
||||
}
|
||||
|
||||
public void remove(String command) {
|
||||
generalGroupBlacklist.remove(command).save();
|
||||
this.generalGroupBlacklist.remove(command).save();
|
||||
}
|
||||
|
||||
public void remove(String command, String server) {
|
||||
GroupBlacklist serverGroupBlacklist = BlacklistCreator.createGroupBlacklist(groupName, server);
|
||||
GroupBlacklist serverGroupBlacklist = BlacklistCreator.createGroupBlacklist(this.groupName, server, true);
|
||||
serverGroupBlacklist.load();
|
||||
serverGroupBlacklist.remove(command).save();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
generalGroupBlacklist.clear().save();
|
||||
this.generalGroupBlacklist.clear().save();
|
||||
}
|
||||
|
||||
public void clear(String server) {
|
||||
GroupBlacklist serverGroupBlacklist = BlacklistCreator.createGroupBlacklist(groupName, server);
|
||||
GroupBlacklist serverGroupBlacklist = BlacklistCreator.createGroupBlacklist(this.groupName, server, true);
|
||||
serverGroupBlacklist.clear().save();
|
||||
serverGroupBlacklist.load();
|
||||
Storage.Files.STORAGE.reload();
|
||||
}
|
||||
|
||||
public void setCommands(List<String> commands) {
|
||||
generalGroupBlacklist.setList(commands);
|
||||
this.generalGroupBlacklist.setList(commands);
|
||||
}
|
||||
|
||||
public boolean hasPermission(Object targetObj) {
|
||||
return PermissionUtil.hasPermission(targetObj, "group." + groupName) || PermissionUtil.hasServerPermission(targetObj, "group." + groupName);
|
||||
return (PermissionUtil.hasPermission(targetObj, "group." + this.groupName) || PermissionUtil.hasServerPermission(targetObj, "group." + this.groupName));
|
||||
}
|
||||
|
||||
public boolean contains(String command) {
|
||||
return generalGroupBlacklist.isListed(command);
|
||||
return this.generalGroupBlacklist.isListed(command);
|
||||
}
|
||||
|
||||
public boolean contains(String command, String server) {
|
||||
return generalGroupBlacklist.isListed(command) || getOrCreateGroupBlacklist(server).isListed(command);
|
||||
server = server.toLowerCase();
|
||||
return (this.generalGroupBlacklist.isListed(command) || getOrCreateGroupBlacklist(server).isListed(command));
|
||||
}
|
||||
|
||||
public boolean containsOnServer(String command, String server) {
|
||||
return getOrCreateGroupBlacklist(server).isListed(command);
|
||||
server = server.toLowerCase();
|
||||
GroupBlacklist serverGroupBlacklist = getOrCreateGroupBlacklist(server);
|
||||
return (serverGroupBlacklist != null && serverGroupBlacklist.isListed(command));
|
||||
}
|
||||
|
||||
public GroupBlacklist getOrCreateGroupBlacklist(String server) {
|
||||
GroupBlacklist groupBlacklist;
|
||||
if(groupServerBlacklist.containsKey(server)) groupBlacklist = groupServerBlacklist.get(server);
|
||||
else {
|
||||
groupBlacklist = BlacklistCreator.createGroupBlacklist(groupName, server);
|
||||
groupServerBlacklist.put(server, groupBlacklist);
|
||||
}
|
||||
return getOrCreateGroupBlacklist(server, false);
|
||||
}
|
||||
|
||||
groupBlacklist.load();
|
||||
public GroupBlacklist getOrCreateGroupBlacklist(String server, boolean ignoreExist) {
|
||||
GroupBlacklist groupBlacklist;
|
||||
server = server.toLowerCase();
|
||||
if (this.groupServerBlacklist.containsKey(server)) {
|
||||
groupBlacklist = this.groupServerBlacklist.get(server);
|
||||
} else {
|
||||
groupBlacklist = BlacklistCreator.createGroupBlacklist(this.groupName, server, ignoreExist);
|
||||
this.groupServerBlacklist.put(server, groupBlacklist);
|
||||
}
|
||||
if (groupBlacklist != null)
|
||||
groupBlacklist.load();
|
||||
return groupBlacklist;
|
||||
}
|
||||
|
||||
public List<String> getCommands() {
|
||||
return generalGroupBlacklist.getCommands();
|
||||
return this.generalGroupBlacklist.getCommands();
|
||||
}
|
||||
|
||||
public List<String> getCommands(String server) {
|
||||
List<String> commands = new ArrayList<>(generalGroupBlacklist.getCommands());
|
||||
commands.addAll(getOrCreateGroupBlacklist(server).getCommands());
|
||||
server = server.toLowerCase();
|
||||
List<String> commands = new ArrayList<>(this.generalGroupBlacklist.getCommands());
|
||||
GroupBlacklist groupBlacklist = getOrCreateGroupBlacklist(server);
|
||||
if (groupBlacklist != null)
|
||||
commands.addAll(groupBlacklist.getCommands());
|
||||
return commands;
|
||||
}
|
||||
|
||||
@@ -109,8 +121,8 @@ public class Group implements Serializable {
|
||||
}
|
||||
|
||||
public void deleteGroup(String server) {
|
||||
final String path = "groups." + groupName + (server != null ? "." + server : "");
|
||||
//Storage.Files.STORAGE.setAndSave(path + ".commands", null);
|
||||
server = (server != null) ? server.toLowerCase() : null;
|
||||
String path = "groups." + this.groupName + ((server != null) ? ("." + server) : "");
|
||||
Storage.Files.STORAGE.setAndSave(path, null);
|
||||
Storage.Files.STORAGE.reload();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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.*;
|
||||
@@ -102,8 +103,11 @@ public class GroupManager {
|
||||
public static List<Group> getGroupsByServer(String server) {
|
||||
List<Group> result = new ArrayList<>();
|
||||
GROUPS.stream().filter(group -> {
|
||||
GroupBlacklist groupBlacklist = group.getOrCreateGroupBlacklist(server);
|
||||
return groupBlacklist != null && !groupBlacklist.getCommands().isEmpty() && groupBlacklist.getCommands().size() >= 1;
|
||||
if (BlacklistCreator.exist(group.getGroupName(), server)) {
|
||||
GroupBlacklist groupBlacklist = group.getOrCreateGroupBlacklist(server);
|
||||
return (groupBlacklist != null && !groupBlacklist.getCommands().isEmpty() && groupBlacklist.getCommands().size() >= 1);
|
||||
}
|
||||
return false;
|
||||
}).forEach(result::add);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ public class MessageTranslator {
|
||||
|
||||
public static String replaceMessage(Object playerObj, String text) {
|
||||
CommandSender sender = playerObj instanceof CommandSender ? (CommandSender) playerObj : new CommandSender(playerObj);
|
||||
text = text.replace("%executor%", sender.getName()).replace("&", "§").replace("%prefix%", Storage.ConfigSections.Messages.PREFIX.PREFIX).replace("%current_version%", Storage.CURRENT_VERSION).replace("%newest_version%", Storage.NEWER_VERSION).replace("\\n", "\n");
|
||||
text = text.replace("%executor%", sender.isPlayer() ? sender.getName() : "").replace("&", "§").replace("%prefix%", Storage.ConfigSections.Messages.PREFIX.PREFIX).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);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user