-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
TownyChatPlayerProperties.java
122 lines (105 loc) · 4.25 KB
/
TownyChatPlayerProperties.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
package com.denizenscript.depenizen.bukkit.properties.towny;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.depenizen.bukkit.bridges.TownyChatBridge;
import com.palmergames.bukkit.TownyChat.Chat;
import com.palmergames.bukkit.TownyChat.channels.Channel;
import com.palmergames.bukkit.TownyChat.channels.ChannelsHolder;
import com.palmergames.bukkit.towny.object.TownyUniverse;
import com.denizenscript.denizen.objects.dPlayer;
import com.denizenscript.denizencore.objects.ElementTag;
import com.denizenscript.denizencore.objects.ListTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.tags.Attribute;
public class TownyChatPlayerProperties implements Property {
@Override
public String getPropertyString() {
return null;
}
@Override
public String getPropertyId() {
return "TownyChatPlayer";
}
@Override
public void adjust(Mechanism mechanism) {
// None
}
public static boolean describes(ObjectTag object) {
return object instanceof dPlayer;
}
public static TownyChatPlayerProperties getFrom(ObjectTag object) {
if (!describes(object)) {
return null;
}
return new TownyChatPlayerProperties((dPlayer) object);
}
public static final String[] handledTags = new String[] {
"townychat"
};
public static final String[] handledMechs = new String[] {
}; // None
private TownyChatPlayerProperties(dPlayer player) {
this.player = player;
}
dPlayer player;
@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
if (attribute.startsWith("townychat")) {
Chat plugin = (Chat) TownyChatBridge.instance.plugin;
ChannelsHolder holder = plugin.getChannelsHandler();
attribute = attribute.fulfill(1);
// <--[tag]
// @attribute <p@player.townychat.channels>
// @returns ListTag(Element)
// @description
// Returns a list of all channels the player is in.
// @Plugin Depenizen, Towny
// -->
if (attribute.startsWith("channel")) {
ListTag chans = new ListTag();
for (Channel c : holder.getAllChannels().values()) {
chans.add(new ElementTag(c.getName()).identify());
}
return chans.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <p@player.townychat.muted_in[<channel name>]>
// @returns ElementTag(Boolean)
// @description
// Returns whether the player is muted in the specified channel.
// @Plugin Depenizen, Towny
// -->
else if (attribute.startsWith("muted_in") && attribute.hasContext(1)) {
Channel c = holder.getChannel(attribute.getAttribute(1));
if (c == null) {
return null;
}
return new ElementTag(c.isMuted(player.getName())).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <p@player.townychat.has_permission[<channel name>]>
// @returns ElementTag(Boolean)
// @description
// Returns whether the player has permissions to join the specified channel.
// @Plugin Depenizen, Towny
// -->
else if (attribute.startsWith("has_permission") && attribute.hasContext(1)) {
Channel c = holder.getChannel(attribute.getContext(1));
if (c == null) {
return null;
}
String perm = c.getPermission();
if (perm == null || !plugin.getTowny().isPermissions()) {
return new ElementTag(true).getAttribute(attribute.fulfill(1));
}
return new ElementTag(TownyUniverse.getPermissionSource().has(player.getPlayerEntity(), perm))
.getAttribute(attribute.fulfill(1));
}
return null;
}
return null;
}
}