-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
dWorld.java
1156 lines (1017 loc) · 37.3 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package net.aufdemrand.denizen.objects;
import net.aufdemrand.denizen.Settings;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.objects.*;
import net.aufdemrand.denizencore.objects.properties.Property;
import net.aufdemrand.denizencore.objects.properties.PropertyParser;
import net.aufdemrand.denizencore.tags.Attribute;
import net.aufdemrand.denizencore.tags.TagContext;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import org.apache.commons.io.FileUtils;
import org.bukkit.*;
import org.bukkit.craftbukkit.v1_10_R1.CraftChunk;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class dWorld implements dObject, Adjustable {
/////////////////////
// STATIC METHODS
/////////////////
static Map<String, dWorld> worlds = new HashMap<String, dWorld>();
public static dWorld mirrorBukkitWorld(World world) {
if (world == null) {
return null;
}
if (worlds.containsKey(world.getName())) {
return worlds.get(world.getName());
}
else {
return new dWorld(world);
}
}
/////////////////////
// OBJECT FETCHER
/////////////////
// <--[language]
// @name w@
// @group Object Fetcher System
// @description
// w@ refers to the 'object identifier' of a dWorld. The 'w@' is notation for Denizen's Object
// Fetcher. The only valid constructor for a dWorld is the name of the world it should be
// associated with. For example, to reference the world named 'world1', use w@world1.
// World names are case insensitive.
// -->
public static dWorld valueOf(String string) {
return valueOf(string, null);
}
@Fetchable("w")
public static dWorld valueOf(String string, TagContext context) {
return valueOf(string, context == null || context.debug);
}
public static dWorld valueOf(String string, boolean announce) {
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) {
if (worlds.containsKey(returnable.getName())) {
return worlds.get(returnable.getName());
}
else {
return new dWorld(returnable);
}
}
else if (announce) {
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;
}
}
return returnable != null;
}
public World getWorld() {
return Bukkit.getWorld(world_name);
}
public String getName() {
return world_name;
}
public List<Entity> getEntities() {
return getWorld().getEntities();
}
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();
if (!worlds.containsKey(world.getName())) {
worlds.put(world.getName(), this);
}
}
@Override
public String getPrefix() {
return prefix;
}
@Override
public String debug() {
return (prefix + "='<A>" + identify() + "<G>' ");
}
@Override
public boolean isUnique() {
return true;
}
@Override
public String getObjectType() {
return "World";
}
@Override
public String identify() {
return "w@" + world_name;
}
@Override
public String identifySimple() {
return identify();
}
@Override
public String toString() {
return identify();
}
@Override
public dObject setPrefix(String prefix) {
this.prefix = prefix;
return this;
}
public static void registerTags() {
/////////////////////
// ENTITY LIST ATTRIBUTES
/////////////////
// <--[tag]
// @attribute <w@world.entities>
// @returns dList(dEntity)
// @description
// Returns a list of entities in this world.
// -->
registerTag("entities", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
ArrayList<dEntity> entities = new ArrayList<dEntity>();
for (Entity entity : ((dWorld) object).getWorld().getEntities()) {
entities.add(new dEntity(entity));
}
return new dList(entities)
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <w@world.living_entities>
// @returns dList(dEntity)
// @description
// Returns a list of living entities in this world.
// -->
registerTag("living_entities", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
ArrayList<dEntity> entities = new ArrayList<dEntity>();
for (Entity entity : ((dWorld) object).getWorld().getLivingEntities()) {
entities.add(new dEntity(entity));
}
return new dList(entities)
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <w@world.players>
// @returns dList(dPlayer)
// @description
// Returns a list of online players in this world.
// -->
registerTag("players", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
ArrayList<dPlayer> players = new ArrayList<dPlayer>();
for (Player player : ((dWorld) object).getWorld().getPlayers()) {
if (!dEntity.isNPC(player)) {
players.add(new dPlayer(player));
}
}
return new dList(players)
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <w@world.spawned_npcs>
// @returns dList(dNPC)
// @description
// Returns a list of spawned NPCs in this world.
// -->
registerTag("spawned_npcs", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
ArrayList<dNPC> npcs = new ArrayList<dNPC>();
World thisWorld = ((dWorld) object).getWorld();
for (NPC npc : CitizensAPI.getNPCRegistry()) {
if (npc.isSpawned() && npc.getEntity().getLocation().getWorld().equals(thisWorld)) {
npcs.add(dNPC.mirrorCitizensNPC(npc));
}
}
return new dList(npcs)
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <w@world.npcs>
// @returns dList(dNPC)
// @description
// Returns a list of all NPCs in this world.
// -->
registerTag("npcs", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
ArrayList<dNPC> npcs = new ArrayList<dNPC>();
World thisWorld = ((dWorld) object).getWorld();
for (NPC npc : CitizensAPI.getNPCRegistry()) {
Location location = npc.getStoredLocation();
if (location != null) {
World world = location.getWorld();
if (world != null && world.equals(thisWorld)) {
npcs.add(dNPC.mirrorCitizensNPC(npc));
}
}
}
return new dList(npcs)
.getAttribute(attribute.fulfill(1));
}
});
/////////////////////
// GEOGRAPHY ATTRIBUTES
/////////////////
// <--[tag]
// @attribute <w@world.can_generate_structures>
// @returns Element(Boolean)
// @description
// Returns whether the world will generate structures.
// -->
registerTag("can_generate_structures", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dWorld) object).getWorld().canGenerateStructures())
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <w@world.loaded_chunks>
// @returns dList(dChunk)
// @description
// Returns a list of all the currently loaded chunks.
// -->
registerTag("loaded_chunks", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
dList chunks = new dList();
for (Chunk ent : ((dWorld) object).getWorld().getLoadedChunks()) {
chunks.add(new dChunk((CraftChunk) ent).identify());
}
return chunks.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <w@world.random_loaded_chunk>
// @returns dChunk
// @description
// Returns a random loaded chunk.
// -->
registerTag("random_loaded_chunk", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
int random = CoreUtilities.getRandom().nextInt(((dWorld) object).getWorld().getLoadedChunks().length);
return new dChunk((CraftChunk) ((dWorld) object).getWorld().getLoadedChunks()[random])
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <w@world.sea_level>
// @returns Element(Number)
// @description
// Returns the level of the sea.
// -->
registerTag("sea_level", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dWorld) object).getWorld().getSeaLevel())
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <w@world.spawn_location>
// @returns dLocation
// @description
// Returns the spawn location of the world.
// -->
registerTag("spawn_location", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new dLocation(((dWorld) object).getWorld().getSpawnLocation())
.getAttribute(attribute.fulfill(1));
}
});
/////////////////////
// IDENTIFICATION ATTRIBUTES
/////////////////
// <--[tag]
// @attribute <w@world.name>
// @returns Element
// @description
// Returns the name of the world.
// -->
registerTag("name", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dWorld) object).getWorld().getName())
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <w@world.seed>
// @returns Element
// @description
// Returns the world seed.
// -->
registerTag("seed", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dWorld) object).getWorld().getSeed())
.getAttribute(attribute.fulfill(1));
}
});
/////////////////////
// SETTINGS ATTRIBUTES
/////////////////
// <--[tag]
// @attribute <w@world.allows_animals>
// @returns Element(Boolean)
// @description
// Returns whether animals can spawn in this world.
// -->
registerTag("allows_animals", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dWorld) object).getWorld().getAllowAnimals())
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <w@world.allows_monsters>
// @returns Element(Boolean)
// @description
// Returns whether monsters can spawn in this world.
// -->
registerTag("allows_monsters", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dWorld) object).getWorld().getAllowMonsters())
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <w@world.allows_pvp>
// @returns Element(Boolean)
// @description
// Returns whether player versus player combat is allowed in this world.
// -->
registerTag("allows_pvp", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dWorld) object).getWorld().getPVP())
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <w@world.auto_save>
// @returns Element(Boolean)
// @description
// Returns whether the world automatically saves.
// -->
registerTag("auto_save", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dWorld) object).getWorld().isAutoSave())
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <w@world.ambient_spawn_limit>
// @returns Element(Number)
// @description
// Returns the number of ambient mobs that can spawn in a chunk in this world.
// -->
registerTag("ambient_spawn_limit", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dWorld) object).getWorld().getAmbientSpawnLimit())
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <w@world.animal_spawn_limit>
// @returns Element(Number)
// @description
// Returns the number of animals that can spawn in a chunk in this world.
// -->
registerTag("animal_spawn_limit", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dWorld) object).getWorld().getAnimalSpawnLimit())
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <w@world.monster_spawn_limit>
// @returns Element(Number)
// @description
// Returns the number of monsters that can spawn in a chunk in this world.
// -->
registerTag("monster_spawn_limit", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dWorld) object).getWorld().getMonsterSpawnLimit())
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <w@world.water_animal_spawn_limit>
// @returns Element(Number)
// @description
// Returns the number of water animals that can spawn in a chunk in this world.
// -->
registerTag("water_animal_spawn_limit", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dWorld) object).getWorld().getWaterAnimalSpawnLimit())
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <w@world.difficulty>
// @returns Element
// @description
// Returns the name of the difficulty level.
// -->
registerTag("difficulty", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dWorld) object).getWorld().getDifficulty().name())
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <w@world.keep_spawn>
// @returns Element(Boolean)
// @description
// Returns whether the world's spawn area should be kept loaded into memory.
// -->
registerTag("keep_spawn", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dWorld) object).getWorld().getKeepSpawnInMemory())
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <w@world.max_height>
// @returns Element(Number)
// @description
// Returns the maximum height of this world.
// -->
registerTag("max_height", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dWorld) object).getWorld().getMaxHeight())
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <w@world.ticks_per_animal_spawn>
// @returns Duration
// @description
// Returns the world's ticks per animal spawn value.
// -->
registerTag("ticks_per_animal_spawn", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Duration(((dWorld) object).getWorld().getTicksPerAnimalSpawns())
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <w@world.ticks_per_monster_spawn>
// @returns Duration
// @description
// Returns the world's ticks per monster spawn value.
// -->
registerTag("ticks_per_monster_spawn", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Duration(((dWorld) object).getWorld().getTicksPerMonsterSpawns())
.getAttribute(attribute.fulfill(1));
}
});
/////////////////////
// TIME ATTRIBUTES
/////////////////
// <--[tag]
// @attribute <w@world.time>
// @returns Element(Number)
// @description
// Returns the relative in-game time of this world.
// -->
registerTag("time", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
attribute = attribute.fulfill(1);
// <--[tag]
// @attribute <w@world.time.duration>
// @returns Durations
// @description
// Returns the relative in-game time of this world as a duration.
// -->
if (attribute.startsWith("duration")) {
return new Duration(((dWorld) object).getWorld().getTime())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <w@world.time.full>
// @returns Duration
// @description
// Returns the in-game time of this world.
// -->
else if (attribute.startsWith("full")) {
return new Element(((dWorld) object).getWorld().getFullTime())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <w@world.time.period>
// @returns Element
// @description
// Returns the time as 'day', 'night', 'dawn', or 'dusk'.
// -->
else if (attribute.startsWith("period")) {
long time = ((dWorld) object).getWorld().getTime();
String period;
if (time >= 23000) {
period = "dawn";
}
else if (time >= 13500) {
period = "night";
}
else if (time >= 12500) {
period = "dusk";
}
else {
period = "day";
}
return new Element(period).getAttribute(attribute.fulfill(1));
}
else {
return new Element(((dWorld) object).getWorld().getTime()).getAttribute(attribute);
}
}
});
// <--[tag]
// @attribute <w@world.moon_phase>
// @returns Element(Number)
// @description
// Returns the current phase of the moon, as an integer from 1 to 8.
// -->
registerTag("moon_phase", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element((int) ((((dWorld) object).getWorld().getFullTime() / 24000) % 8) + 1)
.getAttribute(attribute.fulfill(1));
}
});
registerTag("moonphase", registeredTags.get("moon_phase"));
/////////////////////
// WEATHER ATTRIBUTES
/////////////////
// <--[tag]
// @attribute <w@world.has_storm>
// @returns Element(Boolean)
// @description
// Returns whether there is currently a storm in this world.
// -->
registerTag("has_storm", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dWorld) object).getWorld().hasStorm())
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <w@world.thunder_duration>
// @returns Duration
// @description
// Returns the duration of thunder.
// -->
registerTag("thunder_duration", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Duration((long) ((dWorld) object).getWorld().getThunderDuration())
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <w@world.thundering>
// @returns Element(Boolean)
// @description
// Returns whether it is currently thundering in this world.
// -->
registerTag("thundering", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dWorld) object).getWorld().isThundering())
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <w@world.weather_duration>
// @returns Duration
// @description
// Returns the duration of storms.
// -->
registerTag("weather_duration", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Duration((long) ((dWorld) object).getWorld().getWeatherDuration())
.getAttribute(attribute.fulfill(1));
}
});
/////////////////////
// DEBUG TAGS
/////////////////
// <--[tag]
// @attribute <w@world.prefix>
// @returns Element
// @description
// Returns the prefix of the world dObject.
// -->
registerTag("prefix", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element(((dWorld) object).prefix)
.getAttribute(attribute.fulfill(1));
}
});
// <--[tag]
// @attribute <w@world.type>
// @returns Element
// @description
// Always returns 'World' for dWorld objects. All objects fetchable by the Object Fetcher will return the
// type of object that is fulfilling this attribute.
// -->
registerTag("type", new TagRunnable() {
@Override
public String run(Attribute attribute, dObject object) {
return new Element("World").getAttribute(attribute.fulfill(1));
}
});
}
public static HashMap<String, TagRunnable> registeredTags = new HashMap<String, TagRunnable>();
public static void registerTag(String name, TagRunnable runnable) {
if (runnable.name == null) {
runnable.name = name;
}
registeredTags.put(name, runnable);
}
@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
// TODO: Scrap getAttribute, make this functionality a core system
String attrLow = CoreUtilities.toLowerCase(attribute.getAttributeWithoutContext(1));
TagRunnable tr = registeredTags.get(attrLow);
if (tr != null) {
if (!tr.name.equals(attrLow)) {
net.aufdemrand.denizencore.utilities.debugging.dB.echoError(attribute.getScriptEntry() != null ? attribute.getScriptEntry().getResidingQueue() : null,
"Using deprecated form of tag '" + tr.name + "': '" + attrLow + "'.");
}
return tr.run(attribute, this);
}
// Iterate through this object's properties' attributes
for (Property property : PropertyParser.getProperties(this)) {
String returned = property.getAttribute(attribute);
if (returned != null) {
return returned;
}
}
return new Element(identify()).getAttribute(attribute);
}
public void applyProperty(Mechanism mechanism) {
dB.echoError("Cannot apply properties to a world!");
}
@Override
public void adjust(Mechanism mechanism) {
Element value = mechanism.getValue();
// <--[mechanism]
// @object dWorld
// @name ambient_spawn_limit
// @input Element(Integer)
// @description
// Sets the limit for number of ambient mobs that can spawn in a chunk in this world.
// @tags
// <w@world.ambient_spawn_limit>
// -->
if (mechanism.matches("ambient_spawn_limit")
&& mechanism.requireInteger()) {
getWorld().setAmbientSpawnLimit(value.asInt());
}
// <--[mechanism]
// @object dWorld
// @name animal_spawn_limit
// @input Element(Integer)
// @description
// Sets the limit for number of animals that can spawn in a chunk in this world.
// @tags
// <w@world.animal_spawn_limit>
// -->
if (mechanism.matches("animal_spawn_limit")
&& mechanism.requireInteger()) {
getWorld().setAnimalSpawnLimit(value.asInt());
}
// <--[mechanism]
// @object dWorld
// @name auto_save
// @input Element(Boolean)
// @description
// Sets whether the world will automatically save edits.
// @tags
// <w@world.auto_save>
// -->
if (mechanism.matches("auto_save")
&& mechanism.requireBoolean()) {
getWorld().setAutoSave(value.asBoolean());
}
// <--[mechanism]
// @object dWorld
// @name difficulty
// @input Element
// @description
// Sets the difficulty level of this world.
// Possible values: Peaceful, Easy, Normal, Hard.
// @tags
// <w@world.difficulty>
// -->
if (mechanism.matches("difficulty") && mechanism.requireEnum(true, Difficulty.values())) {
String upper = value.asString().toUpperCase();
Difficulty diff;
if (upper.matches("(PEACEFUL|EASY|NORMAL|HARD)")) {
diff = Difficulty.valueOf(upper);
}
else {
diff = Difficulty.getByValue(value.asInt());
}
if (diff != null) {
getWorld().setDifficulty(diff);
}
}
// <--[mechanism]
// @object dWorld
// @name save
// @input None
// @description
// Saves the world to file.
// @tags
// None
// -->
if (mechanism.matches("save")) {
getWorld().save();
}
// <--[mechanism]
// @object dWorld
// @name destroy
// @input None
// @description
// Unloads the world from the server without saving chunks, then destroys all data that is part of the world.
// Require config setting 'Commands.Delete.Allow file deletion'.
// @tags
// None
// -->
if (mechanism.matches("destroy")) {
if (!Settings.allowDelete()) {
dB.echoError("Unable to delete due to config.");
return;
}
File folder = new File(getWorld().getName());
Bukkit.getServer().unloadWorld(getWorld(), false);
try {
FileUtils.deleteDirectory(folder);
}
catch (Exception ex) {
dB.echoError(ex);
}
return;
}
// <--[mechanism]
// @object dWorld
// @name force_unload
// @input None
// @description
// Unloads the world from the server without saving chunks.
// @tags
// None
// -->
if (mechanism.matches("force_unload")) {
Bukkit.getServer().unloadWorld(getWorld(), false);
return;
}
// <--[mechanism]
// @object dWorld
// @name full_time
// @input Element(Integer)
// @description
// Sets the in-game time on the server.
// @tags
// <w@world.time.full>
// -->
if (mechanism.matches("full_time") && mechanism.requireInteger()) {
getWorld().setFullTime(value.asInt());
}
// <--[mechanism]
// @object dWorld
// @name keep_spawn
// @input Element(Boolean)
// @description
// Sets whether the world's spawn area should be kept loaded into memory.
// @tags
// <w@world.time.full>
// -->
if (mechanism.matches("keep_spawn") && mechanism.requireBoolean()) {
getWorld().setKeepSpawnInMemory(value.asBoolean());
}
// <--[mechanism]
// @object dWorld
// @name monster_spawn_limit
// @input Element(Integer)
// @description
// Sets the limit for number of monsters that can spawn in a chunk in this world.
// @tags
// <w@world.monster_spawn_limit>
// -->
if (mechanism.matches("monster_spawn_limit") && mechanism.requireInteger()) {
getWorld().setMonsterSpawnLimit(value.asInt());
}
// <--[mechanism]
// @object dWorld
// @name allow_pvp