mirror of https://github.com/Minestom/Minestom.git
102 lines
3.2 KiB
Java
102 lines
3.2 KiB
Java
package fr.themode.minestom.entity;
|
|
|
|
import fr.themode.minestom.Main;
|
|
import fr.themode.minestom.instance.Chunk;
|
|
import fr.themode.minestom.net.packet.server.play.EntityTeleportPacket;
|
|
import fr.themode.minestom.net.packet.server.play.PlayerPositionAndLookPacket;
|
|
import fr.themode.minestom.net.packet.server.play.UpdateViewPositionPacket;
|
|
import fr.themode.minestom.net.player.PlayerConnection;
|
|
|
|
import java.util.UUID;
|
|
|
|
public class Player extends LivingEntity {
|
|
|
|
private boolean isSneaking;
|
|
private boolean isSprinting;
|
|
|
|
private long lastKeepAlive;
|
|
|
|
private String username;
|
|
private PlayerConnection playerConnection;
|
|
|
|
// TODO set proper UUID
|
|
public Player(UUID uuid, String username, PlayerConnection playerConnection) {
|
|
this.uuid = uuid;
|
|
this.username = username;
|
|
this.playerConnection = playerConnection;
|
|
}
|
|
|
|
@Override
|
|
public void update() {
|
|
// System.out.println("Je suis l'update");
|
|
EntityTeleportPacket entityTeleportPacket = new EntityTeleportPacket();
|
|
entityTeleportPacket.entityId = getEntityId();
|
|
entityTeleportPacket.x = x;
|
|
entityTeleportPacket.y = y;
|
|
entityTeleportPacket.z = z;
|
|
entityTeleportPacket.yaw = yaw;
|
|
entityTeleportPacket.pitch = pitch;
|
|
entityTeleportPacket.onGround = true;
|
|
for (Player onlinePlayer : Main.getConnectionManager().getOnlinePlayers()) {
|
|
if (!onlinePlayer.equals(this))
|
|
onlinePlayer.getPlayerConnection().sendPacket(entityTeleportPacket);
|
|
}
|
|
playerConnection.sendPacket(new UpdateViewPositionPacket(Math.floorDiv((int) x, 16), Math.floorDiv((int) z, 16)));
|
|
}
|
|
|
|
public boolean chunkTest(double x, double z) {
|
|
Chunk newChunk = getInstance().getChunk((int) Math.floor(x / 16), (int) Math.floor(z / 16));
|
|
if (newChunk == null) {
|
|
PlayerPositionAndLookPacket positionAndLookPacket = new PlayerPositionAndLookPacket();
|
|
positionAndLookPacket.x = getX();
|
|
positionAndLookPacket.y = getY();
|
|
positionAndLookPacket.z = getZ();
|
|
positionAndLookPacket.yaw = getYaw();
|
|
positionAndLookPacket.pitch = getPitch();
|
|
positionAndLookPacket.flags = 0x00;
|
|
positionAndLookPacket.teleportId = 67;
|
|
getPlayerConnection().sendPacket(positionAndLookPacket);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public String getUsername() {
|
|
return username;
|
|
}
|
|
|
|
public PlayerConnection getPlayerConnection() {
|
|
return playerConnection;
|
|
}
|
|
|
|
public void refreshView(float yaw, float pitch) {
|
|
this.yaw = yaw;
|
|
this.pitch = pitch;
|
|
}
|
|
|
|
public void refreshOnGround(boolean onGround) {
|
|
this.onGround = onGround;
|
|
}
|
|
|
|
public void refreshSneaking(boolean sneaking) {
|
|
isSneaking = sneaking;
|
|
}
|
|
|
|
public void refreshSprinting(boolean sprinting) {
|
|
isSprinting = sprinting;
|
|
}
|
|
|
|
public void refreshKeepAlive(long lastKeepAlive) {
|
|
this.lastKeepAlive = lastKeepAlive;
|
|
}
|
|
|
|
public long getLastKeepAlive() {
|
|
return lastKeepAlive;
|
|
}
|
|
|
|
public enum Hand {
|
|
MAIN,
|
|
OFF
|
|
}
|
|
}
|