Search in sources :

Example 1 with Message

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();
    }
}
Also used : Message(com.flowpowered.network.Message) ChatMessage(net.glowstone.net.message.play.game.ChatMessage) ChatMessage(net.glowstone.net.message.play.game.ChatMessage) ParseException(org.json.simple.parser.ParseException)

Example 2 with Message

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;
}
Also used : EntityHeadRotationMessage(net.glowstone.net.message.play.entity.EntityHeadRotationMessage) EntityEquipmentMessage(net.glowstone.net.message.play.entity.EntityEquipmentMessage) Message(com.flowpowered.network.Message) EntityRemoveEffectMessage(net.glowstone.net.message.play.entity.EntityRemoveEffectMessage) EntityHeadRotationMessage(net.glowstone.net.message.play.entity.EntityHeadRotationMessage) EntityEffectMessage(net.glowstone.net.message.play.entity.EntityEffectMessage) EntityEquipmentMessage(net.glowstone.net.message.play.entity.EntityEquipmentMessage)

Example 3 with Message

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.");
}
Also used : Plugin(org.bukkit.plugin.Plugin) GlowBlock(net.glowstone.block.GlowBlock) BlockType(net.glowstone.block.blocktype.BlockType) ItemTable(net.glowstone.block.ItemTable) GameRuleManager(net.glowstone.util.GameRuleManager) EntitySpawnEvent(org.bukkit.event.entity.EntitySpawnEvent) Biome(org.bukkit.block.Biome) ChunkGenerator(org.bukkit.generator.ChunkGenerator) MaterialData(org.bukkit.material.MaterialData) org.bukkit(org.bukkit) AnvilWorldStorageProvider(net.glowstone.io.anvil.AnvilWorldStorageProvider) Block(org.bukkit.block.Block) EntityStatusMessage(net.glowstone.net.message.play.entity.EntityStatusMessage) ToString(lombok.ToString) WorldConfig(net.glowstone.util.config.WorldConfig) BoundingBox(net.glowstone.entity.physics.BoundingBox) org.bukkit.entity(org.bukkit.entity) LightningStrikeEvent(org.bukkit.event.weather.LightningStrikeEvent) BlockPopulator(org.bukkit.generator.BlockPopulator) WorldStorageProvider(net.glowstone.io.WorldStorageProvider) ConcurrentSet(net.glowstone.util.collection.ConcurrentSet) CreatureSpawnEvent(org.bukkit.event.entity.CreatureSpawnEvent) GlowChunk(net.glowstone.chunk.GlowChunk) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) ItemStack(org.bukkit.inventory.ItemStack) InvocationTargetException(java.lang.reflect.InvocationTargetException) WorldFinalValues(net.glowstone.io.WorldMetadataService.WorldFinalValues) MetadataValue(org.bukkit.metadata.MetadataValue) ChunkLock(net.glowstone.chunk.ChunkManager.ChunkLock) Key(net.glowstone.chunk.GlowChunk.Key) GlowFallingBlock(net.glowstone.entity.objects.GlowFallingBlock) GlowStructure(net.glowstone.generator.structures.GlowStructure) EmptySnapshot(net.glowstone.chunk.GlowChunkSnapshot.EmptySnapshot) Setter(lombok.Setter) ThunderChangeEvent(org.bukkit.event.weather.ThunderChangeEvent) java.util(java.util) Getter(lombok.Getter) Message(com.flowpowered.network.Message) WeatherChangeEvent(org.bukkit.event.weather.WeatherChangeEvent) Constructor(java.lang.reflect.Constructor) Level(java.util.logging.Level) Consumer(org.bukkit.util.Consumer) ServerDifficultyMessage(net.glowstone.net.message.play.player.ServerDifficultyMessage) RayUtil(net.glowstone.util.RayUtil) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) GlowItem(net.glowstone.entity.objects.GlowItem) SpawnReason(org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason) org.bukkit.event.world(org.bukkit.event.world) MetadataStore(org.bukkit.metadata.MetadataStore) ChunkSection(net.glowstone.chunk.ChunkSection) StandardMessenger(org.bukkit.plugin.messaging.StandardMessenger) BlockState(org.bukkit.block.BlockState) IOException(java.io.IOException) File(java.io.File) Vector(org.bukkit.util.Vector) net.glowstone.constants(net.glowstone.constants) BlockStateDelegate(net.glowstone.util.BlockStateDelegate) ChunkManager(net.glowstone.chunk.ChunkManager) MetadataStoreBase(org.bukkit.metadata.MetadataStoreBase) net.glowstone.entity(net.glowstone.entity) EntityStatusMessage(net.glowstone.net.message.play.entity.EntityStatusMessage) Message(com.flowpowered.network.Message) ServerDifficultyMessage(net.glowstone.net.message.play.player.ServerDifficultyMessage) InvocationTargetException(java.lang.reflect.InvocationTargetException) CreatureSpawnEvent(org.bukkit.event.entity.CreatureSpawnEvent) EntitySpawnEvent(org.bukkit.event.entity.EntitySpawnEvent)

Example 4 with Message

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()])));
}
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 5 with Message

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);
}
Also used : TitleMessage(net.glowstone.net.message.play.game.TitleMessage) EntityMetadataMessage(net.glowstone.net.message.play.entity.EntityMetadataMessage) OpenWindowMessage(net.glowstone.net.message.play.inv.OpenWindowMessage) BlockBreakAnimationMessage(net.glowstone.net.message.play.game.BlockBreakAnimationMessage) WindowPropertyMessage(net.glowstone.net.message.play.inv.WindowPropertyMessage) UpdateBlockEntityMessage(net.glowstone.net.message.play.game.UpdateBlockEntityMessage) RespawnMessage(net.glowstone.net.message.play.game.RespawnMessage) EntityVelocityMessage(net.glowstone.net.message.play.entity.EntityVelocityMessage) PositionRotationMessage(net.glowstone.net.message.play.game.PositionRotationMessage) HealthMessage(net.glowstone.net.message.play.game.HealthMessage) PluginMessage(net.glowstone.net.message.play.game.PluginMessage) SetWindowSlotMessage(net.glowstone.net.message.play.inv.SetWindowSlotMessage) PlayEffectMessage(net.glowstone.net.message.play.game.PlayEffectMessage) BlockChangeMessage(net.glowstone.net.message.play.game.BlockChangeMessage) MultiBlockChangeMessage(net.glowstone.net.message.play.game.MultiBlockChangeMessage) UnloadChunkMessage(net.glowstone.net.message.play.game.UnloadChunkMessage) StateChangeMessage(net.glowstone.net.message.play.game.StateChangeMessage) SpawnPositionMessage(net.glowstone.net.message.play.game.SpawnPositionMessage) ExperienceMessage(net.glowstone.net.message.play.game.ExperienceMessage) NamedSoundEffectMessage(net.glowstone.net.message.play.game.NamedSoundEffectMessage) UserListHeaderFooterMessage(net.glowstone.net.message.play.game.UserListHeaderFooterMessage) HeldItemMessage(net.glowstone.net.message.play.inv.HeldItemMessage) MapDataMessage(net.glowstone.net.message.play.game.MapDataMessage) StopSoundMessage(net.glowstone.net.message.play.game.StopSoundMessage) CloseWindowMessage(net.glowstone.net.message.play.inv.CloseWindowMessage) ChunkDataMessage(net.glowstone.net.message.play.game.ChunkDataMessage) TimeMessage(net.glowstone.net.message.play.game.TimeMessage) Message(com.flowpowered.network.Message) SetWindowContentsMessage(net.glowstone.net.message.play.inv.SetWindowContentsMessage) PlayParticleMessage(net.glowstone.net.message.play.game.PlayParticleMessage) ResourcePackSendMessage(net.glowstone.net.message.play.player.ResourcePackSendMessage) DestroyEntitiesMessage(net.glowstone.net.message.play.entity.DestroyEntitiesMessage) JoinGameMessage(net.glowstone.net.message.play.game.JoinGameMessage) SignEditorMessage(net.glowstone.net.message.play.game.SignEditorMessage) SetPassengerMessage(net.glowstone.net.message.play.entity.SetPassengerMessage) EntityAnimationMessage(net.glowstone.net.message.play.entity.EntityAnimationMessage) TextMessage(net.glowstone.util.TextMessage) UpdateSignMessage(net.glowstone.net.message.play.game.UpdateSignMessage) UserListItemMessage(net.glowstone.net.message.play.game.UserListItemMessage) ChatMessage(net.glowstone.net.message.play.game.ChatMessage) ArrayList(java.util.ArrayList) MultiBlockChangeMessage(net.glowstone.net.message.play.game.MultiBlockChangeMessage) BlockChangeMessage(net.glowstone.net.message.play.game.BlockChangeMessage) MultiBlockChangeMessage(net.glowstone.net.message.play.game.MultiBlockChangeMessage) Key(net.glowstone.chunk.GlowChunk.Key) NamespacedKey(org.bukkit.NamespacedKey)

Aggregations

Message (com.flowpowered.network.Message)34 LinkedList (java.util.LinkedList)13 EntityMetadataMessage (net.glowstone.net.message.play.entity.EntityMetadataMessage)11 List (java.util.List)10 DestroyEntitiesMessage (net.glowstone.net.message.play.entity.DestroyEntitiesMessage)10 ItemStack (org.bukkit.inventory.ItemStack)10 Vector (org.bukkit.util.Vector)10 ArrayList (java.util.ArrayList)9 Collections (java.util.Collections)8 Getter (lombok.Getter)8 Setter (lombok.Setter)8 EventFactory (net.glowstone.EventFactory)8 EntityVelocityMessage (net.glowstone.net.message.play.entity.EntityVelocityMessage)8 SetPassengerMessage (net.glowstone.net.message.play.entity.SetPassengerMessage)8 TextMessage (net.glowstone.util.TextMessage)8 NotNull (org.jetbrains.annotations.NotNull)8 GlowBlock (net.glowstone.block.GlowBlock)7 GlowPlayer (net.glowstone.entity.GlowPlayer)7 EntityAnimationMessage (net.glowstone.net.message.play.entity.EntityAnimationMessage)7 UserListItemMessage (net.glowstone.net.message.play.game.UserListItemMessage)7