Add range disc + fixes

This commit is contained in:
Athar42
2024-09-08 16:30:08 +02:00
parent ed9f14e35d
commit f332407948
14 changed files with 72 additions and 31 deletions

View File

@@ -1,6 +1,6 @@
plugins {
id 'java'
id 'io.github.goooler.shadow' version '8.1.7'
id "com.gradleup.shadow" version "8.3.0"
}
sourceCompatibility = JavaLanguageVersion.of(java_version as int)
@@ -62,7 +62,7 @@ repositories {
shadowJar {
configurations = [project.configurations.shadow]
archiveClassifier.set("shadow-dev")
archiveClassifier.set("dev")
//relocate 'javazoom', "me.navoei.${mod_id}.javazoom"
//relocate 'org.tritonus', "me.navoei.${mod_id}.tritonus"

View File

@@ -10,8 +10,8 @@ mod_id=customdiscsplugin
# Target an older API to make it compatible with older versions of Simple Voice Chat
voicechat_api_version=2.5.0
command_api_version=9.5.2
command_api_version=9.5.3
plugin_version=3.0
plugin_version=3.1
maven_group=me.Navoei.customdiscsplugin
archives_base_name=custom-discs

View File

@@ -1,6 +1,6 @@
#Sun Aug 11 17:52:06 EDT 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@@ -1,4 +1,4 @@
# Custom Discs v3.0 for Paper 1.21
# Custom Discs v3.1 for Paper 1.21
A Paper fork of henkelmax's Audio Player.
- Play custom music discs using the Simple Voice Chat API. (The voice chat mod is required on the client and server.)
@@ -11,9 +11,14 @@ Downloading Files:
- Example: ```/cd download https://example.com/mysong mysong.mp3```
- Direct Google Drive links: https://lonedev6.github.io/gddl/
Set the range of a disc:
- To set the active range of a playable disc, just use the command ```/cd range <range>``` where <range> is between 1 and the max value set in the config file (default : 256)
- Example: ```/cd range 100```
Permission Nodes (Required to run the commands. Playing discs does not require a permission.):
- ```customdiscs.create``` to create a disc
- ```customdiscs.download``` to download a file
- ```customdiscs.range``` to set the range of the disc
Dependencies:
- This plugin depends on the latest version of ProtocolLib for 1.21 and SimpleVoiceChatBukkit version 2.5.16.
@@ -28,6 +33,9 @@ Default Config.yml:
# The distance from which music discs can be heard in blocks.
music-disc-distance: 16
# The max distance from which music discs can be heard in blocks.
music-disc-max-distance: 256
# The master volume of music discs from 0-1. (You can set values like 0.5 for 50% volume).
music-disc-volume: 1
@@ -38,6 +46,7 @@ max-download-size: 50
help:
- "&8-[&6CustomDiscs Help Page&8]-"
- "&aAuthor&7: &6Navoei"
- "&aContributors&7: &6alfw / &6Athar42"
- "&fGit&0Hub&7: &9&ohttps://github.com/Navoei/CustomDiscs"
```
@@ -60,6 +69,8 @@ create-disc: "&aCreate a disc by doing &7/cd create %filename% \"Custom Lore\"&a
download-error: "&cAn error has occurred while downloading."
now-playing: "&6Now playing: %song_name%"
disc-converted: "&aConverted disc to new format! &fThis is due to changes in newer Minecraft versions which introduced &7JukeboxPlayableComponent&f."
invalid-range: "&cYou need to chose a range between 1 and %range_value%"
create-custom-range: "&7Your range is set to: &a\"%custom_range%\"."
```

View File

@@ -15,6 +15,7 @@ import me.Navoei.customdiscsplugin.event.JukeBox;
import me.Navoei.customdiscsplugin.language.Lang;
import org.bukkit.NamespacedKey;
import org.bukkit.block.Jukebox;
import org.bukkit.entity.Player;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
@@ -34,6 +35,7 @@ public final class CustomDiscs extends JavaPlugin {
public static YamlConfiguration LANG;
public static File LANG_FILE;
public float musicDiscDistance;
public float musicDiscMaxDistance;
public float musicDiscVolume;
@Override
@@ -71,6 +73,7 @@ public final class CustomDiscs extends JavaPlugin {
getServer().getPluginManager().registerEvents(new HopperManager(), this);
musicDiscDistance = getConfig().getInt("music-disc-distance");
musicDiscMaxDistance = getConfig().getInt("music-disc-max-distance");
musicDiscVolume = Float.parseFloat(Objects.requireNonNull(getConfig().getString("music-disc-volume")));
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
@@ -110,7 +113,11 @@ public final class CustomDiscs extends JavaPlugin {
public static CustomDiscs getInstance() {
return instance;
}
public static boolean isMusicDisc(Player p) {
return p.getInventory().getItemInMainHand().getType().toString().contains("MUSIC_DISC");
}
/**
* Load the lang.yml file.
*

View File

@@ -17,6 +17,7 @@ import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.components.JukeboxPlayableComponent;
import org.bukkit.persistence.PersistentDataType;
@@ -43,6 +44,15 @@ public class HopperManager implements Listener {
ItemMeta discMeta = event.getItem().getItemMeta();
String soundFileName = discMeta.getPersistentDataContainer().get(new NamespacedKey(customDiscs, "customdisc"), PersistentDataType.STRING);
PersistentDataContainer persistentDataContainer = event.getItem().getItemMeta().getPersistentDataContainer();
float range = CustomDiscs.getInstance().musicDiscDistance;
NamespacedKey customSoundRangeKey = new NamespacedKey(customDiscs, "customsoundrange");
if(persistentDataContainer.has(customSoundRangeKey, PersistentDataType.FLOAT)) {
range = Math.min(persistentDataContainer.get(customSoundRangeKey, PersistentDataType.FLOAT), CustomDiscs.getInstance().musicDiscMaxDistance);
}
if (discMeta.getJukeboxPlayable().isShowInTooltip()) {
JukeboxPlayableComponent jpc = discMeta.getJukeboxPlayable();
jpc.setShowInTooltip(false);
@@ -52,7 +62,7 @@ public class HopperManager implements Listener {
Path soundFilePath = Path.of(customDiscs.getDataFolder().getPath(), "musicdata", soundFileName);
assert VoicePlugin.voicechatServerApi != null;
playerManager.playLocationalAudio(VoicePlugin.voicechatServerApi, soundFilePath, event.getDestination().getLocation().getBlock(), customActionBarSongPlaying);
playerManager.playLocationalAudio(VoicePlugin.voicechatServerApi, soundFilePath, event.getDestination().getLocation().getBlock(), customActionBarSongPlaying, range);
}

View File

@@ -8,8 +8,8 @@ import de.maxhenkel.voicechat.api.audiochannel.LocationalAudioChannel;
import javazoom.spi.mpeg.sampled.convert.MpegFormatConversionProvider;
import javazoom.spi.mpeg.sampled.file.MpegAudioFileReader;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
@@ -44,7 +44,7 @@ public class PlayerManager {
});
}
public void playLocationalAudio(VoicechatServerApi api, Path soundFilePath, Block block, Component actionbarComponent) {
public void playLocationalAudio(VoicechatServerApi api, Path soundFilePath, Block block, Component actionbarComponent, float range) {
UUID id = UUID.nameUUIDFromBytes(block.getLocation().toString().getBytes());
LocationalAudioChannel audioChannel = api.createLocationalAudioChannel(id, api.fromServerLevel(block.getWorld()), api.createPosition(block.getLocation().getX() + 0.5d, block.getLocation().getY() + 0.5d, block.getLocation().getZ() + 0.5d));
@@ -52,7 +52,7 @@ public class PlayerManager {
if (audioChannel == null) return;
audioChannel.setCategory(VoicePlugin.MUSIC_DISC_CATEGORY);
audioChannel.setDistance(CustomDiscs.getInstance().musicDiscDistance);
audioChannel.setDistance(range);
AtomicBoolean stopped = new AtomicBoolean();
AtomicReference<de.maxhenkel.voicechat.api.audiochannel.AudioPlayer> player = new AtomicReference<>();
@@ -68,7 +68,7 @@ public class PlayerManager {
});
executorService.execute(() -> {
Collection<ServerPlayer> playersInRange = api.getPlayersInRange(api.fromServerLevel(block.getWorld()), api.createPosition(block.getLocation().getX() + 0.5d, block.getLocation().getY() + 0.5d, block.getLocation().getZ() + 0.5d), CustomDiscs.getInstance().musicDiscDistance);
Collection<ServerPlayer> playersInRange = api.getPlayersInRange(api.fromServerLevel(block.getWorld()), api.createPosition(block.getLocation().getX() + 0.5d, block.getLocation().getY() + 0.5d, block.getLocation().getZ() + 0.5d), range);
de.maxhenkel.voicechat.api.audiochannel.AudioPlayer audioPlayer = playChannel(api, audioChannel, block, soundFilePath, playersInRange);
@@ -113,7 +113,7 @@ public class PlayerManager {
Bukkit.getLogger().info("Error Occurred At: " + block.getLocation());
for (ServerPlayer serverPlayer : playersInRange) {
Player bukkitPlayer = (Player) serverPlayer.getPlayer();
bukkitPlayer.sendMessage(ChatColor.RED + "An error has occurred while trying to play this disc.");
bukkitPlayer.sendMessage(NamedTextColor.RED + "An error has occurred while trying to play this disc.");
}
return null;
}

View File

@@ -5,8 +5,9 @@ import dev.jorel.commandapi.executors.CommandArguments;
import me.Navoei.customdiscsplugin.CustomDiscs;
import me.Navoei.customdiscsplugin.command.SubCommands.CreateSubCommand;
import me.Navoei.customdiscsplugin.command.SubCommands.DownloadSubCommand;
import me.Navoei.customdiscsplugin.command.SubCommands.SetRangeSubCommand;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.ChatColor;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
@@ -23,6 +24,7 @@ public class CustomDiscCommand extends CommandAPICommand {
this.withSubcommand(new CreateSubCommand(plugin));
this.withSubcommand(new DownloadSubCommand(plugin));
this.withSubcommand(new SetRangeSubCommand(plugin));
this.executesPlayer(this::onCommandPlayer);
this.executesConsole(this::onCommandConsole);
@@ -38,7 +40,7 @@ public class CustomDiscCommand extends CommandAPICommand {
}
private int onCommandConsole(ConsoleCommandSender executor, CommandArguments arguments) {
executor.sendMessage(ChatColor.RED + "Only players can use this command!");
executor.sendMessage(NamedTextColor.RED + "Only players can use this command!");
return 1;
}
}

View File

@@ -12,7 +12,6 @@ import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.ChatColor;
import org.bukkit.NamespacedKey;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
@@ -36,7 +35,7 @@ public class CreateSubCommand extends CommandAPICommand {
super("create");
this.plugin = plugin;
this.withFullDescription(ChatColor.GRAY + "Creates a custom music disc.");
this.withFullDescription(NamedTextColor.GRAY + "Creates a custom music disc.");
this.withUsage("/customdisc create <filename> \"Custom Lore\"");
this.withArguments(new StringArgument("filename").replaceSuggestions(ArgumentSuggestions.stringCollection((sender) -> {
@@ -60,7 +59,7 @@ public class CreateSubCommand extends CommandAPICommand {
}
private int onCommandPlayer(Player player, CommandArguments arguments) {
if (!isMusicDisc(player)) {
if (!CustomDiscs.isMusicDisc(player)) {
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.NOT_HOLDING_DISC.toString()));
return 1;
}
@@ -113,7 +112,7 @@ public class CreateSubCommand extends CommandAPICommand {
}
private int onCommandConsole(ConsoleCommandSender executor, CommandArguments arguments) {
executor.sendMessage(ChatColor.RED + "Only players can use this command!");
executor.sendMessage(NamedTextColor.RED + "Only players can use this command!");
return 1;
}
@@ -125,8 +124,4 @@ public class CreateSubCommand extends CommandAPICommand {
return "";
}
}
private boolean isMusicDisc(Player p) {
return p.getInventory().getItemInMainHand().getType().toString().contains("MUSIC_DISC");
}
}

View File

@@ -7,8 +7,8 @@ import dev.jorel.commandapi.executors.CommandArguments;
import me.Navoei.customdiscsplugin.CustomDiscs;
import me.Navoei.customdiscsplugin.language.Lang;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.codehaus.plexus.util.FileUtils;
@@ -27,7 +27,7 @@ public class DownloadSubCommand extends CommandAPICommand {
super("download");
this.plugin = plugin;
this.withFullDescription(ChatColor.GRAY + "Downloads a file from a given URL.");
this.withFullDescription(NamedTextColor.GRAY + "Downloads a file from a given URL.");
this.withUsage("/customdisc download <url> <filename.extension>");
this.withArguments(new TextArgument("url"));
@@ -86,7 +86,7 @@ public class DownloadSubCommand extends CommandAPICommand {
}
private int onCommandConsole(ConsoleCommandSender executor, CommandArguments arguments) {
executor.sendMessage(ChatColor.RED + "Only players can use this command!");
executor.sendMessage(NamedTextColor.RED + "Only players can use this command!");
return 1;
}

View File

@@ -10,7 +10,6 @@ import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.block.Block;
@@ -26,6 +25,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.components.JukeboxPlayableComponent;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import java.io.FileNotFoundException;
@@ -51,6 +51,15 @@ public class JukeBox implements Listener{
ItemMeta discMeta = event.getItem().getItemMeta();
String soundFileName = discMeta.getPersistentDataContainer().get(new NamespacedKey(customDiscs, "customdisc"), PersistentDataType.STRING);
PersistentDataContainer persistentDataContainer = event.getItem().getItemMeta().getPersistentDataContainer();
float range = CustomDiscs.getInstance().musicDiscDistance;
NamespacedKey customSoundRangeKey = new NamespacedKey(customDiscs, "customsoundrange");
if(persistentDataContainer.has(customSoundRangeKey, PersistentDataType.FLOAT)) {
range = Math.min(persistentDataContainer.get(customSoundRangeKey, PersistentDataType.FLOAT), CustomDiscs.getInstance().musicDiscMaxDistance);
}
if (discMeta.getJukeboxPlayable().isShowInTooltip()) {
JukeboxPlayableComponent jpc = discMeta.getJukeboxPlayable();
jpc.setShowInTooltip(false);
@@ -69,9 +78,9 @@ public class JukeBox implements Listener{
Component customActionBarSongPlaying = LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.NOW_PLAYING.toString().replace("%song_name%", songName));
assert VoicePlugin.voicechatServerApi != null;
playerManager.playLocationalAudio(VoicePlugin.voicechatServerApi, soundFilePath, block, customActionBarSongPlaying);
playerManager.playLocationalAudio(VoicePlugin.voicechatServerApi, soundFilePath, block, customActionBarSongPlaying, range);
} else {
player.sendMessage(ChatColor.RED + "Sound file not found.");
player.sendMessage(NamedTextColor.RED + "Sound file not found.");
event.setCancelled(true);
throw new FileNotFoundException("Sound file is missing!");
}

View File

@@ -1,6 +1,5 @@
package me.Navoei.customdiscsplugin.language;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.YamlConfiguration;
public enum Lang {
@@ -19,7 +18,9 @@ public enum Lang {
CREATE_DISC("create-disc", "&aCreate a disc by doing &7/cd create filename.extension \"Custom Lore\"&a."),
DOWNLOAD_ERROR("download-error", "&rAn error has occurred while downloading."),
NOW_PLAYING("now-playing","&6Now playing: %song_name%"),
DISC_CONVERTED("disc-converted", "&aConverted disc to new format! &fThis is due to changes in newer Minecraft versions which introduced &7JukeboxPlayableComponent&f.");
DISC_CONVERTED("disc-converted", "&aConverted disc to new format! &fThis is due to changes in newer Minecraft versions which introduced &7JukeboxPlayableComponent&f."),
INVALID_RANGE("invalid-range","&rYou need to chose a range between 1 and %range_value%"),
CREATE_CUSTOM_RANGE("create-custom-range", "&7Your range is set to: &a\"%custom_range%\".");
private final String path;
private final String def;

View File

@@ -3,6 +3,9 @@
# The distance from which music discs can be heard in blocks.
music-disc-distance: 16
# The max distance from which music discs can be heard in blocks.
music-disc-max-distance: 256
# The master volume of music discs from 0-1. (You can set values like 0.5 for 50% volume).
music-disc-volume: 1
@@ -13,4 +16,5 @@ max-download-size: 50
help:
- "&8-[&6CustomDiscs Help Page&8]-"
- "&aAuthor&7: &6Navoei"
- "&aContributors&7: &6alfw / &6Athar42"
- "&fGit&0Hub&7: &9&ohttps://github.com/Navoei/CustomDiscs"

View File

@@ -15,3 +15,5 @@ create-disc: "&aCreate a disc by doing &7/cd create %filename% \"Custom Lore\"&a
download-error: "&cAn error has occurred while downloading."
now-playing: "&6Now playing: %song_name%"
disc-converted: "&aConverted disc to new format! &fThis is due to changes in newer Minecraft versions which introduced &7JukeboxPlayableComponent&f."
invalid-range: "&cYou need to chose a range between 1 and %range_value%"
create-custom-range: "&7Your range is set to: &a\"%custom_range%\"."