Finished recode

This commit is contained in:
Navoei
2025-01-30 19:21:09 -06:00
parent be0a3f8614
commit 4f2deb5468
2 changed files with 14 additions and 5 deletions

View File

@@ -103,6 +103,7 @@ public class PlayerManager {
if (playerMap.containsValue(playerReference)) {
playerMap.remove(id);
}
System.out.println(playerMap);
});
synchronized (stopped) {
if (!stopped.get()) {
@@ -160,7 +161,9 @@ public class PlayerManager {
}
private static short[] readSoundFile(AudioInputStream inputStream) throws IOException {
return VoicePlugin.voicechatApi.getAudioConverter().bytesToShorts(getAudioPacket(inputStream));
byte[] audioPacket = getAudioPacket(inputStream);
if (audioPacket == null) return null;
return VoicePlugin.voicechatApi.getAudioConverter().bytesToShorts(audioPacket);
}
private static byte[] getAudioPacket(AudioInputStream inputStream) throws IOException {
@@ -184,6 +187,8 @@ public class PlayerManager {
private static byte[] adjustVolume(byte[] audioSamples, double volume) {
if (audioSamples == null) return null;
if (volume > 1d || volume < 0d) {
CustomDiscs.getInstance().getLogger().info("Error: The volume must be between 0 and 1 in the config!");
return null;

View File

@@ -45,7 +45,7 @@ public class JukeBox implements Listener{
if (event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getClickedBlock() == null || event.getItem() == null || event.getItem().getItemMeta() == null || block == null) return;
if (event.getClickedBlock().getType() != Material.JUKEBOX) return;
if (isCustomMusicDisc(event) && !jukeboxContainsDisc(block)) {
if (isCustomMusicDisc(event.getItem()) && !jukeboxContainsDisc(block)) {
ItemMeta discMeta = event.getItem().getItemMeta();
String soundFileName = discMeta.getPersistentDataContainer().get(new NamespacedKey(customDiscs, "customdisc"), PersistentDataType.STRING);
@@ -120,6 +120,8 @@ public class JukeBox implements Listener{
Block block = event.getBlock();
if (block.getType() != Material.JUKEBOX) return;
Jukebox jukebox = (Jukebox) block.getState();
if (!isCustomMusicDisc(jukebox.getRecord())) return;
stopDisc(block);
}
@@ -129,6 +131,8 @@ public class JukeBox implements Listener{
for (Block explodedBlock : event.blockList()) {
if (explodedBlock.getType() == Material.JUKEBOX) {
Jukebox jukebox = (Jukebox) explodedBlock.getState();
if (!isCustomMusicDisc(jukebox.getRecord())) return;
stopDisc(explodedBlock);
}
}
@@ -140,9 +144,9 @@ public class JukeBox implements Listener{
return jukebox.getRecord().getType() != Material.AIR;
}
public boolean isCustomMusicDisc(PlayerInteractEvent e) {
if (e.getItem()==null) return false;
return e.getItem().getItemMeta().getPersistentDataContainer().has(new NamespacedKey(customDiscs, "customdisc"));
public boolean isCustomMusicDisc(ItemStack itemStack) {
if (itemStack==null) return false;
return itemStack.getItemMeta().getPersistentDataContainer().has(new NamespacedKey(customDiscs, "customdisc"));
}
private void stopDisc(Block block) {