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);
}
}
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);
}
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;
}
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);
}
}
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();
}
Aggregations