1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-14 02:24:16 +02:00

Typo's and formatting

This commit is contained in:
ElgarL
2011-10-31 09:14:58 +00:00
parent 40683e2429
commit 1d477d8414
3 changed files with 2868 additions and 2846 deletions

View File

@@ -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;
@@ -71,14 +72,12 @@ public class GlobalGroups {
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) {
@@ -120,72 +115,68 @@ public class GlobalGroups {
} }
/** /**
* Write a dataHolder in a specified file * Write the globalgroups.yml file
* @param ph */
* @param groupsFile
*/
public void writeGroups() { public void writeGroups() {
File GlobalGroupsFile = new File(plugin.getDataFolder(), File GlobalGroupsFile = new File(plugin.getDataFolder(), "globalgroups.yml");
"globalgroups.yml");
Map<String, Object> root = new HashMap<String, Object>(); Map<String, Object> root = new HashMap<String, Object>();
Map<String, Object> groupsMap = new HashMap<String, Object>(); Map<String, Object> groupsMap = new HashMap<String, Object>();
root.put("groups", groupsMap); root.put("groups", groupsMap);
for (String groupKey : groups.keySet()) { for (String groupKey : groups.keySet()) {
Group group = groups.get(groupKey); Group group = groups.get(groupKey);
Map<String, Object> aGroupMap = new HashMap<String, Object>(); Map<String, Object> aGroupMap = new HashMap<String, Object>();
groupsMap.put(group.getName(), aGroupMap); groupsMap.put(group.getName(), aGroupMap);
aGroupMap.put("permissions", group.getPermissionList()); aGroupMap.put("permissions", group.getPermissionList());
} }
if (!root.isEmpty()) { if (!root.isEmpty()) {
DumperOptions opt = new DumperOptions(); DumperOptions opt = new DumperOptions();
opt.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); opt.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
final Yaml yaml = new Yaml(opt); final Yaml yaml = new Yaml(opt);
try { try {
yaml.dump(root, new OutputStreamWriter(new FileOutputStream(GlobalGroupsFile), "UTF-8")); yaml.dump(root, new OutputStreamWriter(new FileOutputStream(GlobalGroupsFile), "UTF-8"));
} catch (UnsupportedEncodingException ex) { } catch (UnsupportedEncodingException ex) {
} catch (FileNotFoundException ex) { } catch (FileNotFoundException ex) {
} }
} }
} }
/** /**
* Add a new group if it doesn't already exist. * Add a new group if it doesn't already exist.
* *
* @param newGroup * @param newGroup
*/ */
public Group addGroup(Group newGroup) { public Group addGroup(Group newGroup) {
// Push a new group // 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;