forked from upstream/ProAntiTab
Add Cache For ServerBlacklists
This commit is contained in:
1 parent
978a9c12b9
commit
2256dd9be7
2 files changed
+35
-7
No files matched your search
@@ -14,6 +14,7 @@ import de.rayzs.pat.api.storage.config.settings.*;
|
||||
import de.rayzs.pat.api.storage.storages.IgnoredServersStorage;
|
||||
import de.rayzs.pat.api.storage.storages.PlaceholderStorage;
|
||||
import de.rayzs.pat.plugin.*;
|
||||
import de.rayzs.pat.utils.ExpireCache;
|
||||
import de.rayzs.pat.utils.StringUtils;
|
||||
import de.rayzs.pat.utils.configuration.*;
|
||||
import de.rayzs.pat.utils.Reflection;
|
||||
@@ -22,6 +23,7 @@ import de.rayzs.pat.utils.permission.PermissionUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Storage {
|
||||
|
||||
@@ -185,8 +187,10 @@ public class Storage {
|
||||
private static HashMap<String, GeneralBlacklist> SERVER_BLACKLISTS = new HashMap<>();
|
||||
private static final GeneralBlacklist BLACKLIST = BlacklistCreator.createGeneralBlacklist();
|
||||
private static final IgnoredServersStorage IGNORED_SERVERS = new GeneralIgnoredServers();
|
||||
private static final ExpireCache<String, List<GeneralBlacklist>> CACHED_SERVER_BLACKLIST = new ExpireCache<>(1, TimeUnit.HOURS);
|
||||
|
||||
public static void loadAll() {
|
||||
CACHED_SERVER_BLACKLIST.clear();
|
||||
SERVER_BLACKLISTS.clear();
|
||||
BLACKLIST.load();
|
||||
|
||||
@@ -236,10 +240,22 @@ public class Storage {
|
||||
return blacklists;
|
||||
}
|
||||
|
||||
public static void clearServerBlacklists() {
|
||||
CACHED_SERVER_BLACKLIST.clear();
|
||||
}
|
||||
|
||||
public static void clearServerBlacklists(String server) {
|
||||
if(CACHED_SERVER_BLACKLIST.contains(server))
|
||||
CACHED_SERVER_BLACKLIST.remove(server);
|
||||
}
|
||||
|
||||
public static List<GeneralBlacklist> getBlacklists(String server) {
|
||||
if(CACHED_SERVER_BLACKLIST.contains(server))
|
||||
return CACHED_SERVER_BLACKLIST.get(server);
|
||||
|
||||
List<GeneralBlacklist> blacklists = new ArrayList<>();
|
||||
SERVER_BLACKLISTS.entrySet().stream().filter(entry -> entry.getKey().endsWith("*") ? isServer(entry.getKey(), server) : entry.getKey().equals(server)).forEach(entry -> blacklists.add(entry.getValue()));
|
||||
return blacklists;
|
||||
return CACHED_SERVER_BLACKLIST.putAndGet(server, blacklists);
|
||||
}
|
||||
|
||||
public static boolean isListed(String command, String server) {
|
||||
@@ -250,6 +266,7 @@ public class Storage {
|
||||
blocked = blacklist.isBlocked(command, server, !turn);
|
||||
if(blocked) break;
|
||||
}
|
||||
|
||||
return blocked;
|
||||
}
|
||||
|
||||
|
||||
@@ -305,7 +305,7 @@ public class CommandProcess {
|
||||
|
||||
if (CONFIRMATION.getOrDefault(sender.getUniqueId(), "").equals(confirmationString)) {
|
||||
Storage.Blacklist.getBlacklist(sub).clear().save();
|
||||
handleChange();
|
||||
handleChange(sub);
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.BLACKLIST.CLEAR_SERVER.replace("%server%", sub));
|
||||
} else {
|
||||
CONFIRMATION.put(uuid, confirmationString);
|
||||
@@ -396,7 +396,7 @@ public class CommandProcess {
|
||||
bool = Storage.Blacklist.getBlacklist(sub).isListed(extra);
|
||||
if (!bool) {
|
||||
Storage.Blacklist.getBlacklist(sub).add(extra).save();
|
||||
handleChange();
|
||||
handleChange(sub);
|
||||
}
|
||||
|
||||
sender.sendMessage((bool ? Storage.ConfigSections.Messages.BLACKLIST.ADD_SERVER_FAILED : Storage.ConfigSections.Messages.BLACKLIST.ADD_SERVER_SUCCESS).replace("%server%", sub).replace("%command%", extra));
|
||||
@@ -410,7 +410,7 @@ public class CommandProcess {
|
||||
bool = !Storage.Blacklist.getBlacklist(sub).isListed(extra);
|
||||
if (!bool) {
|
||||
Storage.Blacklist.getBlacklist(sub).remove(extra).save();
|
||||
handleChange();
|
||||
handleChange(sub);
|
||||
}
|
||||
|
||||
sender.sendMessage((bool ? Storage.ConfigSections.Messages.BLACKLIST.REMOVE_SERVER_FAILED : Storage.ConfigSections.Messages.BLACKLIST.REMOVE_SERVER_SUCCESS).replace("%server%", sub).replace("%command%", extra));
|
||||
@@ -423,7 +423,7 @@ public class CommandProcess {
|
||||
for (Group groups : GroupManager.getGroupsByServer(sub))
|
||||
groups.clear(sub);
|
||||
|
||||
handleChange();
|
||||
handleChange(sub);
|
||||
sender.sendMessage(Storage.ConfigSections.Messages.GROUP.CLEAR_SERVER.replace("%group%", extra).replace("%server%", sub));
|
||||
} else {
|
||||
CONFIRMATION.put(uuid, confirmationString);
|
||||
@@ -487,7 +487,7 @@ public class CommandProcess {
|
||||
if (!bool) {
|
||||
group.getOrCreateGroupBlacklist(sub, true);
|
||||
group.add(extra, sub);
|
||||
handleChange();
|
||||
handleChange(sub);
|
||||
}
|
||||
|
||||
sender.sendMessage((bool ? Storage.ConfigSections.Messages.GROUP.ADD_SERVER_FAILED : Storage.ConfigSections.Messages.GROUP.ADD_SERVER_SUCCESS).replace("%server%", sub).replace("%command%", extra).replace("%group%", subExtra));
|
||||
@@ -506,7 +506,7 @@ public class CommandProcess {
|
||||
if (!bool) {
|
||||
group.getOrCreateGroupBlacklist(sub, true);
|
||||
group.remove(extra, sub);
|
||||
handleChange();
|
||||
handleChange(sub);
|
||||
}
|
||||
|
||||
sender.sendMessage((bool ? Storage.ConfigSections.Messages.GROUP.REMOVE_SERVER_FAILED : Storage.ConfigSections.Messages.GROUP.REMOVE_SERVER_SUCCESS).replace("%server%", sub).replace("%command%", extra).replace("%group%", subExtra));
|
||||
@@ -615,6 +615,17 @@ public class CommandProcess {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void handleChange(String server) {
|
||||
Storage.Blacklist.clearServerBlacklists(server);
|
||||
GroupManager.clearServerGroupBlacklists();
|
||||
Communicator.syncData();
|
||||
|
||||
if(Reflection.isVelocityServer()) VelocityAntiTabListener.updateCommands();
|
||||
else WaterfallAntiTabListener.updateCommands();
|
||||
|
||||
Communicator.sendPermissionReset();
|
||||
}
|
||||
|
||||
private static void handleChange() {
|
||||
if(Reflection.isProxyServer()) {
|
||||
|
||||
|
||||
Reference in new issue
Block a user