Add getChunkViewers API

Signed-off-by: Irmo van den Berge <irmo.vandenberge@ziggo.nl>
This commit is contained in:
Irmo van den Berge committed 2024-01-30 19:12:25 +01:00
1 parent a46743bd0b
commit 485f021cae
4 files changed
+48 -1

No files matched your search

@@ -22,6 +22,15 @@ public abstract class PlayerChunkMapHandle extends Template.Handle {
public abstract PlayerChunkHandle getVisibleChunk(int x, int z);
public abstract PlayerChunkHandle getUpdatingChunk(int x, int z);
public abstract boolean isChunkEntered(EntityPlayerHandle entityplayer, int chunkX, int chunkZ);
public java.util.Collection<org.bukkit.entity.Player> getChunkEnteredPlayers(int chunkX, int chunkZ) {
PlayerChunkHandle playerChunk = getVisibleChunk(chunkX, chunkZ);
if (playerChunk == null || playerChunk.getChunkIfLoaded() == null) {
return java.util.Collections.emptyList();
} else {
return playerChunk.getPlayers();
}
}
/**
* Stores class members for <b>net.minecraft.server.level.PlayerChunkMap</b>.
* Methods, fields, and constructors can be used without using Handle Objects.
@@ -49,7 +49,8 @@ public class Common {
"Common:Sound:StopSoundPacket",
"Common:Sound:CloudParser",
"Common:Event:PlayerAdvancementProgressEvent",
"Common:Yaml:ChildWithLiteralName"
"Common:Yaml:ChildWithLiteralName",
"Common:ChunkUtil:getChunkViewers"
).collect(Collectors.toSet());
/**
@@ -10,8 +10,10 @@ import com.bergerkiller.bukkit.common.internal.logic.RegionHandler;
import com.bergerkiller.bukkit.common.wrappers.BlockData;
import com.bergerkiller.bukkit.common.wrappers.ChunkSection;
import com.bergerkiller.bukkit.common.wrappers.HeightMap;
import com.bergerkiller.generated.net.minecraft.server.level.PlayerChunkMapHandle;
import com.bergerkiller.generated.net.minecraft.server.level.WorldServerHandle;
import com.bergerkiller.generated.net.minecraft.world.level.EnumSkyBlockHandle;
import com.bergerkiller.generated.net.minecraft.world.level.WorldHandle;
import com.bergerkiller.generated.net.minecraft.world.level.chunk.ChunkHandle;
import com.bergerkiller.generated.net.minecraft.world.level.chunk.ChunkSectionHandle;
@@ -280,6 +282,30 @@ public class ChunkUtil {
return ChunkHandle.fromBukkit(chunk).getEntities();
}
/**
* Gets a collection of players that are presently viewing / in range of a chunk.
* Block changes are notified to these players.
*
* @param chunk Chunk
* @return Unmodifiable collection of players that view this chunk
*/
public static Collection<Player> getChunkViewers(org.bukkit.Chunk chunk) {
return getChunkViewers(chunk.getWorld(), chunk.getX(), chunk.getZ());
}
/**
* Gets a collection of players that are presently viewing / in range of a chunk.
* Block changes are notified to these players.
*
* @param world World the chunk is in
* @param chunkX The chunk X-coordinate
* @param chunkZ The chunk Z-coordinate
* @return Unmodifiable collection of players that view this chunk
*/
public static Collection<Player> getChunkViewers(org.bukkit.World world, int chunkX, int chunkZ) {
return WorldServerHandle.fromBukkit(world).getPlayerChunkMap().getChunkEnteredPlayers(chunkX, chunkZ);
}
/**
* Checks if a chunk is about be loaded
*
@@ -426,6 +426,17 @@ class PlayerChunkMap {
}
#endif
<code>
public java.util.Collection<org.bukkit.entity.Player> getChunkEnteredPlayers(int chunkX, int chunkZ) {
PlayerChunkHandle playerChunk = getVisibleChunk(chunkX, chunkZ);
if (playerChunk == null || playerChunk.getChunkIfLoaded() == null) {
return java.util.Collections.emptyList();
} else {
return playerChunk.getPlayers();
}
}
</code>
#if version >= 1.14
public boolean isChunkEntered((EntityPlayerHandle) EntityPlayer entityplayer, int chunkX, int chunkZ) {
#if version >= 1.18