2828import com .comphenix .protocol .reflect .StructureModifier ;
2929import com .comphenix .protocol .utility .MinecraftVersion ;
3030import com .comphenix .protocol .wrappers .WrappedChatComponent ;
31+ import com .comphenix .protocol .wrappers .WrappedDataValue ;
3132import com .comphenix .protocol .wrappers .WrappedDataWatcher ;
33+ import com .comphenix .protocol .wrappers .WrappedWatchableObject ;
3234import org .bukkit .Chunk ;
3335import org .bukkit .Location ;
3436import org .bukkit .Material ;
4648import org .maxgamer .quickshop .util .GameVersion ;
4749import org .maxgamer .quickshop .util .Util ;
4850
49- import java .util .*;
51+ import java .util .ArrayList ;
52+ import java .util .Collection ;
53+ import java .util .Collections ;
54+ import java .util .Iterator ;
55+ import java .util .List ;
56+ import java .util .Map ;
57+ import java .util .Objects ;
58+ import java .util .Optional ;
59+ import java .util .Set ;
60+ import java .util .UUID ;
5061import java .util .concurrent .ConcurrentHashMap ;
5162import java .util .concurrent .ConcurrentSkipListSet ;
5263import java .util .concurrent .atomic .AtomicBoolean ;
@@ -391,7 +402,7 @@ private static PacketContainer createFakeItemSpawnPacket(int entityID, Location
391402 default :
392403 //For 1.14+, we should use EntityType
393404 fakeItemPacket .getEntityTypeModifier ().write (0 , EntityType .DROPPED_ITEM );
394- if (VERSION != GameVersion .v1_19_R1 ) {
405+ if (VERSION . ordinal () < GameVersion .v1_19_R1 . ordinal () ) {
395406 //int data to marking there have velocity (at last field)
396407 integerStructureModifier .write (integerStructureModifier .getFields ().size () - 1 , 1 );
397408 }
@@ -445,7 +456,7 @@ private static PacketContainer createFakeItemMetaPacket(int entityID, ItemStack
445456
446457 //Must in the certain slot:https://wiki.vg/Entity_metadata#Item
447458 //Is 1.17-?
448- if (GameVersion . v1_17_R1 . ordinal () > VERSION .ordinal ()) {
459+ if (VERSION . ordinal () < GameVersion . v1_17_R1 .ordinal ()) {
449460// if (version == GameVersion.v1_13_R1 || version == GameVersion.v1_13_R2) {
450461// //For 1.13 is 6
451462// wpw.setObject(6, WrappedDataWatcher.Registry.getItemStackSerializer(false), itemStack);
@@ -458,7 +469,24 @@ private static PacketContainer createFakeItemMetaPacket(int entityID, ItemStack
458469 wpw .setObject (8 , WrappedDataWatcher .Registry .getItemStackSerializer (false ), itemStack );
459470 }
460471 //Add it
461- fakeItemMetaPacket .getWatchableCollectionModifier ().write (0 , wpw .getWatchableObjects ());
472+ //For 1.19.2+, we need to use DataValue instead of WatchableObject
473+ if (VERSION .ordinal () > GameVersion .v1_19_R1 .ordinal ()) {
474+ //Check for new version protocolLib
475+ try {
476+ Class .forName ("com.comphenix.protocol.wrappers.WrappedDataValue" );
477+ } catch (ClassNotFoundException e ) {
478+ throw new RuntimeException ("Unable to initialize packet, ProtocolLib update needed" , e );
479+ }
480+ //Convert List<WrappedWatchableObject> to List<WrappedDataValue>
481+ List <WrappedWatchableObject > wrappedWatchableObjects = wpw .getWatchableObjects ();
482+ List <WrappedDataValue > wrappedDataValues = new java .util .ArrayList <>(wrappedWatchableObjects .size ());
483+ for (WrappedWatchableObject watchableObject : wrappedWatchableObjects ) {
484+ wrappedDataValues .set (watchableObject .getIndex (), new WrappedDataValue (watchableObject .getHandle ()));
485+ }
486+ fakeItemMetaPacket .getDataValueCollectionModifier ().write (0 , wrappedDataValues );
487+ } else {
488+ fakeItemMetaPacket .getWatchableCollectionModifier ().write (0 , wpw .getWatchableObjects ());
489+ }
462490 return fakeItemMetaPacket ;
463491 }
464492
@@ -480,7 +508,7 @@ private static PacketContainer createFakeItemVelocityPacket(int entityID) {
480508 private static PacketContainer createFakeItemDestroyPacket (int entityID ) {
481509 //Also make a DestroyPacket to remove it
482510 PacketContainer fakeItemDestroyPacket = PROTOCOL_MANAGER .createPacket (PacketType .Play .Server .ENTITY_DESTROY );
483- if (GameVersion . v1_17_R1 . ordinal () > VERSION .ordinal ()) {
511+ if (VERSION . ordinal () < GameVersion . v1_17_R1 .ordinal ()) {
484512 //On 1.17-, we need to write an integer array
485513 //Entity to remove
486514 fakeItemDestroyPacket .getIntegerArrays ().write (0 , new int []{entityID });
@@ -492,7 +520,7 @@ private static PacketContainer createFakeItemDestroyPacket(int entityID) {
492520 //Entity to remove
493521 fakeItemDestroyPacket .getIntegers ().write (0 , entityID );
494522 } else {
495- //On 1.17.1 (may be 1.17.1+? it's enough, Mojang, stop the changes), we need add the int list
523+ //On 1.17.1 (maybe 1.17.1+? it's enough, Mojang, stop the changes), we need add the int list
496524 //Entity to remove
497525 try {
498526 fakeItemDestroyPacket .getIntLists ().write (0 , Collections .singletonList (entityID ));
0 commit comments