This commit is contained in:
parent
6a8f982588
commit
0d54e71294
3 changed files with 0 additions and 116 deletions
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2024 Minecon724
|
||||
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
||||
* in the project root for the full license text.
|
||||
*/
|
||||
|
||||
package eu.m724.tweaks.player;
|
||||
|
||||
import de.maxhenkel.voicechat.api.BukkitVoicechatService;
|
||||
import de.maxhenkel.voicechat.api.VoicechatServerApi;
|
||||
import de.maxhenkel.voicechat.api.VolumeCategory;
|
||||
import de.maxhenkel.voicechat.api.audiochannel.AudioPlayer;
|
||||
import de.maxhenkel.voicechat.api.audiochannel.EntityAudioChannel;
|
||||
import de.maxhenkel.voicechat.api.opus.OpusEncoderMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MusicPlayer {
|
||||
private static final String PLAYER_CATEGORY = "music_player";
|
||||
|
||||
private VoicechatServerApi voicechat = null;
|
||||
|
||||
private final Plugin plugin;
|
||||
|
||||
public MusicPlayer(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
BukkitVoicechatService service = plugin.getServer().getServicesManager().load(BukkitVoicechatService.class);
|
||||
service.registerPlugin(new MyVoicechatPlugin(this));
|
||||
}
|
||||
|
||||
void unlock(VoicechatServerApi voicechat) {
|
||||
VolumeCategory category = voicechat.volumeCategoryBuilder()
|
||||
.setId(PLAYER_CATEGORY)
|
||||
.setName("Music players")
|
||||
.build();
|
||||
|
||||
voicechat.registerVolumeCategory(category);
|
||||
|
||||
this.voicechat = voicechat;
|
||||
}
|
||||
|
||||
public void create(Player player) {
|
||||
UUID channelID = UUID.randomUUID();
|
||||
EntityAudioChannel channel = voicechat.createEntityAudioChannel(channelID, voicechat.fromEntity(player));
|
||||
|
||||
channel.setCategory(PLAYER_CATEGORY);
|
||||
channel.setDistance(10);
|
||||
|
||||
short[] arr;
|
||||
try {
|
||||
AudioInputStream audio = AudioSystem.getAudioInputStream(plugin.getResource("music.flac"));
|
||||
int samples = (int) (audio.available() / audio.getFrameLength());
|
||||
arr = new short[samples];
|
||||
for (int i=0; i<audio.available(); i++) {
|
||||
|
||||
}
|
||||
} catch (UnsupportedAudioFileException | IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
AudioPlayer audioPlayer = voicechat.createAudioPlayer(channel, voicechat.createEncoder(OpusEncoderMode.AUDIO), arr);
|
||||
audioPlayer.startPlaying();
|
||||
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2024 Minecon724
|
||||
* Tweaks724 is licensed under the GNU General Public License. See the LICENSE.md file
|
||||
* in the project root for the full license text.
|
||||
*/
|
||||
|
||||
package eu.m724.tweaks.player;
|
||||
|
||||
import de.maxhenkel.voicechat.api.VoicechatApi;
|
||||
import de.maxhenkel.voicechat.api.VoicechatPlugin;
|
||||
import de.maxhenkel.voicechat.api.VoicechatServerApi;
|
||||
import de.maxhenkel.voicechat.api.events.EventRegistration;
|
||||
import de.maxhenkel.voicechat.api.events.VoicechatServerStartedEvent;
|
||||
|
||||
public class MyVoicechatPlugin implements VoicechatPlugin {
|
||||
private final MusicPlayer musicPlayer;
|
||||
|
||||
MyVoicechatPlugin(MusicPlayer musicPlayer) {
|
||||
this.musicPlayer = musicPlayer;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPluginId() {
|
||||
return "tweaks724";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(VoicechatApi api) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerEvents(EventRegistration registration) {
|
||||
registration.registerEvent(VoicechatServerStartedEvent.class, this::onServerStarted);
|
||||
}
|
||||
|
||||
public void onServerStarted(VoicechatServerStartedEvent event) {
|
||||
VoicechatServerApi api = event.getVoicechat();
|
||||
musicPlayer.unlock(api);
|
||||
}
|
||||
}
|
|
@ -6,7 +6,6 @@ website: https://www.spigotmc.org/resources/tweaks724.121057/
|
|||
main: eu.m724.tweaks.TweaksPlugin
|
||||
api-version: 1.21.1
|
||||
depend: [ProtocolLib]
|
||||
#softdepend: [voicechat]
|
||||
|
||||
libraries:
|
||||
- eu.m724:mstats-spigot:0.1.0
|
||||
|
|
Loading…
Reference in a new issue