-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
PVPArenaPlayerProperties.java
144 lines (123 loc) · 5.22 KB
/
PVPArenaPlayerProperties.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package com.denizenscript.depenizen.bukkit.properties.pvparena;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.depenizen.bukkit.objects.pvparena.PVPArenaArenaTag;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import net.slipcor.pvparena.arena.ArenaPlayer;
public class PVPArenaPlayerProperties implements Property {
@Override
public String getPropertyString() {
return null;
}
@Override
public String getPropertyId() {
return "PVPArenaPlayer";
}
@Override
public void adjust(Mechanism mechanism) {
// None
}
public static boolean describes(ObjectTag object) {
return object instanceof PlayerTag;
}
public static PVPArenaPlayerProperties getFrom(ObjectTag object) {
if (!describes(object)) {
return null;
}
else {
return new PVPArenaPlayerProperties((PlayerTag) object);
}
}
public static final String[] handledTags = new String[] {
"pvparena"
};
public static final String[] handledMechs = new String[] {
}; // None
private PVPArenaPlayerProperties(PlayerTag player) {
this.player = ArenaPlayer.parsePlayer(player.getName());
}
ArenaPlayer player;
@Override
public String getAttribute(Attribute attribute) {
if (attribute.startsWith("pvparena")) {
attribute = attribute.fulfill(1);
// <--[tag]
// @attribute <PlayerTag.pvparena.in_arena[<pvparena>]>
// @returns ElementTag(Boolean)
// @plugin Depenizen, PvP Arena
// @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.
// -->
if (attribute.startsWith("inarena") || attribute.startsWith("in_arena")) {
if (player.getArena() == null) {
return new ElementTag(false).getAttribute(attribute.fulfill(1));
}
if (attribute.hasContext(1)) {
PVPArenaArenaTag a = attribute.contextAsType(1, PVPArenaArenaTag.class);
if (a == null) {
return null;
}
return new ElementTag(CoreUtilities.toLowerCase(player.getArena().getName())
.equals(CoreUtilities.toLowerCase(a.getArena().getName())))
.getAttribute(attribute.fulfill(1));
}
else {
return new ElementTag(player.getArena() != null)
.getAttribute(attribute.fulfill(1));
}
}
// <--[tag]
// @attribute <PlayerTag.pvparena.class>
// @returns ElementTag
// @plugin Depenizen, PvP Arena
// @description
// Returns the player's class if they're in an arena. Otherwise, returns null.
// -->
else if (attribute.startsWith("class")) {
return new ElementTag(player.getArenaClass().getName()).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <PlayerTag.pvparena.is_ready>
// @returns ElementTag(Boolean)
// @plugin Depenizen, PvP Arena
// @description
// Returns true if the player is ready.
// -->
else if (attribute.startsWith("isready") || attribute.startsWith("is_ready")) {
return new ElementTag(player.getStatus().equals(ArenaPlayer.Status.READY))
.getAttribute(attribute.fulfill(1));
}
else if (attribute.startsWith("team")) {
attribute = attribute.fulfill(1);
// <--[tag]
// @attribute <PlayerTag.pvparena.team.player_count>
// @returns ElementTag(Number)
// @plugin Depenizen, PvP Arena
// @description
// Returns the number of players in the team.
// -->
if (attribute.startsWith("playercount") || attribute.startsWith("player_count")) {
return new ElementTag(player.getArenaTeam().getTeamMembers().size())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <PlayerTag.pvparena.team.name>
// @returns ElementTag
// @plugin Depenizen, PvP Arena
// @description
// Returns the player's team name if they're in an arena. Otherwise, returns null.
// -->
if (attribute.startsWith("name")) {
return new ElementTag(player.getArenaTeam().getName())
.getAttribute(attribute.fulfill(1));
}
}
}
return null;
}
}