-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
PVPArenaBridge.java
78 lines (71 loc) · 3.31 KB
/
PVPArenaBridge.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
package com.denizenscript.depenizen.bukkit.bridges;
import com.denizenscript.depenizen.bukkit.events.pvparena.PlayerExitsPVPArenaScriptEvent;
import com.denizenscript.depenizen.bukkit.events.pvparena.PlayerJoinsPVPArenaScriptEvent;
import com.denizenscript.depenizen.bukkit.events.pvparena.PlayerLeavesPVPArenaScriptEvent;
import com.denizenscript.depenizen.bukkit.events.pvparena.PVPArenaStartsScriptEvent;
import com.denizenscript.depenizen.bukkit.properties.pvparena.PVPArenaPlayerProperties;
import com.denizenscript.depenizen.bukkit.objects.pvparena.PVPArenaArenaTag;
import com.denizenscript.depenizen.bukkit.Bridge;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizencore.events.ScriptEvent;
import com.denizenscript.denizencore.objects.ObjectFetcher;
import com.denizenscript.denizencore.tags.TagRunnable;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import com.denizenscript.denizencore.tags.ReplaceableTagEvent;
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.tags.TagManager;
import net.slipcor.pvparena.arena.Arena;
import net.slipcor.pvparena.managers.ArenaManager;
public class PVPArenaBridge extends Bridge {
@Override
public void init() {
ScriptEvent.registerScriptEvent(new PVPArenaStartsScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerJoinsPVPArenaScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerLeavesPVPArenaScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerExitsPVPArenaScriptEvent());
PropertyParser.registerProperty(PVPArenaPlayerProperties.class, PlayerTag.class);
ObjectFetcher.registerWithObjectFetcher(PVPArenaArenaTag.class);
TagManager.registerTagHandler(new TagRunnable.RootForm() {
@Override
public void run(ReplaceableTagEvent event) {
tagEvent(event);
}
}, "pvparena");
}
public void tagEvent(ReplaceableTagEvent event) {
Attribute attribute = event.getAttributes();
// <--[tag]
// @attribute <pvparena[<name>]>
// @returns PVPArena
// @plugin Depenizen, PVPArena
// @description
// Returns the PVPArena by the input name.
// -->
if (attribute.hasContext(1)) {
PVPArenaArenaTag arena = attribute.contextAsType(1, PVPArenaArenaTag.class);
if (arena != null) {
event.setReplacedObject(arena.getObjectAttribute(attribute.fulfill(1)));
}
else {
attribute.echoError("Unknown arena '" + attribute.getContext(1) + "' for pvparena[] tag.");
}
return;
}
// <--[tag]
// @attribute <pvparena.list_arenas>
// @returns ListTag(PVPArenaArenaTag)
// @plugin Depenizen, PVPArena
// @description
// Returns a list of all PVPArenas.
// -->
attribute = attribute.fulfill(1);
if (attribute.startsWith("list_arenas")) {
ListTag arenas = new ListTag();
for (Arena a : ArenaManager.getArenas()) {
arenas.addObject(new PVPArenaArenaTag(a));
}
event.setReplacedObject(arenas.getObjectAttribute(attribute.fulfill(1)));
}
}
}