-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
SimpleClansBridge.java
110 lines (102 loc) · 4.19 KB
/
SimpleClansBridge.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
package com.denizenscript.depenizen.bukkit.bridges;
import com.denizenscript.depenizen.bukkit.Bridge;
import com.denizenscript.depenizen.bukkit.properties.simpleclans.SimpleClansPlayerProperties;
import com.denizenscript.depenizen.bukkit.objects.dClan;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.objects.ObjectFetcher;
import net.aufdemrand.denizencore.objects.TagRunnable;
import net.aufdemrand.denizencore.objects.properties.PropertyParser;
import net.aufdemrand.denizencore.tags.ReplaceableTagEvent;
import net.aufdemrand.denizencore.objects.dList;
import net.aufdemrand.denizencore.tags.Attribute;
import net.aufdemrand.denizencore.tags.TagManager;
import net.sacredlabyrinth.phaed.simpleclans.Clan;
import net.sacredlabyrinth.phaed.simpleclans.SimpleClans;
public class SimpleClansBridge extends Bridge {
@Override
public void init() {
ObjectFetcher.registerWithObjectFetcher(dClan.class);
PropertyParser.registerProperty(SimpleClansPlayerProperties.class, dPlayer.class);
TagManager.registerTagHandler(new TagRunnable.RootForm() {
@Override
public void run(ReplaceableTagEvent event) {
tagEvent(event);
}
}, "simpleclans");
TagManager.registerTagHandler(new TagRunnable.RootForm() {
@Override
public void run(ReplaceableTagEvent event) {
clanTagEvent(event);
}
}, "clan");
}
public void clanTagEvent(ReplaceableTagEvent event) {
// <--[tag]
// @attribute <clan[<name>]>
// @returns dClan
// @description
// Returns the clan for the input name.
// @Plugin Depenizen, SimpleClans
// -->
Attribute attribute = event.getAttributes();
if (attribute.startsWith("clan") && attribute.hasContext(1)) {
dClan clan = dClan.valueOf(attribute.getContext(1));
if (clan != null) {
event.setReplacedObject(clan.getObjectAttribute(attribute.fulfill(1)));
}
else if (!event.hasAlternative()) {
dB.echoError("Unknown clan '" + attribute.getContext(1) + "' for clan[] tag.");
}
}
}
public void tagEvent(ReplaceableTagEvent event) {
Attribute attribute = event.getAttributes().fulfill(1);
// <--[tag]
// @attribute <simpleclans.list_clans>
// @returns dList(dClan)
// @description
// Returns a list of all clans.
// @Plugin Depenizen, SimpleClans
// -->
if (attribute.startsWith("list_clans")) {
dList clans = new dList();
for (Clan cl : ((SimpleClans) plugin).getClanManager().getClans()) {
clans.add(new dClan(cl).identify());
}
event.setReplacedObject(clans.getObjectAttribute(attribute.fulfill(1)));
}
// <--[tag]
// @attribute <simpleclans.list_unverified_clans>
// @returns dList(dClan)
// @description
// Returns a list of all unverified clans.
// @Plugin Depenizen, SimpleClans
// -->
else if (attribute.startsWith("list_unverified_clans")) {
dList clans = new dList();
for (Clan cl : ((SimpleClans) plugin).getClanManager().getClans()) {
if (!cl.isVerified()) {
clans.add(new dClan(cl).identify());
}
}
event.setReplacedObject(clans.getObjectAttribute(attribute.fulfill(1)));
}
// <--[tag]
// @attribute <simpleclans.list_verified_clans>
// @returns dList(dClan)
// @description
// Returns a list of all verified clans.
// @Plugin Depenizen, SimpleClans
// -->
else if (attribute.startsWith("list_verified_clans")) {
dList clans = new dList();
for (Clan cl : ((SimpleClans) plugin).getClanManager().getClans()) {
if (cl.isVerified()) {
clans.add(new dClan(cl).identify());
}
}
event.setReplacedObject(clans.getObjectAttribute(attribute.fulfill(1)));
}
}
}