-
-
Notifications
You must be signed in to change notification settings - Fork 107
/
Denizen.java
1263 lines (1114 loc) · 57.4 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 java.io.File;
import java.io.IOException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.aufdemrand.denizen.events.core.*;
import net.aufdemrand.denizen.events.scriptevents.EntityTeleportScriptEvent;
import net.aufdemrand.denizen.events.scriptevents.VehicleMoveScriptEvent;
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.tags.BukkitTagContext;
import net.aufdemrand.denizen.tags.core.*;
import net.aufdemrand.denizen.utilities.entity.CraftFakeArrow;
import net.aufdemrand.denizen.utilities.entity.CraftItemProjectile;
import net.aufdemrand.denizen.utilities.entity.DenizenEntityType;
import net.aufdemrand.denizencore.events.OldEventManager;
import net.aufdemrand.denizen.events.bukkit.SavesReloadEvent;
import net.aufdemrand.denizen.events.bukkit.ScriptReloadEvent;
import net.aufdemrand.denizen.flags.FlagManager;
import net.aufdemrand.denizen.scripts.commands.BukkitCommandRegistry;
import net.aufdemrand.denizencore.events.ScriptEvent;
import net.aufdemrand.denizencore.objects.*;
import net.aufdemrand.denizencore.scripts.*;
import net.aufdemrand.denizencore.scripts.queues.ScriptQueue;
import net.aufdemrand.denizen.scripts.requirements.RequirementChecker;
import net.aufdemrand.denizen.utilities.*;
import net.aufdemrand.denizen.utilities.debugging.LogInterceptor;
import net.aufdemrand.denizen.utilities.maps.DenizenMapManager;
import net.aufdemrand.denizencore.interfaces.dExternal;
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.denizencore.objects.properties.PropertyParser;
import net.aufdemrand.denizen.scripts.containers.core.*;
import net.aufdemrand.denizencore.scripts.queues.core.InstantQueue;
import net.aufdemrand.denizen.scripts.requirements.RequirementRegistry;
import net.aufdemrand.denizen.scripts.triggers.TriggerRegistry;
import net.aufdemrand.denizencore.tags.TagContext;
import net.aufdemrand.denizencore.tags.TagManager;
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.dB;
import net.aufdemrand.denizen.utilities.depends.Depends;
import net.aufdemrand.denizencore.DenizenCore;
import net.aufdemrand.denizencore.DenizenImplementation;
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.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;
// <--[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@,fl@ 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
// | li@val[<items|...>] - slightly more verbose, but tag friendly way to fetch a new list (allows periods)
// | fl@<server_flag_name> - fetches the flag list value of the specified server flag, as a dList
// | fl[<player_object/npc_object]@<flag_name> - fetches the flag list value of the specified player/NPC's flag, as a dList
//
// + ----- 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 = 10;
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_8_R1.Block.getById(0);
}
catch (NoClassDefFoundError 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 {
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);
// 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);
}
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 UtilTags(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 AsyncChatSmartEvent());
OldEventManager.registerSmartEvent(new BiomeEnterExitSmartEvent());
OldEventManager.registerSmartEvent(new BlockFallsSmartEvent());
OldEventManager.registerSmartEvent(new BlockPhysicsSmartEvent());
OldEventManager.registerSmartEvent(new ChunkLoadSmartEvent());
OldEventManager.registerSmartEvent(new ChunkUnloadSmartEvent());
OldEventManager.registerSmartEvent(new CommandSmartEvent());
OldEventManager.registerSmartEvent(new CuboidEnterExitSmartEvent());
OldEventManager.registerSmartEvent(new EntityCombustSmartEvent());
OldEventManager.registerSmartEvent(new EntityDamageSmartEvent());
OldEventManager.registerSmartEvent(new EntityDeathSmartEvent());
OldEventManager.registerSmartEvent(new EntityInteractSmartEvent());
OldEventManager.registerSmartEvent(new EntitySpawnSmartEvent());
OldEventManager.registerSmartEvent(new FlagSmartEvent());
OldEventManager.registerSmartEvent(new ItemMoveSmartEvent());
OldEventManager.registerSmartEvent(new ItemScrollSmartEvent());
OldEventManager.registerSmartEvent(new ListPingSmartEvent());
OldEventManager.registerSmartEvent(new NPCNavigationSmartEvent());
OldEventManager.registerSmartEvent(new PlayerEquipsArmorSmartEvent());
OldEventManager.registerSmartEvent(new PlayerJumpSmartEvent());
OldEventManager.registerSmartEvent(new PlayerStepsOnSmartEvent());
OldEventManager.registerSmartEvent(new PlayerWalkSmartEvent());
OldEventManager.registerSmartEvent(new RedstoneSmartEvent());
OldEventManager.registerSmartEvent(new SyncChatSmartEvent());
OldEventManager.registerSmartEvent(new VehicleCollisionSmartEvent());
eventManager().registerCoreMembers();
ScriptEvent.registerScriptEvent(new VehicleMoveScriptEvent());
ScriptEvent.registerScriptEvent(new EntityTeleportScriptEvent());
ObjectFetcher.registerWithObjectFetcher(dItem.class); // i@
ObjectFetcher.registerWithObjectFetcher(dCuboid.class); // cu@
ObjectFetcher.registerWithObjectFetcher(dEntity.class); // e@
ObjectFetcher.registerWithObjectFetcher(dInventory.class); // in@
ObjectFetcher.registerWithObjectFetcher(dColor.class); // co@
ObjectFetcher.registerWithObjectFetcher(dLocation.class); // l@
ObjectFetcher.registerWithObjectFetcher(dMaterial.class); // m@
if (Depends.citizens != null)
ObjectFetcher.registerWithObjectFetcher(dNPC.class); // n@
ObjectFetcher.registerWithObjectFetcher(dPlayer.class); // p@
ObjectFetcher.registerWithObjectFetcher(dWorld.class); // w@
ObjectFetcher.registerWithObjectFetcher(dChunk.class); // ch@
ObjectFetcher.registerWithObjectFetcher(dPlugin.class); // pl@
ObjectFetcher.registerWithObjectFetcher(dEllipsoid.class); // ellipsoid@
ObjectFetcher.registerWithObjectFetcher(dBiome.class); // b@
// 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(EntityAngry.class, dEntity.class);
propertyParser.registerProperty(EntityColor.class, dEntity.class);
propertyParser.registerProperty(EntityCritical.class, dEntity.class);
propertyParser.registerProperty(EntityElder.class, dEntity.class);
propertyParser.registerProperty(EntityFirework.class, dEntity.class);
propertyParser.registerProperty(EntityFramed.class, dEntity.class);
propertyParser.registerProperty(EntityInfected.class, dEntity.class);
propertyParser.registerProperty(EntityItem.class, dEntity.class);
propertyParser.registerProperty(EntityJumpStrength.class, dEntity.class);
propertyParser.registerProperty(EntityKnockback.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(EntitySitting.class, dEntity.class);
propertyParser.registerProperty(EntitySize.class, dEntity.class);
propertyParser.registerProperty(EntitySkeleton.class, dEntity.class);
propertyParser.registerProperty(EntityTame.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(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(ItemLore.class, dItem.class);
propertyParser.registerProperty(ItemMap.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);
}
catch (Exception e) {
dB.echoError(e);
}
// Run everything else on the first server tick
getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
@Override
public void run() {
try {
DenizenCore.loadScripts();
// Reload notables from notables.yml into memory
notableManager.reloadNotables();
// Load the saves.yml into memory
reloadSaves();
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);
}
/*
* Unloads Denizen on shutdown of the craftbukkit server.
*/
@Override
public void onDisable() {
if(!startedSuccessful) return;
// 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 aufdemrand ASAP about this error! ERR: OPN");
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);
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;
private File scoreboardsConfigFile = null;
private FileConfiguration entityConfig = null;
private File entityConfigFile = null;
public void reloadSaves() {
if (savesConfigFile == null) {
savesConfigFile = new File(getDataFolder(), "saves.yml");
}
savesConfig = YamlConfiguration.loadConfiguration(savesConfigFile);
// Reload dLocations from saves.yml, load them into NotableManager // TODO: probably remove this
dLocation._recallLocations();
// Update saves from name to UUID
updateSaves();
if (scoreboardsConfigFile == null) {
scoreboardsConfigFile = new File(getDataFolder(), "scoreboards.yml");
}
scoreboardsConfig = YamlConfiguration.loadConfiguration(scoreboardsConfigFile);
// Reload scoreboards from scoreboards.yml
ScoreboardHelper._recallScoreboards();
if (entityConfigFile == null) {
entityConfigFile = new File(getDataFolder(), "entities.yml");
}
entityConfig = YamlConfiguration.loadConfiguration(entityConfigFile);
// Load entities from entities.yml
EntityScriptHelper.reloadEntities();
// Load maps from maps.yml
DenizenMapManager.reloadMaps();
Bukkit.getServer().getPluginManager().callEvent(new SavesReloadEvent());
}
public void updateSaves() {
int saves_version = 1;
if (savesConfig.contains("a_saves.version"))
saves_version = savesConfig.getInt("a_saves.version");
if (saves_version == 1) {
dB.log("Updating saves from v1 to v2...");
ConfigurationSection section = savesConfig.getConfigurationSection("Players");
if (section != null) {
ArrayList<String> keyList = new ArrayList<String>(section.getKeys(false));
// Remove UPPERCASE cooldown saves from the list - handled manually
for (int i = 0; i < keyList.size(); i++) {
String key = keyList.get(i);
if (!key.equals(key.toUpperCase()) && keyList.contains(key.toUpperCase())) {
keyList.remove(key.toUpperCase());
}
}
// Handle all actual player saves
for (int i = 0; i < keyList.size(); i++) {
String key = keyList.get(i);
try {
// Flags
ConfigurationSection playerSection = savesConfig.getConfigurationSection("Players." + key);
if (playerSection == null) {
dB.echoError("Can't update saves for player '" + key + "' - broken YAML section!");
continue;
}
Map<String, Object> keys = playerSection.getValues(true);
if (!key.equals(key.toUpperCase()) && savesConfig.contains("Players." + key.toUpperCase())) {
// Cooldowns
keys.putAll(savesConfig.getConfigurationSection("Players." + key.toUpperCase()).getValues(true));
savesConfig.set("Players." + key.toUpperCase(), null);
}
dPlayer player = dPlayer.valueOf(key);
if (player == null) {
dB.echoError("Can't update saves for player '" + key + "' - invalid name!");
savesConfig.createSection("PlayersBACKUP." + key, keys);
// TODO: READ FROM BACKUP AT LOG IN
}
else {
savesConfig.createSection("Players." + player.getSaveName(), keys);
}
savesConfig.set("Players." + key, null);
}
catch (Exception ex) {
dB.echoError(ex);
}
}
}
section = savesConfig.getConfigurationSection("Listeners");
if (section != null) {
for (String key: section.getKeys(false)) {
try {
dPlayer player = dPlayer.valueOf(key);
if (player == null)
dB.log("Warning: can't update listeners for player '" + key + "' - invalid name!");
else // Listeners
savesConfig.createSection("Listeners." + player.getSaveName(), savesConfig.getConfigurationSection("Listeners." + key).getValues(true));
savesConfig.set("Listeners." + key, null);
}
catch (Exception ex) {
dB.echoError(ex);
}
}
}
savesConfig.set("a_saves.version", "2");
dB.log("Done!");
}
}
public FileConfiguration getSaves() {
if (savesConfig == null) {
reloadSaves();
}
return savesConfig;
}
public FileConfiguration getScoreboards() {
if (scoreboardsConfig == null) {
reloadSaves();
}
return scoreboardsConfig;
}
public FileConfiguration getEntities() {
if (entityConfig == null) {
reloadSaves();
}
return entityConfig;
}
public void saveSaves() {
if (savesConfig == null || savesConfigFile == null) {
return;
}
// Save notables
notableManager.saveNotables();
// Save scoreboards to scoreboards.yml
ScoreboardHelper._saveScoreboards();
// Save entities to entities.yml
EntityScriptHelper.saveEntities();
// Save maps to maps.yml
DenizenMapManager.saveMaps();
try {
savesConfig.save(savesConfigFile);
} catch (IOException ex) {
Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Could not save to " + savesConfigFile, ex);
}
try {
scoreboardsConfig.save(scoreboardsConfigFile);
} catch (IOException ex) {
Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Could not save to " + scoreboardsConfigFile, ex);
}
try {
entityConfig.save(entityConfigFile);
} catch (IOException ex) {
Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Could not save to " + entityConfigFile, ex);
}
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String cmdName, String[] args) {
// <--[language]
// @name /ex command
// @group Console Commands
// @description
// The '/ex' command is an easy way to run a single denizen script command in-game. Its syntax,
// aside from '/ex' is exactly the same as any other command. When running a command, some context
// is also supplied, such as '<player>' if being run by a player (versus the console), as well as
// '<npc>' if a NPC is selected by using the '/npc sel' command.
//
// Examples:
// /ex flag <player> test_flag:!
// /ex run 's@npc walk script' as:<npc>
//
// Need to '/ex' a command as a different player or NPC? No problem. Just use the 'npc' and 'player'
// value arguments, or utilize the object fetcher.
//
// Examples:
// /ex narrate player:p@NLBlackEagle 'Your health is <player.health.formatted>.'
// /ex walk npc:n@fred <player.location.cursor_on>
// -->
if (cmdName.equalsIgnoreCase("ex")) {
List<String> entries = new ArrayList<String>();
String entry = "";
for (String arg : args)
entry = entry + arg + " ";
if (entry.length() < 2) {
sender.sendMessage("/ex <dCommand> (arguments)");
return true;
}
if (Settings.showExHelp()) {
if (dB.showDebug)
sender.sendMessage(ChatColor.YELLOW + "Executing dCommand... check the console for debug output!");
else
sender.sendMessage(ChatColor.YELLOW + "Executing dCommand... to see debug, use /denizen debug");
}
entries.add(entry);
InstantQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId("EXCOMMAND"));
dNPC npc = null;
if (Depends.citizens != null && Depends.citizens.getNPCSelector().getSelected(sender) != null)
npc = new dNPC(Depends.citizens.getNPCSelector().getSelected(sender));
List<ScriptEntry> scriptEntries = ScriptBuilder.buildScriptEntries(entries, null,
new BukkitScriptEntryData(sender instanceof Player ? new dPlayer((Player)sender): null, npc));
queue.addEntries(scriptEntries);
queue.start();
return true;
}
//if (Depends.citizens != null)
// return citizens.onCommand(sender, cmd, cmdName, args);
String modifier = args.length > 0 ? args[0] : "";
if (!commandManager.hasCommand(cmd, modifier) && !modifier.isEmpty()) {
return suggestClosestModifier(sender, cmd.getName(), modifier);
}
Object[] methodArgs = { sender };
return commandManager.executeSafe(cmd, args, sender, methodArgs);
}
private boolean suggestClosestModifier(CommandSender sender, String command, String modifier) {
String closest = commandManager.getClosestCommandModifier(command, modifier);
if (!closest.isEmpty()) {
Messaging.send(sender, "<7>Unknown command. Did you mean:");
Messaging.send(sender, " /" + command + " " + closest);