-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
PVPArenaPlayerExtension.java
109 lines (88 loc) · 3.92 KB
/
PVPArenaPlayerExtension.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
package net.gnomeffinway.depenizen.extensions.pvparena;
import net.aufdemrand.denizen.objects.Element;
import net.aufdemrand.denizen.objects.dObject;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.tags.Attribute;
import net.gnomeffinway.depenizen.extensions.dObjectExtension;
import net.slipcor.pvparena.arena.ArenaPlayer;
public class PVPArenaPlayerExtension extends dObjectExtension {
public static boolean describes(dObject pl) {
return pl instanceof dPlayer;
}
public static PVPArenaPlayerExtension getFrom(dObject pl) {
if (!describes(pl)) return null;
else return new PVPArenaPlayerExtension((dPlayer) pl);
}
private PVPArenaPlayerExtension(dPlayer pl) {
player = ArenaPlayer.parsePlayer(pl.getName());
}
ArenaPlayer player = null;
@Override
public String getAttribute(Attribute attribute) {
if (attribute.startsWith("pvparena")) {
attribute = attribute.fulfill(1);
// <--[tag]
// @attribute <p@player.pvparena.class>
// @returns Element
// @description
// Returns the player's class if they're in an arena. Otherwise, returns null.
// @plugin PvP Arena
// -->
if (attribute.startsWith("class")) {
return new Element(player.getArenaClass().getName()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <p@player.pvparena.in_arena[<arena>]>
// @returns Element(Boolean)
// @description
// Returns true if the player is in the specified arena. If no arena is specified,
// this returns true if the player is in any arena.
// @plugin PvP Arena
// -->
else if (attribute.startsWith("inarena") || attribute.startsWith("in_arena")) {
if (attribute.hasContext(1)) {
return new Element(player.getArena().getName().equalsIgnoreCase(attribute.getContext(1)))
.getAttribute(attribute.fulfill(1));
} else {
return new Element(player.getStatus().equals(ArenaPlayer.Status.FIGHT))
.getAttribute(attribute.fulfill(1));
}
}
// <--[tag]
// @attribute <p@player.pvparena.is_ready>
// @returns Element(Boolean)
// @description
// Returns true if the player is ready.
// @plugin PvP Arena
// -->
else if (attribute.startsWith("isready") || attribute.startsWith("is_ready")) {
return new Element(player.getStatus().equals(ArenaPlayer.Status.READY))
.getAttribute(attribute.fulfill(1));
}
else if (attribute.startsWith("team")) {
attribute = attribute.fulfill(1);
// <--[tag]
// @attribute <p@player.pvparena.team.player_count>
// @returns Element(Integer)
// @description
// Returns the number of players in the team.
// @plugin PvP Arena
// -->
if (attribute.startsWith("playercount") || attribute.startsWith("player_count")) {
return new Element(player.getArenaTeam().getTeamMembers().size())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <p@player.pvparena.team>
// @returns Element
// @description
// Returns the player's team name if they're in an arena. Otherwise, returns null.
// @plugin PvP Arena
// -->
return new Element(player.getArenaTeam().getName())
.getAttribute(attribute.fulfill(1));
}
}
return null;
}
}