Plasmo Voice

Plasmo Voice

2M Downloads

PlayerSpeakEndEvent isn't working

yunokn1ght opened this issue · 1 comments

commented

Somehow, there is no PlayerServerActivationEndEvent in the last API version. There is only "PlayerSpeakEndEvent" and ITS NOT WORKING??

Main class:

@Getter
@Addon(id = "pv-vc-mimics", name = "Voicechat Mimics", version = "1.0", authors = {"thatsyuno"})
public final class Main extends JavaPlugin implements AddonInitializer {

    private Main instance;

    @InjectPlasmoVoice
    private PlasmoVoiceServer voiceServer;

    @Override
    public void onEnable() {
        instance = this;
        // saveDefaultConfig(); TODO: сделать конфиг

        PlasmoVoiceServer.getAddonsLoader().load(this);
        getComponentLogger().info(Component.text("VCMimics enabled!"));
    }

    @Override
    public void onAddonInitialize() {
        voiceServer.getEventBus().register(this, new EventListener(this));
        getComponentLogger().info(Component.text("PlasmoVoice addon initialized."));
    }
}

EventListener:

package org.yuno.VCMimics;

import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import su.plo.voice.api.event.EventSubscribe;
import su.plo.voice.api.server.event.audio.source.PlayerSpeakEndEvent;

public class EventListener {

    private Main plugin;

    public EventListener(Main plugin) {
        this.plugin = plugin;
        plugin.getComponentLogger().info(Component.text("Created event listener"));
    }

    @EventSubscribe
    public void onPlayerSpeakEvent(PlayerSpeakEndEvent e) {
        plugin.getComponentLogger().info(Component.text("Player has stoped speaking!"));
    }
}
commented

PlayerServerActivationEndEvent is only available in 2.1.6-SNAPSHOT at snapshots repository (https://repo.plasmoverse.com/snapshots) with latest snapshot build installed.

It's not obvious at all, but PlayerSpeakEndEvent is cancelled when properly handled, so PlayerSpeakEndEvent listeners with >=NORMAL priority is never invoked.
You can either disable ignoreCancelled in EventSubscribe annotation or use LOWEST event listener priority:

@EventSubscribe(ignoreCancelled = false)
fun onSpeakEnd(event: PlayerSpeakEndEvent) {

@EventSubscribe(priority = EventPriority.LOWEST)
fun onSpeakEnd(event: PlayerSpeakEndEvent) {

I'll add description of this nuance to PlayerSpeak*Event classes to avoid further confusion.
And I also recommend using snapshot with PlayerServerActivationEndEvent available, because it doesn't have this issue.