mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2024-08-06 19:24:15 +00:00
Typo's and formatting
This commit is contained in:
parent
0f67d42c99
commit
0731de53b4
|
@ -35,7 +35,7 @@ public class GlobalGroups {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected boolean haveGroupsChanged = false;
|
protected boolean haveGroupsChanged = false;
|
||||||
|
|
||||||
public GlobalGroups(GroupManager plugin) {
|
public GlobalGroups(GroupManager plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
@ -46,19 +46,20 @@ public class GlobalGroups {
|
||||||
* @return the haveGroupsChanged
|
* @return the haveGroupsChanged
|
||||||
*/
|
*/
|
||||||
public boolean haveGroupsChanged() {
|
public boolean haveGroupsChanged() {
|
||||||
if (this.haveGroupsChanged) {
|
if (this.haveGroupsChanged) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for (Group g : groups.values()) {
|
for (Group g : groups.values()) {
|
||||||
if (g.isChanged()) {
|
if (g.isChanged()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param haveGroupsChanged the haveGroupsChanged to set
|
* @param haveGroupsChanged
|
||||||
|
* the haveGroupsChanged to set
|
||||||
*/
|
*/
|
||||||
public void setGroupsChanged(boolean haveGroupsChanged) {
|
public void setGroupsChanged(boolean haveGroupsChanged) {
|
||||||
this.haveGroupsChanged = haveGroupsChanged;
|
this.haveGroupsChanged = haveGroupsChanged;
|
||||||
|
@ -66,19 +67,17 @@ public class GlobalGroups {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void load() {
|
public void load() {
|
||||||
|
|
||||||
GGroups = new YamlConfiguration();
|
GGroups = new YamlConfiguration();
|
||||||
groups = new HashMap<String, Group>();
|
groups = new HashMap<String, Group>();
|
||||||
|
|
||||||
// READ globalGroups FILE
|
// READ globalGroups FILE
|
||||||
File GlobalGroupsFile = new File(plugin.getDataFolder(),
|
File GlobalGroupsFile = new File(plugin.getDataFolder(), "globalgroups.yml");
|
||||||
"globalgroups.yml");
|
|
||||||
|
|
||||||
if (!GlobalGroupsFile.exists()) {
|
if (!GlobalGroupsFile.exists()) {
|
||||||
try {
|
try {
|
||||||
// Create a new file if it doesn't exist.
|
// Create a new file if it doesn't exist.
|
||||||
Tasks.copy(plugin.getResourceAsStream("globalgroups.yml"),
|
Tasks.copy(plugin.getResourceAsStream("globalgroups.yml"), GlobalGroupsFile);
|
||||||
GlobalGroupsFile);
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
GroupManager.logger.log(Level.SEVERE, null, ex);
|
GroupManager.logger.log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
|
@ -87,21 +86,17 @@ public class GlobalGroups {
|
||||||
try {
|
try {
|
||||||
GGroups.load(GlobalGroupsFile);
|
GGroups.load(GlobalGroupsFile);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + GlobalGroupsFile.getPath(), ex);
|
||||||
"The following file couldn't pass on Parser.\n"
|
|
||||||
+ GlobalGroupsFile.getPath(), ex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read all global groups
|
// Read all global groups
|
||||||
Map<String, Object> allGroups = (Map<String, Object>) GGroups
|
Map<String, Object> allGroups = (Map<String, Object>) GGroups.getConfigurationSection("groups").getValues(false);
|
||||||
.getConfigurationSection("groups").getValues(false);
|
|
||||||
|
|
||||||
// Load each groups permissions list.
|
// Load each groups permissions list.
|
||||||
if (allGroups != null)
|
if (allGroups != null)
|
||||||
for (String groupName : allGroups.keySet()) {
|
for (String groupName : allGroups.keySet()) {
|
||||||
Group newGroup = new Group(groupName.toLowerCase());
|
Group newGroup = new Group(groupName.toLowerCase());
|
||||||
Object permissions = GGroups.get("groups." + groupName
|
Object permissions = GGroups.get("groups." + groupName + ".permissions");
|
||||||
+ ".permissions");
|
|
||||||
|
|
||||||
if (permissions instanceof List) {
|
if (permissions instanceof List) {
|
||||||
for (String permission : (List<String>) permissions) {
|
for (String permission : (List<String>) permissions) {
|
||||||
|
@ -114,78 +109,74 @@ public class GlobalGroups {
|
||||||
// Push a new group
|
// Push a new group
|
||||||
addGroup(newGroup);
|
addGroup(newGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalGroupsFile = null;
|
GlobalGroupsFile = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a dataHolder in a specified file
|
* Write the globalgroups.yml file
|
||||||
* @param ph
|
*/
|
||||||
* @param groupsFile
|
|
||||||
*/
|
|
||||||
|
|
||||||
public void writeGroups() {
|
|
||||||
|
|
||||||
File GlobalGroupsFile = new File(plugin.getDataFolder(),
|
|
||||||
"globalgroups.yml");
|
|
||||||
|
|
||||||
Map<String, Object> root = new HashMap<String, Object>();
|
|
||||||
|
|
||||||
Map<String, Object> groupsMap = new HashMap<String, Object>();
|
public void writeGroups() {
|
||||||
root.put("groups", groupsMap);
|
|
||||||
for (String groupKey : groups.keySet()) {
|
|
||||||
Group group = groups.get(groupKey);
|
|
||||||
|
|
||||||
Map<String, Object> aGroupMap = new HashMap<String, Object>();
|
File GlobalGroupsFile = new File(plugin.getDataFolder(), "globalgroups.yml");
|
||||||
groupsMap.put(group.getName(), aGroupMap);
|
|
||||||
|
|
||||||
aGroupMap.put("permissions", group.getPermissionList());
|
Map<String, Object> root = new HashMap<String, Object>();
|
||||||
}
|
|
||||||
|
|
||||||
if (!root.isEmpty()) {
|
Map<String, Object> groupsMap = new HashMap<String, Object>();
|
||||||
DumperOptions opt = new DumperOptions();
|
root.put("groups", groupsMap);
|
||||||
opt.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
for (String groupKey : groups.keySet()) {
|
||||||
final Yaml yaml = new Yaml(opt);
|
Group group = groups.get(groupKey);
|
||||||
try {
|
|
||||||
yaml.dump(root, new OutputStreamWriter(new FileOutputStream(GlobalGroupsFile), "UTF-8"));
|
|
||||||
} catch (UnsupportedEncodingException ex) {
|
|
||||||
} catch (FileNotFoundException ex) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
Map<String, Object> aGroupMap = new HashMap<String, Object>();
|
||||||
|
groupsMap.put(group.getName(), aGroupMap);
|
||||||
/**
|
|
||||||
* Add a new group if it doesn't already exist.
|
aGroupMap.put("permissions", group.getPermissionList());
|
||||||
*
|
}
|
||||||
* @param newGroup
|
|
||||||
*/
|
if (!root.isEmpty()) {
|
||||||
public Group addGroup(Group newGroup) {
|
DumperOptions opt = new DumperOptions();
|
||||||
// Push a new group
|
opt.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||||
|
final Yaml yaml = new Yaml(opt);
|
||||||
|
try {
|
||||||
|
yaml.dump(root, new OutputStreamWriter(new FileOutputStream(GlobalGroupsFile), "UTF-8"));
|
||||||
|
} catch (UnsupportedEncodingException ex) {
|
||||||
|
} catch (FileNotFoundException ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new group if it doesn't already exist.
|
||||||
|
*
|
||||||
|
* @param newGroup
|
||||||
|
*/
|
||||||
|
public Group addGroup(Group newGroup) {
|
||||||
|
// Push a new group
|
||||||
if (!groups.containsKey(newGroup.getName().toLowerCase())) {
|
if (!groups.containsKey(newGroup.getName().toLowerCase())) {
|
||||||
groups.put(newGroup.getName().toLowerCase(), newGroup);
|
groups.put(newGroup.getName().toLowerCase(), newGroup);
|
||||||
this.setGroupsChanged(true);
|
this.setGroupsChanged(true);
|
||||||
return newGroup;
|
return newGroup;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a group if it exist.
|
* Delete a group if it exist.
|
||||||
*
|
*
|
||||||
* @param newGroup
|
* @param newGroup
|
||||||
*/
|
*/
|
||||||
public boolean removeGroup(String groupName) {
|
public boolean removeGroup(String groupName) {
|
||||||
// Push a new group
|
// Push a new group
|
||||||
if (groups.containsKey(groupName.toLowerCase())) {
|
if (groups.containsKey(groupName.toLowerCase())) {
|
||||||
groups.remove(groupName.toLowerCase());
|
groups.remove(groupName.toLowerCase());
|
||||||
this.setGroupsChanged(true);
|
this.setGroupsChanged(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the Global Group exists in the globalgroups.yml
|
* Returns true if the Global Group exists in the globalgroups.yml
|
||||||
|
@ -209,8 +200,7 @@ public class GlobalGroups {
|
||||||
if (!hasGroup(groupName.toLowerCase()))
|
if (!hasGroup(groupName.toLowerCase()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return groups.get(groupName.toLowerCase()).hasSamePermissionNode(
|
return groups.get(groupName.toLowerCase()).hasSamePermissionNode(permissionNode);
|
||||||
permissionNode);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,8 +212,7 @@ public class GlobalGroups {
|
||||||
* @param permissionNode
|
* @param permissionNode
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public PermissionCheckResult checkPermission(String groupName,
|
public PermissionCheckResult checkPermission(String groupName, String permissionNode) {
|
||||||
String permissionNode) {
|
|
||||||
|
|
||||||
PermissionCheckResult result = new PermissionCheckResult();
|
PermissionCheckResult result = new PermissionCheckResult();
|
||||||
result.askedPermission = permissionNode;
|
result.askedPermission = permissionNode;
|
||||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue