Search in sources :

Example 1 with MessagePlayOutStopSounds

use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutStopSounds in project LanternServer by LanternPowered.

the class CommandStopSound method completeSpec.

@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
    specBuilder.arguments(GenericArguments.player(Text.of("player")), GenericArguments.optional(GenericArguments.catalogedElement(Text.of("category"), SoundCategory.class)), GenericArguments.optional(GenericArguments.catalogedElement(Text.of("sound"), SoundType.class))).executor((src, args) -> {
        SoundCategory category = args.<SoundCategory>getOne("category").orElse(null);
        String type = args.<SoundType>getOne("sound").map(CatalogType::getId).orElse(null);
        LanternPlayer player = args.<LanternPlayer>getOne("player").get();
        player.getConnection().send(new MessagePlayOutStopSounds(type, category));
        return CommandResult.success();
    });
}
Also used : SoundType(org.spongepowered.api.effect.sound.SoundType) MessagePlayOutStopSounds(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutStopSounds) SoundCategory(org.spongepowered.api.effect.sound.SoundCategory) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer)

Example 2 with MessagePlayOutStopSounds

use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutStopSounds in project LanternServer by LanternPowered.

the class CodecPlayInOutCustomPayload method encode0.

@Override
protected MessageResult encode0(CodecContext context, Message message) throws CodecException {
    if (message instanceof MessagePlayInOutBrand) {
        return new MessageResult("MC|Brand", context.byteBufAlloc().buffer().writeString(((MessagePlayInOutBrand) message).getBrand()));
    } else if (message instanceof MessagePlayOutOpenBook) {
        final ByteBuffer buf = context.byteBufAlloc().buffer();
        buf.writeVarInt(((MessagePlayOutOpenBook) message).getHandType() == HandTypes.MAIN_HAND ? 0 : 1);
        return new MessageResult("MC|BOpen", buf);
    } else if (message instanceof MessagePlayOutStopSounds) {
        final MessagePlayOutStopSounds message0 = (MessagePlayOutStopSounds) message;
        final ByteBuffer buf = context.byteBufAlloc().buffer();
        buf.writeString(message0.getCategory() == null ? "" : message0.getCategory().getName());
        buf.writeString(message0.getSound() == null ? "" : message0.getSound());
        return new MessageResult("MC|StopSound", buf);
    }
    throw new EncoderException("Unsupported message type: " + message);
}
Also used : EncoderException(io.netty.handler.codec.EncoderException) MessagePlayOutStopSounds(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutStopSounds) MessagePlayInOutBrand(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutBrand) MessagePlayOutOpenBook(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutOpenBook) ByteBuffer(org.lanternpowered.server.network.buffer.ByteBuffer)

Aggregations

MessagePlayOutStopSounds (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutStopSounds)2 EncoderException (io.netty.handler.codec.EncoderException)1 LanternPlayer (org.lanternpowered.server.entity.living.player.LanternPlayer)1 ByteBuffer (org.lanternpowered.server.network.buffer.ByteBuffer)1 MessagePlayInOutBrand (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutBrand)1 MessagePlayOutOpenBook (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutOpenBook)1 SoundCategory (org.spongepowered.api.effect.sound.SoundCategory)1 SoundType (org.spongepowered.api.effect.sound.SoundType)1