-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
EssentialsBridge.java
85 lines (78 loc) · 3.58 KB
/
EssentialsBridge.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
package com.denizenscript.depenizen.bukkit.bridges;
import com.denizenscript.depenizen.bukkit.events.essentials.*;
import com.denizenscript.depenizen.bukkit.properties.essentials.EssentialsItemProperties;
import com.denizenscript.depenizen.bukkit.properties.essentials.EssentialsPlayerProperties;
import com.denizenscript.depenizen.bukkit.Bridge;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.commands.WarpNotFoundException;
import com.denizenscript.denizen.objects.ItemTag;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizencore.events.ScriptEvent;
import com.denizenscript.denizencore.tags.TagRunnable;
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.tags.ReplaceableTagEvent;
import com.denizenscript.denizencore.tags.TagManager;
import net.ess3.api.InvalidWorldException;
import org.bukkit.Location;
public class EssentialsBridge extends Bridge {
public static EssentialsBridge instance;
@Override
public void init() {
instance = this;
TagManager.registerTagHandler(new TagRunnable.RootForm() {
@Override
public void run(ReplaceableTagEvent event) {
tagEvent(event);
}
}, "essentials");
ScriptEvent.registerScriptEvent(new PlayerAFKStatusScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerGodModeStatusScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerJailStatusScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerMuteStatusScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerBalanceChangeScriptEvent());
PropertyParser.registerProperty(EssentialsPlayerProperties.class, PlayerTag.class);
PropertyParser.registerProperty(EssentialsItemProperties.class, ItemTag.class);
}
public void tagEvent(ReplaceableTagEvent event) {
Attribute attribute = event.getAttributes().fulfill(1);
// <--[tag]
// @attribute <essentials.warp[<warp name>]>
// @returns LocationTag
// @plugin Depenizen, Essentials
// @description
// Returns the location of the warp name.
// -->
if (attribute.startsWith("warp")) {
if (attribute.hasContext(1)) {
Essentials essentials = (Essentials) plugin;
try {
Location loc = essentials.getWarps().getWarp(attribute.getContext(1));
event.setReplacedObject(new LocationTag(loc).getObjectAttribute(attribute.fulfill(1)));
}
catch (WarpNotFoundException e) {
attribute.echoError("Warp not found");
}
catch (InvalidWorldException e) {
attribute.echoError("Invalid world for getting warp");
}
}
}
// <--[tag]
// @attribute <essentials.list_warps>
// @returns ListTag
// @plugin Depenizen, Essentials
// @description
// Returns a list of all Warp names.
// -->
if (attribute.startsWith("list_warps")) {
Essentials essentials = (Essentials) plugin;
ListTag warps = new ListTag();
warps.addAll(essentials.getWarps().getList());
event.setReplacedObject(warps.getObjectAttribute(attribute.fulfill(1)));
}
}
}