7171import com .google .common .base .Strings ;
7272import com .google .common .collect .BiMap ;
7373import com .google .common .collect .HashBiMap ;
74- import io .netty .util .internal .PlatformDependent ;
7574import it .unimi .dsi .fastutil .bytes .ByteOpenHashSet ;
7675import it .unimi .dsi .fastutil .ints .Int2ObjectOpenHashMap ;
7776import it .unimi .dsi .fastutil .ints .IntArrayList ;
@@ -171,7 +170,7 @@ public class Player extends EntityHuman implements CommandSender, InventoryHolde
171170 protected Vector3 newPosition ;
172171 protected Vector3 sleeping ;
173172 private BlockVector3 lastRightClickPos ;
174- private final Queue <Vector3 > clientMovements = PlatformDependent . newMpscQueue ( 4 );
173+ private Queue <Vector3 > clientMovements = new ArrayDeque <>( );
175174
176175 protected boolean connected = true ;
177176 protected final InetSocketAddress socketAddress ;
@@ -254,6 +253,10 @@ public class Player extends EntityHuman implements CommandSender, InventoryHolde
254253 protected Map <Integer , FormWindow > serverSettings = new Int2ObjectOpenHashMap <>();
255254
256255 protected Map <Long , DummyBossBar > dummyBossBars = new Long2ObjectLinkedOpenHashMap <>();
256+ /**
257+ * Requested resource pack chunks
258+ */
259+ private Map <UUID , IntOpenHashSet > resourceChunksRequested = new HashMap <>();
257260
258261 private AsyncTask preLoginEventTask ;
259262 protected boolean shouldLogin ;
@@ -872,7 +875,9 @@ public String getDisplayName() {
872875 public void setDisplayName (String displayName ) {
873876 if (displayName == null ) {
874877 displayName = "" ;
875- server .getLogger ().debug ("Warning: setDisplayName: argument is null" , new Throwable ("" ));
878+ if (Nukkit .DEBUG > 1 ) {
879+ server .getLogger ().debug ("Warning: setDisplayName: argument is null" , new Throwable ("" ));
880+ }
876881 }
877882 this .displayName = displayName ;
878883 updatePlayerListData (true );
@@ -995,7 +1000,9 @@ public String getButtonText() {
9951000 public void setButtonText (String text ) {
9961001 if (text == null ) {
9971002 text = "" ;
998- server .getLogger ().debug ("Warning: setButtonText: argument is null" , new Throwable ("" ));
1003+ if (Nukkit .DEBUG > 1 ) {
1004+ server .getLogger ().debug ("Warning: setButtonText: argument is null" , new Throwable ("" ));
1005+ }
9991006 }
10001007 if (!text .equals (buttonText )) {
10011008 this .buttonText = text ;
@@ -2419,9 +2426,29 @@ public boolean onUpdate(int currentTick) {
24192426 Math .cos (Math .toRadians (this .yaw )) * Math .cos (Math .toRadians (this .pitch )) * multiplier ));
24202427 }
24212428
2422- if (this .age % 5 == 0 && this .isBreakingBlock () && !this .isCreative ()) {
2423- //this.level.addLevelSoundEvent(this.breakingBlock, LevelSoundEventPacket.SOUND_HIT, blockRuntimeId);
2424- this .level .addParticle (new PunchBlockParticle (this .breakingBlock , this .breakingBlock , this .breakingBlockFace ));
2429+ if (this .age % 5 == 0 ) {
2430+ if (this .isBreakingBlock () && !this .isCreative ()) {
2431+ /*if (this.protocol >= ProtocolInfo.v1_20_0_23) {
2432+ this.level.addLevelSoundEvent(this.breakingBlock, LevelSoundEventPacket.SOUND_HIT, blockRuntimeId);
2433+ }*/
2434+ this .level .addParticle (new PunchBlockParticle (this .breakingBlock , this .breakingBlock , this .breakingBlockFace ));
2435+ }
2436+
2437+ if (this .isUsingItem ()) {
2438+ Item food = this .getInventory ().getItemInHandFast ();
2439+
2440+ if (food instanceof ItemEdible ) {
2441+ EntityEventPacket pk = new EntityEventPacket ();
2442+ pk .eid = this .id ;
2443+ pk .event = EntityEventPacket .EATING_ITEM ;
2444+ pk .data = food .getNetworkId () << 16 ;
2445+ this .dataPacket (pk );
2446+
2447+ for (Player p : this .getViewers ().values ()) {
2448+ p .dataPacket (pk );
2449+ }
2450+ }
2451+ }
24252452 }
24262453
24272454 this .checkTeleportPosition ();
@@ -3089,12 +3116,21 @@ public void onCompletion(Server server) {
30893116 ResourcePackClientResponsePacket responsePacket = (ResourcePackClientResponsePacket ) packet ;
30903117 switch (responsePacket .responseStatus ) {
30913118 case ResourcePackClientResponsePacket .STATUS_REFUSED :
3119+ server .getLogger ().debug (username + ": got ResourcePackClientResponse STATUS_REFUSED" );
30923120 this .close ("" , "disconnectionScreen.noReason" );
30933121 return ;
30943122 case ResourcePackClientResponsePacket .STATUS_SEND_PACKS :
3123+ Set <UUID > sent = new HashSet <>();
30953124 for (ResourcePackClientResponsePacket .Entry entry : responsePacket .packEntries ) {
30963125 ResourcePack resourcePack = this .server .getResourcePackManager ().getPackById (entry .uuid );
30973126 if (resourcePack == null ) {
3127+ server .getLogger ().debug (username + ": resource pack not found with uuid " + entry .uuid );
3128+ this .close ("" , "disconnectionScreen.resourcePack" );
3129+ return ;
3130+ }
3131+
3132+ if (!sent .add (entry .uuid )) {
3133+ server .getLogger ().debug (username + ": duplicate resource pack found with uuid " + entry .uuid );
30983134 this .close ("" , "disconnectionScreen.resourcePack" );
30993135 return ;
31003136 }
@@ -3127,6 +3163,13 @@ public void onCompletion(Server server) {
31273163 ResourcePackChunkRequestPacket requestPacket = (ResourcePackChunkRequestPacket ) packet ;
31283164 ResourcePack resourcePack = this .server .getResourcePackManager ().getPackById (requestPacket .packId );
31293165 if (resourcePack == null ) {
3166+ server .getLogger ().debug (username + ": resource pack chunk not found with uuid " + requestPacket .packId );
3167+ this .close ("" , "disconnectionScreen.resourcePack" );
3168+ return ;
3169+ }
3170+
3171+ if (!resourceChunksRequested .computeIfAbsent (requestPacket .packId , k -> new IntOpenHashSet ()).add (requestPacket .chunkIndex )) {
3172+ server .getLogger ().debug (username + ": duplicate request for resource chunk " + requestPacket .packId + "/" + requestPacket .chunkIndex );
31303173 this .close ("" , "disconnectionScreen.resourcePack" );
31313174 return ;
31323175 }
@@ -3214,12 +3257,6 @@ public void onCompletion(Server server) {
32143257 if (inputX >= -1.001 && inputX <= 1.001 && inputY >= -1.001 && inputY <= 1.001 ) {
32153258 ((EntityControllable ) riding ).onPlayerInput (this , inputX , inputY );
32163259 }
3217- } else if (this .riding instanceof EntityBoat && authPacket .getInputData ().contains (AuthInputAction .IN_CLIENT_PREDICTED_IN_VEHICLE )) {
3218- if (this .riding .getId () == authPacket .getPredictedVehicle () && this .riding .isControlling (this )) {
3219- if (this .temporalVector .setComponents (authPacket .getPosition ().getX (), authPacket .getPosition ().getY (), authPacket .getPosition ().getZ ()).distanceSquared (this .riding ) < 16 ) {
3220- ((EntityBoat ) this .riding ).onInput (authPacket .getPosition ().getX (), authPacket .getPosition ().getY (), authPacket .getPosition ().getZ (), authPacket .getHeadYaw ());
3221- }
3222- }
32233260 }
32243261
32253262 if (!this .isSpectator () && authPacket .getInputData ().contains (AuthInputAction .MISSED_SWING )) {
@@ -3730,8 +3767,7 @@ public void onCompletion(Server server) {
37303767
37313768 AnimatePacket animatePacket = (AnimatePacket ) packet ;
37323769
3733- if (animatePacket .action != AnimatePacket .Action .SWING_ARM &&
3734- !(this .riding != null && (animatePacket .action == AnimatePacket .Action .ROW_LEFT || animatePacket .action == AnimatePacket .Action .ROW_RIGHT ))) {
3770+ if (animatePacket .action != AnimatePacket .Action .SWING_ARM ) {
37353771 return ;
37363772 }
37373773
@@ -3741,17 +3777,6 @@ public void onCompletion(Server server) {
37413777 return ;
37423778 }
37433779
3744- AnimatePacket .Action animation = animationEvent .getAnimationType ();
3745-
3746- switch (animation ) {
3747- case ROW_RIGHT :
3748- case ROW_LEFT :
3749- if (this .riding instanceof EntityBoat ) {
3750- ((EntityBoat ) this .riding ).onPaddle (animation , animatePacket .rowingTime );
3751- }
3752- break ;
3753- }
3754-
37553780 animatePacket = new AnimatePacket ();
37563781 animatePacket .eid = this .getId ();
37573782 animatePacket .action = animationEvent .getAnimationType ();
@@ -3769,17 +3794,6 @@ public void onCompletion(Server server) {
37693794 }
37703795
37713796 switch (entityEventPacket .event ) {
3772- case EntityEventPacket .EATING_ITEM :
3773- if (entityEventPacket .data == 0 || entityEventPacket .eid != this .id ) {
3774- this .getServer ().getLogger ().debug (username + ": entity event eid mismatch" );
3775- return ;
3776- }
3777-
3778- entityEventPacket .eid = this .id ;
3779- entityEventPacket .isEncoded = false ;
3780- this .dataPacket (entityEventPacket );
3781- Server .broadcastPacket (this .getViewers ().values (), entityEventPacket );
3782- return ;
37833797 case EntityEventPacket .ENCHANT :
37843798 if (entityEventPacket .eid != this .id ) {
37853799 this .getServer ().getLogger ().debug (username + ": entity event eid mismatch" );
@@ -4439,7 +4453,7 @@ public void onCompletion(Server server) {
44394453 if (!item .onUse (this , ticksUsed )) {
44404454 this .needSendHeldItem = true ;
44414455 }
4442- } else {
4456+ } else if (!( item instanceof ProjectileItem )) { // Fix newer versions showing player eating splash potions
44434457 this .setUsingItem (true );
44444458 }
44454459 }
@@ -5424,6 +5438,8 @@ public void close(TextContainer message, String reason, boolean notify) {
54245438
54255439 this .inventory = null ;
54265440 this .chunk = null ;
5441+ this .clientMovements = null ;
5442+ this .resourceChunksRequested = null ;
54275443
54285444 this .server .removePlayer (this );
54295445
@@ -5433,8 +5449,6 @@ public void close(TextContainer message, String reason, boolean notify) {
54335449 this .server .removeOnlinePlayer (this );
54345450 this .loggedIn = false ;
54355451 }
5436-
5437- this .clientMovements .clear ();
54385452 }
54395453
54405454 /**
0 commit comments