@@ -183,6 +183,7 @@ public class Player extends EntityHuman implements CommandSender, InventoryHolde
183
183
protected boolean removeFormat = true ;
184
184
185
185
protected String username ;
186
+ private String unverifiedUsername = "" ;
186
187
protected String iusername ;
187
188
protected String displayName ;
188
189
@@ -1552,7 +1553,7 @@ protected void handleMovement(Vector3 clientPos) {
1552
1553
else this .speed .setComponents (0 , 0 , 0 );
1553
1554
}
1554
1555
1555
- if ((this .isFoodEnabled () || this .getServer ().getDifficulty () == 0 ) && distance >= 0.05 ) {
1556
+ if ((this .isFoodEnabled () || this .getServer ().getDifficulty () == 0 ) && distance >= 0.05 && this . riding == null ) {
1556
1557
double jump = 0 ;
1557
1558
double swimming = this .isInsideOfWater () ? 0.015 * distance : 0 ;
1558
1559
double distance2 = distance ;
@@ -1711,11 +1712,11 @@ public boolean onUpdate(int currentTick) {
1711
1712
1712
1713
if (!this .isSpectator () && this .speed != null ) {
1713
1714
if (this .onGround ) {
1714
- if (this .inAirTicks != 0 ) {
1715
- this .startAirTicks = 5 ;
1715
+ if (this .isGliding () ) {
1716
+ this .setGliding ( false ) ;
1716
1717
}
1717
- this . inAirTicks = 0 ;
1718
- this .highestPosition = this . y ;
1718
+
1719
+ this .resetFallDistance () ;
1719
1720
} else {
1720
1721
if (this .checkMovement && !this .isGliding () && !server .getAllowFlight () && !this .getAdventureSettings ().get (Type .ALLOW_FLIGHT ) && this .inAirTicks > 20 && !this .isSleeping () && !this .isImmobile () && !this .isSwimming () && this .riding == null && !this .hasEffect (Effect .LEVITATION ) && !this .hasEffect (Effect .SLOW_FALLING )) {
1721
1722
double expectedVelocity = (-this .getGravity ()) / ((double ) this .getDrag ()) - ((-this .getGravity ()) / ((double ) this .getDrag ())) * Math .exp (-((double ) this .getDrag ()) * ((double ) (this .inAirTicks - this .startAirTicks )));
@@ -2162,11 +2163,17 @@ public void handleDataPacket(DataPacket packet) {
2162
2163
this .loginPacketReceived = true ;
2163
2164
2164
2165
LoginPacket loginPacket = (LoginPacket ) packet ;
2165
- this .username = TextFormat .clean (loginPacket .username );
2166
- this .displayName = this .username ;
2167
- this .iusername = this .username .toLowerCase ();
2168
2166
2169
- this .setDataProperty (new StringEntityData (DATA_NAMETAG , this .username ), false );
2167
+ this .unverifiedUsername = TextFormat .clean (loginPacket .username );
2168
+
2169
+ if (loginPacket .skin == null ) {
2170
+ this .close ("" , "disconnectionScreen.invalidSkin" );
2171
+ return ;
2172
+ }
2173
+
2174
+ if (this .server .getOnlinePlayers ().size () >= this .server .getMaxPlayers () && this .kick (PlayerKickEvent .Reason .SERVER_FULL , "disconnectionScreen.serverFull" , false )) {
2175
+ return ;
2176
+ }
2170
2177
2171
2178
this .loginChainData = ClientChainData .read (loginPacket );
2172
2179
@@ -2175,9 +2182,12 @@ public void handleDataPacket(DataPacket packet) {
2175
2182
break ;
2176
2183
}
2177
2184
2178
- if (this .server .getOnlinePlayers ().size () >= this .server .getMaxPlayers () && this .kick (PlayerKickEvent .Reason .SERVER_FULL , "disconnectionScreen.serverFull" , false )) {
2179
- break ;
2180
- }
2185
+ // Do not set username before the user is authenticated
2186
+ this .username = this .unverifiedUsername ;
2187
+ this .unverifiedUsername = null ;
2188
+ this .displayName = this .username ;
2189
+ this .iusername = this .username .toLowerCase ();
2190
+ this .setDataProperty (new StringEntityData (DATA_NAMETAG , this .username ), false );
2181
2191
2182
2192
this .randomClientId = loginPacket .clientId ;
2183
2193
@@ -2560,7 +2570,7 @@ public void onCompletion(Server server) {
2560
2570
}
2561
2571
this .getServer ().getPluginManager ().callEvent (playerToggleFlightEvent );
2562
2572
if (playerToggleFlightEvent .isCancelled ()) {
2563
- this .getAdventureSettings ().update ();
2573
+ this .getAdventureSettings ().update (false );
2564
2574
} else {
2565
2575
this .getAdventureSettings ().set (AdventureSettings .Type .FLYING , playerToggleFlightEvent .isFlying ());
2566
2576
}
@@ -2573,13 +2583,13 @@ public void onCompletion(Server server) {
2573
2583
}
2574
2584
this .getServer ().getPluginManager ().callEvent (playerToggleFlightEvent );
2575
2585
if (playerToggleFlightEvent .isCancelled ()) {
2576
- this .getAdventureSettings ().update ();
2586
+ this .getAdventureSettings ().update (false );
2577
2587
} else {
2578
2588
this .getAdventureSettings ().set (AdventureSettings .Type .FLYING , playerToggleFlightEvent .isFlying ());
2579
2589
}
2580
2590
}
2581
2591
2582
- Vector3 clientPosition = authPacket .getPosition ().subtract (0 , this .getEyeHeight (), 0 ).asVector3 ();
2592
+ Vector3 clientPosition = authPacket .getPosition ().subtract (0 , this .riding == null ? this . getBaseOffset () : this . riding . getMountedOffset ( this ). getY (), 0 ).asVector3 ();
2583
2593
2584
2594
double distSqrt = clientPosition .distanceSquared (this );
2585
2595
if (distSqrt == 0.0 && authPacket .getYaw () % 360 == this .yaw && authPacket .getPitch () % 360 == this .pitch ) {
@@ -2956,6 +2966,17 @@ public void onCompletion(Server server) {
2956
2966
pk .wasServerInitiated = false ;
2957
2967
pk .windowId = -1 ;
2958
2968
this .dataPacket (pk );
2969
+ } else { // Close bugged inventory
2970
+ ContainerClosePacket pk = new ContainerClosePacket ();
2971
+ pk .windowId = containerClosePacket .windowId ;
2972
+ pk .wasServerInitiated = false ;
2973
+ this .dataPacket (pk );
2974
+
2975
+ for (Inventory open : new ArrayList <>(this .windows .keySet ())) {
2976
+ if (open instanceof ContainerInventory ) {
2977
+ this .removeWindow (open );
2978
+ }
2979
+ }
2959
2980
}
2960
2981
break ;
2961
2982
case ProtocolInfo .CRAFTING_EVENT_PACKET :
@@ -3002,23 +3023,13 @@ public void onCompletion(Server server) {
3002
3023
SetPlayerGameTypePacket setPlayerGameTypePacket1 = new SetPlayerGameTypePacket ();
3003
3024
setPlayerGameTypePacket1 .gamemode = this .gamemode & 0x01 ;
3004
3025
this .dataPacket (setPlayerGameTypePacket1 );
3005
- this .getAdventureSettings ().update ();
3026
+ this .getAdventureSettings ().update (false );
3006
3027
break ;
3007
3028
}
3008
3029
this .setGamemode (setPlayerGameTypePacket .gamemode , true );
3009
3030
Command .broadcastCommandMessage (this , new TranslationContainer ("commands.gamemode.success.self" , Server .getGamemodeString (this .gamemode )));
3010
3031
}
3011
3032
break ;
3012
- case ProtocolInfo .ITEM_FRAME_DROP_ITEM_PACKET :
3013
- ItemFrameDropItemPacket itemFrameDropItemPacket = (ItemFrameDropItemPacket ) packet ;
3014
- Vector3 vector3 = this .temporalVector .setComponents (itemFrameDropItemPacket .x , itemFrameDropItemPacket .y , itemFrameDropItemPacket .z );
3015
- if (vector3 .distanceSquared (this ) < 1000 ) {
3016
- BlockEntity itemFrame = this .level .getBlockEntity (vector3 );
3017
- if (itemFrame instanceof BlockEntityItemFrame ) {
3018
- ((BlockEntityItemFrame ) itemFrame ).dropItem (this );
3019
- }
3020
- }
3021
- break ;
3022
3033
case ProtocolInfo .MAP_INFO_REQUEST_PACKET :
3023
3034
MapInfoRequestPacket pk = (MapInfoRequestPacket ) packet ;
3024
3035
Item mapItem = null ;
@@ -3207,7 +3218,7 @@ public void onCompletion(Server server) {
3207
3218
3208
3219
this .setDataFlag (DATA_FLAGS , DATA_FLAG_ACTION , false );
3209
3220
3210
- if (this .canInteract (blockVector .add (0.5 , 0.5 , 0.5 ), this .isCreative () ? 13 : 7 )) {
3221
+ if (this .canInteract (blockVector .add (0.5 , 0.5 , 0.5 ), this .isCreative () ? 14 : 8 )) {
3211
3222
if (this .isCreative ()) {
3212
3223
Item i = inventory .getItemInHand ();
3213
3224
if (this .level .useItemOn (blockVector .asVector3 (), i , face , useItemData .clickPos .x , useItemData .clickPos .y , useItemData .clickPos .z , this ) != null ) {
@@ -3255,7 +3266,7 @@ public void onCompletion(Server server) {
3255
3266
3256
3267
Item oldItem = i .clone ();
3257
3268
3258
- if (this .canInteract (blockVector .add (0.5 , 0.5 , 0.5 ), this .isCreative () ? 13 : 7 ) && (i = this .level .useBreakOn (blockVector .asVector3 (), face , i , this , true )) != null ) {
3269
+ if (this .canInteract (blockVector .add (0.5 , 0.5 , 0.5 ), this .isCreative () ? 14 : 8 ) && (i = this .level .useBreakOn (blockVector .asVector3 (), face , i , this , true )) != null ) {
3259
3270
if (this .isSurvival ()) {
3260
3271
this .getFoodData ().updateFoodExpLevel (0.005 );
3261
3272
if (!i .equals (oldItem ) || i .getCount () != oldItem .getCount ()) {
@@ -3679,7 +3690,7 @@ private void onBlockBreakComplete(BlockVector3 blockPos, BlockFace face) {
3679
3690
Item handItem = this .getInventory ().getItemInHand ();
3680
3691
Item clone = handItem .clone ();
3681
3692
3682
- boolean canInteract = this .canInteract (blockPos .add (0.5 , 0.5 , 0.5 ), this .isCreative () ? 13 : 7 );
3693
+ boolean canInteract = this .canInteract (blockPos .add (0.5 , 0.5 , 0.5 ), this .isCreative () ? 14 : 8 );
3683
3694
if (canInteract ) {
3684
3695
handItem = this .level .useBreakOn (blockPos .asVector3 (), face , handItem , this , true );
3685
3696
if (handItem == null ) {
@@ -4039,7 +4050,7 @@ public void close(TextContainer message, String reason, boolean notify) {
4039
4050
this .server .getPluginManager ().unsubscribeFromPermission (Server .BROADCAST_CHANNEL_USERS , this );
4040
4051
this .spawned = false ;
4041
4052
this .server .getLogger ().info (this .getServer ().getLanguage ().translateString ("nukkit.player.logOut" ,
4042
- TextFormat .AQUA + (this .getName () == null ? "" : this .getName ()) + TextFormat .WHITE ,
4053
+ TextFormat .AQUA + (this .getName () == null ? this . unverifiedUsername : this .getName ()) + TextFormat .WHITE ,
4043
4054
this .getAddress (),
4044
4055
String .valueOf (this .getPort ()),
4045
4056
this .getServer ().getLanguage ().translateString (reason )));
@@ -4332,6 +4343,8 @@ protected void respawn() {
4332
4343
4333
4344
this .setSprinting (false );
4334
4345
this .setSneaking (false );
4346
+ this .setSwimming (false );
4347
+ this .setGliding (false );
4335
4348
4336
4349
this .setDataProperty (new ShortEntityData (Player .DATA_AIR , 400 ), false );
4337
4350
this .deadTicks = 0 ;
@@ -4610,6 +4623,8 @@ public void sendPosition(Vector3 pos, double yaw, double pitch, int mode, Player
4610
4623
if (targets != null ) {
4611
4624
Server .broadcastPacket (targets , pk );
4612
4625
} else {
4626
+ this .clientMovements .clear ();
4627
+
4613
4628
this .dataPacket (pk );
4614
4629
}
4615
4630
}
0 commit comments