This commit is contained in:
Eoghanmc22 2020-11-20 13:38:41 -05:00
commit 62663ccb64
2 changed files with 8 additions and 9 deletions

View File

@ -57,7 +57,6 @@ public final class EntityManager {
private void waitingPlayersTick() { private void waitingPlayersTick() {
Player waitingPlayer; Player waitingPlayer;
while ((waitingPlayer = waitingPlayers.poll()) != null) { while ((waitingPlayer = waitingPlayers.poll()) != null) {
waitingPlayer.init();
PlayerLoginEvent loginEvent = new PlayerLoginEvent(waitingPlayer); PlayerLoginEvent loginEvent = new PlayerLoginEvent(waitingPlayer);
waitingPlayer.callEvent(PlayerLoginEvent.class, loginEvent); waitingPlayer.callEvent(PlayerLoginEvent.class, loginEvent);
@ -65,6 +64,8 @@ public final class EntityManager {
Check.notNull(spawningInstance, "You need to specify a spawning instance in the PlayerLoginEvent"); Check.notNull(spawningInstance, "You need to specify a spawning instance in the PlayerLoginEvent");
waitingPlayer.init();
spawningInstance.scheduleNextTick(waitingPlayer::setInstance); spawningInstance.scheduleNextTick(waitingPlayer::setInstance);
} }
} }

View File

@ -697,7 +697,7 @@ public class Player extends LivingEntity implements CommandSender {
sendDimension(instanceDimensionType); sendDimension(instanceDimensionType);
} }
final long[] visibleChunks = ChunkUtils.getChunksInRange(firstSpawn ? getRespawnPoint() : position, getChunkRange()); final long[] visibleChunks = ChunkUtils.getChunksInRange(position, getChunkRange());
final int length = visibleChunks.length; final int length = visibleChunks.length;
AtomicInteger counter = new AtomicInteger(0); AtomicInteger counter = new AtomicInteger(0);
@ -709,8 +709,9 @@ public class Player extends LivingEntity implements CommandSender {
if (chunk != null) { if (chunk != null) {
chunk.addViewer(this); chunk.addViewer(this);
if (chunk.getChunkX() == ChunkUtils.getChunkCoordinate((int) getPosition().getX()) && if (chunk.getChunkX() == ChunkUtils.getChunkCoordinate((int) getPosition().getX()) &&
chunk.getChunkZ() == ChunkUtils.getChunkCoordinate((int) getPosition().getZ())) chunk.getChunkZ() == ChunkUtils.getChunkCoordinate((int) getPosition().getZ())) {
updateViewPosition(chunk); updateViewPosition(chunk);
}
} }
final boolean isLast = counter.get() == length - 1; final boolean isLast = counter.get() == length - 1;
if (isLast) { if (isLast) {
@ -742,15 +743,12 @@ public class Player extends LivingEntity implements CommandSender {
private void spawnPlayer(Instance instance, boolean firstSpawn) { private void spawnPlayer(Instance instance, boolean firstSpawn) {
this.viewableEntities.forEach(entity -> entity.removeViewer(this)); this.viewableEntities.forEach(entity -> entity.removeViewer(this));
super.setInstance(instance);
if (firstSpawn) { if (firstSpawn) {
this.position = getRespawnPoint(); teleport(getRespawnPoint());
this.cacheX = position.getX();
this.cacheY = position.getY();
this.cacheZ = position.getZ();
updatePlayerPosition();
} }
super.setInstance(instance);
PlayerSpawnEvent spawnEvent = new PlayerSpawnEvent(this, instance, firstSpawn); PlayerSpawnEvent spawnEvent = new PlayerSpawnEvent(this, instance, firstSpawn);
callEvent(PlayerSpawnEvent.class, spawnEvent); callEvent(PlayerSpawnEvent.class, spawnEvent);