-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
dWorld.java
208 lines (152 loc) · 5.6 KB
/
dWorld.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package net.aufdemrand.denizen.objects;
import net.aufdemrand.denizen.tags.Attribute;
import net.aufdemrand.denizen.utilities.debugging.dB;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class dWorld implements dObject {
@ObjectFetcher("w")
public static dPlayer valueOf(String string) {
if (string == null) return null;
string = string.replace("w@", "");
////////
// Match world name
World returnable = null;
for (World world : Bukkit.getWorlds())
if (world.getName().equalsIgnoreCase(string))
returnable = world;
if (returnable != null) new dWorld(returnable);
else dB.echoError("Invalid World! '" + string
+ "' could not be found.");
return null;
}
public static boolean matches(String arg) {
arg = arg.replace("w@", "");
World returnable = null;
for (World world : Bukkit.getWorlds())
if (world.getName().equalsIgnoreCase(arg))
returnable = world;
if (returnable != null) return true;
return false;
}
public World getWorld() {
return Bukkit.getWorld(world_name);
}
private String prefix;
String world_name;
public dWorld(World world) {
this(null, world);
}
public dWorld(String prefix, World world) {
if (prefix == null) this.prefix = "World";
else this.prefix = prefix;
this.world_name = world.getName();
}
@Override
public String getPrefix() {
return prefix;
}
@Override
public String debug() {
return (prefix + "='<A>" + identify() + "<G>' ");
}
@Override
public boolean isUnique() {
return true;
}
@Override
public String getType() {
return "World";
}
@Override
public String identify() {
return "w@" + world_name;
}
@Override
public String toString() {
return "w@" + world_name;
}
@Override
public dObject setPrefix(String prefix) {
this.prefix = prefix;
return this;
}
@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) return null;
if (attribute.startsWith("can_generate_structures"))
return new Element(String.valueOf(getWorld().canGenerateStructures()))
.getAttribute(attribute.fulfill(1));
getWorld().getName())
.getAttribute(attribute.fulfill(1));
getWorld().getAllowAnimals())
.getAttribute(attribute.fulfill(1));
getWorld().getAllowMonsters())
.getAttribute(attribute.fulfill(1));
getWorld().getAmbientSpawnLimit())
.getAttribute(attribute.fulfill(1));
getWorld().getAnimalSpawnLimit())
.getAttribute(attribute.fulfill(1));
if (attribute.startsWith("highest_block")) {
// TODO: finish
int x = 1;
int z = 1;
return new dLocation(getWorld().getHighestBlockAt(x, z).getLocation())
.getAttribute(attribute.fulfill(1));
}
// getWorld().getChunkAt()
if (attribute.startsWith("difficulty"))
return new Element(getWorld().getDifficulty().name())
.getAttribute(attribute.fulfill(1));
if (attribute.startsWith("players")) {
List<String> players = new ArrayList<String>();
for(Player player : getWorld().getPlayers())
players.add(player.getName());
return new dList(players)
.getAttribute(attribute.fulfill(1));
}
if (attribute.startsWith("sea_level"))
return new Element(String.valueOf(getWorld().getSeaLevel()))
.getAttribute(attribute.fulfill(1));
if (attribute.startsWith("seed"))
return new Element(String.valueOf(getWorld().getSeed()))
.getAttribute(attribute.fulfill(1));
// getWorld().getEntities())
// .getAttribute(attribute.fulfill(1));
//
// getWorld().getEntitiesByClass())
// .getAttribute(attribute.fulfill(1));
//
// getWorld().getEntitiesByClasses())
// .getAttribute(attribute.fulfill(1));
if (attribute.startsWith("time"))
return new Element(String.valueOf(getWorld().getTime()))
.getAttribute(attribute.fulfill(1));
if (attribute.startsWith("weather_duration"))
return Duration.valueOf(String.valueOf(getWorld().getWeatherDuration()) + "t")
.getAttribute(attribute.fulfill(1));
if (attribute.startsWith("has_storm"))
return new Element(String.valueOf(getWorld().hasStorm()))
.getAttribute(attribute.fulfill(1));
if (attribute.startsWith("prefix"))
return new Element(prefix)
.getAttribute(attribute.fulfill(1));
if (attribute.startsWith("debug.log")) {
dB.log(debug());
return new Element(Boolean.TRUE.toString())
.getAttribute(attribute.fulfill(2));
}
if (attribute.startsWith("debug.no_color")) {
return new Element(ChatColor.stripColor(debug()))
.getAttribute(attribute.fulfill(2));
}
if (attribute.startsWith("debug")) {
return new Element(debug())
.getAttribute(attribute.fulfill(1));
}
return new Element(identify()).getAttribute(attribute.fulfill(0));
}
}