Search in sources :

Example 66 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 67 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)

Example 68 with GlowPlayer

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

the class ClientChunkManager method sendChunks.

/**
 * Send all queued chunks to the client and mark them as sent
 */
public synchronized void sendChunks() {
    if (!(this.getSession().getPlayer() instanceof GlowPlayer)) {
        return;
    }
    ChunkLocation chunkLocation;
    while ((chunkLocation = this.chunksQueue.poll()) != null) {
        this.sendChunk(chunkLocation.getX(), chunkLocation.getZ());
        this.chunksLoaded.add(chunkLocation);
    }
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) ChunkLocation(org.dragonet.ChunkLocation)

Example 69 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)

Aggregations

GlowPlayer (net.glowstone.entity.GlowPlayer)69 ItemStack (org.bukkit.inventory.ItemStack)15 Vector (org.bukkit.util.Vector)10 EventFactory (net.glowstone.EventFactory)9 Location (org.bukkit.Location)9 Player (org.bukkit.entity.Player)9 GlowEntity (net.glowstone.entity.GlowEntity)8 Message (com.flowpowered.network.Message)7 ArrayList (java.util.ArrayList)7 GlowBlock (net.glowstone.block.GlowBlock)7 Material (org.bukkit.Material)6 World (org.bukkit.World)6 Entity (org.bukkit.entity.Entity)6 List (java.util.List)5 GlowWorld (net.glowstone.GlowWorld)5 LocalizedStringImpl (net.glowstone.i18n.LocalizedStringImpl)5 BlockFace (org.bukkit.block.BlockFace)5 CommandTarget (net.glowstone.command.CommandTarget)4 AsyncableMessage (com.flowpowered.network.AsyncableMessage)3 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)3