-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
WorldScriptHelper.java
4549 lines (3829 loc) · 160 KB
/
WorldScriptHelper.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.scripts.containers.core;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import net.aufdemrand.denizen.Settings;
import net.aufdemrand.denizen.objects.Duration;
import net.aufdemrand.denizen.objects.Element;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.objects.aH.Argument;
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.objects.dInventory;
import net.aufdemrand.denizen.objects.dItem;
import net.aufdemrand.denizen.objects.dList;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.objects.dMaterial;
import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.dObject;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.objects.dWorld;
import net.aufdemrand.denizen.scripts.ScriptBuilder;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.commands.core.DetermineCommand;
import net.aufdemrand.denizen.scripts.queues.ScriptQueue;
import net.aufdemrand.denizen.scripts.queues.core.InstantQueue;
import net.aufdemrand.denizen.tags.TagManager;
import net.aufdemrand.denizen.utilities.Conversion;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.entity.Position;
import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player;
import org.bukkit.entity.Sheep;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockCanBuildEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockGrowEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockRedstoneEvent;
import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.EntityBlockFormEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreeperPowerEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityPortalEnterEvent;
import org.bukkit.event.entity.EntityPortalExitEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.EntityTameEvent;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.entity.EntityTeleportEvent;
import org.bukkit.event.entity.EntityUnleashEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.HorseJumpEvent;
import org.bukkit.event.entity.ItemDespawnEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.PigZapEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.entity.PlayerLeashEntityEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.entity.SheepDyeWoolEvent;
import org.bukkit.event.entity.SheepRegrowWoolEvent;
import org.bukkit.event.entity.SlimeSplitEvent;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.inventory.BrewEvent;
import org.bukkit.event.inventory.FurnaceBurnEvent;
import org.bukkit.event.inventory.FurnaceExtractEvent;
import org.bukkit.event.inventory.FurnaceSmeltEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerEggThrowEvent;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerLevelChangeEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerShearEntityEvent;
import org.bukkit.event.player.PlayerToggleFlightEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.event.player.PlayerToggleSprintEvent;
import org.bukkit.event.server.ServerCommandEvent;
import org.bukkit.event.vehicle.VehicleBlockCollisionEvent;
import org.bukkit.event.vehicle.VehicleCreateEvent;
import org.bukkit.event.vehicle.VehicleDamageEvent;
import org.bukkit.event.vehicle.VehicleDestroyEvent;
import org.bukkit.event.vehicle.VehicleEnterEvent;
import org.bukkit.event.vehicle.VehicleEntityCollisionEvent;
import org.bukkit.event.vehicle.VehicleExitEvent;
import org.bukkit.event.weather.LightningStrikeEvent;
import org.bukkit.event.weather.WeatherChangeEvent;
import org.bukkit.event.world.PortalCreateEvent;
import org.bukkit.event.world.SpawnChangeEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.event.world.WorldInitEvent;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldSaveEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.BlockIterator;
@SuppressWarnings("deprecation")
public class WorldScriptHelper implements Listener {
public static Map<String, WorldScriptContainer> world_scripts = new ConcurrentHashMap<String, WorldScriptContainer>(8, 0.9f, 1);
public WorldScriptHelper() {
DenizenAPI.getCurrentInstance().getServer().getPluginManager()
.registerEvents(this, DenizenAPI.getCurrentInstance());
}
/////////////////////
// EVENT HANDLER
/////////////////
public static String doEvents(List<String> eventNames, dNPC npc, Player player, Map<String, dObject> context) {
String determination = "none";
if (dB.showEventsFiring) dB.log("Fired for '" + eventNames.toString() + "'");
for (WorldScriptContainer script : world_scripts.values()) {
if (script == null) continue;
for (String eventName : eventNames) {
// Check for event's name with and without dObject prefixes
if (!script.contains("EVENTS.ON " + eventName.toUpperCase()))
continue;
// Fetch script from Event
//
// Note: a "new dPlayer(null)" will not be null itself,
// so keep a ternary operator here
List<ScriptEntry> entries = script.getEntries
(player != null ? new dPlayer(player) : null,
npc, "events.on " + eventName);
if (entries.isEmpty()) continue;
dB.report("Event",
aH.debugObj("Type", "On " + eventName)
+ script.getAsScriptArg().debug()
+ (npc != null ? aH.debugObj("NPC", npc.toString()) : "")
+ (player != null ? aH.debugObj("Player", player.getName()) : "")
+ (context != null ? aH.debugObj("Context", context.toString()) : ""));
dB.echoDebug(dB.DebugElement.Header, "Building event 'On " + eventName.toUpperCase() + "' for " + script.getName());
// Create new ID -- this is what we will look for when determining an outcome
long id = DetermineCommand.getNewId();
// Add the reqId to each of the entries for the determine command (this may be slightly outdated, add to TODO)
ScriptBuilder.addObjectToEntries(entries, "ReqId", id);
// Add entries and context to the queue
ScriptQueue queue = InstantQueue.getQueue(null).addEntries(entries);
if (context != null) {
for (Map.Entry<String, dObject> entry : context.entrySet()) {
queue.addContext(entry.getKey(), entry.getValue());
}
}
// Start the queue!
queue.start();
// Check the determination
if (DetermineCommand.hasOutcome(id))
determination = DetermineCommand.getOutcome(id);
}
}
return determination;
}
/////////////////////
// BLOCK EVENTS
/////////////////
// <--[event]
// @Events
// player breaks block
// player breaks <material>
// player breaks block with <item>
// player breaks <material> with <item>
// player breaks block with <material>
// player breaks <material> with <material>
//
// @Triggers when a player breaks a block.
// @Context
// <context.location> returns the dLocation the block was broken at.
// <context.material> returns the dMaterial of the block that was broken.
//
// @Determine
// "CANCELLED" to stop the block from breaking.
// "NOTHING" to make the block drop no items.
// dList(dItem) to make the block drop a specified list of items.
//
// -->
@EventHandler
public void blockBreak(BlockBreakEvent event) {
Map<String, dObject> context = new HashMap<String, dObject>();
Block block = event.getBlock();
dMaterial material = new dMaterial(event.getBlock().getType());
context.put("location", new dLocation(block.getLocation()));
context.put("material", material);
dItem item = new dItem(event.getPlayer().getItemInHand());
dMaterial itemMaterial = item.getMaterial();
List<String> events = new ArrayList<String>();
events.add("player breaks block");
events.add("player breaks " + material.identify());
events.add("player breaks block with " + item.identify());
events.add("player breaks " + material.identify() + " with " + item.identify());
events.add("player breaks block with " + itemMaterial.identify());
events.add("player breaks " + material.identify() + " with " + itemMaterial.identify());
String determination = doEvents(events, null, event.getPlayer(), context);
if (determination.toUpperCase().startsWith("CANCELLED"))
event.setCancelled(true);
// Make nothing drop, usually used as "drop:nothing"
else if (determination.toUpperCase().startsWith("NOTHING")) {
event.setCancelled(true);
block.setType(Material.AIR);
}
// Get a dList of dItems to drop
else if (Argument.valueOf(determination).matchesArgumentList(dItem.class)) {
// Cancel the event
event.setCancelled(true);
block.setType(Material.AIR);
// Get the list of items
Object list = dList.valueOf(determination).filter(dItem.class);
@SuppressWarnings("unchecked")
List<dItem> newItems = (List<dItem>) list;
for (dItem newItem : newItems) {
block.getWorld().dropItemNaturally(block.getLocation(),
newItem.getItemStack()); // Drop each item
}
}
}
// <--[event]
// @Events
// block burns
// <block> burns
//
// @Triggers when a block is destroyed by fire.
// @Context
// <context.location> returns the dLocation the block was burned at.
// <context.material> returns the dMaterial of the block that was burned.
//
// @Determine
// "CANCELLED" to stop the block from being destroyed.
//
// -->
@EventHandler
public void blockBurn(BlockBurnEvent event) {
Map<String, dObject> context = new HashMap<String, dObject>();
context.put("location", new dLocation(event.getBlock().getLocation()));
dMaterial material = new dMaterial(event.getBlock().getType());
String determination = doEvents(Arrays.asList
("block burns",
material.identify() + " burns"),
null, null, context);
if (determination.toUpperCase().startsWith("CANCELLED"))
event.setCancelled(true);
}
// <--[event]
// @Events
// block being built
// block being built on <material>
// <material> being built
// <material> being built on <material>
//
// @Triggers when an attempt is made to build a block on another block. Not necessarily caused by players.
// @Context
// <context.location> returns the dLocation of the block the player is trying to build on.
// <context.old_material> returns the dMaterial of the block the player is trying to build on.
// <context.new_material> returns the dMaterial of the block the player is trying to build.
//
// @Determine
// "BUILDABLE" to allow the building.
// "CANCELLED" to cancel the building.
//
// -->
@EventHandler
public void blockCanBuild(BlockCanBuildEvent event) {
Map<String, dObject> context = new HashMap<String, dObject>();
dMaterial oldMaterial = new dMaterial(event.getBlock().getType());
dMaterial newMaterial = new dMaterial(event.getMaterial());
context.put("location", new dLocation(event.getBlock().getLocation()));
context.put("old_material", oldMaterial);
context.put("new_material", newMaterial);
String determination = doEvents(Arrays.asList
("block being built",
"block being built on " + oldMaterial.identify(),
newMaterial.identify() + " being built",
newMaterial.identify() + " being built on " +
oldMaterial.identify()),
null, null, context);
if (determination.toUpperCase().startsWith("BUILDABLE"))
event.setBuildable(true);
if (determination.toUpperCase().startsWith("CANCELLED"))
event.setBuildable(false);
}
// <--[event]
// @Events
// player damages block
// player damages <material>
//
// @Triggers when a block is damaged by a player.
// @Context
// <context.location> returns the dLocation the block that was damaged.
// <context.material> returns the dMaterial of the block that was damaged.
//
// @Determine
// "CANCELLED" to stop the block from being damaged.
// "INSTABREAK" to make the block get broken instantly.
//
// -->
@EventHandler
public void blockDamage(BlockDamageEvent event) {
Map<String, dObject> context = new HashMap<String, dObject>();
dMaterial material = new dMaterial(event.getBlock().getType());
context.put("location", new dLocation(event.getBlock().getLocation()));
context.put("material", material);
String determination = doEvents(Arrays.asList
("player damages block",
"player damages " + material.identify()),
null, event.getPlayer(), context);
if (determination.toUpperCase().startsWith("CANCELLED"))
event.setCancelled(true);
if (determination.toUpperCase().startsWith("INSTABREAK"))
event.setInstaBreak(true);
}
// <--[event]
// @Events
// block dispenses item
// block dispenses <item>
// <block> dispenses item
// <block> dispenses <item>
//
// @Triggers when a block dispenses an item.
// @Context
// <context.location> returns the dLocation of the dispenser.
// <context.item> returns the dItem of the item being dispensed.
//
// @Determine
// "CANCELLED" to stop the block from dispensing.
// Element(Double) to set the power with which the item is shot.
//
// -->
@EventHandler
public void blockDispense(BlockDispenseEvent event) {
Map<String, dObject> context = new HashMap<String, dObject>();
dItem item = new dItem(event.getItem());
dMaterial material = new dMaterial(event.getBlock().getType());
context.put("location", new dLocation(event.getBlock().getLocation()));
context.put("item", item);
String determination = doEvents(Arrays.asList
("block dispenses item",
"block dispenses " + item.identify(),
material.identify() + " dispenses item",
material.identify() + " dispenses " + item.identify()),
null, null, context);
if (determination.toUpperCase().startsWith("CANCELLED"))
event.setCancelled(true);
else if (Argument.valueOf(determination)
.matchesPrimitive(aH.PrimitiveType.Double)) {
event.setVelocity(event.getVelocity().normalize()
.multiply(aH.getDoubleFrom(determination)));
}
}
// <--[event]
// @Events
// block fades
// <block> fades
//
// @Triggers when a block fades, melts or disappears based on world conditions.
// @Context
// <context.location> returns the dLocation the block faded at.
// <context.material> returns the dMaterial of the block that faded.
//
// @Determine
// "CANCELLED" to stop the block from fading.
//
// -->
@EventHandler
public void blockFade(BlockFadeEvent event) {
Map<String, dObject> context = new HashMap<String, dObject>();
dMaterial material = new dMaterial(event.getBlock().getType());
context.put("location", new dLocation(event.getBlock().getLocation()));
context.put("material", material);
String determination = doEvents(Arrays.asList
("block fades",
material.identify() + " fades"),
null, null, context);
if (determination.toUpperCase().startsWith("CANCELLED"))
event.setCancelled(true);
}
// <--[event]
// @Events
// block forms
// <block> forms
//
// @Triggers when a block is formed based on world conditions,
// e.g. when snow forms in a snow storm or ice forms
// in a snowy biome
// @Context
// <context.location> returns the dLocation the block.
// <context.material> returns the dMaterial of the block.
//
// @Determine
// "CANCELLED" to stop the block from forming.
//
// -->
@EventHandler
public void blockForm(BlockFormEvent event) {
Map<String, dObject> context = new HashMap<String, dObject>();
dMaterial material = new dMaterial(event.getBlock().getType());
context.put("location", new dLocation(event.getBlock().getLocation()));
context.put("material", material);
String determination = doEvents(Arrays.asList
("block forms",
material.identify() + " forms"),
null, null, context);
if (determination.toUpperCase().startsWith("CANCELLED"))
event.setCancelled(true);
}
// <--[event]
// @Events
// liquid spreads
// <liquid block> spreads
//
// @Triggers when a liquid block spreads.
// @Context
// <context.destination> returns the dLocation the block spread to.
// <context.location> returns the dLocation the block spread from.
// <context.material> returns the dMaterial of the block that spread.
//
// @Determine
// "CANCELLED" to stop the block from spreading.
//
// -->
@EventHandler
public void blockFromTo(BlockFromToEvent event) {
Map<String, dObject> context = new HashMap<String, dObject>();
dMaterial material = new dMaterial(event.getBlock().getType());
context.put("location", new dLocation(event.getBlock().getLocation()));
context.put("destination", new dLocation(event.getToBlock().getLocation()));
context.put("material", material);
String determination = doEvents(Arrays.asList
("liquid spreads",
material.identify() + " spreads"),
null, null, context);
if (determination.toUpperCase().startsWith("CANCELLED"))
event.setCancelled(true);
}
// <--[event]
// @Events
// block grows
// <block> grows
//
// @Triggers when a block grows naturally in the world,
// e.g. when wheat, sugar canes, cactuses,
// watermelons or pumpkins grow
// @Context
// <context.location> returns the dLocation the block.
// <context.material> returns the dMaterial of the block.
//
// @Determine
// "CANCELLED" to stop the block from growing.
//
// -->
@EventHandler
public void blockGrow(BlockGrowEvent event) {
Map<String, dObject> context = new HashMap<String, dObject>();
dMaterial material = new dMaterial(event.getBlock().getType());
context.put("location", new dLocation(event.getBlock().getLocation()));
context.put("material", material);
String determination = doEvents(Arrays.asList
("block grows",
material.identify() + " grows"),
null, null, context);
if (determination.toUpperCase().startsWith("CANCELLED"))
event.setCancelled(true);
}
// <--[event]
// @Events
// block ignites
// <block> ignites
//
// @Triggers when a block is set on fire.
// @Context
// <context.location> returns the dLocation the block was set on fire at.
// <context.material> returns the dMaterial of the block that was set on fire.
//
// @Determine
// "CANCELLED" to stop the block from being ignited.
//
// -->
@EventHandler
public void blockIgnite(BlockIgniteEvent event) {
Map<String, dObject> context = new HashMap<String, dObject>();
dMaterial material = new dMaterial(event.getBlock().getType());
context.put("location", new dLocation(event.getBlock().getLocation()));
context.put("material", material);
String determination = doEvents(Arrays.asList
("block ignites",
material.identify() + " ignites"),
null, event.getPlayer(), context);
if (determination.toUpperCase().startsWith("CANCELLED"))
event.setCancelled(true);
}
// <--[event]
// @Events
// piston extends
// <block> extends
//
// @Triggers when a piston extends.
// @Context
// <context.location> returns the dLocation of the piston.
// <context.material> returns the dMaterial of the piston.
// <context.length> returns the number of blocks that will be moved by the piston.
//
// @Determine
// "CANCELLED" to stop the piston from extending.
//
// -->
@EventHandler
public void blockPistonExtend(BlockPistonExtendEvent event) {
Map<String, dObject> context = new HashMap<String, dObject>();
dMaterial material = new dMaterial(event.getBlock().getType());
context.put("location", new dLocation(event.getBlock().getLocation()));
context.put("material", material);
context.put("length", new Element(event.getLength()));
String determination = doEvents(Arrays.asList
("piston extends",
material.identify() + " extends"),
null, null, context);
if (determination.toUpperCase().startsWith("CANCELLED"))
event.setCancelled(true);
}
// <--[event]
// @Events
// piston retracts
// <block> retracts
//
// @Triggers when a piston retracts.
// @Context
// <context.location> returns the dLocation of the piston.
// <context.retract_location> returns the new dLocation of the block that
// will be moved by the piston if it is sticky.
// <context.material> returns the dMaterial of the piston.
//
// @Determine
// "CANCELLED" to stop the piston from retracting.
//
// -->
@EventHandler
public void blockPistonRetract(BlockPistonRetractEvent event) {
Map<String, dObject> context = new HashMap<String, dObject>();
dMaterial material = new dMaterial(event.getBlock().getType());
context.put("location", new dLocation(event.getBlock().getLocation()));
context.put("retract_location", new dLocation(event.getRetractLocation()));
context.put("material", material);
String determination = doEvents(Arrays.asList
("piston retracts",
material.identify() + " retracts"),
null, null, context);
if (determination.toUpperCase().startsWith("CANCELLED"))
event.setCancelled(true);
}
// <--[event]
// @Events
// player places block
// player places <block>
//
// @Triggers when a player places a block.
// @Context
// <context.location> returns the dLocation of the block that was placed.
// <context.material> returns the dMaterial of the block that was placed.
//
// @Determine
// "CANCELLED" to stop the block from being placed.
//
// -->
@EventHandler
public void blockPlace(BlockPlaceEvent event) {
Map<String, dObject> context = new HashMap<String, dObject>();
dMaterial material = new dMaterial(event.getBlock().getType());
context.put("location", new dLocation(event.getBlock().getLocation()));
context.put("material", material);
String determination = doEvents(Arrays.asList
("player places block",
"player places " + material.identify()),
null, event.getPlayer(), context);
if (determination.toUpperCase().startsWith("CANCELLED"))
event.setCancelled(true);
}
// <--[event]
// @Events
// block powers
// <block> powers
// block unpowers
// <block> unpowers
//
// @Triggers when a block is (un)powered.
// @Context
// <context.location> returns the dLocation of the block that was (un)powered.
// <context.material> returns the dMaterial of the block that was (un)powered.
//
// @Determine
// "CANCELLED" to stop the block from being (un)powered.
//
// -->
@EventHandler
public void blockRedstone(BlockRedstoneEvent event) {
Map<String, dObject> context = new HashMap<String, dObject>();
dMaterial material = new dMaterial(event.getBlock().getType());
context.put("location", new dLocation(event.getBlock().getLocation()));
context.put("material", material);
List<String> events = new ArrayList<String>();
if (event.getNewCurrent() > 0) {
events.add("block powers");
events.add(material.identify() + " powers");
events.add("block powered");
events.add(material.identify() + " powered");
}
else {
events.add("block unpowers");
events.add(material.identify() + " unpowers");
events.add("block unpowered");
events.add(material.identify() + " unpowered");
}
String determination = doEvents(events, null, null, context);
if (determination.toUpperCase().startsWith("CANCELLED"))
event.setNewCurrent(event.getOldCurrent());
}
// <--[event]
// @Events
// block spreads
// <block> spreads
//
// @Triggers when a block spreads based on world conditions,
// e.g. when fire spreads, when mushrooms spread
// @Context
// <context.location> returns the dLocation the block.
// <context.material> returns the dMaterial of the block.
//
// @Determine
// "CANCELLED" to stop the block from growing.
//
// -->
@EventHandler
public void blockSpread(BlockSpreadEvent event) {
Map<String, dObject> context = new HashMap<String, dObject>();
dMaterial material = new dMaterial(event.getBlock().getType());
context.put("location", new dLocation(event.getBlock().getLocation()));
context.put("material", material);
String determination = doEvents(Arrays.asList
("block spreads",
material.identify() + " spreads"),
null, null, context);
if (determination.toUpperCase().startsWith("CANCELLED"))
event.setCancelled(true);
}
// <--[event]
// @Events
// brewing stand brews
//
// @Triggers when a brewing stand brews a potion.
// @Context
// <context.location> returns the dLocation of the brewing stand.
// <context.inventory> returns the dInventory of the brewing stand's contents.
//
// @Determine
// "CANCELLED" to stop the brewing stand from brewing.
//
// -->
@EventHandler
public void brew(BrewEvent event) {
Map<String, dObject> context = new HashMap<String, dObject>();
context.put("location", new dLocation(event.getBlock().getLocation()));
context.put("inventory", new dInventory(event.getContents()));
String determination = doEvents(Arrays.asList
("brewing stand brews"),
null, null, context);
if (determination.toUpperCase().startsWith("CANCELLED"))
event.setCancelled(true);
}
// <--[event]
// @Events
// entity forms block
// entity forms <block>
// <entity> forms block
// <entity> forms <block>
//
// @Triggers when a block is formed by an entity,
// e.g. when a snowman forms snow
// @Context
// <context.location> returns the dLocation the block.
// <context.material> returns the dMaterial of the block.
// <context.entity> returns the dEntity that formed the block.
//
// @Determine
// "CANCELLED" to stop the block from forming.
//
// -->
@EventHandler
public void entityBlockForm(EntityBlockFormEvent event) {
Map<String, dObject> context = new HashMap<String, dObject>();
dMaterial material = new dMaterial(event.getBlock().getType());
dEntity entity = new dEntity(event.getEntity());
String entityType = entity.getEntityType().name();
context.put("location", new dLocation(event.getBlock().getLocation()));
context.put("material", material);
context.put("entity", entity.getDenizenObject());
String determination = doEvents(Arrays.asList
("entity forms block",
"entity forms " + material.identify(),
entityType + " forms block",
entityType + " forms " + material.identify()),
null, null, context);
if (determination.toUpperCase().startsWith("CANCELLED"))
event.setCancelled(true);
}
// <--[event]
// @Events
// furnace burns item
// furnace burns <item>
//
// @Triggers when a furnace burns an item used as fuel.
// @Context
// <context.location> returns the dLocation of the furnace.
// <context.item> returns the dItem burnt.
//
// @Determine
// "CANCELLED" to stop the furnace from burning the item.
// Element(Integer) to set the burn time for this fuel.
//
// -->
@EventHandler
public void furnaceBurn(FurnaceBurnEvent event) {
Map<String, dObject> context = new HashMap<String, dObject>();
dItem item = new dItem(event.getFuel());
context.put("location", new dLocation(event.getBlock().getLocation()));
context.put("item", item);
String determination = doEvents(Arrays.asList
("furnace burns item",
"furnace burns " + item.identify()),
null, null, context);
if (determination.toUpperCase().startsWith("CANCELLED"))
event.setCancelled(true);
else if (Argument.valueOf(determination)
.matchesPrimitive(aH.PrimitiveType.Integer)) {
event.setBurnTime(aH.getIntegerFrom(determination));
}
}
// <--[event]
// @Events
// player takes item from furnace
// player takes <item> from furnace
// player takes <material> from furnace
//
// @Triggers when a player takes an item from a furnace.
// @Context
// <context.location> returns the dLocation of the furnace.
// <context.item> returns the dItem taken out of the furnace.
//
// @Determine
// Element(Integer) to set the amount of experience the player will get.
//
// -->
@EventHandler
public void furnaceExtract(FurnaceExtractEvent event) {
Map<String, dObject> context = new HashMap<String, dObject>();
dMaterial itemMaterial = new dMaterial(event.getItemType());
dItem item = new dItem(itemMaterial, event.getItemAmount());
context.put("location", new dLocation(event.getBlock().getLocation()));
context.put("item", item);
String determination = doEvents(Arrays.asList
("player takes item from furnace",
"player takes " + item.identify() + " from furnace",
"player takes " + itemMaterial.identify() + " from furnace"),
null, event.getPlayer(), context);
if (Argument.valueOf(determination)
.matchesPrimitive(aH.PrimitiveType.Integer)) {
event.setExpToDrop(aH.getIntegerFrom(determination));
}
}
// <--[event]
// @Events
// furnace smelts item (into <item>)
// furnace smelts <item> (into <item>)
//
// @Triggers when a furnace smelts an item.
// @Context
// <context.location> returns the dLocation of the furnace.
// <context.source> returns the dItem that is smelted.
// <context.result> returns the dItem that is the result of the smelting.
//
// @Determine
// "CANCELLED" to stop the furnace from smelting the item.
// dItem to set the item that is the result of the smelting.
//
// -->
@EventHandler
public void furnaceSmelt(FurnaceSmeltEvent event) {
Map<String, dObject> context = new HashMap<String, dObject>();
dItem source = new dItem(event.getSource());
dItem result = new dItem(event.getResult());
context.put("location", new dLocation(event.getBlock().getLocation()));
context.put("source_item", source);
context.put("result_item", result);
String determination = doEvents(Arrays.asList
("furnace smelts item",
"furnace smelts " + source.identify(),
"furnace smelts item into " + result.identify(),
"furnace smelts " + source.identify() + " into " + result.identify()),
null, null, context);
if (determination.toUpperCase().startsWith("CANCELLED"))
event.setCancelled(true);
else if (dItem.matches(determination)) {
event.setResult(dItem.valueOf(determination).getItemStack());
}
}