mirror of
https://github.com/SPAWNRYS-ban/FUCK-CustomDiscs.git
synced 2025-12-10 13:30:24 +05:00
Mp3 Support
Mp3 support for custom discs!
This commit is contained in:
11
build.gradle
11
build.gradle
@@ -1,5 +1,6 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id "com.github.johnrengelman.shadow" version "7.1.0"
|
||||
}
|
||||
|
||||
sourceCompatibility = JavaLanguageVersion.of(java_version as int)
|
||||
@@ -21,6 +22,9 @@ dependencies {
|
||||
implementation("com.googlecode.soundlibs:mp3spi:${mp3spi_version}") {
|
||||
exclude group: 'junit', module: 'junit'
|
||||
}
|
||||
shadow("com.googlecode.soundlibs:mp3spi:${mp3spi_version}") {
|
||||
exclude group: 'junit', module: 'junit'
|
||||
}
|
||||
|
||||
implementation 'com.google.code.findbugs:jsr305:3.0.2'
|
||||
|
||||
@@ -47,3 +51,10 @@ repositories {
|
||||
}
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
configurations = [project.configurations.shadow]
|
||||
classifier 'shadow-dev'
|
||||
//relocate 'javazoom', "me.navoei.${mod_id}.javazoom"
|
||||
//relocate 'org.tritonus', "me.navoei.${mod_id}.tritonus"
|
||||
}
|
||||
@@ -6,10 +6,11 @@ mp3spi_version=1.9.5.4
|
||||
|
||||
bukkit_api_version=1.19
|
||||
bukkit_version=1.19-R0.1-SNAPSHOT
|
||||
mod_id=customdiscsplugin
|
||||
|
||||
# Target an older API to make it compatible with older versions of Simple Voice Chat
|
||||
voicechat_api_version=2.2.22
|
||||
|
||||
plugin_version=1.0.0
|
||||
plugin_version=1.2
|
||||
maven_group=me.Navoei.customdiscsplugin
|
||||
archives_base_name=custom-discs
|
||||
@@ -2,6 +2,9 @@ package me.Navoei.customdiscsplugin.event;
|
||||
|
||||
import de.maxhenkel.voicechat.api.audiochannel.AudioPlayer;
|
||||
import de.maxhenkel.voicechat.api.audiochannel.LocationalAudioChannel;
|
||||
import javazoom.spi.mpeg.sampled.convert.MpegFormatConversionProvider;
|
||||
import javazoom.spi.mpeg.sampled.file.MpegAudioFileReader;
|
||||
import javazoom.spi.mpeg.sampled.file.MpegEncoding;
|
||||
import me.Navoei.customdiscsplugin.CustomDiscs;
|
||||
import me.Navoei.customdiscsplugin.VoicePlugin;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -29,13 +32,14 @@ import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class JukeBox implements Listener {
|
||||
public class JukeBox implements Listener{
|
||||
|
||||
private final Map<UUID, AudioPlayer> playerMap = new ConcurrentHashMap<>();
|
||||
public static AudioFormat FORMAT = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 48000F, 16, 1, 2, 48000F, false);
|
||||
@@ -126,7 +130,9 @@ public class JukeBox implements Listener {
|
||||
if (!container.has(key, PersistentDataType.BYTE_ARRAY)) return;
|
||||
container.get(key, PersistentDataType.BYTE_ARRAY);
|
||||
|
||||
block.getWorld().dropItemNaturally(block.getLocation(), ItemStack.deserializeBytes(container.get(key, PersistentDataType.BYTE_ARRAY)));
|
||||
Location dropItemLocation = new Location(block.getWorld(), block.getLocation().getX(), block.getLocation().getY()+0.5d, block.getLocation().getZ());
|
||||
|
||||
block.getWorld().dropItemNaturally(dropItemLocation, ItemStack.deserializeBytes(container.get(key, PersistentDataType.BYTE_ARRAY)));
|
||||
|
||||
container.remove(key);
|
||||
tileState.update();
|
||||
@@ -220,13 +226,23 @@ public class JukeBox implements Listener {
|
||||
}
|
||||
|
||||
public static byte[] convertFormat(Path file, AudioFormat audioFormat) throws UnsupportedAudioFileException, IOException {
|
||||
try (AudioInputStream source = AudioSystem.getAudioInputStream(file.toFile())) {
|
||||
AudioFormat sourceFormat = source.getFormat();
|
||||
AudioFormat convertFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, sourceFormat.getSampleRate(), 16, sourceFormat.getChannels(), sourceFormat.getChannels() * 2, sourceFormat.getSampleRate(), false);
|
||||
AudioInputStream stream1 = AudioSystem.getAudioInputStream(convertFormat, source);
|
||||
AudioInputStream stream2 = AudioSystem.getAudioInputStream(audioFormat, stream1);
|
||||
return stream2.readAllBytes();
|
||||
AudioInputStream finalInputStream = null;
|
||||
|
||||
if (getFileExtension(file.toFile().toString()).equals("wav")) {
|
||||
AudioInputStream inputStream = AudioSystem.getAudioInputStream(file.toFile());
|
||||
finalInputStream = AudioSystem.getAudioInputStream(audioFormat, inputStream);
|
||||
} else if (getFileExtension(file.toFile().toString()).equals("mp3")) {
|
||||
|
||||
AudioInputStream inputStream = new MpegAudioFileReader().getAudioInputStream(file.toFile());
|
||||
AudioFormat baseFormat = inputStream.getFormat();
|
||||
AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16, baseFormat.getChannels(), baseFormat.getChannels() * 2, baseFormat.getFrameRate(), false);
|
||||
AudioInputStream convertedInputStream = new MpegFormatConversionProvider().getAudioInputStream(decodedFormat, inputStream);
|
||||
finalInputStream = AudioSystem.getAudioInputStream(audioFormat, convertedInputStream);
|
||||
|
||||
}
|
||||
|
||||
assert finalInputStream != null;
|
||||
return finalInputStream.readAllBytes();
|
||||
}
|
||||
|
||||
public boolean isCustomMusicDisc(PlayerInteractEvent e) {
|
||||
@@ -285,4 +301,13 @@ public class JukeBox implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private static String getFileExtension(String s) {
|
||||
int index = s.lastIndexOf(".");
|
||||
if (index > 0) {
|
||||
return s.substring(index + 1);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ main: me.Navoei.customdiscsplugin.CustomDiscs
|
||||
api-version: ${bukkit_api_version}
|
||||
prefix: CustomDiscs
|
||||
authors: [ "Navoei" ]
|
||||
description: A plugin which used the Simple Voice Chat API to add custom music discs.
|
||||
description: A plugin which uses the Simple Voice Chat API to add custom music discs.
|
||||
depend: [ voicechat ]
|
||||
|
||||
commands:
|
||||
|
||||
Reference in New Issue
Block a user