use of com.flowpowered.network.Message in project Glowstone by GlowstoneMC.
the class GlowServer method broadcast.
@Override
public void broadcast(BaseComponent... components) {
try {
Message packet = new ChatMessage((JSONObject) parser.parse(ComponentSerializer.toString(components)));
broadcastPacket(packet);
} catch (ParseException e) {
//should never happen
e.printStackTrace();
}
}
use of com.flowpowered.network.Message in project Glowstone by GlowstoneMC.
the class GlowLivingEntity method createUpdateMessage.
@Override
public List<Message> createUpdateMessage() {
List<Message> messages = super.createUpdateMessage();
messages.addAll(equipmentMonitor.getChanges().stream().map(change -> new EntityEquipmentMessage(id, change.slot, change.item)).collect(Collectors.toList()));
if (headRotated) {
messages.add(new EntityHeadRotationMessage(id, Position.getIntHeadYaw(headYaw)));
headRotated = false;
}
attributeManager.applyMessages(messages);
return messages;
}
use of com.flowpowered.network.Message in project Glowstone by GlowstoneMC.
the class GlowWorld method spawn.
public GlowEntity spawn(Location location, Class<? extends GlowEntity> clazz, SpawnReason reason) throws IllegalArgumentException {
GlowEntity entity = null;
if (TNTPrimed.class.isAssignableFrom(clazz)) {
entity = new GlowTNTPrimed(location, null);
}
if (entity == null) {
try {
Constructor<? extends GlowEntity> constructor = clazz.getConstructor(Location.class);
entity = constructor.newInstance(location);
GlowEntity impl = entity;
// function.accept(entity); TODO: work on type mismatches
EntitySpawnEvent spawnEvent;
if (entity instanceof LivingEntity) {
spawnEvent = EventFactory.callEvent(new CreatureSpawnEvent((LivingEntity) entity, reason));
} else {
spawnEvent = EventFactory.callEvent(new EntitySpawnEvent(entity));
}
if (!spawnEvent.isCancelled()) {
List<Message> spawnMessage = entity.createSpawnMessage();
getRawPlayers().stream().filter(player -> player.canSeeEntity(impl)).forEach(player -> player.getSession().sendAll(spawnMessage.toArray(new Message[spawnMessage.size()])));
} else {
// TODO: separate spawning and construction for better event cancellation
entity.remove();
}
} catch (NoSuchMethodException e) {
GlowServer.logger.log(Level.WARNING, "Invalid entity spawn: ", e);
} catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
GlowServer.logger.log(Level.SEVERE, "Unable to spawn entity: ", e);
}
}
if (entity != null) {
return entity;
}
throw new UnsupportedOperationException("Not supported yet.");
}
use of com.flowpowered.network.Message 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()])));
}
use of com.flowpowered.network.Message in project Glowstone by GlowstoneMC.
the class GlowPlayer method processBlockChanges.
/**
* Process and send pending BlockChangeMessages.
*/
private void processBlockChanges() {
for (Key key : knownChunks) {
List<BlockChangeMessage> messages = world.getChunkManager().getBlockChanges(key);
int size = messages.size();
if (size == 1) {
session.send(messages.get(0));
} else if (size > 1) {
session.send(new MultiBlockChangeMessage(key.getX(), key.getZ(), messages));
}
}
processPersonalBlockChanges();
// now send post-block-change messages
List<Message> postMessages = new ArrayList<>(afterBlockChanges);
afterBlockChanges.clear();
postMessages.forEach(session::send);
}
Aggregations