@@ -55,11 +55,16 @@ public class DynmapMobsPlugin extends JavaPlugin {
55
55
boolean nolabels ;
56
56
boolean vtinyicons ;
57
57
boolean vnolabels ;
58
+ boolean inc_coord ;
59
+ boolean vinc_coord ;
58
60
boolean stop ;
59
61
boolean reload = false ;
60
62
static String obcpackage ;
61
63
Method gethandle ;
62
64
65
+ HashMap <String , Integer > lookup_cache = new HashMap <String , Integer >();
66
+ HashMap <String , Integer > vlookup_cache = new HashMap <String , Integer >();
67
+
63
68
public static String mapClassName (String n ) {
64
69
if (n .startsWith ("org.bukkit.craftbukkit" )) {
65
70
return obcpackage + n .substring ("org.bukkit.craftbukkit" .length ());
@@ -219,22 +224,38 @@ private void updateMobs() {
219
224
int i ;
220
225
221
226
/* See if entity is mob we care about */
222
- for (i = 0 ; i < mobs .length ; i ++) {
223
- if ((mobs [i ].mobclass != null ) && mobs [i ].mobclass .isInstance (le )){
224
- if (mobs [i ].entclsid == null ) {
225
- break ;
226
- }
227
- else if (gethandle != null ) {
228
- Object obcentity = null ;
229
- try {
230
- obcentity = gethandle .invoke (le );
231
- } catch (Exception x ) {
232
- }
233
- if ((mobs [i ].entclass != null ) && (obcentity != null ) && (mobs [i ].entclass .isInstance (obcentity ))) {
227
+ String clsid = null ;
228
+ if (gethandle != null ) {
229
+ try {
230
+ clsid = gethandle .invoke (le ).getClass ().getName ();
231
+ } catch (Exception x ) {
232
+ }
233
+ }
234
+ if (clsid == null )
235
+ clsid = le .getClass ().getName ();
236
+ Integer idx = lookup_cache .get (clsid );
237
+ if (idx == null ) {
238
+ for (i = 0 ; i < mobs .length ; i ++) {
239
+ if ((mobs [i ].mobclass != null ) && mobs [i ].mobclass .isInstance (le )){
240
+ if (mobs [i ].entclsid == null ) {
234
241
break ;
235
242
}
243
+ else if (gethandle != null ) {
244
+ Object obcentity = null ;
245
+ try {
246
+ obcentity = gethandle .invoke (le );
247
+ } catch (Exception x ) {
248
+ }
249
+ if ((mobs [i ].entclass != null ) && (obcentity != null ) && (mobs [i ].entclass .isInstance (obcentity ))) {
250
+ break ;
251
+ }
252
+ }
236
253
}
237
254
}
255
+ lookup_cache .put (clsid , i );
256
+ }
257
+ else {
258
+ i = idx ;
238
259
}
239
260
if (i >= mobs .length ) {
240
261
continue ;
@@ -326,8 +347,12 @@ else if(mobs[i].mobid.equals("villager")) {
326
347
double y = Math .round (loc .getY () / res ) * res ;
327
348
double z = Math .round (loc .getZ () / res ) * res ;
328
349
Marker m = mobicons .remove (le .getEntityId ());
329
- if (nolabels )
350
+ if (nolabels ) {
330
351
label = "" ;
352
+ }
353
+ else if (inc_coord ) {
354
+ label = label + " [" + (int )x + "," + (int )y + "," + (int )z + "]" ;
355
+ }
331
356
if (m == null ) { /* Not found? Need new one */
332
357
m = set .createMarker ("mob" +le .getEntityId (), label , w .getName (), x , y , z , mobs [i ].icon , false );
333
358
}
@@ -359,22 +384,38 @@ private void updateVehicles() {
359
384
int i ;
360
385
361
386
/* See if entity is vehicle we care about */
362
- for (i = 0 ; i < vehicles .length ; i ++) {
363
- if ((vehicles [i ].mobclass != null ) && vehicles [i ].mobclass .isInstance (le )){
364
- if (vehicles [i ].entclsid == null ) {
365
- break ;
366
- }
367
- else if (gethandle != null ) {
368
- Object obcentity = null ;
369
- try {
370
- obcentity = gethandle .invoke (le );
371
- } catch (Exception x ) {
372
- }
373
- if ((vehicles [i ].entclass != null ) && (obcentity != null ) && (vehicles [i ].entclass .isInstance (obcentity ))) {
387
+ String clsid = null ;
388
+ if (gethandle != null ) {
389
+ try {
390
+ clsid = gethandle .invoke (le ).getClass ().getName ();
391
+ } catch (Exception x ) {
392
+ }
393
+ }
394
+ if (clsid == null )
395
+ clsid = le .getClass ().getName ();
396
+ Integer idx = vlookup_cache .get (clsid );
397
+ if (idx == null ) {
398
+ for (i = 0 ; i < vehicles .length ; i ++) {
399
+ if ((vehicles [i ].mobclass != null ) && vehicles [i ].mobclass .isInstance (le )){
400
+ if (vehicles [i ].entclsid == null ) {
374
401
break ;
375
402
}
403
+ else if (gethandle != null ) {
404
+ Object obcentity = null ;
405
+ try {
406
+ obcentity = gethandle .invoke (le );
407
+ } catch (Exception x ) {
408
+ }
409
+ if ((vehicles [i ].entclass != null ) && (obcentity != null ) && (vehicles [i ].entclass .isInstance (obcentity ))) {
410
+ break ;
411
+ }
412
+ }
376
413
}
377
414
}
415
+ vlookup_cache .put (clsid , i );
416
+ }
417
+ else {
418
+ i = idx ;
378
419
}
379
420
if (i >= vehicles .length ) {
380
421
continue ;
@@ -409,8 +450,11 @@ else if(gethandle != null) {
409
450
double y = Math .round (loc .getY () / res ) * res ;
410
451
double z = Math .round (loc .getZ () / res ) * res ;
411
452
Marker m = vehicleicons .remove (le .getEntityId ());
412
- if (nolabels )
453
+ if (vnolabels )
413
454
label = "" ;
455
+ else if (vinc_coord ) {
456
+ label = label + " [" + (int )x + "," + (int )y + "," + (int )z + "]" ;
457
+ }
414
458
if (m == null ) { /* Not found? Need new one */
415
459
m = vset .createMarker ("vehicle" +le .getEntityId (), label , w .getName (), x , y , z , vehicles [i ].icon , false );
416
460
}
@@ -500,6 +544,7 @@ private void activate() {
500
544
}
501
545
mobicons .clear ();
502
546
vehicleicons .clear ();
547
+ lookup_cache .clear ();
503
548
}
504
549
else {
505
550
reload = true ;
@@ -562,6 +607,7 @@ private void activate() {
562
607
set .setMinZoom (minzoom );
563
608
tinyicons = cfg .getBoolean ("layer.tinyicons" , false );
564
609
nolabels = cfg .getBoolean ("layer.nolabels" , false );
610
+ inc_coord = cfg .getBoolean ("layer.inc-coord" , false );
565
611
/* Get position resolution */
566
612
res = cfg .getDouble ("update.resolution" , 1.0 );
567
613
/* Set up update job - based on period */
@@ -627,6 +673,7 @@ private void activate() {
627
673
vset .setMinZoom (minzoom );
628
674
vtinyicons = cfg .getBoolean ("vehiclelayer.tinyicons" , false );
629
675
vnolabels = cfg .getBoolean ("vehiclelayer.nolabels" , false );
676
+ vinc_coord = cfg .getBoolean ("vehiclelayer.inc-coord" , false );
630
677
/* Get position resolution */
631
678
res = cfg .getDouble ("update.resolution" , 1.0 );
632
679
/* Set up update job - based on period */
@@ -655,6 +702,7 @@ public void onDisable() {
655
702
}
656
703
mobicons .clear ();
657
704
vehicleicons .clear ();
705
+ lookup_cache .clear ();
658
706
stop = true ;
659
707
}
660
708
0 commit comments