-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
dServer.java
128 lines (98 loc) · 3.04 KB
/
dServer.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package net.gnomeffinway.depenizen.objects.bungee;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.Fetchable;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.tags.Attribute;
import net.aufdemrand.denizencore.tags.TagContext;
import java.util.HashMap;
import java.util.Map;
public class dServer implements dObject {
private static final Map<String, dServer> onlineServers = new HashMap<String, dServer>();
public static void addOnlineServer(String name) {
onlineServers.put(name.toLowerCase(), new dServer(name));
}
public static void removeOnlineServer(String name) {
name = name.toLowerCase();
if (onlineServers.containsKey(name))
onlineServers.remove(name);
}
/////////////////////
// OBJECT FETCHER
/////////////////
public static dServer valueOf(String string) {
return valueOf(string, null);
}
@Fetchable("server")
public static dServer valueOf(String string, TagContext context) {
if (string == null) return null;
////////
// Match faction name
string = string.toLowerCase().replace("server@", "");
if (onlineServers.containsKey(string)) {
return onlineServers.get(string);
}
dB.echoError("Specified server '" + string + "' does not exist or is not online.");
return null;
}
public static boolean matches(String arg) {
if (onlineServers.containsKey(arg.toLowerCase().replace("server@", "")))
return true;
return false;
}
/////////////////////
// STATIC CONSTRUCTORS
/////////////////
String name;
private dServer(String name) {
this.name = name;
}
public String getName() {
return name;
}
/////////////////////
// dObject Methods
/////////////////
private String prefix = "Server";
@Override
public String getPrefix() {
return prefix;
}
@Override
public dServer setPrefix(String prefix) {
this.prefix = prefix;
return this;
}
public String debug() {
return (prefix + "='<A>" + identify() + "<G>' ");
}
@Override
public boolean isUnique() {
return true;
}
@Override
public String getObjectType() {
return "Server";
}
@Override
public String identify() {
return "server@" + name;
}
@Override
public String identifySimple() {
return identify();
}
@Override
public String getAttribute(Attribute attribute) {
// <--[tag]
// @attribute <server@Server.name>
// @returns Element
// @description
// The name of the server as set by its Depenizen's config.yml file.
// -->
if (attribute.startsWith("name")) {
return new Element(name).getAttribute(attribute.fulfill(1));
}
return new Element(identify()).getAttribute(attribute);
}
}