Search in sources :

Example 21 with Player

use of io.xol.chunkstories.api.player.Player in project chunkstories-api by Hugobros3.

the class PacketEntity method process.

public void process(PacketSender sender, DataInputStream in, PacketReceptionContext processor) throws IOException, UnknownComponentException {
    long entityUUID = in.readLong();
    short entityTypeID = in.readShort();
    if (entityTypeID == -1)
        return;
    World world = processor.getWorld();
    if (world == null)
        return;
    Entity entity = world.getEntityByUUID(entityUUID);
    boolean addToWorld = false;
    // Create an entity if the servers tells you to do so
    if (entity == null) {
        if (world instanceof WorldMaster && sender instanceof RemotePlayer) {
            ((Player) sender).sendMessage("You are sending packets to the server about a removed entity. Ignoring those.");
            return;
        } else {
            entity = processor.getWorld().getContentTranslator().getEntityForId(entityTypeID).create(// This is technically wrong
            new Location(world, 0, 0, 0));
            entity.setUUID(entityUUID);
            addToWorld = true;
        }
    }
    int componentId = in.readInt();
    // Loop throught all components
    while (componentId != 0) {
        try {
            entity.getComponents().tryPullComponentInStream(componentId, sender, in);
        } catch (UnknownComponentException e) {
            processor.logger().warn(e.getMessage());
        }
        componentId = in.readInt();
    }
    // Add to world if it was missing and we didn't receive the despawn flag
    if (addToWorld && entity.exists()) {
        // Only the WorldMaster is allowed to spawn new entities in the world
        if (processor instanceof ClientPacketsProcessor)
            processor.getWorld().addEntity(entity);
    }
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) Player(io.xol.chunkstories.api.player.Player) RemotePlayer(io.xol.chunkstories.api.server.RemotePlayer) ClientPacketsProcessor(io.xol.chunkstories.api.client.net.ClientPacketsProcessor) RemotePlayer(io.xol.chunkstories.api.server.RemotePlayer) UnknownComponentException(io.xol.chunkstories.api.exceptions.UnknownComponentException) World(io.xol.chunkstories.api.world.World) PacketWorld(io.xol.chunkstories.api.net.PacketWorld) WorldMaster(io.xol.chunkstories.api.world.WorldMaster) Location(io.xol.chunkstories.api.Location)

Example 22 with Player

use of io.xol.chunkstories.api.player.Player in project chunkstories-api by Hugobros3.

the class EntityComponentInventory method push.

@Override
protected void push(StreamTarget destinator, DataOutputStream stream) throws IOException {
    // Check that person has permission
    if (destinator instanceof Player) {
        Player player = (Player) destinator;
        Entity entity = player.getControlledEntity();
        // Abort if the entity don't have access
        if (!this.actualInventory.isAccessibleTo(entity)) {
            // System.out.println(player + "'s " + entity + " don't have access to "+this);
            stream.writeByte(UpdateMode.NEVERMIND.ordinal());
            return;
        }
    }
    stream.writeByte(UpdateMode.TOTAL_REFRESH.ordinal());
    actualInventory.pushInventory(destinator, stream);
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) Player(io.xol.chunkstories.api.player.Player)

Example 23 with Player

use of io.xol.chunkstories.api.player.Player in project chunkstories-api by Hugobros3.

the class ItemVoxel method onControllerInput.

@Override
public boolean onControllerInput(Entity entity, ItemPile pile, Input input, Controller controller) {
    try {
        if (entity.getWorld() instanceof WorldMaster && input.getName().equals("mouse.right")) {
            // Require entities to be of the right kind
            if (!(entity instanceof EntityWorldModifier))
                return true;
            if (!(entity instanceof EntityControllable))
                return true;
            EntityWorldModifier modifierEntity = (EntityWorldModifier) entity;
            EntityControllable playerEntity = (EntityControllable) entity;
            boolean isEntityCreativeMode = (entity instanceof EntityCreative) && (((EntityCreative) entity).isCreativeMode());
            Location blockLocation = null;
            blockLocation = playerEntity.getBlockLookingAt(false);
            if (blockLocation != null) {
                FutureCell fvc = new FutureCell(entity.getWorld().peekSafely(blockLocation));
                fvc.setVoxel(voxel);
                // Opaque blocks overwrite the original light with zero.
                if (voxel.getDefinition().isOpaque()) {
                    fvc.setBlocklight(0);
                    fvc.setSunlight(0);
                }
                // Glowy stuff should glow
                // if(voxel.getDefinition().getEmittedLightLevel() > 0)
                fvc.setBlocklight(voxel.getEmittedLightLevel(fvc));
                // Player events mod
                if (controller instanceof Player) {
                    Player player = (Player) controller;
                    CellData ctx = entity.getWorld().peek(blockLocation);
                    PlayerVoxelModificationEvent event = new PlayerVoxelModificationEvent(ctx, fvc, isEntityCreativeMode ? EntityCreative.CREATIVE_MODE : this, player);
                    // Anyone has objections ?
                    entity.getWorld().getGameContext().getPluginManager().fireEvent(event);
                    if (event.isCancelled())
                        return true;
                    entity.getWorld().getSoundManager().playSoundEffect("sounds/gameplay/voxel_place.ogg", Mode.NORMAL, fvc.getLocation(), 1.0f, 1.0f);
                }
                entity.getWorld().poke(fvc, modifierEntity);
                // Decrease stack size
                if (!isEntityCreativeMode) {
                    int currentAmount = pile.getAmount();
                    currentAmount--;
                    pile.setAmount(currentAmount);
                }
            } else {
                // No space found :/
                return true;
            }
        }
    } catch (WorldException e) {
    }
    return false;
}
Also used : FutureCell(io.xol.chunkstories.api.world.cell.FutureCell) Player(io.xol.chunkstories.api.player.Player) PlayerVoxelModificationEvent(io.xol.chunkstories.api.events.player.voxel.PlayerVoxelModificationEvent) WorldException(io.xol.chunkstories.api.exceptions.world.WorldException) EntityWorldModifier(io.xol.chunkstories.api.entity.interfaces.EntityWorldModifier) EntityCreative(io.xol.chunkstories.api.entity.interfaces.EntityCreative) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable) CellData(io.xol.chunkstories.api.world.cell.CellData) WorldMaster(io.xol.chunkstories.api.world.WorldMaster) Location(io.xol.chunkstories.api.Location)

Example 24 with Player

use of io.xol.chunkstories.api.player.Player in project chunkstories by Hugobros3.

the class VirtualServerParticlesManager method spawnParticleAtPositionWithVelocity.

@Override
public void spawnParticleAtPositionWithVelocity(String particleTypeName, Vector3dc location, Vector3dc velocity) {
    Iterator<Player> i = worldServer.getPlayers();
    while (i.hasNext()) {
        Player player = i.next();
        tellPlayer(player, particleTypeName, location, velocity);
    }
}
Also used : Player(io.xol.chunkstories.api.player.Player) ServerPlayer(io.xol.chunkstories.server.player.ServerPlayer)

Example 25 with Player

use of io.xol.chunkstories.api.player.Player in project chunkstories by Hugobros3.

the class WorldServer method tick.

@Override
public void tick() {
    processIncommingPackets();
    super.tick();
    // Update client tracking
    Iterator<Player> playersIterator = this.getPlayers();
    while (playersIterator.hasNext()) {
        Player player = playersIterator.next();
        // System.out.println("client: "+client);
        if (player.hasSpawned()) {
            // Update whatever he sees
            ((ServerPlayer) player).updateTrackedEntities();
        }
        // Update time & weather
        PacketTime packetTime = new PacketTime(this);
        packetTime.time = this.getTime();
        packetTime.overcastFactor = this.getWeather();
        player.pushPacket(packetTime);
    }
    virtualServerSoundManager.update();
    // TODO this should work per-world
    this.getServer().getHandler().flushAll();
}
Also used : PacketTime(io.xol.chunkstories.api.net.packets.PacketTime) Player(io.xol.chunkstories.api.player.Player) ServerPlayer(io.xol.chunkstories.server.player.ServerPlayer) ServerPlayer(io.xol.chunkstories.server.player.ServerPlayer)

Aggregations

Player (io.xol.chunkstories.api.player.Player)33 Location (io.xol.chunkstories.api.Location)12 Entity (io.xol.chunkstories.api.entity.Entity)9 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)8 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)7 ServerPlayer (io.xol.chunkstories.server.player.ServerPlayer)5 LocalPlayer (io.xol.chunkstories.api.client.LocalPlayer)4 Controller (io.xol.chunkstories.api.entity.Controller)4 World (io.xol.chunkstories.api.world.World)4 EntityCreative (io.xol.chunkstories.api.entity.interfaces.EntityCreative)3 PlayerVoxelModificationEvent (io.xol.chunkstories.api.events.player.voxel.PlayerVoxelModificationEvent)3 WorldException (io.xol.chunkstories.api.exceptions.world.WorldException)3 ItemPile (io.xol.chunkstories.api.item.inventory.ItemPile)3 FutureCell (io.xol.chunkstories.api.world.cell.FutureCell)3 HeightmapImplementation (io.xol.chunkstories.world.summary.HeightmapImplementation)3 ByteBuffer (java.nio.ByteBuffer)3 ClientInterface (io.xol.chunkstories.api.client.ClientInterface)2 EntityWorldModifier (io.xol.chunkstories.api.entity.interfaces.EntityWorldModifier)2 EventItemDroppedToWorld (io.xol.chunkstories.api.events.item.EventItemDroppedToWorld)2 PlayerMoveItemEvent (io.xol.chunkstories.api.events.player.PlayerMoveItemEvent)2