Skip to content

Commit

Permalink
feat: update API
Browse files Browse the repository at this point in the history
  • Loading branch information
Apehum committed May 18, 2024
1 parent 7145f8e commit 8dddbc6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.plo.slib.api.permission.PermissionDefault;
import su.plo.voice.api.event.EventPriority;
import su.plo.voice.api.event.EventSubscribe;
import su.plo.voice.api.server.PlasmoBaseVoiceServer;
import su.plo.voice.api.server.audio.capture.SelfActivationInfo;
import su.plo.voice.api.server.audio.capture.PlayerActivationInfo;
import su.plo.voice.api.server.audio.capture.ServerActivation;
import su.plo.voice.api.server.audio.line.BaseServerSourceLine;
import su.plo.voice.api.server.audio.source.ServerBroadcastSource;
import su.plo.voice.api.server.event.audio.source.ServerSourcePacketEvent;
import su.plo.voice.api.server.player.VoicePlayer;
import su.plo.voice.broadcast.BroadcastAddon;
import su.plo.voice.proto.packets.tcp.clientbound.SourceAudioEndPacket;
import su.plo.voice.proto.packets.tcp.clientbound.SourceInfoPacket;
import su.plo.voice.proto.packets.tcp.serverbound.PlayerAudioEndPacket;
import su.plo.voice.proto.packets.udp.clientbound.SourceAudioPacket;
import su.plo.voice.proto.packets.udp.serverbound.PlayerAudioPacket;
Expand All @@ -29,8 +25,6 @@ public final class BroadcastActivation {

private final PlasmoBaseVoiceServer voiceServer;

private final SelfActivationInfo selfActivationInfo;

private final BroadcastAddon addon;

private final BroadcastWidePrinter widePrinter;
Expand All @@ -47,8 +41,6 @@ public BroadcastActivation(
) {
this.voiceServer = voiceServer;

this.selfActivationInfo = new SelfActivationInfo(voiceServer.getUdpConnectionManager());

this.addon = addon;

this.widePrinter = widePrinter;
Expand Down Expand Up @@ -82,35 +74,6 @@ public void register() {
).build();
}

@EventSubscribe(priority = EventPriority.HIGHEST)
public void onSourceSendPacket(@NotNull ServerSourcePacketEvent event) {
if (!(event.getSource() instanceof ServerBroadcastSource)) return;

ServerBroadcastSource source = (ServerBroadcastSource) event.getSource();
if (source.getSender() == null) return;

VoicePlayer sender = source.getSender();
if (addon.getBroadcastSource(sender, false)
.map(source::equals)
.orElse(false)) return;

if (!selfActivationInfo.getLastPlayerActivationIds()
.containsKey(sender.getInstance().getUuid())
) {
return;
}

if (event.getPacket() instanceof SourceInfoPacket) {
selfActivationInfo.updateSelfSourceInfo(
sender,
source,
((SourceInfoPacket) event.getPacket()).getSourceInfo()
);
} else if (event.getPacket() instanceof SourceAudioEndPacket) {
sender.sendPacket(event.getPacket());
}
}

private ServerActivation.Result onActivation(@NotNull VoicePlayer player, @NotNull PlayerAudioPacket packet) {
return getBroadcastSource(player, packet.getActivationId(), packet.isStereo())
.map((source) -> {
Expand Down Expand Up @@ -147,12 +110,7 @@ private boolean sendAudioPacket(
(short) 0
);

if (source.sendAudioPacket(sourcePacket, packet.getActivationId())) {
selfActivationInfo.sendAudioInfo(player, source, packet.getActivationId(), sourcePacket);
return true;
}

return false;
return source.sendAudioPacket(sourcePacket, new PlayerActivationInfo(player, packet));
}

private boolean sendAudioEndPacket(@NotNull ServerBroadcastSource source,
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ lombok = { module = "org.projectlombok:lombok", version.ref = "lombok" }

plasmovoice-server = { module = "su.plo.voice.api:server", version.ref = "plasmovoice" }
plasmovoice-proxy = { module = "su.plo.voice.api:proxy", version.ref = "plasmovoice" }
plasmovoice-server-common = { module = "su.plo.voice.api:server-common", version.ref = "plasmovoice" }
plasmovoice-server-common = { module = "su.plo.voice.api:server-proxy-common", version.ref = "plasmovoice" }

[plugins]
plasmovoice = { id = "su.plo.voice.plugin.entrypoints", version.ref = "plasmovoice-plugin" }
Expand Down

0 comments on commit 8dddbc6

Please sign in to comment.