Small cleanup

This commit is contained in:
themode 2020-12-16 00:13:40 +01:00
parent 7bcca8ff9f
commit 7750934a3f
3 changed files with 12 additions and 5 deletions

View File

@ -193,7 +193,7 @@ public class Player extends LivingEntity implements CommandSender {
// Tick related
private final PlayerTickEvent playerTickEvent = new PlayerTickEvent(this);
public Player(UUID uuid, String username, PlayerConnection playerConnection) {
public Player(@NotNull UUID uuid, @NotNull String username, @NotNull PlayerConnection playerConnection) {
super(EntityType.PLAYER);
this.uuid = uuid; // Override Entity#uuid defined in the constructor
this.username = username;
@ -214,7 +214,6 @@ public class Player extends LivingEntity implements CommandSender {
this.gameMode = GameMode.SURVIVAL;
this.dimensionType = DimensionType.OVERWORLD;
this.levelFlat = true;
refreshPosition(0, 0, 0);
getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(0.1f);
// FakePlayer init its connection there

View File

@ -3,6 +3,7 @@ package net.minestom.server.listener;
import net.minestom.server.entity.Player;
import net.minestom.server.event.player.PlayerMoveEvent;
import net.minestom.server.instance.Chunk;
import net.minestom.server.instance.Instance;
import net.minestom.server.network.packet.client.play.ClientPlayerPacket;
import net.minestom.server.network.packet.client.play.ClientPlayerPositionAndRotationPacket;
import net.minestom.server.network.packet.client.play.ClientPlayerPositionPacket;
@ -52,6 +53,13 @@ public class PlayerPositionListener {
private static void processMovement(@NotNull Player player, float x, float y, float z,
float yaw, float pitch, boolean onGround) {
final Instance instance = player.getInstance();
// Prevent moving before the player spawned, probably a modified client (or high latency?)
if (instance == null) {
return;
}
// Prevent the player from moving during a teleport
final float distance = player.getPosition().getDistance(x, y, z);
final int chunkRange = player.getChunkRange() * Chunk.CHUNK_SECTION_SIZE;
@ -60,12 +68,12 @@ public class PlayerPositionListener {
}
// Try to move in an unloaded chunk, prevent it
if (!ChunkUtils.isLoaded(player.getInstance(), x, z)) {
if (!ChunkUtils.isLoaded(instance, x, z)) {
player.teleport(player.getPosition());
return;
}
final Position currentPosition = player.getPosition().copy();
final Position currentPosition = player.getPosition().clone();
Position newPosition = new Position(x, y, z, yaw, pitch);
final Position cachedPosition = newPosition.clone();

View File

@ -138,7 +138,7 @@ public final class NettyServer {
if (System.getProperty("io.netty.allocator.maxOrder") == null) {
// The default page size is 8192 bytes, a bit shift of 5 makes it 262KB
// largely enough for this kind of server
// largely enough for this type of server
System.setProperty("io.netty.allocator.maxOrder", "5");
}
}