summaryrefslogtreecommitdiffstats
path: root/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils
diff options
context:
space:
mode:
Diffstat (limited to 'EssentialsGroupManager/src/org/anjocaido/groupmanager/utils')
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/GMLoggerHandler.java17
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/GroupManagerPermissions.java7
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/PermissionCheckResult.java37
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/StringPermissionComparator.java35
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/Tasks.java106
5 files changed, 123 insertions, 79 deletions
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/GMLoggerHandler.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/GMLoggerHandler.java
index de5348b17..df305aa38 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/GMLoggerHandler.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/GMLoggerHandler.java
@@ -8,19 +8,24 @@ import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
+
/**
- *
+ *
* @author gabrielcouto
*/
-public class GMLoggerHandler extends ConsoleHandler {
-
+public class GMLoggerHandler extends ConsoleHandler
+{
@Override
- public void publish(LogRecord record) {
+ public void publish(LogRecord record)
+ {
String message = "GroupManager - " + record.getLevel() + " - " + record.getMessage();
- if (record.getLevel().equals(Level.SEVERE) || record.getLevel().equals(Level.WARNING)) {
+ if (record.getLevel().equals(Level.SEVERE) || record.getLevel().equals(Level.WARNING))
+ {
System.err.println(message);
- } else {
+ }
+ else
+ {
System.out.println(message);
}
}
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/GroupManagerPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/GroupManagerPermissions.java
index 4a7298b9c..624c6769a 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/GroupManagerPermissions.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/GroupManagerPermissions.java
@@ -4,13 +4,14 @@
*/
package org.anjocaido.groupmanager.utils;
+
/**
* Just a list of commands for this plugin
- *
+ *
* @author gabrielcouto
*/
-public enum GroupManagerPermissions {
-
+public enum GroupManagerPermissions
+{
manuadd,
manudel,
manuaddsub,
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/PermissionCheckResult.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/PermissionCheckResult.java
index eb6633863..df6e4b1cc 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/PermissionCheckResult.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/PermissionCheckResult.java
@@ -6,15 +6,16 @@ package org.anjocaido.groupmanager.utils;
import org.anjocaido.groupmanager.data.DataUnit;
+
/**
- *
+ *
* @author gabrielcouto
*/
-public class PermissionCheckResult {
-
+public class PermissionCheckResult
+{
/**
* It should be the owner of the access level found.
- *
+ *
* Use instanceof to find the owner type
*/
public DataUnit owner;
@@ -27,40 +28,34 @@ public class PermissionCheckResult {
*/
public String askedPermission;
/**
- * The result conclusion of the search.
- * It determines if the owner can do, or not.
- *
+ * The result conclusion of the search. It determines if the owner can do, or not.
+ *
* It even determines if it has an owner.
*/
public Type resultType = Type.NOTFOUND;
+
/**
* The type of result the search can give.
*/
- public enum Type {
-
+ public enum Type
+ {
/**
- * If found a matching node starting with '+'.
- * It means the user CAN do the permission.
+ * If found a matching node starting with '+'. It means the user CAN do the permission.
*/
EXCEPTION,
/**
- * If found a matching node starting with '-'.
- * It means the user CANNOT do the permission.
+ * If found a matching node starting with '-'. It means the user CANNOT do the permission.
*/
NEGATION,
/**
- * If just found a common matching node.
- * IT means the user CAN do the permission.
+ * If just found a common matching node. IT means the user CAN do the permission.
*/
FOUND,
/**
- * If no matchin node was found.
- * It means the user CANNOT do the permission.
- *
- * owner field and accessLevel field should not be considered,
- * when type is
- * NOTFOUND
+ * If no matchin node was found. It means the user CANNOT do the permission.
+ *
+ * owner field and accessLevel field should not be considered, when type is NOTFOUND
*/
NOTFOUND
}
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/StringPermissionComparator.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/StringPermissionComparator.java
index 5a56cd9fc..38cb15349 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/StringPermissionComparator.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/StringPermissionComparator.java
@@ -6,45 +6,54 @@ package org.anjocaido.groupmanager.utils;
import java.util.Comparator;
+
/**
- *
+ *
* @author gabrielcouto
*/
-public class StringPermissionComparator implements Comparator<String> {
-
+public class StringPermissionComparator implements Comparator<String>
+{
@Override
- public int compare(String permA, String permB) {
+ public int compare(String permA, String permB)
+ {
boolean ap = permA.startsWith("+");
boolean bp = permB.startsWith("+");
boolean am = permA.startsWith("-");
boolean bm = permB.startsWith("-");
- if (ap && bp) {
+ if (ap && bp)
+ {
return 0;
}
- if (ap && !bp) {
+ if (ap && !bp)
+ {
return -1;
}
- if (!ap && bp) {
+ if (!ap && bp)
+ {
return 1;
}
- if (am && bm) {
+ if (am && bm)
+ {
return 0;
}
- if (am && !bm) {
+ if (am && !bm)
+ {
return -1;
}
- if (!am && bm) {
+ if (!am && bm)
+ {
return 1;
}
return permA.compareToIgnoreCase(permB);
}
-
private static StringPermissionComparator instance;
- public static StringPermissionComparator getInstance() {
+ public static StringPermissionComparator getInstance()
+ {
- if (instance == null) {
+ if (instance == null)
+ {
instance = new StringPermissionComparator();
}
return instance;
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/Tasks.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/Tasks.java
index d75737c66..da345338d 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/Tasks.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/utils/Tasks.java
@@ -22,19 +22,21 @@ import java.util.List;
import org.anjocaido.groupmanager.GroupManager;
import org.anjocaido.groupmanager.data.Group;
+
/**
- *
+ *
* @author gabrielcouto
*/
-public abstract class Tasks {
-
+public abstract class Tasks
+{
/**
* Gets the exception stack trace as a string.
- *
+ *
* @param exception
* @return stack trace as a string
*/
- public static String getStackTraceAsString(Exception exception) {
+ public static String getStackTraceAsString(Exception exception)
+ {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
@@ -42,7 +44,8 @@ public abstract class Tasks {
return sw.toString();
}
- public static void copy(InputStream src, File dst) throws IOException {
+ public static void copy(InputStream src, File dst) throws IOException
+ {
InputStream in = src;
OutputStream out = new FileOutputStream(dst);
@@ -50,17 +53,22 @@ public abstract class Tasks {
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
- while ((len = in.read(buf)) > 0) {
+ while ((len = in.read(buf)) > 0)
+ {
out.write(buf, 0, len);
}
out.close();
- try {
+ try
+ {
in.close();
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
}
}
- public static void copy(File src, File dst) throws IOException {
+ public static void copy(File src, File dst) throws IOException
+ {
InputStream in = new FileInputStream(src);
copy(in, dst);
@@ -68,11 +76,12 @@ public abstract class Tasks {
/**
* Appends a string to a file
- *
+ *
* @param data
* @param file
*/
- public static void appendStringToFile(String data, String file) throws IOException {
+ public static void appendStringToFile(String data, String file) throws IOException
+ {
FileWriter outStream = new FileWriter("." + System.getProperty("file.separator") + file, true);
@@ -88,16 +97,24 @@ public abstract class Tasks {
out.close();
}
- public static void removeOldFiles(GroupManager gm, File folder) {
-
- if (folder.isDirectory()) {
- long oldTime = System.currentTimeMillis() - (((long) gm.getGMConfig().getBackupDuration() * 60 * 60) * 1000);
- for (File olds : folder.listFiles()) {
- if (olds.isFile()) {
- if (olds.lastModified() < oldTime) {
- try {
+ public static void removeOldFiles(GroupManager gm, File folder)
+ {
+
+ if (folder.isDirectory())
+ {
+ long oldTime = System.currentTimeMillis() - (((long)gm.getGMConfig().getBackupDuration() * 60 * 60) * 1000);
+ for (File olds : folder.listFiles())
+ {
+ if (olds.isFile())
+ {
+ if (olds.lastModified() < oldTime)
+ {
+ try
+ {
olds.delete();
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
}
}
}
@@ -105,7 +122,8 @@ public abstract class Tasks {
}
}
- public static String getDateString() {
+ public static String getDateString()
+ {
GregorianCalendar now = new GregorianCalendar();
String date = "";
@@ -117,59 +135,75 @@ public abstract class Tasks {
return date;
}
- public static String getStringListInString(List<String> list) {
+ public static String getStringListInString(List<String> list)
+ {
- if (list == null) {
+ if (list == null)
+ {
return "";
}
String result = "";
- for (int i = 0; i < list.size(); i++) {
+ for (int i = 0; i < list.size(); i++)
+ {
result += list.get(i);
- if (i < list.size() - 1) {
+ if (i < list.size() - 1)
+ {
result += ", ";
}
}
return result;
}
- public static String getStringArrayInString(String[] list) {
+ public static String getStringArrayInString(String[] list)
+ {
- if (list == null) {
+ if (list == null)
+ {
return "";
}
String result = "";
- for (int i = 0; i < list.length; i++) {
+ for (int i = 0; i < list.length; i++)
+ {
result += list[i];
- if (i < ((list.length) - 1)) {
+ if (i < ((list.length) - 1))
+ {
result += ", ";
}
}
return result;
}
- public static String getGroupListInString(List<Group> list) {
+ public static String getGroupListInString(List<Group> list)
+ {
- if (list == null) {
+ if (list == null)
+ {
return "";
}
String result = "";
- for (int i = 0; i < list.size(); i++) {
+ for (int i = 0; i < list.size(); i++)
+ {
result += list.get(i).getName();
- if (i < list.size() - 1) {
+ if (i < list.size() - 1)
+ {
result += ", ";
}
}
return result;
}
- public static String join(String[] arr, String separator) {
+ public static String join(String[] arr, String separator)
+ {
if (arr.length == 0)
+ {
return "";
+ }
String out = arr[0].toString();
for (int i = 1; i < arr.length; i++)
+ {
out += separator + arr[i];
+ }
return out;
}
-
}