-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
Denizen.java
1613 lines (1436 loc) · 75 KB
/
Denizen.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;
import net.aufdemrand.denizen.events.block.*;
import net.aufdemrand.denizen.events.bukkit.SavesReloadEvent;
import net.aufdemrand.denizen.events.bukkit.ScriptReloadEvent;
import net.aufdemrand.denizen.events.core.CommandSmartEvent;
import net.aufdemrand.denizen.events.core.CuboidEnterExitSmartEvent;
import net.aufdemrand.denizen.events.core.FlagSmartEvent;
import net.aufdemrand.denizen.events.core.NPCNavigationSmartEvent;
import net.aufdemrand.denizen.events.core.PlayerEquipsArmorSmartEvent;
import net.aufdemrand.denizen.events.entity.*;
import net.aufdemrand.denizen.events.player.*;
import net.aufdemrand.denizen.events.world.*;
import net.aufdemrand.denizen.flags.FlagManager;
import net.aufdemrand.denizen.listeners.ListenerRegistry;
import net.aufdemrand.denizen.npc.dNPCRegistry;
import net.aufdemrand.denizen.npc.speech.DenizenChat;
import net.aufdemrand.denizen.npc.traits.*;
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.objects.notable.NotableManager;
import net.aufdemrand.denizen.objects.properties.bukkit.BukkitElementProperties;
import net.aufdemrand.denizen.objects.properties.bukkit.BukkitListProperties;
import net.aufdemrand.denizen.objects.properties.bukkit.BukkitQueueProperties;
import net.aufdemrand.denizen.objects.properties.bukkit.BukkitScriptProperties;
import net.aufdemrand.denizen.objects.properties.entity.*;
import net.aufdemrand.denizen.objects.properties.inventory.InventoryContents;
import net.aufdemrand.denizen.objects.properties.inventory.InventoryHolder;
import net.aufdemrand.denizen.objects.properties.inventory.InventorySize;
import net.aufdemrand.denizen.objects.properties.inventory.InventoryTitle;
import net.aufdemrand.denizen.objects.properties.item.*;
import net.aufdemrand.denizen.scripts.commands.BukkitCommandRegistry;
import net.aufdemrand.denizen.scripts.containers.core.*;
import net.aufdemrand.denizen.scripts.requirements.RequirementChecker;
import net.aufdemrand.denizen.scripts.requirements.RequirementRegistry;
import net.aufdemrand.denizen.scripts.triggers.TriggerRegistry;
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizen.tags.core.*;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.MetricsLite;
import net.aufdemrand.denizen.utilities.RuntimeCompiler;
import net.aufdemrand.denizen.utilities.ScoreboardHelper;
import net.aufdemrand.denizen.utilities.Utilities;
import net.aufdemrand.denizen.utilities.command.CommandManager;
import net.aufdemrand.denizen.utilities.command.Injector;
import net.aufdemrand.denizen.utilities.command.messaging.Messaging;
import net.aufdemrand.denizen.utilities.debugging.LogInterceptor;
import net.aufdemrand.denizen.utilities.debugging.StatsRecord;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.depends.Depends;
import net.aufdemrand.denizen.utilities.entity.CraftFakeArrow;
import net.aufdemrand.denizen.utilities.entity.CraftFakePlayer;
import net.aufdemrand.denizen.utilities.entity.CraftItemProjectile;
import net.aufdemrand.denizen.utilities.entity.DenizenEntityType;
import net.aufdemrand.denizen.utilities.maps.DenizenMapManager;
import net.aufdemrand.denizen.utilities.packets.intercept.DenizenPacketListener;
import net.aufdemrand.denizencore.DenizenCore;
import net.aufdemrand.denizencore.DenizenImplementation;
import net.aufdemrand.denizencore.events.OldEventManager;
import net.aufdemrand.denizencore.events.ScriptEvent;
import net.aufdemrand.denizencore.interfaces.dExternal;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.ObjectFetcher;
import net.aufdemrand.denizencore.objects.aH;
import net.aufdemrand.denizencore.objects.dList;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.objects.dScript;
import net.aufdemrand.denizencore.objects.properties.PropertyParser;
import net.aufdemrand.denizencore.scripts.ScriptBuilder;
import net.aufdemrand.denizencore.scripts.ScriptEntry;
import net.aufdemrand.denizencore.scripts.ScriptEntryData;
import net.aufdemrand.denizencore.scripts.ScriptHelper;
import net.aufdemrand.denizencore.scripts.ScriptRegistry;
import net.aufdemrand.denizencore.scripts.queues.ScriptQueue;
import net.aufdemrand.denizencore.scripts.queues.core.InstantQueue;
import net.aufdemrand.denizencore.tags.TagContext;
import net.aufdemrand.denizencore.tags.TagManager;
import net.aufdemrand.denizencore.utilities.debugging.Debuggable;
import net.aufdemrand.denizencore.utilities.debugging.dB.DebugElement;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.trait.TraitInfo;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.io.File;
import java.io.IOException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
// <--[language]
// @name dObjects
// @group Object System
// @description
// dObjects are a system put into place by Denizen that make working with things, or 'objects',
// in Minecraft and Denizen easier. Many parts of scripts will require some kind of object as an
// argument, identifier/type, or such as in world events, part of an event name. The dObjects notation
// system helps both you and Denizen know what type of objects are being referenced and worked with.
//
// So when should you use dObjects? In arguments, event names, replaceable tags, configs, flags, and
// more! If you're just a beginner, you've probably been using them without even realizing it!
//
// dObject is a broader term for a 'type' of object that more specifically represents something,
// such as a dLocation or dScript, often times just referred to as a 'location' or 'script'. Denizen
// employs many object types that you should be familiar with. You'll notice that many times objects
// are reference with their 'dObject notation' which is in the format of 'x@', the x being the specific
// notation of an object type. Example: player objects use the p@ notation, and locations use l@.
// The use of this notation is encouraged, but not always required.
//
// Let's take the tag system, for example. It uses the dObjects system pretty heavily. For instance,
// every time you use <player.name> or <npc.id>, you're using a dObject, which brings us to a simple
// clarification: Why <player.name> and not <p@player.name>? That's because Denizen allows Players,
// NPCs and other 'in-context objects' to be linked to certain scripts. In short, <player> already
// contains a reference to a specific player, such as the player that died in a world event 'on player dies'.
// <p@player.name> would incorrectly reference the player named 'player', however this format is often
// used to help with usage of a tag, simply indicating 'any player object'.
//
// dObjects can be used to CREATE new instances of objects, too! Though not all types allow 'new'
// objects to be created, many do, such as dItems. With the use of tags, it's easy to reference a specific
// item, say -- an item in the Player's hand -- items are also able to use a constructor to make a new item,
// and say, drop it in the world. Take the case of the command/usage '- drop i@diamond_ore'. The item object
// used is a brand new diamond_ore, which is then dropped by the command to a location of your choice -- just
// specify an additional location argument.
//
// There's a great deal more to learn about dObjects, so be sure to check out each object type for more
// specific information. While all dObjects share some features, many contain goodies on top of that!
//
// Here's an overview of each object type that is implemented by the Denizen core:
//
// + ----- dPlayer ----- +
// | object notation: p@ can reference unique objects: yes can be notable: no
// | constructors: ( <>'s represent non-static information and are not literal)
// | p@<UUID> - fetches an online or offline player with the specified UUID
// | p@<player_name> - Outdated constructor for back-support, fetches by name instead of UUID
//
// + ----- dNPC ---------+
// | object notation: n@ can reference unique objects: yes can be notable: no
// | constructors: ( <>'s represent non-static information and are not literal)
// | n@<npc_id> - fetches the NPC with the specified ID
// | n@<npc_name> - fetches the first NPC found with the specified name
//
// + ----- dLocation ----+
// | object notation: l@ can reference unique objects: no can be notable: yes
// | constructors: ( <>'s represent non-static information and are not literal)
// | l@<x>,<y>,<z>,<world_name> - fetches a specific location
// | l@<x>,<y>,<z>,<pitch>,<yaw>,<world_name> - fetches a specific location and direction
// | l@<notable_location_name> - fetches the location that has been 'noted' with the specified ID
//
// + ----- dEntity ------+
// | object notation: e@ can reference unique objects: yes can be notable: no
// | constructors: ( <>'s represent non-static information and are not literal)
// | e@<entity_type> - fetches a new entity with the specified type as implemented by Bukkit's entity type enumeration
// | e@<entity_type>,<setting> - fetches a new entity of the specified type with a custom setting unique to the type
// | e@<entity_script_name> - fetches a new custom entity as specified by the referenced entity script (soon)
// | e@<entity_id> - fetches the entity that has the (temporary) entity ID set by Bukkit
// | e@random - fetches a new, random entity
//
// + ----- dItem --------+
// | object notation: i@ can reference unique objects: no can be notable: yes
// | constructors: ( <>'s represent non-static information and are not literal)
// | i@<material_name> - fetches a new item of the specified material
// | i@<material_name>,<data> - fetches a new item with the specified data
// | i@<item_script_name> - fetches a new custom item as specified by the referenced item script
// | i@<notable_name> - fetches the item that has been noted with the specified ID
//
// + ----- dWorld -------+
// | object notation: w@ can reference unique objects: yes can be notable: no
// | constructors: ( <>'s represent non-static information and are not literal)
// | w@<world_name> - fetches the world with the specified name
//
// + ----- dColor -------+
// | object notation: co@ can reference unique objects: no can be notable: soon
// | constructors: ( <>'s represent non-static information and are not literal)
// | co@<color_name> - fetches a named color, as implemented by Bukkit's color enumeration
// | co@<r>,<g>,<b> - fetches a color made of the specified Red,Green,Blue value
// | co@random - fetches a random color
//
// + ----- dCuboid ------+
// | object notation: cu@ can reference unique objects: no can be notable: yes
// | constructors: ( <>'s represent non-static information and are not literal)
// | cu@<position_1>|<position_2>|... - fetches a new cuboid encompassing a region from position 1 to 2, from 2 to 3, ...
// | cu@<notable_name> - fetches the cuboid that has been noted with the specified ID
//
// + ----- dEllipsoid ------+
// | object notation: ellipsoid@ can reference unique objects: no can be notable: yes
// | constructors: ( <>'s represent non-static information and are not literal)
// | ellipsoid@<x>,<y>,<z>,<world>,<xrad>,<yrad>,<zrad>... - fetches a new ellispoid at the position with the given radius
// | ellipsoid@<notable_name> - fetches the ellipsoid that has been noted with the specified ID
//
// + ----- dChunk ------+
// | object notation: ch@ can reference unique objects: yes can be notable: no
// | constructors: ( <>'s represent non-static information and are not literal)
// | ch@<x>,<y>,<world> - fetches a chunk at the given chunk location
//
// + ----- dInventory ---+
// | object notation: in@ can reference unique objects: yes can be notable: yes
// | constructors: ( <>'s represent non-static information and are not literal)
// | in@player[holder=<player>] - fetches the specified Player's inventory (Works for offline players)
// | in@enderchest[holder=<player>] - fetches the specified Player's enderchest inventory (Works for offline players)
// | in@npc[holder=<npc>] - fetches the specified NPC's inventory
// | in@entity[holder=<entity>] - fetches the specified object's inventory, such as a Player, NPC, or Mule
// | in@location[holder=<location>] - fetches the contents of a chest or other 'inventory' block
// | in@<notable_inventory_name> - fetches the inventory that has been 'noted' with the specified ID
// | in@<inventory_script_name> - fetches a new custom inventory as specified by the referenced inventory script
// | in@generic - represents a generic, customizable virtual inventory to be used with inventory properties (See <@link language Virtual Inventories>)
//
// + ----- dMaterial ----+
// | object notation: m@ can reference unique objects: no can be notable: no
// | constructors: ( <>'s represent non-static information and are not literal)
// | m@<material_name> - fetches the material as specified by Bukkit's material enumeration
// | m@<material_name>,<data> - fetches the material as specified by Bukkit's material enumeration with specified data
// | m@<data_variety_material> - fetches the material specified by Denizen's 'data variety' dMaterials
// | m@random - fetches a random material
//
// + ----- dList -------+
// | object notation: li@ can reference unique objects: yes can be notable: no
// | constructors: ( <>'s represent non-static information and are not literal)
// | li@<items|...> - fetches a new list with the elements specified, separated by a pipe (|) character
//
// + ----- dScript -------+
// | object notation: s@ can reference unique objects: yes can be notable: no
// | constructors: ( <>'s represent non-static information and are not literal)
// | s@<script_container_name> - fetches the script container with the specified name
//
// + ----- Duration ------+
// | object notation: d@ can reference unique objects: no can be notable: no
// | constructors: ( <>'s represent non-static information and are not literal)
// | d@<duration> - fetches a duration object with the specified amount of time
// | d@<low>-<high> - fetches a duration that is randomly selected between the specified 'low' and 'high'
//
// + ----- dPlugin -------+
// | object notation: pl@ can reference unique objects: yes can be notable: no
// | constructors: ( <>'s represent non-static information and are not literal)
// | pl@<plugin_name> - fetches the plugin with the specified name
//
// + ----- Element ------+
// | object notation: el@ can reference unique objects: no can be notable: no
// | constructors: ( <>'s represent non-static information and are not literal)
// | el@<value> - fetches an element with the specified value
// | el@val[<value>] - slightly more verbose, but tag friendly way to fetch a new element (allows periods)
//
// + ----- Queue ------+
// | object notation: q@ can reference unique objects: yes can be notable: no
// | constructors: ( <>'s represent non-static information and are not literal)
// | q@<id> - fetches the queue with the given ID
//
// -->
public class Denizen extends JavaPlugin implements DenizenImplementation {
public final static int configVersion = 12;
public static String versionTag = null;
private boolean startedSuccessful = false;
public static final LogInterceptor logInterceptor = new LogInterceptor();
private CommandManager commandManager;
public CommandManager getCommandManager() {
return commandManager;
}
/*
* Denizen Registries
*/
private BukkitCommandRegistry commandRegistry = new BukkitCommandRegistry();
private TriggerRegistry triggerRegistry = new TriggerRegistry();
private RequirementRegistry requirementRegistry = new RequirementRegistry(this);
private ListenerRegistry listenerRegistry = new ListenerRegistry();
private dNPCRegistry dNPCRegistry;
public BukkitCommandRegistry getCommandRegistry() {
return commandRegistry;
}
public dNPCRegistry getNPCRegistry() {
return dNPCRegistry;
}
public ListenerRegistry getListenerRegistry() {
return listenerRegistry;
}
public RequirementRegistry getRequirementRegistry() {
return requirementRegistry;
}
public TriggerRegistry getTriggerRegistry() {
return triggerRegistry;
}
/*
* Denizen Property Parser
*/
private PropertyParser propertyParser;
public PropertyParser getPropertyParser() {
return propertyParser;
}
/*
* Denizen Managers
*/
private FlagManager flagManager = new FlagManager(this);
private TagManager tagManager = new TagManager();
private NotableManager notableManager = new NotableManager();
private OldEventManager eventManager;
public OldEventManager eventManager() {
return eventManager;
}
public FlagManager flagManager() {
return flagManager;
}
public TagManager tagManager() {
return tagManager;
}
public NotableManager notableManager() {
return notableManager;
}
public Depends depends = new Depends();
public RuntimeCompiler runtimeCompiler;
private BukkitWorldScriptHelper ws_helper;
public final static long startTime = System.currentTimeMillis();
private RequirementChecker requirementChecker;
/**
* Gets the currently loaded instance of the RequirementChecker
*
* @return ScriptHelper
*/
public RequirementChecker getRequirementChecker() {
return requirementChecker;
}
/*
* Sets up Denizen on start of the CraftBukkit server.
*/
@Override
public void onEnable() {
try {
net.minecraft.server.v1_10_R1.Block.getById(0);
}
catch (Throwable e) {
getLogger().warning("-------------------------------------");
getLogger().warning("This Denizen version is not compatible with this CraftBukkit version! Deactivating Denizen!");
getLogger().warning("-------------------------------------");
getServer().getPluginManager().disablePlugin(this);
startedSuccessful = false;
return;
}
try {
org.spigotmc.AsyncCatcher.enabled = false;
}
catch (Throwable e) {
dB.echoError("Running not-Spigot?!");
}
try {
versionTag = this.getDescription().getVersion();
// Load Denizen's core
DenizenCore.init(this);
// Activate dependencies
depends.initialize();
if (Depends.citizens == null || !Depends.citizens.isEnabled()) {
getLogger().warning("Citizens does not seem to be activated! Denizen will have greatly reduced functionality!");
//getServer().getPluginManager().disablePlugin(this);
//return;
}
startedSuccessful = true;
requirementChecker = new RequirementChecker();
// Startup procedure
dB.log(ChatColor.LIGHT_PURPLE + "+-------------------------+");
dB.log(ChatColor.YELLOW + " _/_ _ ._ _ _ ");
dB.log(ChatColor.YELLOW + "(/(-/ )/ /_(-/ ) " + ChatColor.GRAY + " scriptable minecraft");
dB.log("");
dB.log(ChatColor.GRAY + "by: " + ChatColor.WHITE + "aufdemrand");
dB.log(ChatColor.GRAY + "version: " + ChatColor.WHITE + versionTag);
dB.log(ChatColor.LIGHT_PURPLE + "+-------------------------+");
}
catch (Exception e) {
dB.echoError(e);
}
try {
MetricsLite metrics = new MetricsLite(this);
metrics.start();
}
catch (Exception e) {
dB.echoError(e);
}
try {
// Create the dNPC Registry
dNPCRegistry = new dNPCRegistry(this);
// Create our CommandManager to handle '/denizen' commands
commandManager = new CommandManager();
commandManager.setInjector(new Injector(this));
commandManager.register(DenizenCommandHandler.class);
// If Citizens is enabled, let it handle '/npc' commands
if (Depends.citizens != null) {
Depends.citizens.registerCommandClass(NPCCommandHandler.class);
}
// Register DenizenEntityTypes
DenizenEntityType.registerEntityType("ITEM_PROJECTILE", CraftItemProjectile.class);
DenizenEntityType.registerEntityType("FAKE_ARROW", CraftFakeArrow.class);
DenizenEntityType.registerEntityType("FAKE_PLAYER", CraftFakePlayer.class);
// Track all player names for quick dPlayer matching
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
dPlayer.notePlayer(player);
}
}
catch (Exception e) {
dB.echoError(e);
}
try {
DenizenCore.setCommandRegistry(getCommandRegistry());
getCommandRegistry().registerCoreMembers();
}
catch (Exception e) {
dB.echoError(e);
}
try {
// Register script-container types
ScriptRegistry._registerCoreTypes();
// Populate config.yml if it doesn't yet exist.
saveDefaultConfig();
reloadConfig();
}
catch (Exception e) {
dB.echoError(e);
}
try {
ScriptRegistry._registerType("interact", InteractScriptContainer.class);
ScriptRegistry._registerType("book", BookScriptContainer.class);
ScriptRegistry._registerType("item", ItemScriptContainer.class);
ScriptRegistry._registerType("entity", EntityScriptContainer.class);
ScriptRegistry._registerType("assignment", AssignmentScriptContainer.class);
ScriptRegistry._registerType("format", FormatScriptContainer.class);
ScriptRegistry._registerType("inventory", InventoryScriptContainer.class);
ScriptRegistry._registerType("command", CommandScriptContainer.class);
ScriptRegistry._registerType("map", MapScriptContainer.class);
ScriptRegistry._registerType("version", VersionScriptContainer.class);
}
catch (Exception e) {
dB.echoError(e);
}
try {
// Ensure the Scripts and Midi folder exist
new File(getDataFolder() + "/scripts").mkdirs();
new File(getDataFolder() + "/midi").mkdirs();
new File(getDataFolder() + "/schematics").mkdirs();
// Ensure the example Denizen.mid sound file is available
if (!new File(getDataFolder() + "/midi/Denizen.mid").exists()) {
String sourceFile = URLDecoder.decode(Denizen.class.getProtectionDomain().getCodeSource().getLocation().getFile());
dB.log("Denizen.mid not found, extracting from " + sourceFile);
Utilities.extractFile(new File(sourceFile), "Denizen.mid", getDataFolder() + "/midi/");
}
}
catch (Exception e) {
dB.echoError(e);
}
try {
// Warn if configuration is outdated / too new
if (!getConfig().isSet("Config.Version") ||
getConfig().getInt("Config.Version", 0) < configVersion) {
dB.echoError("Your Denizen config file is from an older version. " +
"Some settings will not be available unless you generate a new one. " +
"This is easily done by stopping the server, deleting the current config.yml file in the Denizen folder " +
"and restarting the server.");
}
// Create the command script handler for listener
ws_helper = new BukkitWorldScriptHelper();
ItemScriptHelper is_helper = new ItemScriptHelper();
InventoryScriptHelper in_helper = new InventoryScriptHelper();
EntityScriptHelper es_helper = new EntityScriptHelper();
CommandScriptHelper cs_helper = new CommandScriptHelper();
}
catch (Exception e) {
dB.echoError(e);
}
try {
if (Depends.citizens != null) {
// Register traits
// TODO: should this be a separate function?
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(TriggerTrait.class).withName("triggers"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(PushableTrait.class).withName("pushable"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(AssignmentTrait.class).withName("assignment"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(NicknameTrait.class).withName("nickname"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(HealthTrait.class).withName("health"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(ConstantsTrait.class).withName("constants"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(HungerTrait.class).withName("hunger"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(SittingTrait.class).withName("sitting"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(FishingTrait.class).withName("fishing"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(SleepingTrait.class).withName("sleeping"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(ParticlesTrait.class).withName("particles"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(SneakingTrait.class).withName("sneaking"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(InvisibleTrait.class).withName("invisible"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(MobproxTrait.class).withName("mobprox"));
// Register Speech AI
CitizensAPI.getSpeechFactory().register(DenizenChat.class, "denizen_chat");
}
// If Program AB, used for reading Artificial Intelligence Markup Language
// 2.0, is included as a dependency at Denizen/lib/Ab.jar, register the
// ChatbotTrait
if (Depends.hasProgramAB) {
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(ChatbotTrait.class).withName("chatbot"));
}
// Compile and load Denizen externals
runtimeCompiler = new RuntimeCompiler(this);
runtimeCompiler.loader();
}
catch (Exception e) {
dB.echoError(e);
}
// Register Core Members in the Denizen Registries
try {
if (Depends.citizens != null) {
getTriggerRegistry().registerCoreMembers();
}
getRequirementRegistry().registerCoreMembers();
getListenerRegistry().registerCoreMembers();
}
catch (Exception e) {
dB.echoError(e);
}
try {
tagManager().registerCoreTags();
new CuboidTags(this);
new EntityTags(this);
new LocationTags(this);
new PlayerTags(this);
new ServerTags(this);
new TextTags(this);
new ParseTags(this);
if (Depends.citizens != null) {
new NPCTags(this);
new AnchorTags(this);
new ConstantTags(this);
}
new FlagTags(this);
new NotableLocationTags(this);
eventManager = new OldEventManager();
// Register all the 'Core' SmartEvents.
OldEventManager.registerSmartEvent(new CommandSmartEvent());
OldEventManager.registerSmartEvent(new CuboidEnterExitSmartEvent());
OldEventManager.registerSmartEvent(new FlagSmartEvent());
OldEventManager.registerSmartEvent(new NPCNavigationSmartEvent());
OldEventManager.registerSmartEvent(new PlayerEquipsArmorSmartEvent());
eventManager().registerCoreMembers();
ScriptEvent.registerScriptEvent(new BiomeEnterExitScriptEvent());
ScriptEvent.registerScriptEvent(new BlockBuiltScriptEvent());
ScriptEvent.registerScriptEvent(new BlockBurnsScriptEvent());
ScriptEvent.registerScriptEvent(new BlockDispensesScriptEvent());
ScriptEvent.registerScriptEvent(new BlockFadesScriptEvent());
ScriptEvent.registerScriptEvent(new BlockFallsScriptEvent());
ScriptEvent.registerScriptEvent(new BlockFormsScriptEvent());
ScriptEvent.registerScriptEvent(new BlockGrowsScriptEvent());
ScriptEvent.registerScriptEvent(new BlockIgnitesScriptEvent());
ScriptEvent.registerScriptEvent(new BlockPhysicsScriptEvent());
ScriptEvent.registerScriptEvent(new BlockSpreadsScriptEvent());
ScriptEvent.registerScriptEvent(new BrewsScriptEvent());
ScriptEvent.registerScriptEvent(new ChatScriptEvent());
ScriptEvent.registerScriptEvent(new ChunkLoadScriptEvent());
ScriptEvent.registerScriptEvent(new ChunkUnloadScriptEvent());
ScriptEvent.registerScriptEvent(new CreeperPoweredScriptEvent());
ScriptEvent.registerScriptEvent(new EntityBreaksHangingScriptEvent());
ScriptEvent.registerScriptEvent(new EntityChangesBlockScriptEvent());
ScriptEvent.registerScriptEvent(new EntityCombustsScriptEvent());
ScriptEvent.registerScriptEvent(new EntityCreatePortalScriptEvent());
ScriptEvent.registerScriptEvent(new EntityDamagedScriptEvent());
ScriptEvent.registerScriptEvent(new EntityDeathScriptEvent());
ScriptEvent.registerScriptEvent(new EntityDespawnScriptEvent());
ScriptEvent.registerScriptEvent(new EntityEntersPortalScriptEvent());
ScriptEvent.registerScriptEvent(new EntityEntersVehicleScriptEvent());
ScriptEvent.registerScriptEvent(new EntityExitsPortalScriptEvent());
ScriptEvent.registerScriptEvent(new EntityExitsVehicleScriptEvent());
ScriptEvent.registerScriptEvent(new EntityExplodesScriptEvent());
ScriptEvent.registerScriptEvent(new EntityExplosionPrimesScriptEvent());
ScriptEvent.registerScriptEvent(new EntityFoodLevelChangeScriptEvent());
ScriptEvent.registerScriptEvent(new EntityFormsBlockScriptEvent());
ScriptEvent.registerScriptEvent(new EntityGlideScriptEvent());
ScriptEvent.registerScriptEvent(new EntityHealsScriptEvent());
ScriptEvent.registerScriptEvent(new EntityInteractScriptEvent());
ScriptEvent.registerScriptEvent(new EntityKilledScriptEvent());
ScriptEvent.registerScriptEvent(new EntityShootsBowEvent());
ScriptEvent.registerScriptEvent(new EntitySpawnScriptEvent());
ScriptEvent.registerScriptEvent(new EntityTamesScriptEvent());
ScriptEvent.registerScriptEvent(new EntityTargetsScriptEvent());
ScriptEvent.registerScriptEvent(new EntityTeleportScriptEvent());
ScriptEvent.registerScriptEvent(new EntityUnleashedScriptEvent());
ScriptEvent.registerScriptEvent(new FireworkBurstsScriptEvent());
ScriptEvent.registerScriptEvent(new FurnaceBurnsItemScriptEvent());
ScriptEvent.registerScriptEvent(new FurnaceSmeltsItemScriptEvent());
ScriptEvent.registerScriptEvent(new HangingBreaksScriptEvent());
ScriptEvent.registerScriptEvent(new HorseJumpsScriptEvent());
ScriptEvent.registerScriptEvent(new InventoryPicksUpItemScriptEvent());
ScriptEvent.registerScriptEvent(new ItemDespawnsScriptEvent());
ScriptEvent.registerScriptEvent(new ItemEnchantedScriptEvent());
ScriptEvent.registerScriptEvent(new ItemMergesScriptEvent());
ScriptEvent.registerScriptEvent(new ItemMoveScriptEvent());
ScriptEvent.registerScriptEvent(new ItemRecipeFormedScriptEvent());
ScriptEvent.registerScriptEvent(new ItemScrollScriptEvent());
ScriptEvent.registerScriptEvent(new ItemSpawnsScriptEvent());
ScriptEvent.registerScriptEvent(new LeafDecaysScriptEvent());
ScriptEvent.registerScriptEvent(new LightningStrikesScriptEvent());
ScriptEvent.registerScriptEvent(new LingeringPotionSplashScriptEvent());
ScriptEvent.registerScriptEvent(new LiquidSpreadScriptEvent());
ScriptEvent.registerScriptEvent(new ListPingScriptEvent());
ScriptEvent.registerScriptEvent(new PigZappedScriptEvent());
ScriptEvent.registerScriptEvent(new PistonExtendsScriptEvent());
ScriptEvent.registerScriptEvent(new PistonRetractsScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerAnimatesScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerBreaksBlockScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerBreaksItemScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerChangesGamemodeScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerChangesSignScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerChangesWorldScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerChangesXPScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerClosesInvScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerConsumesScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerCraftsItemScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerDamagesBlockScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerDragsInInvScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerDropsItemScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerEditsBookScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerEmptiesBucketScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerEntersBedScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerFillsBucketScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerFishesScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerFlyingScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerItemTakesDamageScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerJoinsScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerJumpScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerKickedScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerLeashesEntityScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerLeavesBedScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerLevelsUpScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerLoginScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerOpensInvScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerPicksUpScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerPlacesBlockScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerPlacesHangingScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerQuitsScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerReceivesMessageScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerRespawnsScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerRightClicksAtEntityScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerRightClicksEntityScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerShearsScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerSneakScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerSprintScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerStatisticIncrementsScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerStepsOnScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerSwapsItemsScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerTakesFromFurnaceScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerThrowsEggScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerUsesPortalScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerWalkScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerWalksOverScriptEvent());
ScriptEvent.registerScriptEvent(new PortalCreateScriptEvent());
ScriptEvent.registerScriptEvent(new PotionSplashScriptEvent());
ScriptEvent.registerScriptEvent(new ProjectileHitsScriptEvent());
ScriptEvent.registerScriptEvent(new ProjectileLaunchedScriptEvent());
ScriptEvent.registerScriptEvent(new RedstoneScriptEvent());
ScriptEvent.registerScriptEvent(new ResourcePackStatusScriptEvent());
ScriptEvent.registerScriptEvent(new SheepDyedScriptEvent());
ScriptEvent.registerScriptEvent(new SheepRegrowsScriptEvent());
ScriptEvent.registerScriptEvent(new SlimeSplitsScriptEvent());
ScriptEvent.registerScriptEvent(new SpawnChangeScriptEvent());
ScriptEvent.registerScriptEvent(new StructureGrowsScriptEvent());
ScriptEvent.registerScriptEvent(new VehicleCollidesBlockScriptEvent());
ScriptEvent.registerScriptEvent(new VehicleCollidesEntityScriptEvent());
ScriptEvent.registerScriptEvent(new VehicleCreatedScriptEvent());
ScriptEvent.registerScriptEvent(new VehicleDamagedScriptEvent());
ScriptEvent.registerScriptEvent(new VehicleDestroyedScriptEvent());
ScriptEvent.registerScriptEvent(new VehicleMoveScriptEvent());
ScriptEvent.registerScriptEvent(new WeatherChangesScriptEvent());
ScriptEvent.registerScriptEvent(new WorldInitsScriptEvent());
ScriptEvent.registerScriptEvent(new WorldLoadsScriptEvent());
ScriptEvent.registerScriptEvent(new WorldSavesScriptEvent());
ScriptEvent.registerScriptEvent(new WorldUnloadsScriptEvent());
ObjectFetcher.registerWithObjectFetcher(dBiome.class); // b@
dBiome.registerTags(); // TODO: Automate this once all classes have tag registries
ObjectFetcher.registerWithObjectFetcher(dChunk.class); // ch@
dChunk.registerTags(); // TODO: Automate this once all classes have tag registries
ObjectFetcher.registerWithObjectFetcher(dColor.class); // co@
dColor.registerTags(); // TODO: Automate this once all classes have tag registries
ObjectFetcher.registerWithObjectFetcher(dCuboid.class); // cu@
dCuboid.registerTags(); // TODO: Automate this once all classes have tag registries
ObjectFetcher.registerWithObjectFetcher(dEllipsoid.class); // ellipsoid@
dEllipsoid.registerTags(); // TODO: Automate this once all classes have tag registries
ObjectFetcher.registerWithObjectFetcher(dEntity.class); // e@
ObjectFetcher.registerWithObjectFetcher(dInventory.class); // in@
ObjectFetcher.registerWithObjectFetcher(dItem.class); // i@
dItem.registerTags(); // TODO: Automate this once all classes have tag registries
ObjectFetcher.registerWithObjectFetcher(dLocation.class); // l@
ObjectFetcher.registerWithObjectFetcher(dMaterial.class); // m@
dMaterial.registerTags(); // TODO: Automate this once all classes have tag registries
if (Depends.citizens != null) {
ObjectFetcher.registerWithObjectFetcher(dNPC.class); // n@
}
ObjectFetcher.registerWithObjectFetcher(dPlayer.class); // p@
ObjectFetcher.registerWithObjectFetcher(dPlugin.class); // pl@
dPlugin.registerTags(); // TODO: Automate this once all classes have tag registries
ObjectFetcher.registerWithObjectFetcher(dWorld.class); // w@
dWorld.registerTags(); // TODO: Automate this once all classes have tag registries
// Register Core dObjects with the ObjectFetcher
ObjectFetcher._registerCoreObjects();
}
catch (Exception e) {
dB.echoError(e);
}
try {
// Initialize non-standard dMaterials
dMaterial._initialize();
// Initialize Property Parser
propertyParser = new PropertyParser();
// register properties that add Bukkit code to core objects
propertyParser.registerProperty(BukkitScriptProperties.class, dScript.class);
propertyParser.registerProperty(BukkitQueueProperties.class, ScriptQueue.class);
propertyParser.registerProperty(BukkitElementProperties.class, Element.class);
propertyParser.registerProperty(BukkitListProperties.class, dList.class);
// register core dEntity properties
propertyParser.registerProperty(EntityAge.class, dEntity.class);
propertyParser.registerProperty(EntityAI.class, dEntity.class);
propertyParser.registerProperty(EntityAnger.class, dEntity.class);
propertyParser.registerProperty(EntityAngry.class, dEntity.class);
propertyParser.registerProperty(EntityArmorBonus.class, dEntity.class);
propertyParser.registerProperty(EntityArmorPose.class, dEntity.class);
propertyParser.registerProperty(EntityArms.class, dEntity.class);
propertyParser.registerProperty(EntityBasePlate.class, dEntity.class);
propertyParser.registerProperty(EntityChestCarrier.class, dEntity.class);
propertyParser.registerProperty(EntityColor.class, dEntity.class);
propertyParser.registerProperty(EntityCritical.class, dEntity.class);
propertyParser.registerProperty(EntityCustomName.class, dEntity.class);
propertyParser.registerProperty(EntityPotionEffects.class, dEntity.class);
propertyParser.registerProperty(EntityElder.class, dEntity.class);
propertyParser.registerProperty(EntityEquipment.class, dEntity.class);
propertyParser.registerProperty(EntityFirework.class, dEntity.class);
propertyParser.registerProperty(EntityFramed.class, dEntity.class);
propertyParser.registerProperty(EntityGravity.class, dEntity.class);
propertyParser.registerProperty(EntityHealth.class, dEntity.class);
propertyParser.registerProperty(EntityInfected.class, dEntity.class);
propertyParser.registerProperty(EntityInventory.class, dEntity.class);
propertyParser.registerProperty(EntityInvulnerable.class, dEntity.class);
propertyParser.registerProperty(EntityItem.class, dEntity.class);
propertyParser.registerProperty(EntityJumpStrength.class, dEntity.class);
propertyParser.registerProperty(EntityKnockback.class, dEntity.class);
propertyParser.registerProperty(EntityMarker.class, dEntity.class);
propertyParser.registerProperty(EntityPainting.class, dEntity.class);
propertyParser.registerProperty(EntityPotion.class, dEntity.class);
propertyParser.registerProperty(EntityPowered.class, dEntity.class);
propertyParser.registerProperty(EntityProfession.class, dEntity.class);
propertyParser.registerProperty(EntityRotation.class, dEntity.class);
propertyParser.registerProperty(EntitySmall.class, dEntity.class);
propertyParser.registerProperty(EntitySilent.class, dEntity.class);
propertyParser.registerProperty(EntitySitting.class, dEntity.class);
propertyParser.registerProperty(EntitySize.class, dEntity.class);
propertyParser.registerProperty(EntitySkeleton.class, dEntity.class);
propertyParser.registerProperty(EntitySpeed.class, dEntity.class);
propertyParser.registerProperty(EntityTame.class, dEntity.class);
propertyParser.registerProperty(EntityVisible.class, dEntity.class);
// register core dInventory properties
propertyParser.registerProperty(InventoryHolder.class, dInventory.class); // Holder must be loaded first to initiate correctly
propertyParser.registerProperty(InventorySize.class, dInventory.class); // Same with size...(Too small for contents)
propertyParser.registerProperty(InventoryContents.class, dInventory.class);
propertyParser.registerProperty(InventoryTitle.class, dInventory.class);
// register core dItem properties
propertyParser.registerProperty(ItemApple.class, dItem.class);
propertyParser.registerProperty(ItemBaseColor.class, dItem.class);
propertyParser.registerProperty(ItemBook.class, dItem.class);
propertyParser.registerProperty(ItemDisplayname.class, dItem.class);
propertyParser.registerProperty(ItemDurability.class, dItem.class);
propertyParser.registerProperty(ItemDye.class, dItem.class);
propertyParser.registerProperty(ItemEnchantments.class, dItem.class);
propertyParser.registerProperty(ItemFirework.class, dItem.class);
propertyParser.registerProperty(ItemFlags.class, dItem.class);
propertyParser.registerProperty(ItemLore.class, dItem.class);
propertyParser.registerProperty(ItemMap.class, dItem.class);
propertyParser.registerProperty(ItemNBT.class, dItem.class);
propertyParser.registerProperty(ItemPatterns.class, dItem.class);
propertyParser.registerProperty(ItemPlantgrowth.class, dItem.class);
propertyParser.registerProperty(ItemPotion.class, dItem.class);
propertyParser.registerProperty(ItemQuantity.class, dItem.class);
propertyParser.registerProperty(ItemSkullskin.class, dItem.class);
propertyParser.registerProperty(ItemSpawnEgg.class, dItem.class);
propertyParser.registerProperty(ItemUnbreakable.class, dItem.class);
}
catch (Exception e) {
dB.echoError(e);
}
try {
for (World world : getServer().getWorlds()) {
EntityScriptHelper.linkWorld(world);
}
}
catch (Exception e) {
dB.echoError(e);
}
// Enable custom inbound packet listener
DenizenPacketListener.enable();
// Run everything else on the first server tick
getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
@Override
public void run() {
try {
DenizenCore.loadScripts();
// Load the saves.yml into memory
reloadSaves();
// Fire the 'on Pre Server Start' world event
ws_helper.serverPreStartEvent();
// Reload notables from notables.yml into memory
notableManager.reloadNotables();
dB.log(ChatColor.LIGHT_PURPLE + "+-------------------------+");
// Fire the 'on Server Start' world event
ws_helper.serverStartEvent();
}
catch (Exception e) {
dB.echoError(e);
}
}
}, 1);
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
@Override
public void run() {
DenizenCore.tick(50); // Sadly, minecraft has no delta timing, so a tick is always 50ms.
}
}, 1, 1);
new BukkitRunnable() {
@Override
public void run() {
if (Settings.canRecordStats()) {
new StatsRecord().start();
}
}
}.runTaskTimer(this, 100, 20 * 60 * 60);
}
/*
* Unloads Denizen on shutdown of the craftbukkit server.
*/
@Override
public void onDisable() {
if (!startedSuccessful) {
return;
}
// <--[event]
// @Events
// shutdown
//
// @Warning not all plugins will be loaded and delayed scripts will be dropped.
//
// @Triggers when the server is shutting down.
//
// @Context
// None.
//
// -->
HashMap<String, dObject> context = new HashMap<String, dObject>();
OldEventManager.doEvents(Arrays.asList("shutdown"), new BukkitScriptEntryData(null, null), context);
// Disable the log interceptor... otherwise bad things on /reload
logInterceptor.standardOutput();
// Save notables
notableManager.saveNotables();
// Save scoreboards
ScoreboardHelper._saveScoreboards();
// Save entities
EntityScriptHelper.saveEntities();
// Save offline player inventories
InventoryScriptHelper._savePlayerInventories();
// Deconstruct listeners (server shutdown seems not to be triggering a PlayerQuitEvent)
for (Player player : this.getServer().getOnlinePlayers()) {
getListenerRegistry().deconstructPlayer(dPlayer.mirrorBukkitPlayer(player));
}
for (OfflinePlayer player : this.getServer().getOfflinePlayers()) {
try {
getListenerRegistry().deconstructPlayer(dPlayer.mirrorBukkitPlayer(player));
}
catch (Exception e) {
if (player == null) {
dB.echoError("Tell the Denizen team ASAP about this error! ERR: OPN: " + e.toString());
}
else {
dB.echoError("'" + player.getName() + "' is having trouble deconstructing! " +
"You might have a corrupt player file!");
}
}
}
// Unload loaded dExternals
for (dExternal external : RuntimeCompiler.loadedExternals) {
external.unload();
}
RuntimeCompiler.loadedExternals.clear();
//Disable core members
getCommandRegistry().disableCoreMembers();
getLogger().log(Level.INFO, " v" + getDescription().getVersion() + " disabled.");
Bukkit.getServer().getScheduler().cancelTasks(this);
HandlerList.unregisterAll(this);
for (World world : getServer().getWorlds()) {
EntityScriptHelper.unlinkWorld(world);
}
saveSaves();
}
/*
* Reloads, retrieves and saves progress information in
* Denizen/saves.yml and Denizen/scoreboards.yml
*/
private FileConfiguration savesConfig = null;
private File savesConfigFile = null;
private FileConfiguration scoreboardsConfig = null;