package de.perms.utils;
import java.util.List;
import org.bukkit.Bukkit;
import de.perms.main.FileManager;
import de.perms.main.Permissions;
public class GroupManager {
Permissions plugin = Permissions.getInstance();
FileManager fm = plugin.getFileManager();
public boolean existGroups() {
if (fm.fileExists(fm.groups)) {
if (fm.groupscfg.isConfigurationSection("Groups") && !fm.groupscfg.getString("Groups").equals(null)) {
return true;
}
}
return false;
}
public boolean existGroup(String group) {
if (existGroups()) {
if (fm.groupscfg.contains("Groups." + group)) {
return true;
}
}
return false;
}
public void createGroup(String group) {
if (!existGroup(group)) {
fm.groupscfg.set("Groups." + group, "");
}
}
public void renameGroup(String group, String name) {
if (existGroup(group)) {
List<String> members = null;
if (hasGroupMembers(group)) {
members = getGroupMembers(group);
}
removeGroup(group);
createGroup(name);
setGroupMembers(name, members);
}
}
public void removeGroup(String group) {
if (existGroup(group)) {
fm.groupscfg.set("Groups." + group, null);
}
}
public void removeGroups() {
if (existGroups()) {
fm.groupscfg.set("Groups", null);
}
}
public boolean hasGroupMembers(String group) {
if (existGroup(group)) {
if (fm.groupscfg.contains("Groups." + group + ".Members")) {
return true;
}
}
return false;
}
public boolean hasGroupPermissions(String group) {
if (existGroup(group)) {
if (fm.groupscfg.contains("Groups." + group + ".Permissions")) {
return true;
}
}
return false;
}
public boolean hasGroupMember(String group, String playername) {
if (existGroup(group)) {
if (hasGroupMembers(group)) {
if (getGroupMembers(group).contains(Bukkit.getPlayer(playername).getUniqueId().toString())) {
return true;
}
}
}
return false;
}
public boolean hasGroupPermission(String group, String permission) {
if (existGroup(group)) {
if (hasGroupMembers(group)) {
if (getGroupPermissions(group).contains(permission)) {
return true;
}
}
}
return false;
}
public void addGroupMember(String group, String playername) {
if (existGroup(group)) {
if (!hasGroupMember(group, playername)) {
List<String> members = getGroupMembers(group);
members.add(Bukkit.getPlayer(playername).getUniqueId().toString());
fm.groupscfg.set("Groups." + group + ".Members", members);
}
}
}
public void addGroupPermission(String group, String permission) {
if (existGroup(group)) {
if (!hasGroupPermission(group, permission)) {
List<String> permissions = getGroupMembers(group);
permissions.add(permission);
fm.groupscfg.set("Groups." + group + ".Permissions", permissions);
}
}
}
public void removeGroupMember(String group, String playername) {
if (existGroup(group)) {
if (hasGroupMember(group, playername)) {
}
}
}
public void removeGroupPermission(String group, String permission) {
if (existGroup(group)) {
if (hasGroupPermission(group, permission)) {
}
}
}
public void removeGroupMembers(String group) {
if (existGroup(group)) {
if (hasGroupMembers(group)) {
List<String> members = getGroupMembers(group);
members.clear();
setGroupMembers(group, members);
}
}
}
public void removeGroupPermissions(String group) {
if (existGroup(group)) {
if (hasGroupPermissions(group)) {
List<String> permissions = getGroupPermissions(group);
permissions.clear();
setGroupPermissions(group, permissions);
}
}
}
public void setGroupMembers(String group, List<String> members) {
if (existGroup(group)) {
fm.groupscfg.set("Groups." + group + ".Members", members);
}
}
public void setGroupPermissions(String group, List<String> permissions) {
if (existGroup(group)) {
fm.groupscfg.set("Groups." + group + ".Permissions", permissions);
}
}
public List<String> getGroupMembers(String group) {
// Gibt die UUID der Spieler aus. (als String)
if (existGroup(group)) {
if (hasGroupMembers(group)) {
List<String> members = fm.groupscfg.getStringList("Groups." + group + ".Members");
return members;
}
}
return null;
}
public List<String> getGroupPermissions(String group) {
// Gibt die UUID der Spieler aus. (als String)
if (existGroup(group)) {
if (hasGroupPermissions(group)) {
List<String> permissions = fm.groupscfg.getStringList("Groups." + group + ".Permissions");
return permissions;
}
}
return null;
}
public List<String> getGroups() {
if (existGroups()) {
return fm.groupscfg.getStringList("Groups");
}
return null;
}
}
Paste Hosted With By Wklejamy.pl