first commit
Build AsminVoicechat / prepare-release (push) Successful in 14s
Build AsminVoicechat / build-and-test (17) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (18) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (19) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (20) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (21) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (22) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (23) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (24) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (25) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (26) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (27-ea) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (16) (push) Canceled after 38s

This commit is contained in:
asminme committed 2026-10-24 15:18:03 +02:00
commit bbccd4a815
454 files changed
+45050

No files matched your search

@@ -0,0 +1,162 @@
/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* io.netty.buffer.Unpooled
* org.bukkit.Bukkit
* org.bukkit.entity.Player
* org.bukkit.event.EventHandler
* org.bukkit.event.Listener
* org.bukkit.event.player.PlayerJoinEvent
* org.bukkit.event.player.PlayerQuitEvent
* org.bukkit.plugin.Plugin
*/
package de.maxhenkel.voicechat.net;
import de.maxhenkel.voicechat.Voicechat;
import de.maxhenkel.voicechat.net.AddCategoryPacket;
import de.maxhenkel.voicechat.net.AddGroupPacket;
import de.maxhenkel.voicechat.net.CreateGroupPacket;
import de.maxhenkel.voicechat.net.JoinGroupPacket;
import de.maxhenkel.voicechat.net.JoinedGroupPacket;
import de.maxhenkel.voicechat.net.LeaveGroupPacket;
import de.maxhenkel.voicechat.net.Packet;
import de.maxhenkel.voicechat.net.PlayerStatePacket;
import de.maxhenkel.voicechat.net.PlayerStatesPacket;
import de.maxhenkel.voicechat.net.RemoveCategoryPacket;
import de.maxhenkel.voicechat.net.RemoveGroupPacket;
import de.maxhenkel.voicechat.net.RemovePlayerStatePacket;
import de.maxhenkel.voicechat.net.RequestSecretPacket;
import de.maxhenkel.voicechat.net.SecretPacket;
import de.maxhenkel.voicechat.net.UpdateStatePacket;
import de.maxhenkel.voicechat.util.FriendlyByteBuf;
import io.netty.buffer.Unpooled;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.Plugin;
public class NetManager
implements Listener {
private final Set<String> packets = new HashSet<String>();
public void onEnable() {
this.packets.clear();
Bukkit.getPluginManager().registerEvents((Listener)this, (Plugin)Voicechat.INSTANCE);
try {
this.registerIncomingPacket(UpdateStatePacket.class);
this.registerIncomingPacket(RequestSecretPacket.class);
this.registerIncomingPacket(CreateGroupPacket.class);
this.registerIncomingPacket(JoinGroupPacket.class);
this.registerIncomingPacket(LeaveGroupPacket.class);
this.registerOutgoingPacket(SecretPacket.class);
this.registerOutgoingPacket(PlayerStatesPacket.class);
this.registerOutgoingPacket(PlayerStatePacket.class);
this.registerOutgoingPacket(RemovePlayerStatePacket.class);
this.registerOutgoingPacket(AddGroupPacket.class);
this.registerOutgoingPacket(RemoveGroupPacket.class);
this.registerOutgoingPacket(JoinedGroupPacket.class);
this.registerOutgoingPacket(AddCategoryPacket.class);
this.registerOutgoingPacket(RemoveCategoryPacket.class);
}
catch (Exception e) {
throw new IllegalStateException("Failed to register voice chat packets", e);
}
}
public void onDisable() {
Set incomingChannels = Bukkit.getMessenger().getIncomingChannels((Plugin)Voicechat.INSTANCE);
Set outgoingChannels = Bukkit.getMessenger().getOutgoingChannels((Plugin)Voicechat.INSTANCE);
for (String channel : incomingChannels) {
Bukkit.getMessenger().unregisterIncomingPluginChannel((Plugin)Voicechat.INSTANCE, channel);
}
for (String channel : outgoingChannels) {
Bukkit.getMessenger().unregisterOutgoingPluginChannel((Plugin)Voicechat.INSTANCE, channel);
}
this.packets.clear();
}
public Set<String> getPackets() {
return this.packets;
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Set outgoingChannels = Bukkit.getMessenger().getOutgoingChannels((Plugin)Voicechat.INSTANCE);
for (String channel : outgoingChannels) {
Voicechat.compatibility.addChannel(event.getPlayer(), channel);
}
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
Set outgoingChannels = Bukkit.getMessenger().getOutgoingChannels((Plugin)Voicechat.INSTANCE);
for (String channel : outgoingChannels) {
Voicechat.compatibility.removeChannel(event.getPlayer(), channel);
}
}
private <T extends Packet<?>> void registerIncomingPacket(Class<T> packetClass) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
Constructor c = packetClass.getDeclaredConstructor(new Class[0]);
String id = ((Packet)c.newInstance(new Object[0])).getID().toString();
this.packets.add(id);
Bukkit.getMessenger().registerIncomingPluginChannel((Plugin)Voicechat.INSTANCE, id, (s, player, bytes) -> {
Packet packet;
if (!Voicechat.SERVER.getRateLimiter().allow(player.getUniqueId())) {
Voicechat.LOGGER.warn("Player {} exceeded packet rate limit", player.getDisplayName());
player.kickPlayer(Voicechat.TRANSLATIONS.rateLimitKickMessage.get());
return;
}
try {
packet = (Packet)c.newInstance(new Object[0]);
}
catch (Exception e) {
Voicechat.LOGGER.error("Failed to create new packet instance of {}", packetClass.getSimpleName(), e);
return;
}
FriendlyByteBuf buffer = new FriendlyByteBuf(Unpooled.wrappedBuffer((byte[])bytes));
packet.fromBytes(buffer);
packet.onPacket(player);
});
}
private <T extends Packet<?>> void registerOutgoingPacket(Class<T> packetClass) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
String id = ((Packet)packetClass.getDeclaredConstructor(new Class[0]).newInstance(new Object[0])).getID().toString();
this.packets.add(id);
Bukkit.getMessenger().registerOutgoingPluginChannel((Plugin)Voicechat.INSTANCE, id);
}
public static void sendToClient(Player player, Packet<?> p) {
Voicechat.compatibility.runTask(() -> {
if (!Voicechat.SERVER.isCompatible(player)) {
return;
}
try {
FriendlyByteBuf buf = new FriendlyByteBuf();
p.toBytes(buf);
byte[] bytes = new byte[buf.readableBytes()];
buf.readBytes(bytes);
player.sendPluginMessage((Plugin)Voicechat.INSTANCE, p.getID().toString(), bytes);
}
catch (Exception e) {
Voicechat.LOGGER.error("Failed to send packet to '{}'", player.getName(), e);
}
});
}
public static void sendMessage(Player player, String key, String ... args) {
Voicechat.compatibility.sendTranslationMessage(player, key, args);
}
public static void sendStatusMessage(Player player, String key, String ... args) {
Voicechat.compatibility.sendStatusMessage(player, key, args);
}
}