20
20
import org .bukkit .ChatColor ;
21
21
import org .bukkit .Location ;
22
22
import org .bukkit .Material ;
23
+ import org .bukkit .Server ;
24
+ import org .bukkit .UnsafeValues ;
23
25
import org .bukkit .block .Block ;
24
26
import org .bukkit .block .BlockState ;
25
27
import org .bukkit .block .CreatureSpawner ;
41
43
import com .sk89q .worldguard .protection .flags .Flags ;
42
44
import com .sk89q .worldguard .protection .regions .RegionContainer ;
43
45
import com .sk89q .worldguard .protection .regions .RegionQuery ;
46
+ import com .vdurmont .semver4j .Semver ;
44
47
45
48
import de .dustplanet .silkspawners .SilkSpawners ;
46
49
import de .dustplanet .silkspawners .compat .api .NMSProvider ;
@@ -160,7 +163,21 @@ private boolean setupNMSProvider() {
160
163
// Rare cases might trigger API usage before SilkSpawners
161
164
if (version == null ) {
162
165
final String packageName = Bukkit .getServer ().getClass ().getPackage ().getName ();
163
- version = (packageName .substring (packageName .lastIndexOf ('.' ) + 1 ));
166
+ String nmsVersion = packageName .substring (packageName .lastIndexOf ('.' ) + 1 );
167
+ if (nmsVersion .equals ("craftbukkit" )) {
168
+ try {
169
+ String minecraftVersion = (String ) Server .class .getDeclaredMethod ("getMinecraftVersion" ).invoke (Bukkit .getServer ());
170
+ Semver semver = new Semver (minecraftVersion );
171
+ if (semver .isGreaterThanOrEqualTo ("1.20.5" )) {
172
+ @ SuppressWarnings ("deprecation" )
173
+ int protocolVersion = (Integer ) UnsafeValues .class .getDeclaredMethod ("getProtocolVersion" )
174
+ .invoke (Bukkit .getUnsafe ());
175
+ version = SilkSpawners .PROTOCOL_VERSION_PACKAGE_MAP .get (protocolVersion );
176
+ }
177
+ } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e ) {
178
+ e .printStackTrace ();
179
+ }
180
+ }
164
181
}
165
182
166
183
final FileConfiguration config = plugin .getConfig ();
@@ -320,7 +337,7 @@ public boolean isVanillaBossBar() {
320
337
*
321
338
* @deprecated Use {@link SilkUtil#newEggItem(String, int, String)} instead.
322
339
* @param entityID which mob should be spawned
323
- * @param amount the amount of spawn eggs
340
+ * @param amount the amount of spawn eggs
324
341
* @return the ItemStack
325
342
*/
326
343
@ Deprecated
@@ -331,8 +348,8 @@ public ItemStack newEggItem(final String entityID, final int amount) {
331
348
/**
332
349
* Returns a new ItemStack of a spawn egg with the specified amount and mob.
333
350
*
334
- * @param entityID which mob should be spawned
335
- * @param amount the amount of spawn eggs
351
+ * @param entityID which mob should be spawned
352
+ * @param amount the amount of spawn eggs
336
353
* @param displayName the display name of the egg in case of unknown entities
337
354
* @return the ItemStack
338
355
*/
@@ -344,10 +361,10 @@ public ItemStack newEggItem(final String entityID, final int amount, final Strin
344
361
/**
345
362
* This method will make a new MobSpawner with a custom entityID, name and amount.
346
363
*
347
- * @param entityID the mob
364
+ * @param entityID the mob
348
365
* @param customName if the MobSpawner should be named different
349
- * @param amount the wanted amount
350
- * @param forceLore whether the lore tag should be forces
366
+ * @param amount the wanted amount
367
+ * @param forceLore whether the lore tag should be forces
351
368
* @return the ItemStack with the configured options
352
369
*/
353
370
public ItemStack newSpawnerItem (final String entityID , final String customName , final int amount , final boolean forceLore ) {
@@ -395,10 +412,12 @@ public String getStoredEggEntityID(final ItemStack item) {
395
412
if (isUsingReflection ()) {
396
413
// Now try reflection for NBT tag
397
414
entityID = nmsProvider .getSilkSpawnersNBTEntityID (item );
415
+ plugin .getLogger ().log (Level .FINE , "EntityID from egg item stack (custom tag) is {0}" , entityID );
398
416
if (entityID != null ) {
399
417
return entityID ;
400
418
}
401
419
entityID = nmsProvider .getVanillaEggNBTEntityID (item );
420
+ plugin .getLogger ().log (Level .FINE , "EntityID from egg item stack (vanilla tag) is {0}" , entityID );
402
421
if (entityID != null ) {
403
422
return entityID ;
404
423
}
@@ -423,10 +442,12 @@ public String getStoredEggEntityID(final ItemStack item) {
423
442
public String getStoredSpawnerItemEntityID (final ItemStack item ) {
424
443
if (isUsingReflection ()) {
425
444
String entityID = nmsProvider .getSilkSpawnersNBTEntityID (item );
445
+ plugin .getLogger ().log (Level .FINE , "EntityID from item stack (custom tag) is {0}" , entityID );
426
446
if (StringUtils .isNotBlank (entityID )) {
427
447
return entityID ;
428
448
}
429
449
entityID = nmsProvider .getVanillaNBTEntityID (item );
450
+ plugin .getLogger ().log (Level .FINE , "EntityID from item stack (vanilla tag) is {0}" , entityID );
430
451
if (StringUtils .isNotBlank (entityID )) {
431
452
return entityID .replace ("minecraft:" , "" );
432
453
}
@@ -505,7 +526,7 @@ public String getSpawnerEntityID(final Block block) {
505
526
/**
506
527
* Set the specified MonterSpawner to another entity ID.
507
528
*
508
- * @param block MonsterSpawner
529
+ * @param block MonsterSpawner
509
530
* @param entity the wanted entity
510
531
*/
511
532
public void setSpawnerEntityID (final Block block , final String entity ) {
@@ -539,9 +560,9 @@ public void setSpawnerEntityID(final Block block, final String entity) {
539
560
/**
540
561
* Set a spawner (if allowed) to a new mob.
541
562
*
542
- * @param block the MonsterSpawner
543
- * @param entityID the new entity ID
544
- * @param player the player
563
+ * @param block the MonsterSpawner
564
+ * @param entityID the new entity ID
565
+ * @param player the player
545
566
* @param messageDenied the message which is shown, when the player can't build here see {@link #canBuildHere(Player, Location)}
546
567
* @return whether the operation was successful or not
547
568
*/
@@ -559,8 +580,8 @@ public boolean setSpawnerType(final Block block, final String entityID, final Pl
559
580
/**
560
581
* Sets a spawner item or egg to a new ID.
561
582
*
562
- * @param item ItemStack (Egg or Spawner)
563
- * @param entityID wanted entity ID
583
+ * @param item ItemStack (Egg or Spawner)
584
+ * @param entityID wanted entity ID
564
585
* @param customName if a custom name should be used (null for none)
565
586
* @return the updated ItemStack
566
587
*/
@@ -706,7 +727,7 @@ public List<String> scanEntityMap() {
706
727
/**
707
728
* Notify a player about the spawner.
708
729
*
709
- * @param player the player
730
+ * @param player the player
710
731
* @param spawnerName the creature name
711
732
*/
712
733
@ SuppressWarnings ("deprecation" )
@@ -892,7 +913,7 @@ private void getWorldGuard() {
892
913
/**
893
914
* Checks if a player can build here (WorldGuard).
894
915
*
895
- * @param player the player
916
+ * @param player the player
896
917
* @param location the location to check
897
918
* @return the result, true or false
898
919
*/
@@ -934,9 +955,9 @@ public boolean isLegacySpawnEggs() {
934
955
/**
935
956
* Helper methods to check if a player has any of the aliases permissions for a given mobID.
936
957
*
937
- * @param permissible - the permissible to check the permission for
958
+ * @param permissible - the permissible to check the permission for
938
959
* @param basePermission - the basis permission without the specific mob
939
- * @param entityID - the internal mob ID (not display name)
960
+ * @param entityID - the internal mob ID (not display name)
940
961
* @return the permission check result, true if the player has got the permission, false otherwise
941
962
*/
942
963
public boolean hasPermission (final Permissible permissible , final String basePermission , final String entityID ) {
0 commit comments