mirror of
https://github.com/RayzsYT/ProAntiTab.git
synced 2026-12-03 05:49:42 -05:00
Add Group-System
This commit is contained in:
1 parent
a127838615
commit
732c09a331
2 files changed
+142
No files matched your search
@@ -0,0 +1,71 @@
|
||||
package de.rayzs.pat.utils.group;
|
||||
|
||||
import de.rayzs.pat.plugin.listeners.BukkitAntiTabListener;
|
||||
import de.rayzs.pat.utils.*;
|
||||
import java.util.*;
|
||||
|
||||
public class Group {
|
||||
|
||||
private final String groupName;
|
||||
private final List<String> commands;
|
||||
|
||||
public Group(String groupName) {
|
||||
this.groupName = groupName.toLowerCase();
|
||||
this.commands = (List<String>) Storage.STORAGE.getOrSet(this.groupName, new ArrayList<>());
|
||||
}
|
||||
|
||||
public Group(String groupName, List<String> commands) {
|
||||
this.groupName = groupName.toLowerCase();
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
public void add(String command) {
|
||||
command = command.toLowerCase();
|
||||
if(contains(command)) return;
|
||||
commands.add(command);
|
||||
save();
|
||||
|
||||
if(Storage.BLOCKED_COMMANDS_LIST.contains(command)) {
|
||||
Storage.BLOCKED_COMMANDS_LIST.add(command);
|
||||
Storage.save();
|
||||
}
|
||||
|
||||
if(!Reflection.isBungeecordServer()) BukkitAntiTabListener.updateCommands();
|
||||
}
|
||||
|
||||
public void remove(String command) {
|
||||
command = command.toLowerCase();
|
||||
if(!contains(command)) return;
|
||||
commands.remove(command);
|
||||
save();
|
||||
|
||||
if(!Reflection.isBungeecordServer()) BukkitAntiTabListener.updateCommands();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
commands.clear();
|
||||
save();
|
||||
|
||||
if(!Reflection.isBungeecordServer()) BukkitAntiTabListener.updateCommands();
|
||||
}
|
||||
|
||||
public boolean hasPermission(Object targetObj) {
|
||||
return PermissionUtil.hasPermission(targetObj, "proantitab.bypass.group." + groupName);
|
||||
}
|
||||
|
||||
public void save() {
|
||||
Storage.STORAGE.setAndSave(groupName, commands);
|
||||
}
|
||||
|
||||
public boolean contains(String command) {
|
||||
return commands.contains(command);
|
||||
}
|
||||
|
||||
public List<String> getCommands() {
|
||||
return commands;
|
||||
}
|
||||
|
||||
public String getGroupName() {
|
||||
return groupName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package de.rayzs.pat.utils.group;
|
||||
|
||||
import de.rayzs.pat.utils.Storage;
|
||||
import java.util.*;
|
||||
|
||||
public class GroupManager {
|
||||
|
||||
private static final List<Group> GROUPS = new ArrayList<>();
|
||||
|
||||
public static void initialize() {
|
||||
Storage.STORAGE.getKeys(true).stream().filter(key -> !key.equals("commands")).forEach(GroupManager::registerGroup);
|
||||
}
|
||||
|
||||
public static boolean canAccessCommand(Object targetObj, String command) {
|
||||
return GROUPS.stream().filter(group -> group.contains(command) && group.hasPermission(command)).findFirst().orElse(null) != null;
|
||||
}
|
||||
|
||||
public static void registerGroup(String groupName) {
|
||||
if(isGroupRegistered(groupName)) return;
|
||||
GROUPS.add(new Group(groupName));
|
||||
}
|
||||
|
||||
public static void addToGroup(String groupName, String command) {
|
||||
Group group = getGroupByName(groupName);
|
||||
if(groupName == null) return;
|
||||
group.add(command);
|
||||
}
|
||||
|
||||
public static void removeFromGroup(String groupName, String command) {
|
||||
Group group = getGroupByName(groupName);
|
||||
if(groupName == null) return;
|
||||
group.remove(command);
|
||||
}
|
||||
|
||||
public static void unregisterGroup(String groupName) {
|
||||
Group group = getGroupByName(groupName);
|
||||
if(group == null) return;
|
||||
Storage.STORAGE.setAndSave(group.getGroupName(), null);
|
||||
GROUPS.remove(group);
|
||||
}
|
||||
|
||||
public static Group getGroupByName(String groupName) {
|
||||
return GROUPS.stream().filter(group -> group.getGroupName().equals(groupName)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public static List<Group> getGroups() {
|
||||
return GROUPS;
|
||||
}
|
||||
|
||||
public static List<String> getGroupNames() {
|
||||
List<String> result = new ArrayList<>();
|
||||
GROUPS.forEach(group -> result.add(group.getGroupName()));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<String> getGroupByNameOnlyIncludingCommand(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) {
|
||||
List<String> result = new ArrayList<>();
|
||||
GROUPS.stream().filter(group -> !group.contains(command)).forEach(group -> result.add(group.getGroupName()));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isGroupRegistered(String groupName) {
|
||||
return getGroupByName(groupName) != null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user