-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathDynmapMobsPlugin.java
1394 lines (1323 loc) · 62.6 KB
/
DynmapMobsPlugin.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 org.dynmap.mobs;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.*;
import org.bukkit.entity.Villager.Profession;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.dynmap.DynmapAPI;
import org.dynmap.markers.Marker;
import org.dynmap.markers.MarkerAPI;
import org.dynmap.markers.MarkerIcon;
import org.dynmap.markers.MarkerSet;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class DynmapMobsPlugin extends JavaPlugin {
private static Logger log;
Plugin dynmap;
DynmapAPI api;
MarkerAPI markerapi;
FileConfiguration cfg;
MarkerSet mset;
MarkerSet hset;
MarkerSet pset;
MarkerSet vset;
double res; /* Position resolution */
long updperiod;
long vupdperiod;
int hideifundercover;
int hideifshadow;
boolean tinyicons;
boolean nolabels;
boolean vtinyicons;
boolean vnolabels;
boolean inc_coord;
boolean vinc_coord;
boolean stop;
boolean reload = false;
static String obcpackage;
static String nmspackage;
Method gethandle;
int updates_per_tick = 20;
int vupdates_per_tick = 20;
HashMap<String, Integer> mlookup_cache = new HashMap<String, Integer>();
HashMap<String, Integer> hlookup_cache = new HashMap<String, Integer>();
HashMap<String, Integer> plookup_cache = new HashMap<String, Integer>();
HashMap<String, Integer> vlookup_cache = new HashMap<String, Integer>();
@Override
public void onLoad() {
log = this.getLogger();
}
public static String mapClassName(String n) {
if(n.startsWith("org.bukkit.craftbukkit")) {
n = getOBCPackage() + n.substring("org.bukkit.craftbukkit".length());
}
else if(n.startsWith("net.minecraft.server")) {
n = getNMSPackage() + n.substring("net.minecraft.server".length());
}
return n;
}
/* Mapping of mobs to icons */
private static class MobMapping {
String mobid;
boolean enabled;
Class<Entity> mobclass;
Class<?> entclass;
String cls_id;
String entclsid;
String label;
MarkerIcon icon;
MobMapping(String id, String clsid, String lbl) {
this(id, clsid, lbl, null);
}
@SuppressWarnings("unchecked")
MobMapping(String id, String clsid, String lbl, String entclsid) {
mobid = id;
label = lbl;
cls_id = clsid;
}
public void init() {
try {
mobclass = (Class<Entity>) Class.forName(mapClassName(cls_id));
} catch (ClassNotFoundException cnfx) {
mobclass = null;
}
try {
this.entclsid = entclsid;
if(entclsid != null) {
entclass = (Class<?>) Class.forName(mapClassName(entclsid));
}
} catch (ClassNotFoundException cnfx) {
entclass = null;
}
}
};
MobMapping mocreat_mobs[];
MobMapping hostile_mobs[];
MobMapping passive_mobs[];
MobMapping vehicles[];
private Map<Integer, Marker> mocreat_mobicons = new HashMap<Integer, Marker>();
private Map<Integer, Marker> hostile_mobicons = new HashMap<Integer, Marker>();
private Map<Integer, Marker> passive_mobicons = new HashMap<Integer, Marker>();
private Map<Integer, Marker> vehicleicons = new HashMap<Integer, Marker>();
private MobMapping config_mocreat_mobs[] = {
// Mo'Creatures
new MobMapping("horse", "org.bukkit.entity.Animals", "Horse", "net.minecraft.server.MoCEntityHorse"),
new MobMapping("fireogre", "org.bukkit.entity.Monster", "Fire Ogre", "net.minecraft.server.MoCEntityFireOgre"),
new MobMapping("caveogre", "org.bukkit.entity.Monster", "Cave Ogre", "net.minecraft.server.MoCEntityCaveOgre"),
new MobMapping("ogre", "org.bukkit.entity.Monster", "Ogre", "net.minecraft.server.MoCEntityOgre"),
new MobMapping("boar", "org.bukkit.entity.Pig", "Boar", "net.minecraft.server.MoCEntityBoar"),
new MobMapping("polarbear", "org.bukkit.entity.Animals", "Polar Bear", "net.minecraft.server.MoCEntityPolarBear"),
new MobMapping("bear", "org.bukkit.entity.Animals", "Bear", "net.minecraft.server.MoCEntityBear"),
new MobMapping("duck", "org.bukkit.entity.Chicken", "Duck", "net.minecraft.server.MoCEntityDuck"),
new MobMapping("bigcat", "org.bukkit.entity.Animals", "Big Cat", "net.minecraft.server.MoCEntityBigCat"),
new MobMapping("deer", "org.bukkit.entity.Animals", "Deer", "net.minecraft.server.MoCEntityDeer"),
new MobMapping("wildwolf", "org.bukkit.entity.Monster", "Wild Wolf", "net.minecraft.server.MoCEntityWWolf"),
new MobMapping("flamewraith", "org.bukkit.entity.Monster", "Flame Wraith", "net.minecraft.server.MoCEntityFlameWraith"),
new MobMapping("wraith", "org.bukkit.entity.Monster", "Wraith", "net.minecraft.server.MoCEntityWraith"),
new MobMapping("bunny", "org.bukkit.entity.Animals", "Bunny", "net.minecraft.server.MoCEntityBunny"),
new MobMapping("bird", "org.bukkit.entity.Animals", "Bird", "net.minecraft.server.MoCEntityBird"),
new MobMapping("fox", "org.bukkit.entity.Animals", "Fox", "net.minecraft.server.MoCEntityFox"),
new MobMapping("werewolf", "org.bukkit.entity.Monster", "Werewolf", "net.minecraft.server.MoCEntityWerewolf"),
new MobMapping("shark", "org.bukkit.entity.WaterMob", "Shark", "net.minecraft.server.MoCEntityShark"),
new MobMapping("dolphin", "org.bukkit.entity.WaterMob", "Shark", "net.minecraft.server.MoCEntityDolphin"),
new MobMapping("fishy", "org.bukkit.entity.WaterMob", "Fishy", "net.minecraft.server.MoCEntityFishy"),
new MobMapping("kitty", "org.bukkit.entity.Animals", "Kitty", "net.minecraft.server.MoCEntityKitty"),
new MobMapping("hellrat", "org.bukkit.entity.Monster", "Hell Rat", "net.minecraft.server.MoCEntityHellRat"),
new MobMapping("rat", "org.bukkit.entity.Monster", "Rat", "net.minecraft.server.MoCEntityRat"),
new MobMapping("mouse", "org.bukkit.entity.Animals", "Mouse", "net.minecraft.server.MoCEntityMouse"),
new MobMapping("scorpion", "org.bukkit.entity.Monster", "Scorpion", "net.minecraft.server.MoCEntityScorpion"),
new MobMapping("turtle", "org.bukkit.entity.Animals", "Turtle", "net.minecraft.server.MoCEntityTurtle"),
new MobMapping("crocodile", "org.bukkit.entity.Animals", "Crocodile", "net.minecraft.server.MoCEntityCrocodile"),
new MobMapping("ray", "org.bukkit.entity.WaterMob", "Ray", "net.minecraft.server.MoCEntityRay"),
new MobMapping("jellyfish", "org.bukkit.entity.WaterMob", "Jelly Fish", "net.minecraft.server.MoCEntityJellyFish"),
new MobMapping("goat", "org.bukkit.entity.Animals", "Goat", "net.minecraft.server.MoCEntityGoat"),
new MobMapping("snake", "org.bukkit.entity.Animals", "Snake", "net.minecraft.server.MoCEntitySnake"),
new MobMapping("ostrich", "org.bukkit.entity.Animals", "Ostrich", "net.minecraft.server.MoCEntityOstrich")
};
private MobMapping config_hostile_mobs[] = {
// Standard hostile
new MobMapping("elderguardian", "org.bukkit.entity.ElderGuardian", "Elder Guardian"),
new MobMapping("witherskeleton", "org.bukkit.entity.WitherSkeleton", "Wither Skeleton"),
new MobMapping("stray", "org.bukkit.entity.Stray", "Stray"),
new MobMapping("husk", "org.bukkit.entity.Husk", "Husk"),
new MobMapping("zombievillager", "org.bukkit.entity.ZombieVillager", "Zombie Villager"),
new MobMapping("evoker", "org.bukkit.entity.Evoker", "Evoker"),
new MobMapping("vex", "org.bukkit.entity.Vex", "Vex"),
new MobMapping("vindicator", "org.bukkit.entity.Vindicator", "Vindicator"),
new MobMapping("creeper", "org.bukkit.entity.Creeper", "Creeper"),
new MobMapping("skeleton", "org.bukkit.entity.Skeleton", "Skeleton"),
new MobMapping("giant", "org.bukkit.entity.Giant", "Giant"),
new MobMapping("ghast", "org.bukkit.entity.Ghast", "Ghast"),
new MobMapping("drowned", "org.bukkit.entity.Drowned", "Drowned"),
new MobMapping("phantom", "org.bukkit.entity.Phantom", "Phantom"),
new MobMapping("zombiepigman", "org.bukkit.entity.PigZombie", "Zombie Pigman"),
new MobMapping("zombie", "org.bukkit.entity.Zombie", "Zombie"), /* Must be last zombie type */
new MobMapping("enderman", "org.bukkit.entity.Enderman", "Enderman"),
new MobMapping("cavespider", "org.bukkit.entity.CaveSpider", "Cave Spider"),
new MobMapping("spider", "org.bukkit.entity.Spider", "Spider"), /* Must be last spider type */
new MobMapping("spiderjockey", "org.bukkit.entity.Spider", "Spider Jockey"), /* Must be just after spider */
new MobMapping("silverfish", "org.bukkit.entity.Silverfish", "Silverfish"),
new MobMapping("blaze", "org.bukkit.entity.Blaze", "Blaze"),
new MobMapping("magmacube", "org.bukkit.entity.MagmaCube", "Magma Cube"),
new MobMapping("slime", "org.bukkit.entity.Slime", "Slime"), /* Must be last slime type */
new MobMapping("enderdragon", "org.bukkit.entity.EnderDragon", "Ender Dragon"),
new MobMapping("wither", "org.bukkit.entity.Wither", "Wither"),
new MobMapping("witch", "org.bukkit.entity.Witch", "Witch"),
new MobMapping("endermite", "org.bukkit.entity.Endermite", "Endermite"),
new MobMapping("guardian", "org.bukkit.entity.Guardian", "Guardian"),
new MobMapping("shulker", "org.bukkit.entity.Shulker", "Shulker"),
new MobMapping("ravager", "org.bukkit.entity.Ravager", "Ravager"),
new MobMapping("illusioner", "org.bukkit.entity.Illusioner", "Illusioner"),
new MobMapping("pillager", "org.bukkit.entity.Pillager", "Pillager")
};
private MobMapping config_passive_mobs[] = {
// Standard passive
new MobMapping("skeletonhorse", "org.bukkit.entity.SkeletonHorse", "Skeleton Horse"),
new MobMapping("zombiehorse", "org.bukkit.entity.ZombieHorse", "Zombie Horse"),
new MobMapping("donkey", "org.bukkit.entity.Donkey", "Donkey"),
new MobMapping("mule", "org.bukkit.entity.Mule", "Mule"),
new MobMapping("bat", "org.bukkit.entity.Bat", "Bat"),
new MobMapping("pig", "org.bukkit.entity.Pig", "Pig"),
new MobMapping("sheep", "org.bukkit.entity.Sheep", "Sheep"),
new MobMapping("cow", "org.bukkit.entity.Cow", "Cow"),
new MobMapping("chicken", "org.bukkit.entity.Chicken", "Chicken"),
new MobMapping("chickenjockey", "org.bukkit.entity.Chicken", "Chicken Jockey"), /* Must be just after chicken */
new MobMapping("squid", "org.bukkit.entity.Squid", "Squid"),
new MobMapping("wolf", "org.bukkit.entity.Wolf", "Wolf"),
new MobMapping("tamedwolf", "org.bukkit.entity.Wolf", "Wolf"), /* Must be just after wolf */
new MobMapping("mooshroom", "org.bukkit.entity.MushroomCow", "Mooshroom"),
new MobMapping("snowgolem", "org.bukkit.entity.Snowman", "Snow Golem"),
new MobMapping("ocelot", "org.bukkit.entity.Ocelot", "Ocelot"),
new MobMapping("cat", "org.bukkit.entity.Cat", "Cat"),
new MobMapping("golem", "org.bukkit.entity.IronGolem", "Iron Golem"),
new MobMapping("vanillahorse", "org.bukkit.entity.Horse", "Horse"),
new MobMapping("rabbit", "org.bukkit.entity.Rabbit", "Rabbit"),
new MobMapping("vanillapolarbear", "org.bukkit.entity.PolarBear", "Polar Bear"),
new MobMapping("llama", "org.bukkit.entity.Llama", "Llama"),
new MobMapping("traderllama", "org.bukkit.entity.TraderLlama", "Trader Llama"),
new MobMapping("wandering_trader", "org.bukkit.entity.WanderingTrader", "Wandering Trader"),
new MobMapping("villager", "org.bukkit.entity.Villager", "Villager"),
new MobMapping("vanilladolphin", "org.bukkit.entity.Dolphin", "Dolphin"),
new MobMapping("cod", "org.bukkit.entity.Cod", "Cod"),
new MobMapping("salmon", "org.bukkit.entity.Salmon", "Salmon"),
new MobMapping("pufferfish", "org.bukkit.entity.PufferFish", "Pufferfish"),
new MobMapping("tropicalfish", "org.bukkit.entity.TropicalFish", "Tropical Fish"),
new MobMapping("vanillaturtle", "org.bukkit.entity.Turtle", "Turtle"),
new MobMapping("parrot", "org.bukkit.entity.Parrot", "Parrot"),
new MobMapping("panda", "org.bukkit.entity.Panda", "Panda"),
new MobMapping("vanillafox", "org.bukkit.entity.Fox", "Fox" ),
new MobMapping("bee", "org.bukkit.entity.Bee", "Bee" )
};
private MobMapping config_vehicles[] = {
// Command Minecart
new MobMapping("command-minecart", "org.bukkit.entity.minecart.CommandMinecart", "Command Minecart"),
// Explosive Minecart
new MobMapping("explosive-minecart", "org.bukkit.entity.minecart.ExplosiveMinecart", "Explosive Minecart"),
// Hopper Minecart
new MobMapping("hopper-minecart", "org.bukkit.entity.minecart.HopperMinecart", "Hopper Minecart"),
// Powered Minecart
new MobMapping("powered-minecart", "org.bukkit.entity.minecart.PoweredMinecart", "Powered Minecart"),
// Rideable Minecart
new MobMapping("minecart", "org.bukkit.entity.minecart.RideableMinecart", "Minecart"),
// Spawner Minecart
new MobMapping("spawner-minecart", "org.bukkit.entity.minecart.SpawnerMinecart", "Spawner Minecart"),
// Storage Minecart
new MobMapping("storage-minecart", "org.bukkit.entity.minecart.StorageMinecart", "Storage Minecart"),
// Boat
new MobMapping("boat", "org.bukkit.entity.Boat", "Boat")
};
public static void info(String msg) {
log.log(Level.INFO, msg);
}
public static void severe(String msg) {
log.log(Level.SEVERE, msg);
}
private class MoCreatMobUpdate implements Runnable {
Map<Integer,Marker> newmap = new HashMap<Integer,Marker>(); /* Build new map */
ArrayList<World> worldsToDo = null;
List<LivingEntity> mobsToDo = null;
int mobIndex = 0;
World curWorld = null;
public void run() {
if(stop || mocreat_mobs == null || mocreat_mobs.length == 0 || mset == null ) {
return;
}
// If needed, prime world list
if (worldsToDo == null) {
worldsToDo = new ArrayList<World>(getServer().getWorlds());
}
while (mobsToDo == null) {
if (worldsToDo.isEmpty()) {
// Now, review old map - anything left is gone
for(Marker oldm : mocreat_mobicons.values()) {
oldm.deleteMarker();
}
// And replace with new map
mocreat_mobicons = newmap;
// Schedule next run
getServer().getScheduler().scheduleSyncDelayedTask(DynmapMobsPlugin.this, new MoCreatMobUpdate(), updperiod);
return;
}
else {
curWorld = worldsToDo.remove(0); // Get next world
mobsToDo = curWorld.getLivingEntities(); // Get living entities
mobIndex = 0;
if ((mobsToDo != null) && mobsToDo.isEmpty()) {
mobsToDo = null;
}
}
}
// Process up to limit per tick
for (int cnt = 0; cnt < updates_per_tick; cnt++) {
if (mobIndex >= mobsToDo.size()) {
mobsToDo = null;
break;
}
// Get next entity
LivingEntity le = mobsToDo.get(mobIndex);
mobIndex++;
int i;
/* See if entity is mob we care about */
String clsid = null;
if(gethandle != null) {
try {
clsid = gethandle.invoke(le).getClass().getName();
} catch (Exception x) {
}
}
if(clsid == null)
clsid = le.getClass().getName();
Integer idx = mlookup_cache.get(clsid);
if(idx == null) {
for(i = 0; i < mocreat_mobs.length; i++) {
if((mocreat_mobs[i].mobclass != null) && mocreat_mobs[i].mobclass.isInstance(le)){
if (mocreat_mobs[i].entclsid == null) {
break;
}
else if(gethandle != null) {
Object obcentity = null;
try {
obcentity = gethandle.invoke(le);
} catch (Exception x) {
}
if ((mocreat_mobs[i].entclass != null) && (obcentity != null) && (mocreat_mobs[i].entclass.isInstance(obcentity))) {
break;
}
}
}
}
mlookup_cache.put(clsid, i);
}
else {
i = idx;
}
if(i >= mocreat_mobs.length) {
continue;
}
String label = null;
if(i >= mocreat_mobs.length) {
continue;
}
if(label == null) {
label = mocreat_mobs[i].label;
}
if (le.getCustomName() != null) {
label = le.getCustomName() + " (" + label + ")";
}
Location loc = le.getLocation();
Block blk = null;
if(hideifshadow < 15) {
blk = loc.getBlock();
if(blk.getLightLevel() <= hideifshadow) {
continue;
}
}
if(hideifundercover < 15) {
if(blk == null) blk = loc.getBlock();
if(blk.getLightFromSky() <= hideifundercover) {
continue;
}
}
/* See if we already have marker */
double x = Math.round(loc.getX() / res) * res;
double y = Math.round(loc.getY() / res) * res;
double z = Math.round(loc.getZ() / res) * res;
Marker m = mocreat_mobicons.remove(le.getEntityId());
if(nolabels) {
label = "";
}
else if(inc_coord) {
label = label + " [" + (int)x + "," + (int)y + "," + (int)z + "]";
}
if(m == null) { /* Not found? Need new one */
m = mset.createMarker("mocreat_mob"+le.getEntityId(), label, curWorld.getName(), x, y, z, mocreat_mobs[i].icon, false);
}
else { /* Else, update position if needed */
m.setLocation(curWorld.getName(), x, y, z);
m.setLabel(label);
m.setMarkerIcon(mocreat_mobs[i].icon);
}
if (m != null) {
newmap.put(le.getEntityId(), m); /* Add to new map */
}
}
getServer().getScheduler().scheduleSyncDelayedTask(DynmapMobsPlugin.this, this, 1);
}
}
private class HostileMobUpdate implements Runnable {
Map<Integer,Marker> newmap = new HashMap<Integer,Marker>(); /* Build new map */
ArrayList<World> worldsToDo = null;
List<LivingEntity> mobsToDo = null;
int mobIndex = 0;
World curWorld = null;
public void run() {
if(stop || hostile_mobs == null || hostile_mobs.length == 0 || hset == null ) {
return;
}
// If needed, prime world list
if (worldsToDo == null) {
worldsToDo = new ArrayList<World>(getServer().getWorlds());
}
while (mobsToDo == null) {
if (worldsToDo.isEmpty()) {
// Now, review old map - anything left is gone
for(Marker oldm : hostile_mobicons.values()) {
oldm.deleteMarker();
}
// And replace with new map
hostile_mobicons = newmap;
// Schedule next run
getServer().getScheduler().scheduleSyncDelayedTask(DynmapMobsPlugin.this, new HostileMobUpdate(), updperiod);
return;
}
else {
curWorld = worldsToDo.remove(0); // Get next world
mobsToDo = curWorld.getLivingEntities(); // Get living entities
mobIndex = 0;
if ((mobsToDo != null) && mobsToDo.isEmpty()) {
mobsToDo = null;
}
}
}
// Process up to limit per tick
for (int cnt = 0; cnt < updates_per_tick; cnt++) {
if (mobIndex >= mobsToDo.size()) {
mobsToDo = null;
break;
}
// Get next entity
LivingEntity le = mobsToDo.get(mobIndex);
mobIndex++;
int i;
/* See if entity is mob we care about */
String clsid = null;
if(gethandle != null) {
try {
clsid = gethandle.invoke(le).getClass().getName();
} catch (Exception x) {
}
}
if(clsid == null)
clsid = le.getClass().getName();
Integer idx = hlookup_cache.get(clsid);
if(idx == null) {
for(i = 0; i < hostile_mobs.length; i++) {
if((hostile_mobs[i].mobclass != null) && hostile_mobs[i].mobclass.isInstance(le)){
if (hostile_mobs[i].entclsid == null) {
break;
}
else if(gethandle != null) {
Object obcentity = null;
try {
obcentity = gethandle.invoke(le);
} catch (Exception x) {
}
if ((hostile_mobs[i].entclass != null) && (obcentity != null) && (hostile_mobs[i].entclass.isInstance(obcentity))) {
break;
}
}
}
}
hlookup_cache.put(clsid, i);
}
else {
i = idx;
}
if(i >= hostile_mobs.length) {
continue;
}
String label = null;
if(hostile_mobs[i].mobid.equals("spider")) { /* Check for jockey */
if(le.getPassenger() != null) { /* Has passenger? */
i = findNext(i, "spiderjockey", hostile_mobs); /* Make jockey */
}
}
if(i >= hostile_mobs.length) {
continue;
}
if(label == null) {
label = hostile_mobs[i].label;
}
if (le.getCustomName() != null) {
label = le.getCustomName() + " (" + label + ")";
}
Location loc = le.getLocation();
Block blk = null;
if(hideifshadow < 15) {
blk = loc.getBlock();
if(blk.getLightLevel() <= hideifshadow) {
continue;
}
}
if(hideifundercover < 15) {
if(blk == null) blk = loc.getBlock();
if(blk.getLightFromSky() <= hideifundercover) {
continue;
}
}
/* See if we already have marker */
double x = Math.round(loc.getX() / res) * res;
double y = Math.round(loc.getY() / res) * res;
double z = Math.round(loc.getZ() / res) * res;
Marker m = hostile_mobicons.remove(le.getEntityId());
if(nolabels) {
label = "";
}
else if(inc_coord) {
label = label + " [" + (int)x + "," + (int)y + "," + (int)z + "]";
}
if(m == null) { /* Not found? Need new one */
m = hset.createMarker("hostile_mob"+le.getEntityId(), label, curWorld.getName(), x, y, z, hostile_mobs[i].icon, false);
}
else { /* Else, update position if needed */
m.setLocation(curWorld.getName(), x, y, z);
m.setLabel(label);
m.setMarkerIcon(hostile_mobs[i].icon);
}
if (m != null) {
newmap.put(le.getEntityId(), m); /* Add to new map */
}
}
getServer().getScheduler().scheduleSyncDelayedTask(DynmapMobsPlugin.this, this, 1);
}
}
private class PassiveMobUpdate implements Runnable {
Map<Integer,Marker> newmap = new HashMap<Integer,Marker>(); /* Build new map */
ArrayList<World> worldsToDo = null;
List<LivingEntity> mobsToDo = null;
int mobIndex = 0;
World curWorld = null;
public void run() {
if(stop || passive_mobs == null || passive_mobs.length == 0 || pset == null ) {
return;
}
// If needed, prime world list
if (worldsToDo == null) {
worldsToDo = new ArrayList<World>(getServer().getWorlds());
}
while (mobsToDo == null) {
if (worldsToDo.isEmpty()) {
// Now, review old map - anything left is gone
for(Marker oldm : passive_mobicons.values()) {
oldm.deleteMarker();
}
// And replace with new map
passive_mobicons = newmap;
// Schedule next run
getServer().getScheduler().scheduleSyncDelayedTask(DynmapMobsPlugin.this, new PassiveMobUpdate(), updperiod);
return;
}
else {
curWorld = worldsToDo.remove(0); // Get next world
mobsToDo = curWorld.getLivingEntities(); // Get living entities
mobIndex = 0;
if ((mobsToDo != null) && mobsToDo.isEmpty()) {
mobsToDo = null;
}
}
}
// Process up to limit per tick
for (int cnt = 0; cnt < updates_per_tick; cnt++) {
if (mobIndex >= mobsToDo.size()) {
mobsToDo = null;
break;
}
// Get next entity
LivingEntity le = mobsToDo.get(mobIndex);
mobIndex++;
int i;
/* See if entity is mob we care about */
String clsid = null;
if(gethandle != null) {
try {
clsid = gethandle.invoke(le).getClass().getName();
} catch (Exception x) {
}
}
if(clsid == null)
clsid = le.getClass().getName();
Integer idx = plookup_cache.get(clsid);
if(idx == null) {
for(i = 0; i < passive_mobs.length; i++) {
if((passive_mobs[i].mobclass != null) && passive_mobs[i].mobclass.isInstance(le)){
if (passive_mobs[i].entclsid == null) {
break;
}
else if(gethandle != null) {
Object obcentity = null;
try {
obcentity = gethandle.invoke(le);
} catch (Exception x) {
}
if ((passive_mobs[i].entclass != null) && (obcentity != null) && (passive_mobs[i].entclass.isInstance(obcentity))) {
break;
}
}
}
}
plookup_cache.put(clsid, i);
}
else {
i = idx;
}
if(i >= passive_mobs.length) {
continue;
}
String label = null;
if(passive_mobs[i].mobid.equals("chicken")) { /* Check for jockey */
if(le.getPassenger() != null) { /* Has passenger? */
i = findNext(i, "chickenjockey", passive_mobs); /* Make jockey , passive_mobs*/
}
}
else if(passive_mobs[i].mobid.equals("wolf")) { /* Check for tamed wolf */
Wolf wolf = (Wolf)le;
if(wolf.isTamed()) {
i = findNext(i, "tamedwolf", passive_mobs);
AnimalTamer t = wolf.getOwner();
if((t != null) && (t instanceof OfflinePlayer)) {
label = "Wolf (" + ((OfflinePlayer)t).getName() + ")";
}
}
}
else if(passive_mobs[i].mobid.equals("cat")) { /* Check for tamed cat */
Cat cat = (Cat)le;
if(cat.isTamed()) {
i = findNext(i, "cat", passive_mobs);
AnimalTamer t = cat.getOwner();
if((t != null) && (t instanceof OfflinePlayer)) {
label = "Cat (" + ((OfflinePlayer)t).getName() + ")";
}
}
}
else if(passive_mobs[i].mobid.equals("vanillahorse")) { /* Check for tamed horse */
Horse horse = (Horse)le;
if(horse.isTamed()) {
i = findNext(i, "vanillahorse", passive_mobs);
AnimalTamer t = horse.getOwner();
if((t != null) && (t instanceof OfflinePlayer)) {
label = "Horse (" + ((OfflinePlayer)t).getName() + ")";
}
}
}
else if(passive_mobs[i].mobid.equals("traderllama")) { /* Check for tamed traderllama */
TraderLlama traderllama = (TraderLlama)le;
if(traderllama.isTamed()) {
i = findNext(i, "traderllama", passive_mobs);
AnimalTamer t = traderllama.getOwner();
if((t != null) && (t instanceof OfflinePlayer)) {
label = "TraderLlama (" + ((OfflinePlayer)t).getName() + ")";
}
}
}
else if(passive_mobs[i].mobid.equals("llama")) { /* Check for tamed llama */
Llama llama = (Llama)le;
if(llama.isTamed()) {
i = findNext(i, "llama", passive_mobs);
AnimalTamer t = llama.getOwner();
if((t != null) && (t instanceof OfflinePlayer)) {
label = "Llama (" + ((OfflinePlayer)t).getName() + ")";
}
}
}
else if(passive_mobs[i].mobid.equals("parrot")) { /* Check for tamed parrot */
Parrot parrot = (Parrot)le;
if(parrot.isTamed()) {
i = findNext(i, "parrot", passive_mobs);
AnimalTamer t = parrot.getOwner();
if((t != null) && (t instanceof OfflinePlayer)) {
label = "Parrot (" + ((OfflinePlayer)t).getName() + ")";
}
}
}
else if(passive_mobs[i].mobid.equals("villager")) {
Villager v = (Villager)le;
Profession p = v.getProfession();
if(p != null) {
switch(p) {
case NONE:
label = "Villager";
break;
case ARMORER:
label = "Armorer";
break;
case BUTCHER:
label = "Butcher";
break;
case CARTOGRAPHER:
label = "Cartographer";
break;
case CLERIC:
label = "Cleric";
break;
case FARMER:
label = "Farmer";
break;
case FISHERMAN:
label = "Fisherman";
break;
case FLETCHER:
label = "Fletcher";
break;
case LEATHERWORKER:
label = "Leatherworker";
break;
case LIBRARIAN:
label = "Librarian";
break;
case MASON:
label = "Mason";
break;
case NITWIT:
label = "Nitwit";
break;
case SHEPHERD:
label = "Shepherd";
break;
case TOOLSMITH:
label = "Toolsmith";
break;
case WEAPONSMITH:
label = "Weaponsmith";
break;
}
}
}
else if(passive_mobs[i].mobid.equals("vanillahorse")
|| passive_mobs[i].mobid.equals("llama")
|| passive_mobs[i].mobid.equals("traderllama")
|| passive_mobs[i].mobid.equals("donkey")
|| passive_mobs[i].mobid.equals("mule")
|| passive_mobs[i].mobid.equals("zombiehorse")
|| passive_mobs[i].mobid.equals("skeletonhorse")) { /* Check for rider */
if(le.getPassenger() != null) { /* Has passenger? */
Entity e = le.getPassenger();
if (e instanceof Player) {
label = label + " (" + ((Player)e).getName() + ")";
}
}
}
if(i >= passive_mobs.length) {
continue;
}
if(label == null) {
label = passive_mobs[i].label;
}
if (le.getCustomName() != null) {
label = le.getCustomName() + " (" + label + ")";
}
Location loc = le.getLocation();
Block blk = null;
if(hideifshadow < 15) {
blk = loc.getBlock();
if(blk.getLightLevel() <= hideifshadow) {
continue;
}
}
if(hideifundercover < 15) {
if(blk == null) blk = loc.getBlock();
if(blk.getLightFromSky() <= hideifundercover) {
continue;
}
}
/* See if we already have marker */
double x = Math.round(loc.getX() / res) * res;
double y = Math.round(loc.getY() / res) * res;
double z = Math.round(loc.getZ() / res) * res;
Marker m = passive_mobicons.remove(le.getEntityId());
if(nolabels) {
label = "";
}
else if(inc_coord) {
label = label + " [" + (int)x + "," + (int)y + "," + (int)z + "]";
}
if(m == null) { /* Not found? Need new one */
m = pset.createMarker("passive_mob"+le.getEntityId(), label, curWorld.getName(), x, y, z, passive_mobs[i].icon, false);
}
else { /* Else, update position if needed */
m.setLocation(curWorld.getName(), x, y, z);
m.setLabel(label);
m.setMarkerIcon(passive_mobs[i].icon);
}
if (m != null) {
newmap.put(le.getEntityId(), m); /* Add to new map */
}
}
getServer().getScheduler().scheduleSyncDelayedTask(DynmapMobsPlugin.this, this, 1);
}
}
private class VehicleUpdate implements Runnable {
Map<Integer,Marker> newmap = new HashMap<Integer,Marker>(); /* Build new map */
ArrayList<World> worldsToDo = null;
List<Entity> vehiclesToDo = null;
int vehiclesIndex = 0;
World curWorld = null;
public void run() {
if(stop || (vehicles == null) || (vehicles.length == 0) || (vset == null)) {
return;
}
// If needed, prime world list
if (worldsToDo == null) {
worldsToDo = new ArrayList<World>(getServer().getWorlds());
}
while (vehiclesToDo == null) {
if (worldsToDo.isEmpty()) {
// Now, review old map - anything left is gone
for(Marker oldm : vehicleicons.values()) {
oldm.deleteMarker();
}
// And replace with new map
vehicleicons = newmap;
// Schedule next run
getServer().getScheduler().scheduleSyncDelayedTask(DynmapMobsPlugin.this, new VehicleUpdate(), vupdperiod);
return;
}
else {
curWorld = worldsToDo.remove(0); // Get next world
vehiclesToDo = new ArrayList<Entity>(curWorld.getEntitiesByClasses(org.bukkit.entity.Vehicle.class)); // Get vehicles
vehiclesIndex = 0;
if ((vehiclesToDo != null) && vehiclesToDo.isEmpty()) {
vehiclesToDo = null;
}
}
}
// Process up to limit per tick
for (int cnt = 0; cnt < vupdates_per_tick; cnt++) {
if (vehiclesIndex >= vehiclesToDo.size()) {
vehiclesToDo = null;
break;
}
// Get next entity
Entity le = vehiclesToDo.get(vehiclesIndex);
vehiclesIndex++;
int i;
/* See if entity is vehicle we care about */
String clsid = null;
if(gethandle != null) {
try {
clsid = gethandle.invoke(le).getClass().getName();
} catch (Exception x) {
}
}
if(clsid == null)
clsid = le.getClass().getName();
Integer idx = vlookup_cache.get(clsid);
if(idx == null) {
for(i = 0; i < vehicles.length; i++) {
if((vehicles[i].mobclass != null) && vehicles[i].mobclass.isInstance(le)){
if (vehicles[i].entclsid == null) {
break;
}
else if(gethandle != null) {
Object obcentity = null;
try {
obcentity = gethandle.invoke(le);
} catch (Exception x) {
}
if ((vehicles[i].entclass != null) && (obcentity != null) && (vehicles[i].entclass.isInstance(obcentity))) {
break;
}
}
}
}
vlookup_cache.put(clsid, i);
}
else {
i = idx;
}
if(i >= vehicles.length) {
continue;
}
String label = null;
if(i >= vehicles.length) {
continue;
}
if(label == null) {
label = vehicles[i].label;
}
Location loc = le.getLocation();
if(curWorld.isChunkLoaded(loc.getBlockX() >> 4, loc.getBlockZ() >> 4) == false) {
continue;
}
Block blk = null;
if(hideifshadow < 15) {
blk = loc.getBlock();
if(blk.getLightLevel() <= hideifshadow) {
continue;
}
}
if(hideifundercover < 15) {
if(blk == null) blk = loc.getBlock();
if(blk.getLightFromSky() <= hideifundercover) {
continue;
}
}
/* See if we already have marker */
double x = Math.round(loc.getX() / res) * res;
double y = Math.round(loc.getY() / res) * res;
double z = Math.round(loc.getZ() / res) * res;
Marker m = vehicleicons.remove(le.getEntityId());
if(vnolabels)
label = "";
else if(vinc_coord) {
label = label + " [" + (int)x + "," + (int)y + "," + (int)z + "]";
}
if(m == null) { /* Not found? Need new one */
m = vset.createMarker("vehicle"+le.getEntityId(), label, curWorld.getName(), x, y, z, vehicles[i].icon, false);
}
else { /* Else, update position if needed */
m.setLocation(curWorld.getName(), x, y, z);
m.setLabel(label);
m.setMarkerIcon(vehicles[i].icon);
}
newmap.put(le.getEntityId(), m); /* Add to new map */
}
getServer().getScheduler().scheduleSyncDelayedTask(DynmapMobsPlugin.this, this, 1);
}
}
private int findNext(int idx, String mobid, MobMapping[] mobs) {
idx++;
if ((idx < mobs.length) && mobs[idx].mobid.equals(mobid)) {
return idx;
}
else {
return mobs.length;
}
}
private class OurServerListener implements Listener {
@EventHandler(priority=EventPriority.MONITOR)
public void onPluginEnable(PluginEnableEvent event) {
Plugin p = event.getPlugin();
String name = p.getDescription().getName();
if(name.equals("dynmap")) {
activate();
}
}
}
public void onEnable() {
info("initializing");
PluginManager pm = getServer().getPluginManager();
/* Get dynmap */
dynmap = pm.getPlugin("dynmap");
if(dynmap == null) {
severe("Cannot find dynmap!");
return;
}
api = (DynmapAPI)dynmap; /* Get API */
getServer().getPluginManager().registerEvents(new OurServerListener(), this);
/* If enabled, activate */
if(dynmap.isEnabled())
activate();
try {
MetricsLite ml = new MetricsLite(this);
ml.start();
} catch (IOException iox) {
}
}