-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewConfigFileFormat
More file actions
64 lines (49 loc) · 1.75 KB
/
NewConfigFileFormat
File metadata and controls
64 lines (49 loc) · 1.75 KB
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
message-category:
default:
SERVER_STOP: Testing the server..
KICK_FULL: '%msg'
PLAYER_QUIT: '%msg'
KICK_WHITELIST: '%msg'
KICK_KICK_LEAVEMSG: '%msg'
KICK_KICK_REASON: '%msg'
PLAYER_JOIN: Hello &b%pName&f in world %world
KICK_BANNED: '%msg'
permnode1:
SERVER_STOP: Oh well...
permnode2:
PLAYER_JOIN: Welcome the admin
where permnode1 is messagechanger.message.permnode1 and permnode2 is messagechanger.message.permnode2
code like this:
private static List<String> readStringList(String root) {
YamlConfiguration config = load();
List<String> list = new ArrayList<String>();
for (String key : config.getConfigurationSection(root).getKeys(false)) {
list.add(key);
}
return list;
}
private static HashMap<String, List<String>> messages = new HashMap<String, List<String>>();
private static List<String> messageCategory;
messageCategory = readStringList("message-category");
Iterator<String> it = messageCategory.iterator();
String next = null;
while (it.hasNext()) {
next = it.next();
messages.put(next, readStringList("message-category."+next);
}
retrieval of data via
Iterator<String> it = messageCategory.iterator();
String permNnode;
String msg;
while (it.hasNext()) {
permNode = it.next();
if (player.hasPermission("messagechanger.message."+ permNode)) {
msg = getMessage(permNode, event);
}
}
if (msg == null) {
msg = getMessage("default", event);
}
sendMessage(msg, event);
where getMessages uses String permNode to get the message for the specific Event event, if the message is empty because permNode doesn't exist it returns null
where sendMessage will send the String msg via the correct Handler for the Event event