/* * Decompiled with CFR 0.152. * * Could not load the following classes: * javax.annotation.Nullable * org.bukkit.Bukkit * org.bukkit.World * org.bukkit.entity.Player */ package de.maxhenkel.voicechat.plugins.impl; import de.maxhenkel.voicechat.Voicechat; import de.maxhenkel.voicechat.api.Entity; import de.maxhenkel.voicechat.api.Group; import de.maxhenkel.voicechat.api.Position; import de.maxhenkel.voicechat.api.ServerLevel; import de.maxhenkel.voicechat.api.ServerPlayer; import de.maxhenkel.voicechat.api.VoicechatConnection; import de.maxhenkel.voicechat.api.VoicechatServerApi; import de.maxhenkel.voicechat.api.VolumeCategory; import de.maxhenkel.voicechat.api.audiochannel.AudioChannel; import de.maxhenkel.voicechat.api.audiochannel.AudioPlayer; import de.maxhenkel.voicechat.api.audiochannel.EntityAudioChannel; import de.maxhenkel.voicechat.api.audiochannel.LocationalAudioChannel; import de.maxhenkel.voicechat.api.audiochannel.StaticAudioChannel; import de.maxhenkel.voicechat.api.audiolistener.AudioListener; import de.maxhenkel.voicechat.api.audiolistener.PlayerAudioListener; import de.maxhenkel.voicechat.api.audiosender.AudioSender; import de.maxhenkel.voicechat.api.config.ConfigAccessor; import de.maxhenkel.voicechat.api.opus.OpusEncoder; import de.maxhenkel.voicechat.api.packets.ConvertablePacket; import de.maxhenkel.voicechat.api.packets.EntitySoundPacket; import de.maxhenkel.voicechat.api.packets.LocationalSoundPacket; import de.maxhenkel.voicechat.api.packets.StaticSoundPacket; import de.maxhenkel.voicechat.plugins.PluginManager; import de.maxhenkel.voicechat.plugins.impl.GroupImpl; import de.maxhenkel.voicechat.plugins.impl.PositionImpl; import de.maxhenkel.voicechat.plugins.impl.ServerPlayerImpl; import de.maxhenkel.voicechat.plugins.impl.VoicechatApiImpl; import de.maxhenkel.voicechat.plugins.impl.VoicechatConnectionImpl; import de.maxhenkel.voicechat.plugins.impl.VolumeCategoryImpl; import de.maxhenkel.voicechat.plugins.impl.audiochannel.AudioPlayerImpl; import de.maxhenkel.voicechat.plugins.impl.audiochannel.AudioSupplier; import de.maxhenkel.voicechat.plugins.impl.audiochannel.EntityAudioChannelImpl; import de.maxhenkel.voicechat.plugins.impl.audiochannel.LocationalAudioChannelImpl; import de.maxhenkel.voicechat.plugins.impl.audiochannel.StaticAudioChannelImpl; import de.maxhenkel.voicechat.plugins.impl.audiolistener.PlayerAudioListenerImpl; import de.maxhenkel.voicechat.plugins.impl.audiosender.AudioSenderImpl; import de.maxhenkel.voicechat.plugins.impl.config.ConfigAccessorImpl; import de.maxhenkel.voicechat.plugins.impl.packets.ConvertablePacketImpl; import de.maxhenkel.voicechat.plugins.impl.packets.EntitySoundPacketImpl; import de.maxhenkel.voicechat.plugins.impl.packets.LocationalSoundPacketImpl; import de.maxhenkel.voicechat.plugins.impl.packets.StaticSoundPacketImpl; import de.maxhenkel.voicechat.voice.common.PlayerState; import de.maxhenkel.voicechat.voice.common.SoundPacket; import de.maxhenkel.voicechat.voice.server.ClientConnection; import de.maxhenkel.voicechat.voice.server.Group; import de.maxhenkel.voicechat.voice.server.Server; import de.maxhenkel.voicechat.voice.server.ServerPlayerManager; import java.util.Collection; import java.util.Collections; import java.util.UUID; import java.util.function.Predicate; import java.util.function.Supplier; import java.util.stream.Collectors; import javax.annotation.Nullable; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.Player; public class VoicechatServerApiImpl extends VoicechatApiImpl implements VoicechatServerApi { private static final VoicechatServerApiImpl INSTANCE = new VoicechatServerApiImpl(); private VoicechatServerApiImpl() { } public static VoicechatServerApiImpl instance() { return INSTANCE; } @Override public void sendEntitySoundPacketTo(VoicechatConnection connection, EntitySoundPacket p) { if (p instanceof EntitySoundPacketImpl) { VoicechatServerApiImpl.sendPacket(connection, ((EntitySoundPacketImpl)p).getPacket()); } } @Override public void sendLocationalSoundPacketTo(VoicechatConnection connection, LocationalSoundPacket p) { if (p instanceof LocationalSoundPacketImpl) { VoicechatServerApiImpl.sendPacket(connection, ((LocationalSoundPacketImpl)p).getPacket()); } } @Override public void sendStaticSoundPacketTo(VoicechatConnection connection, StaticSoundPacket p) { if (p instanceof StaticSoundPacketImpl) { VoicechatServerApiImpl.sendPacket(connection, ((StaticSoundPacketImpl)p).getPacket()); } } @Override public ConvertablePacket createPacket() { return new ConvertablePacketImpl(); } @Override @Nullable public EntityAudioChannel createEntityAudioChannel(UUID channelId, Entity entity) { Server server = Voicechat.SERVER.getServer(); if (server == null) { return null; } return new EntityAudioChannelImpl(channelId, server, entity); } @Override @Nullable public LocationalAudioChannel createLocationalAudioChannel(UUID channelId, ServerLevel level, Position initialPosition) { Server server = Voicechat.SERVER.getServer(); if (server == null) { return null; } if (initialPosition instanceof PositionImpl) { return new LocationalAudioChannelImpl(channelId, server, level, (PositionImpl)initialPosition); } throw new IllegalArgumentException("initialPosition is not an instance of PositionImpl"); } @Override @Nullable public StaticAudioChannel createStaticAudioChannel(UUID channelId, ServerLevel level, VoicechatConnection connection) { Server server = Voicechat.SERVER.getServer(); if (server == null) { return null; } StaticAudioChannelImpl staticAudioChannel = new StaticAudioChannelImpl(channelId, server); staticAudioChannel.addTarget(connection); return staticAudioChannel; } @Override @Nullable public StaticAudioChannel createStaticAudioChannel(UUID channelId) { Server server = Voicechat.SERVER.getServer(); if (server == null) { return null; } return new StaticAudioChannelImpl(channelId, server); } @Override public AudioPlayer createAudioPlayer(AudioChannel audioChannel, OpusEncoder encoder, Supplier audioSupplier) { return new AudioPlayerImpl(audioChannel, encoder, audioSupplier); } @Override public AudioPlayer createAudioPlayer(AudioChannel audioChannel, OpusEncoder encoder, short[] audio) { return new AudioPlayerImpl(audioChannel, encoder, new AudioSupplier(audio)); } @Override public AudioSender createAudioSender(VoicechatConnection connection) { return new AudioSenderImpl(connection.getPlayer().getUuid()); } @Override public boolean registerAudioSender(AudioSender sender) { if (!(sender instanceof AudioSenderImpl)) { return false; } return AudioSenderImpl.registerAudioSender((AudioSenderImpl)sender); } @Override public boolean unregisterAudioSender(AudioSender sender) { if (!(sender instanceof AudioSenderImpl)) { return false; } return AudioSenderImpl.unregisterAudioSender((AudioSenderImpl)sender); } @Override public PlayerAudioListener.Builder playerAudioListenerBuilder() { return new PlayerAudioListenerImpl.BuilderImpl(); } @Override public boolean registerAudioListener(AudioListener listener) { return PluginManager.instance().registerAudioListener(listener); } @Override public boolean unregisterAudioListener(AudioListener listener) { return this.unregisterAudioListener(listener.getListenerId()); } @Override public boolean unregisterAudioListener(UUID listenerId) { return PluginManager.instance().unregisterAudioListener(listenerId); } public static void sendPacket(VoicechatConnection receiver, SoundPacket soundPacket) { if (!(receiver.getPlayer() instanceof ServerPlayerImpl)) { throw new IllegalArgumentException("ServerPlayer is not an instance of ServerPlayerImpl"); } VoicechatServerApiImpl.sendPacket(((ServerPlayerImpl)receiver.getPlayer()).getRealServerPlayer(), soundPacket); } public static void sendPacket(Player receiver, SoundPacket soundPacket) { Server server = Voicechat.SERVER.getServer(); if (server == null) { return; } PlayerState state = server.getPlayerStateManager().getState(receiver.getUniqueId()); if (state == null) { return; } ClientConnection c = server.getConnections().get(receiver.getUniqueId()); server.sendSoundPacket(null, null, receiver, state, c, soundPacket, "plugin"); } @Override @Nullable public VoicechatConnection getConnectionOf(UUID playerUuid) { Player player = Bukkit.getPlayer((UUID)playerUuid); if (player == null) { return null; } return VoicechatConnectionImpl.fromPlayer(player); } @Override public de.maxhenkel.voicechat.api.Group createGroup(String name, @Nullable String password) { return this.createGroup(name, password, false); } @Override public de.maxhenkel.voicechat.api.Group createGroup(String name, @Nullable String password, boolean persistent) { return this.groupBuilder().setName(name).setPassword(password).setPersistent(persistent).build(); } @Override public Group.Builder groupBuilder() { return new GroupImpl.BuilderImpl(); } @Override public boolean removeGroup(UUID groupId) { Server server = Voicechat.SERVER.getServer(); if (server == null) { return false; } return server.getGroupManager().removeGroup(groupId); } @Override @Nullable public de.maxhenkel.voicechat.api.Group getGroup(UUID groupId) { Server server = Voicechat.SERVER.getServer(); if (server == null) { return null; } return new GroupImpl(server.getGroupManager().getGroup(groupId)); } @Override public Collection getGroups() { Server server = Voicechat.SERVER.getServer(); if (server == null) { return Collections.emptyList(); } return server.getGroupManager().getGroups().values().stream().map(group -> new GroupImpl((Group)group)).collect(Collectors.toList()); } @Override @Nullable public UUID getSecret(UUID userId) { return null; } @Override public Collection getPlayersInRange(ServerLevel level, Position pos, double range, @Nullable Predicate filter) { if (pos instanceof PositionImpl) { return ServerPlayerManager.getPlayersInRange((World)level.getServerLevel(), ((PositionImpl)pos).getPosition(), range, filter == null ? null : player -> filter.test(new ServerPlayerImpl((Player)player))).stream().map(ServerPlayerImpl::new).collect(Collectors.toList()); } throw new IllegalArgumentException("Position is not an instance of PositionImpl"); } @Override public double getBroadcastRange() { return Math.max(Voicechat.SERVER_CONFIG.voiceChatDistance.get(), Voicechat.SERVER_CONFIG.broadcastRange.get()); } @Override public void registerVolumeCategory(VolumeCategory category) { if (!(category instanceof VolumeCategoryImpl)) { throw new IllegalArgumentException("VolumeCategory is not an instance of VolumeCategoryImpl"); } Server server = Voicechat.SERVER.getServer(); if (server == null) { return; } server.getCategoryManager().addCategory((VolumeCategoryImpl)category); PluginManager.instance().onRegisterVolumeCategory(category); } @Override public void unregisterVolumeCategory(String categoryId) { Server server = Voicechat.SERVER.getServer(); if (server == null) { return; } VolumeCategoryImpl category = server.getCategoryManager().removeCategory(categoryId); if (category != null) { PluginManager.instance().onUnregisterVolumeCategory(category); } } @Override public Collection getVolumeCategories() { Server server = Voicechat.SERVER.getServer(); if (server == null) { return Collections.emptyList(); } return server.getCategoryManager().getCategories().stream().map(VolumeCategory.class::cast).collect(Collectors.toList()); } @Override public ConfigAccessor getServerConfig() { return new ConfigAccessorImpl(Voicechat.SERVER_CONFIG.voiceChatDistance.getConfig()); } }