Search in sources :

Example 21 with GlowPlayer

use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.

the class ItemItemFrame method rightClickBlock.

@Override
public void rightClickBlock(GlowPlayer player, GlowBlock target, BlockFace face, ItemStack holding, Vector clickedLoc) {
    GlowItemFrame entity = new GlowItemFrame(player, target.getLocation().getBlock().getRelative(face).getLocation(), face);
    List<Message> spawnMessage = entity.createSpawnMessage();
    entity.getWorld().getRawPlayers().stream().filter(p -> p.canSeeEntity(entity)).forEach(p -> p.getSession().sendAll(spawnMessage.toArray(new Message[spawnMessage.size()])));
}
Also used : Vector(org.bukkit.util.Vector) GlowBlock(net.glowstone.block.GlowBlock) List(java.util.List) Message(com.flowpowered.network.Message) GlowPlayer(net.glowstone.entity.GlowPlayer) BlockFace(org.bukkit.block.BlockFace) GlowItemFrame(net.glowstone.entity.objects.GlowItemFrame) ItemStack(org.bukkit.inventory.ItemStack) Message(com.flowpowered.network.Message) GlowItemFrame(net.glowstone.entity.objects.GlowItemFrame)

Example 22 with GlowPlayer

use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.

the class GlowSession method pulse.

/**
     * Pulse this session, performing any updates needed.
     */
void pulse() {
    // drop the previous placement if needed
    if (previousPlacementTicks > 0 && --previousPlacementTicks == 0) {
        previousPlacement = null;
    }
    // process messages
    Message message;
    while ((message = messageQueue.poll()) != null) {
        if (disconnected) {
            // disconnected, we are just seeing extra messages now
            break;
        }
        super.messageReceived(message);
    }
    // check if the client is disconnected
    if (disconnected) {
        connectionManager.sessionInactivated(this);
        if (player == null) {
            return;
        }
        player.remove();
        Message userListMessage = UserListItemMessage.removeOne(player.getUniqueId());
        for (GlowPlayer player : server.getRawOnlinePlayers()) {
            if (player.canSee(this.player)) {
                player.getSession().send(userListMessage);
            } else {
                player.stopHidingDisconnectedPlayer(this.player);
            }
        }
        GlowServer.logger.info(player.getName() + " [" + address + "] lost connection");
        if (player.isSleeping()) {
            player.leaveBed(false);
        }
        server.getBossBarManager().clearBossBars(player);
        String text = EventFactory.onPlayerQuit(player).getQuitMessage();
        if (online && text != null && !text.isEmpty()) {
            server.broadcastMessage(text);
        }
        // statistics
        player.incrementStatistic(Statistic.LEAVE_GAME);
        for (Player p : server.getOnlinePlayers()) {
            if (p.getUniqueId().equals(player.getUniqueId())) {
                continue;
            }
            GlowPlayer other = (GlowPlayer) p;
            if (!other.canSee(player)) {
                continue;
            }
            other.getSession().send(new DestroyEntitiesMessage(Collections.singletonList(player.getEntityId())));
        }
        // in case we are disposed twice
        player = null;
    }
}
Also used : DestroyEntitiesMessage(net.glowstone.net.message.play.entity.DestroyEntitiesMessage) GlowPlayer(net.glowstone.entity.GlowPlayer) Player(org.bukkit.entity.Player) KickMessage(net.glowstone.net.message.KickMessage) Message(com.flowpowered.network.Message) PingMessage(net.glowstone.net.message.play.game.PingMessage) LoginSuccessMessage(net.glowstone.net.message.login.LoginSuccessMessage) DestroyEntitiesMessage(net.glowstone.net.message.play.entity.DestroyEntitiesMessage) SetCompressionMessage(net.glowstone.net.message.SetCompressionMessage) BlockPlacementMessage(net.glowstone.net.message.play.player.BlockPlacementMessage) UserListItemMessage(net.glowstone.net.message.play.game.UserListItemMessage) AsyncableMessage(com.flowpowered.network.AsyncableMessage) GlowPlayer(net.glowstone.entity.GlowPlayer)

Example 23 with GlowPlayer

use of net.glowstone.entity.GlowPlayer in project Dragonet-Legacy by DragonetMC.

the class RemoveBlockPacketTranslator method handleSpecific.

@Override
public Message[] handleSpecific(RemoveBlockPacket packet) {
    if (!(this.getSession().getPlayer() instanceof Player)) {
        return null;
    }
    if (getSession().getPlayer().getGameMode().equals(GameMode.CREATIVE)) {
        final GlowPlayer player = getSession().getPlayer();
        GlowWorld world = player.getWorld();
        GlowBlock block = world.getBlockAt(packet.x, packet.y, packet.z);
        PlayerInteractEvent interactEvent = EventFactory.onPlayerInteract(player, Action.LEFT_CLICK_BLOCK, block, BlockFace.UP);
        if (interactEvent.isCancelled()) {
            player.sendBlockChange(block.getLocation(), block.getType(), block.getData());
            return null;
        }
        block.setType(Material.AIR);
    } else {
        //Not Creative
        DiggingMessage msgFinishBreak = new DiggingMessage(DiggingMessage.FINISH_DIGGING, packet.x, packet.y, packet.z, 1);
        return new Message[] { msgFinishBreak };
    }
    return null;
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) Player(org.bukkit.entity.Player) GlowBlock(net.glowstone.block.GlowBlock) DiggingMessage(net.glowstone.net.message.play.player.DiggingMessage) Message(com.flowpowered.networking.Message) DiggingMessage(net.glowstone.net.message.play.player.DiggingMessage) GlowPlayer(net.glowstone.entity.GlowPlayer) PlayerInteractEvent(org.bukkit.event.player.PlayerInteractEvent) GlowWorld(net.glowstone.GlowWorld)

Example 24 with GlowPlayer

use of net.glowstone.entity.GlowPlayer in project Dragonet-Legacy by DragonetMC.

the class ClientChunkManager method prepareLoginChunks.

/**
     * Automatically prepare chunks
     */
public void prepareLoginChunks() {
    if (!(this.getSession().getPlayer() instanceof GlowPlayer)) {
        return;
    }
    int chunkX = this.getSession().getPlayer().getLocation().getChunk().getX();
    int chunkZ = this.getSession().getPlayer().getLocation().getChunk().getZ();
    for (int distance = 5; distance >= 0; distance--) {
        for (int x = chunkX - distance; x < chunkX + distance; x++) {
            for (int z = chunkZ - distance; z < chunkZ + distance; z++) {
                if (Math.sqrt((chunkX - x) * (chunkX - x) + (chunkZ - z) * (chunkZ - z)) < 5) {
                    this.prepareChunk(new ChunkLocation(x, z));
                }
            }
        }
    }
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) ChunkLocation(org.dragonet.ChunkLocation)

Example 25 with GlowPlayer

use of net.glowstone.entity.GlowPlayer in project Dragonet-Legacy by DragonetMC.

the class ClientChunkManager method autoPrepareChunks.

/**
     * Automatically prepare chunks
     */
public void autoPrepareChunks() {
    if (!(this.getSession().getPlayer() instanceof GlowPlayer)) {
        return;
    }
    int chunkX = this.getSession().getPlayer().getLocation().getChunk().getX();
    int chunkZ = this.getSession().getPlayer().getLocation().getChunk().getZ();
    for (int distance = 6; distance >= 0; distance--) {
        for (int x = chunkX - distance; x < chunkX + distance; x++) {
            for (int z = chunkZ - distance; z < chunkZ + distance; z++) {
                if (Math.sqrt((chunkX - x) * (chunkX - x) + (chunkZ - z) * (chunkZ - z)) < 8) {
                    this.prepareChunk(new ChunkLocation(x, z));
                }
            }
        }
    }
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) ChunkLocation(org.dragonet.ChunkLocation)

Aggregations

GlowPlayer (net.glowstone.entity.GlowPlayer)39 ItemStack (org.bukkit.inventory.ItemStack)10 GlowBlock (net.glowstone.block.GlowBlock)5 Player (org.bukkit.entity.Player)5 Message (com.flowpowered.network.Message)4 Location (org.bukkit.Location)4 GlowWorld (net.glowstone.GlowWorld)3 ItemType (net.glowstone.block.itemtype.ItemType)3 UserListItemMessage (net.glowstone.net.message.play.game.UserListItemMessage)3 BlockPlacementMessage (net.glowstone.net.message.play.player.BlockPlacementMessage)3 Material (org.bukkit.Material)3 Block (org.bukkit.block.Block)3 BlockFace (org.bukkit.block.BlockFace)3 Vector (org.bukkit.util.Vector)3 ChunkLocation (org.dragonet.ChunkLocation)3 PEPacket (org.dragonet.net.packet.minecraft.PEPacket)3 AsyncableMessage (com.flowpowered.network.AsyncableMessage)2 Message (com.flowpowered.networking.Message)2 ArrayList (java.util.ArrayList)2 BlockType (net.glowstone.block.blocktype.BlockType)2