Search in sources :

Example 1 with SoundType

use of org.spongepowered.api.effect.sound.SoundType 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 SoundType

use of org.spongepowered.api.effect.sound.SoundType in project LanternServer by LanternPowered.

the class CommandPlaySound method completeSpec.

@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
    specBuilder.arguments(GenericArguments.catalogedElement(Text.of("sound"), SoundType.class), GenericArguments.catalogedElement(Text.of("category"), SoundCategory.class), GenericArguments.player(Text.of("player")), GenericArguments.optional(GenericArguments2.targetedVector3d(Text.of("position"))), GenericArguments.optional(GenericArguments2.doubleNum(Text.of("volume")), 1.0), GenericArguments.optional(GenericArguments2.doubleNum(Text.of("pitch"), 1.0)), GenericArguments.optional(GenericArguments2.doubleNum(Text.of("minimum-volume"), 0.0))).executor((src, args) -> {
        SoundType soundType = args.<SoundType>getOne("sound").get();
        SoundCategory soundCategory = args.<SoundCategory>getOne("category").get();
        LanternPlayer player = args.<LanternPlayer>getOne("player").get();
        double volume = GenericMath.clamp(args.<Double>getOne("volume").orElse(1.0), 0.0, Double.MAX_VALUE);
        // Volume greater then 1 will increase the distance the sound can be heared
        double soundDistance = volume <= 1.0 ? 16.0 : volume * 16.0;
        double pitch = GenericMath.clamp(args.<Double>getOne("pitch").orElse(1.0), 0.5, 2.0);
        double minVolume = GenericMath.clamp(args.<Double>getOne("minimum-volume").orElse(0.0), 0.0, 1.0);
        Vector3d playerPos = player.getPosition();
        Vector3d position = args.<Vector3d>getOne("position").orElse(playerPos);
        // is a minimum volume specified
        if (minVolume > 0.0 && playerPos != position && position.distanceSquared(playerPos) > soundDistance * soundDistance) {
            position = position.sub(playerPos).normalize().mul(FOUR_VECTOR).add(playerPos);
            volume = minVolume;
        }
        player.playSound(soundType, soundCategory, position, volume, pitch);
        return CommandResult.success();
    });
}
Also used : SoundType(org.spongepowered.api.effect.sound.SoundType) SoundCategory(org.spongepowered.api.effect.sound.SoundCategory) Vector3d(com.flowpowered.math.vector.Vector3d) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer)

Example 3 with SoundType

use of org.spongepowered.api.effect.sound.SoundType in project UltimateChat by FabioZumbi12.

the class UCMessages method mention.

private static String mention(Object sender, Object receiver, String msg) {
    if (UChat.get().getConfig().root().mention.enable) {
        for (Player p : Sponge.getServer().getOnlinePlayers()) {
            if (!sender.equals(p) && Arrays.stream(msg.split(" ")).anyMatch(p.getName()::equalsIgnoreCase)) {
                if (receiver instanceof Player && receiver.equals(p)) {
                    String mentionc = UChat.get().getConfig().root().mention.color_template.replace("{mentioned-player}", p.getName());
                    mentionc = formatTags("", mentionc, sender, p, "", new UCChannel("mention"));
                    if (msg.contains(mentionc) || sender instanceof CommandSource && !UChat.get().getPerms().hasPerm((CommandSource) sender, "chat.mention")) {
                        msg = msg.replaceAll("(?i)\\b" + p.getName() + "\\b", p.getName());
                        continue;
                    }
                    Optional<SoundType> sound = Sponge.getRegistry().getType(SoundType.class, UChat.get().getConfig().root().mention.playsound);
                    if (sound.isPresent() && !msg.contains(mentionc)) {
                        p.playSound(sound.get(), p.getLocation().getPosition(), 1, 1);
                    }
                    msg = msg.replace(mentionc, p.getName());
                    msg = msg.replaceAll("(?i)\\b" + p.getName() + "\\b", mentionc);
                } else {
                    msg = msg.replaceAll("(?i)\\b" + p.getName() + "\\b", p.getName());
                }
            }
        }
    }
    return msg;
}
Also used : SoundType(org.spongepowered.api.effect.sound.SoundType) Player(org.spongepowered.api.entity.living.player.Player) ClanPlayer(nl.riebie.mcclans.api.ClanPlayer) CommandSource(org.spongepowered.api.command.CommandSource)

Aggregations

SoundType (org.spongepowered.api.effect.sound.SoundType)3 LanternPlayer (org.lanternpowered.server.entity.living.player.LanternPlayer)2 SoundCategory (org.spongepowered.api.effect.sound.SoundCategory)2 Vector3d (com.flowpowered.math.vector.Vector3d)1 ClanPlayer (nl.riebie.mcclans.api.ClanPlayer)1 MessagePlayOutStopSounds (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutStopSounds)1 CommandSource (org.spongepowered.api.command.CommandSource)1 Player (org.spongepowered.api.entity.living.player.Player)1