Search in sources :

Example 1 with ChunkManager

use of net.minecraft.world.server.ChunkManager in project dynmap by webbukkit.

the class ForgeMapChunkCache method readChunk.

public CompoundNBT readChunk(int x, int z) {
    try {
        ChunkManager acl = cps.chunkManager;
        ChunkPos coord = new ChunkPos(x, z);
        CompoundNBT rslt = acl.readChunk(coord);
        if (rslt != null) {
            rslt = rslt.getCompound("Level");
            // Don't load uncooked chunks
            String stat = rslt.getString("Status");
            ChunkStatus cs = ChunkStatus.byName(stat);
            if ((stat == null) || // Needs to be at least lighted
            (!cs.isAtLeast(ChunkStatus.LIGHT))) {
                rslt = null;
            }
        }
        // Log.info(String.format("loadChunk(%d,%d)=%s", x, z, (rslt != null) ? rslt.toString() : "null"));
        return rslt;
    } catch (Exception exc) {
        Log.severe(String.format("Error reading chunk: %s,%d,%d", dw.getName(), x, z), exc);
        return null;
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) ChunkStatus(net.minecraft.world.chunk.ChunkStatus) ChunkPos(net.minecraft.util.math.ChunkPos) ChunkManager(net.minecraft.world.server.ChunkManager) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with ChunkManager

use of net.minecraft.world.server.ChunkManager in project dynmap by webbukkit.

the class ForgeMapChunkCache method readChunk.

public CompoundNBT readChunk(int x, int z) {
    try {
        ChunkManager acl = cps.chunkManager;
        ChunkPos coord = new ChunkPos(x, z);
        CompoundNBT rslt = acl.readChunk(coord);
        if (rslt != null) {
            rslt = rslt.getCompound("Level");
            // Don't load uncooked chunks
            String stat = rslt.getString("Status");
            ChunkStatus cs = ChunkStatus.byName(stat);
            if ((stat == null) || // Needs to be at least lighted
            (!cs.isAtLeast(ChunkStatus.LIGHT))) {
                rslt = null;
            }
        }
        // Log.info(String.format("loadChunk(%d,%d)=%s", x, z, (rslt != null) ? rslt.toString() : "null"));
        return rslt;
    } catch (Exception exc) {
        Log.severe(String.format("Error reading chunk: %s,%d,%d", dw.getName(), x, z), exc);
        return null;
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) ChunkStatus(net.minecraft.world.chunk.ChunkStatus) ChunkPos(net.minecraft.util.math.ChunkPos) ChunkManager(net.minecraft.world.server.ChunkManager) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with ChunkManager

use of net.minecraft.world.server.ChunkManager in project Magma-1.16.x by magmafoundation.

the class CraftPlayer method hidePlayer0.

private void hidePlayer0(@Nullable Plugin plugin, Player player) {
    Validate.notNull(player, "hidden player cannot be null");
    if (getHandle().connection == null)
        return;
    if (equals(player))
        return;
    Set<WeakReference<Plugin>> hidingPlugins = hiddenPlayers.get(player.getUniqueId());
    if (hidingPlugins != null) {
        // Some plugins are already hiding the player. Just mark that this
        // plugin wants the player hidden too and end.
        hidingPlugins.add(getPluginWeakReference(plugin));
        return;
    }
    hidingPlugins = new HashSet<>();
    hidingPlugins.add(getPluginWeakReference(plugin));
    hiddenPlayers.put(player.getUniqueId(), hidingPlugins);
    // Remove this player from the hidden player's EntityTrackerEntry
    ChunkManager tracker = ((ServerWorld) entity.level).getChunkSource().chunkMap;
    ServerPlayerEntity other = ((CraftPlayer) player).getHandle();
    ChunkManager.EntityTracker entry = tracker.entityMap.get(other.getId());
    if (entry != null) {
        entry.removePlayer(getHandle());
    }
    // Remove the hidden player from this player user list, if they're on it
    if (other.sentListPacket) {
        getHandle().connection.send(new SPlayerListItemPacket(SPlayerListItemPacket.Action.REMOVE_PLAYER, other));
    }
}
Also used : SPlayerListItemPacket(net.minecraft.network.play.server.SPlayerListItemPacket) WeakReference(java.lang.ref.WeakReference) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ChunkManager(net.minecraft.world.server.ChunkManager)

Example 4 with ChunkManager

use of net.minecraft.world.server.ChunkManager in project Magma-1.16.x by magmafoundation.

the class CraftPlayer method showPlayer0.

private void showPlayer0(@Nullable Plugin plugin, Player player) {
    Validate.notNull(player, "shown player cannot be null");
    if (getHandle().connection == null)
        return;
    if (equals(player))
        return;
    Set<WeakReference<Plugin>> hidingPlugins = hiddenPlayers.get(player.getUniqueId());
    if (hidingPlugins == null) {
        // Player isn't hidden
        return;
    }
    hidingPlugins.remove(getPluginWeakReference(plugin));
    if (!hidingPlugins.isEmpty()) {
        // Some other plugins still want the player hidden
        return;
    }
    hiddenPlayers.remove(player.getUniqueId());
    ChunkManager tracker = ((ServerWorld) entity.level).getChunkSource().chunkMap;
    ServerPlayerEntity other = ((CraftPlayer) player).getHandle();
    getHandle().connection.send(new SPlayerListItemPacket(SPlayerListItemPacket.Action.ADD_PLAYER, other));
    ChunkManager.EntityTracker entry = tracker.entityMap.get(other.getId());
    if (entry != null && !entry.seenBy.contains(getHandle())) {
        entry.updatePlayer(getHandle());
    }
}
Also used : SPlayerListItemPacket(net.minecraft.network.play.server.SPlayerListItemPacket) WeakReference(java.lang.ref.WeakReference) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ChunkManager(net.minecraft.world.server.ChunkManager)

Example 5 with ChunkManager

use of net.minecraft.world.server.ChunkManager in project LoliServer by Loli-Server.

the class CraftPlayer method showPlayer0.

private void showPlayer0(@Nullable Plugin plugin, Player player) {
    Validate.notNull(player, "shown player cannot be null");
    if (getHandle().connection == null)
        return;
    if (equals(player))
        return;
    Set<WeakReference<Plugin>> hidingPlugins = hiddenPlayers.get(player.getUniqueId());
    if (hidingPlugins == null) {
        // Player isn't hidden
        return;
    }
    hidingPlugins.remove(getPluginWeakReference(plugin));
    if (!hidingPlugins.isEmpty()) {
        // Some other plugins still want the player hidden
        return;
    }
    hiddenPlayers.remove(player.getUniqueId());
    ChunkManager tracker = ((ServerWorld) entity.level).getChunkSource().chunkMap;
    ServerPlayerEntity other = ((CraftPlayer) player).getHandle();
    getHandle().connection.send(new SPlayerListItemPacket(SPlayerListItemPacket.Action.ADD_PLAYER, other));
    tracker.updateTrackingState(tracker, getHandle(), other.getId());
}
Also used : SPlayerListItemPacket(net.minecraft.network.play.server.SPlayerListItemPacket) WeakReference(java.lang.ref.WeakReference) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ChunkManager(net.minecraft.world.server.ChunkManager)

Aggregations

ChunkManager (net.minecraft.world.server.ChunkManager)6 WeakReference (java.lang.ref.WeakReference)4 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)4 SPlayerListItemPacket (net.minecraft.network.play.server.SPlayerListItemPacket)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 CompoundNBT (net.minecraft.nbt.CompoundNBT)2 ChunkPos (net.minecraft.util.math.ChunkPos)2 ChunkStatus (net.minecraft.world.chunk.ChunkStatus)2