-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
CoreUtilities.java
76 lines (64 loc) · 2.18 KB
/
CoreUtilities.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package net.aufdemrand.denizencore.utilities;
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class CoreUtilities {
static Random random = new Random();
public static Random getRandom() {
return random;
}
protected static FilenameFilter scriptsFilter;
static {
scriptsFilter = new FilenameFilter() {
public boolean accept(File file, String fileName) {
if(fileName.startsWith(".")) return false;
String ext = fileName.substring(fileName.lastIndexOf('.') + 1);
return ext.equalsIgnoreCase("YML") || ext.equalsIgnoreCase("DSCRIPT");
}
};
}
/**
* Lists all files in the given directory.
*
* @param dir The directory to search in
* @return A {@link java.io.File} collection
*/
public static List<File> listDScriptFiles(File dir) {
List<File> files = new ArrayList<File>();
File[] entries = dir.listFiles();
for (File file : entries) {
// Add file
if (scriptsFilter == null || scriptsFilter.accept(dir, file.getName())) {
files.add(file);
}
// Add subdirectories
if (file.isDirectory()) {
files.addAll(listDScriptFiles(file));
}
}
return files;
}
public static List<String> Split(String str, char c) {
List<String> strings = new ArrayList<String>();
int start = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == c) {
strings.add(str.substring(start, i));
start = i + 1;
}
}
strings.add(str.substring(start, str.length()));
return strings;
}
public static String toLowerCase(String input) {
char[] data = input.toCharArray();
for (int i = 0; i < data.length; i++) {
if (data[i] >= 'A' && data[i] <= 'Z') {
data[i] -= 'A' - 'a';
}
}
return new String(data);
}
}