mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-27 11:38:03 +01:00
Cleanup
This commit is contained in:
parent
35973c227e
commit
066b3dc417
@ -749,11 +749,19 @@ public class Player extends LivingEntity implements CommandSender {
|
|||||||
|
|
||||||
super.setInstance(instance);
|
super.setInstance(instance);
|
||||||
|
|
||||||
|
// runnable used to send newly visible chunks to player once spawned in the instance
|
||||||
|
final Runnable refreshRunnable = () -> {
|
||||||
|
final Chunk chunk = getChunk();
|
||||||
|
if (chunk != null) {
|
||||||
|
refreshVisibleChunks(chunk);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (spawnPosition != null && !position.isSimilar(spawnPosition)) {
|
if (spawnPosition != null && !position.isSimilar(spawnPosition)) {
|
||||||
teleport(spawnPosition,
|
teleport(spawnPosition,
|
||||||
position.inSameChunk(spawnPosition) ? () -> refreshVisibleChunks(getChunk()) : null);
|
position.inSameChunk(spawnPosition) ? refreshRunnable : null);
|
||||||
} else {
|
} else {
|
||||||
refreshVisibleChunks(getChunk());
|
refreshRunnable.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerSpawnEvent spawnEvent = new PlayerSpawnEvent(this, instance, firstSpawn);
|
PlayerSpawnEvent spawnEvent = new PlayerSpawnEvent(this, instance, firstSpawn);
|
||||||
|
@ -264,11 +264,11 @@ public class Position implements PublicCloneable<Position> {
|
|||||||
* @return true if 'this' is in the same chunk as {@code position}
|
* @return true if 'this' is in the same chunk as {@code position}
|
||||||
*/
|
*/
|
||||||
public boolean inSameChunk(@NotNull Position position) {
|
public boolean inSameChunk(@NotNull Position position) {
|
||||||
final int chunkX1 = ChunkUtils.getChunkCoordinate((int) Math.floor(getX()));
|
final int chunkX1 = ChunkUtils.getChunkCoordinate((int) getX());
|
||||||
final int chunkZ1 = ChunkUtils.getChunkCoordinate((int) Math.floor(getZ()));
|
final int chunkZ1 = ChunkUtils.getChunkCoordinate((int) getZ());
|
||||||
|
|
||||||
final int chunkX2 = ChunkUtils.getChunkCoordinate((int) Math.floor(position.getX()));
|
final int chunkX2 = ChunkUtils.getChunkCoordinate((int) position.getX());
|
||||||
final int chunkZ2 = ChunkUtils.getChunkCoordinate((int) Math.floor(position.getZ()));
|
final int chunkZ2 = ChunkUtils.getChunkCoordinate((int) position.getZ());
|
||||||
|
|
||||||
return chunkX1 == chunkX2 && chunkZ1 == chunkZ2;
|
return chunkX1 == chunkX2 && chunkZ1 == chunkZ2;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user