mirror of
https://github.com/SPAWNRYS-ban/FUCK-CustomDiscs.git
synced 2025-12-10 13:30:24 +05:00
Complications with Goathorns
Goat horns removed due to complications in cancelling sound events.
This commit is contained in:
@@ -15,15 +15,10 @@ Set the range of a disc:
|
||||
- To set the active range of a playable disc, just use the command ```/cd range <range>```. The range can be between 1 and the max value set in the config file (default : 256)
|
||||
- Example: ```/cd range 100```
|
||||
|
||||
Set the cooldown for a modified goat horn: (GOAT HORNS ARE EXPERIMENTAL!!! Please report any issues.)
|
||||
- To set a different cooldown timer than the one set by the config, just use the command ```/cd goatcooldown <cooldown>``` where <cooldown> is between 0 and the max value set in the config file (default : 6000)
|
||||
- Example: ```/cd goatcooldown 7```
|
||||
|
||||
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
|
||||
- ```customdiscs.horncooldown``` to set the cooldown for your modified goat horn
|
||||
|
||||
Dependencies:
|
||||
- This plugin depends on the latest version of ProtocolLib for 1.21 and SimpleVoiceChatBukkit version 2.5.16.
|
||||
|
||||
@@ -11,14 +11,11 @@ import de.maxhenkel.voicechat.api.BukkitVoicechatService;
|
||||
import dev.jorel.commandapi.CommandAPI;
|
||||
import dev.jorel.commandapi.CommandAPIBukkitConfig;
|
||||
import me.Navoei.customdiscsplugin.command.CustomDiscCommand;
|
||||
import me.Navoei.customdiscsplugin.event.GoatHorn;
|
||||
import me.Navoei.customdiscsplugin.event.JukeBox;
|
||||
import me.Navoei.customdiscsplugin.language.Lang;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.block.Jukebox;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@@ -39,9 +36,6 @@ public final class CustomDiscs extends JavaPlugin {
|
||||
public float musicDiscDistance;
|
||||
public float musicDiscMaxDistance;
|
||||
public float musicDiscVolume;
|
||||
public float hornCooldown;
|
||||
public int hornMaxCooldown;
|
||||
public int hornMaxCooldownTicks;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
@@ -75,14 +69,11 @@ public final class CustomDiscs extends JavaPlugin {
|
||||
}
|
||||
|
||||
getServer().getPluginManager().registerEvents(new JukeBox(), this);
|
||||
getServer().getPluginManager().registerEvents(new GoatHorn(), this);
|
||||
getServer().getPluginManager().registerEvents(new HopperManager(), this);
|
||||
|
||||
musicDiscDistance = Objects.requireNonNull(getConfig().getInt("music-disc-distance"));
|
||||
musicDiscMaxDistance = Objects.requireNonNull(getConfig().getInt("music-disc-max-distance"));
|
||||
musicDiscVolume = Float.parseFloat(Objects.requireNonNull(getConfig().getString("music-disc-volume")));
|
||||
hornCooldown = Float.parseFloat(Objects.requireNonNull(getConfig().getString("horn-cooldown")));
|
||||
hornMaxCooldown = Objects.requireNonNull(getConfig().getInt("horn-max-cooldown"));
|
||||
|
||||
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
|
||||
|
||||
@@ -101,61 +101,6 @@ public class PlayerManager {
|
||||
});
|
||||
}
|
||||
|
||||
public void playLocationalAudioHorn(VoicechatServerApi api, Path soundFilePath, Player 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));
|
||||
|
||||
if (audioChannel == null) return;
|
||||
|
||||
audioChannel.setCategory(VoicePlugin.GOAT_HORN_CATEGORY);
|
||||
audioChannel.setDistance(range);
|
||||
|
||||
AtomicBoolean stopped = new AtomicBoolean();
|
||||
AtomicReference<de.maxhenkel.voicechat.api.audiochannel.AudioPlayer> player = new AtomicReference<>();
|
||||
|
||||
playerMap.put(id, () -> {
|
||||
synchronized (stopped) {
|
||||
stopped.set(true);
|
||||
de.maxhenkel.voicechat.api.audiochannel.AudioPlayer audioPlayer = player.get();
|
||||
if (audioPlayer != null) {
|
||||
audioPlayer.stopPlaying();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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), range);
|
||||
|
||||
de.maxhenkel.voicechat.api.audiochannel.AudioPlayer audioPlayer = playChannelHorn(api, audioChannel, block, soundFilePath, playersInRange);
|
||||
|
||||
for (ServerPlayer serverPlayer : playersInRange) {
|
||||
Player bukkitPlayer = (Player) serverPlayer.getPlayer();
|
||||
bukkitPlayer.sendActionBar(actionbarComponent);
|
||||
}
|
||||
|
||||
if (audioPlayer == null) {
|
||||
playerMap.remove(id);
|
||||
return;
|
||||
}
|
||||
|
||||
audioPlayer.setOnStopped(() -> {
|
||||
|
||||
//Bukkit.getScheduler().runTask(CustomDiscs.getInstance(), () -> HopperManager.instance().discToHopper(block));
|
||||
|
||||
playerMap.remove(id);
|
||||
});
|
||||
|
||||
synchronized (stopped) {
|
||||
if (!stopped.get()) {
|
||||
player.set(audioPlayer);
|
||||
} else {
|
||||
audioPlayer.stopPlaying();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private de.maxhenkel.voicechat.api.audiochannel.AudioPlayer playChannel(VoicechatServerApi api, AudioChannel audioChannel, Block block, Path soundFilePath, Collection<ServerPlayer> playersInRange) {
|
||||
try {
|
||||
@@ -174,24 +119,6 @@ public class PlayerManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private de.maxhenkel.voicechat.api.audiochannel.AudioPlayer playChannelHorn(VoicechatServerApi api, AudioChannel audioChannel, Player block, Path soundFilePath, Collection<ServerPlayer> playersInRange) {
|
||||
try {
|
||||
short[] audio = readSoundFile(soundFilePath);
|
||||
AudioPlayer audioPlayer = api.createAudioPlayer(audioChannel, api.createEncoder(), audio);
|
||||
audioPlayer.startPlaying();
|
||||
return audioPlayer;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Bukkit.getLogger().info("Error Occurred At: " + block.getLocation());
|
||||
for (ServerPlayer serverPlayer : playersInRange) {
|
||||
Player bukkitPlayer = (Player) serverPlayer.getPlayer();
|
||||
bukkitPlayer.sendMessage(NamedTextColor.RED + "An error has occurred while trying to play this horn.");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static short[] readSoundFile(Path file) throws UnsupportedAudioFileException, IOException, LineUnavailableException {
|
||||
return VoicePlugin.voicechatApi.getAudioConverter().bytesToShorts(convertFormat(file, FORMAT));
|
||||
}
|
||||
|
||||
@@ -69,24 +69,6 @@ public class VoicePlugin implements VoicechatPlugin {
|
||||
.setIcon(getMusicDiscIcon())
|
||||
.build();
|
||||
voicechatServerApi.registerVolumeCategory(musicDiscs);
|
||||
|
||||
goatHorns = voicechatServerApi.volumeCategoryBuilder()
|
||||
.setId(GOAT_HORN_CATEGORY)
|
||||
.setName("Goat Horns")
|
||||
.setDescription("The volume of goat horns")
|
||||
.setIcon(getGoatHornsIcon())
|
||||
.build();
|
||||
voicechatServerApi.registerVolumeCategory(goatHorns);
|
||||
|
||||
/*
|
||||
playerHeads = voicechatServerApi.volumeCategoryBuilder()
|
||||
.setId(PLAYER_HEAD_CATEGORY)
|
||||
.setName("Player Heads")
|
||||
.setDescription("The volume of player heads (not enabled)")
|
||||
.setIcon(getPlayerHeadsIcon())
|
||||
.build();
|
||||
voicechatServerApi.registerVolumeCategory(playerHeads);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
@@ -116,62 +98,5 @@ public class VoicePlugin implements VoicechatPlugin {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private int[][] getGoatHornsIcon() {
|
||||
try {
|
||||
Enumeration<URL> resources = CustomDiscs.getInstance().getClass().getClassLoader().getResources("goat_horn_category.png");
|
||||
|
||||
while (resources.hasMoreElements()) {
|
||||
BufferedImage bufferedImage = ImageIO.read(resources.nextElement().openStream());
|
||||
if (bufferedImage.getWidth() != 16) {
|
||||
continue;
|
||||
}
|
||||
if (bufferedImage.getHeight() != 16) {
|
||||
continue;
|
||||
}
|
||||
int[][] image = new int[16][16];
|
||||
for (int x = 0; x < bufferedImage.getWidth(); x++) {
|
||||
for (int y = 0; y < bufferedImage.getHeight(); y++) {
|
||||
image[x][y] = bufferedImage.getRGB(x, y);
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
private int[][] getPlayerHeadsIcon() {
|
||||
try {
|
||||
Enumeration<URL> resources = CustomDiscs.getInstance().getClass().getClassLoader().getResources("player_head_category.png");
|
||||
|
||||
while (resources.hasMoreElements()) {
|
||||
BufferedImage bufferedImage = ImageIO.read(resources.nextElement().openStream());
|
||||
if (bufferedImage.getWidth() != 16) {
|
||||
continue;
|
||||
}
|
||||
if (bufferedImage.getHeight() != 16) {
|
||||
continue;
|
||||
}
|
||||
int[][] image = new int[16][16];
|
||||
for (int x = 0; x < bufferedImage.getWidth(); x++) {
|
||||
for (int y = 0; y < bufferedImage.getHeight(); y++) {
|
||||
image[x][y] = bufferedImage.getRGB(x, y);
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
@@ -6,7 +6,6 @@ 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 me.Navoei.customdiscsplugin.command.SubCommands.SetHornCooldownSubCommand;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
@@ -26,7 +25,6 @@ public class CustomDiscCommand extends CommandAPICommand {
|
||||
this.withSubcommand(new CreateSubCommand(plugin));
|
||||
this.withSubcommand(new DownloadSubCommand(plugin));
|
||||
this.withSubcommand(new SetRangeSubCommand(plugin));
|
||||
this.withSubcommand(new SetHornCooldownSubCommand(plugin));
|
||||
|
||||
this.executesPlayer(this::onCommandPlayer);
|
||||
this.executesConsole(this::onCommandConsole);
|
||||
|
||||
@@ -67,7 +67,7 @@ public class CreateSubCommand extends CommandAPICommand {
|
||||
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
|
||||
if (!isMusicDisc(item) && !isGoatHorn(item)) {
|
||||
if (!isMusicDisc(item)) {
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.NOT_HOLDING_DISC.toString()));
|
||||
return 1;
|
||||
}
|
||||
@@ -98,41 +98,20 @@ public class CreateSubCommand extends CommandAPICommand {
|
||||
|
||||
String song_name = Objects.requireNonNull(arguments.getByClass("song_name", String.class));
|
||||
|
||||
if (isMusicDisc(item)) {
|
||||
// IF DISC
|
||||
ItemStack disc = new ItemStack(player.getInventory().getItemInMainHand());
|
||||
ItemMeta meta = disc.getItemMeta();
|
||||
@Nullable List<Component> itemLore = new ArrayList<>();
|
||||
final TextComponent customLoreSong = Component.text().decoration(TextDecoration.ITALIC, false).content(song_name).color(NamedTextColor.GRAY).build();
|
||||
itemLore.add(customLoreSong);
|
||||
meta.lore(itemLore);
|
||||
ItemStack disc = new ItemStack(player.getInventory().getItemInMainHand());
|
||||
ItemMeta meta = disc.getItemMeta();
|
||||
@Nullable List<Component> itemLore = new ArrayList<>();
|
||||
final TextComponent customLoreSong = Component.text().decoration(TextDecoration.ITALIC, false).content(song_name).color(NamedTextColor.GRAY).build();
|
||||
itemLore.add(customLoreSong);
|
||||
meta.lore(itemLore);
|
||||
|
||||
JukeboxPlayableComponent jpc = meta.getJukeboxPlayable();
|
||||
jpc.setShowInTooltip(false);
|
||||
meta.setJukeboxPlayable(jpc);
|
||||
JukeboxPlayableComponent jpc = meta.getJukeboxPlayable();
|
||||
jpc.setShowInTooltip(false);
|
||||
meta.setJukeboxPlayable(jpc);
|
||||
|
||||
PersistentDataContainer data = meta.getPersistentDataContainer();
|
||||
data.set(new NamespacedKey(this.plugin, "customdisc"), PersistentDataType.STRING, filename);
|
||||
player.getInventory().getItemInMainHand().setItemMeta(meta);
|
||||
|
||||
} else if (isGoatHorn(item)) {
|
||||
// IF HORN
|
||||
ItemStack goat_horn = new ItemStack(player.getInventory().getItemInMainHand());
|
||||
ItemMeta meta = goat_horn.getItemMeta();
|
||||
@Nullable List<Component> itemLore = new ArrayList<>();
|
||||
final TextComponent customLoreSong = Component.text().decoration(TextDecoration.ITALIC, false).content(song_name).color(NamedTextColor.GRAY).build();
|
||||
itemLore.add(customLoreSong);
|
||||
meta.lore(itemLore);
|
||||
|
||||
meta.addItemFlags(ItemFlag.HIDE_ADDITIONAL_TOOLTIP);
|
||||
|
||||
PersistentDataContainer data = meta.getPersistentDataContainer();
|
||||
data.set(new NamespacedKey(this.plugin, "customhorn"), PersistentDataType.STRING, filename);
|
||||
player.getInventory().getItemInMainHand().setItemMeta(meta);
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
|
||||
PersistentDataContainer data = meta.getPersistentDataContainer();
|
||||
data.set(new NamespacedKey(this.plugin, "customdisc"), PersistentDataType.STRING, filename);
|
||||
player.getInventory().getItemInMainHand().setItemMeta(meta);
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.CREATE_FILENAME.toString().replace("%filename%", filename)));
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.CREATE_CUSTOM_NAME.toString().replace("%custom_name%", song_name)));
|
||||
return 1;
|
||||
@@ -156,7 +135,4 @@ public class CreateSubCommand extends CommandAPICommand {
|
||||
return item.getType().toString().contains("MUSIC_DISC");
|
||||
}
|
||||
|
||||
public static boolean isGoatHorn(ItemStack item) {
|
||||
return item.getType().toString().contains("GOAT_HORN");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
package me.Navoei.customdiscsplugin.command.SubCommands;
|
||||
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.arguments.FloatArgument;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import io.papermc.paper.datacomponent.DataComponentTypes;
|
||||
import io.papermc.paper.datacomponent.item.JukeboxPlayable;
|
||||
import io.papermc.paper.datacomponent.item.UseCooldown;
|
||||
import me.Navoei.customdiscsplugin.CustomDiscs;
|
||||
import me.Navoei.customdiscsplugin.language.Lang;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.components.UseCooldownComponent;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.Objects;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class SetHornCooldownSubCommand extends CommandAPICommand {
|
||||
private final CustomDiscs plugin;
|
||||
|
||||
public SetHornCooldownSubCommand(CustomDiscs plugin) {
|
||||
super("goatcooldown");
|
||||
this.plugin = plugin;
|
||||
|
||||
this.withFullDescription(NamedTextColor.GRAY + "Set the cooldown for a modified goat horn (range from 0 to "+ this.plugin.hornMaxCooldown +" in seconds).");
|
||||
this.withUsage("/cd goatcooldown <range>");
|
||||
|
||||
this.withArguments(new FloatArgument("goatcooldown"));
|
||||
|
||||
this.executesPlayer(this::onCommandPlayer);
|
||||
this.executesConsole(this::onCommandConsole);
|
||||
}
|
||||
|
||||
private int onCommandPlayer(Player player, CommandArguments arguments) {
|
||||
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
|
||||
if (!isCustomGoatHorn(item)) {
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.NOT_HOLDING_GOATHORN.toString()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!player.hasPermission("customdiscs.horncooldown")) {
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.NO_PERMISSION.toString()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
Float goatcooldown = Objects.requireNonNull(arguments.getByClass("goatcooldown", Float.class));
|
||||
|
||||
if ( goatcooldown < 0 || goatcooldown > this.plugin.hornMaxCooldown) {
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.INVALID_COOLDOWN.toString().replace("%cooldown_value%", Float.toString(this.plugin.hornMaxCooldown))));
|
||||
return 1;
|
||||
}
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.getPersistentDataContainer().set(new NamespacedKey(plugin, "horncooldown"), PersistentDataType.INTEGER, goatcooldown.intValue());
|
||||
item.setItemMeta(meta);
|
||||
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.CREATE_CUSTOM_GOAT_COOLDOWN.toString().replace("%custom_goat_cooldown%", Float.toString(goatcooldown))));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
private int onCommandConsole(ConsoleCommandSender executor, CommandArguments arguments) {
|
||||
executor.sendMessage(NamedTextColor.RED + "Only players can use this command : '"+arguments+"'!");
|
||||
return 1;
|
||||
}
|
||||
|
||||
public boolean isCustomGoatHorn(ItemStack item) {
|
||||
if (item==null) return false;
|
||||
return item.getType().toString().contains("GOAT_HORN") && item.getItemMeta().getPersistentDataContainer().has(new NamespacedKey(plugin, "customhorn"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public class SetRangeSubCommand extends CommandAPICommand {
|
||||
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
|
||||
if (!isCustomDisc(item) && !isCustomGoatHorn(item)) {
|
||||
if (!isCustomDisc(item)) {
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.NOT_HOLDING_DISC.toString()));
|
||||
return 1;
|
||||
}
|
||||
@@ -59,22 +59,12 @@ public class SetRangeSubCommand extends CommandAPICommand {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (isCustomDisc(item)) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
PersistentDataContainer data = meta.getPersistentDataContainer();
|
||||
data.set(new NamespacedKey(this.plugin, "range"), PersistentDataType.FLOAT, range);
|
||||
player.getInventory().getItemInMainHand().setItemMeta(meta);
|
||||
} else if (isCustomGoatHorn(item)) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
PersistentDataContainer data = meta.getPersistentDataContainer();
|
||||
data.set(new NamespacedKey(this.plugin, "range"), PersistentDataType.FLOAT, range);
|
||||
player.getInventory().getItemInMainHand().setItemMeta(meta);
|
||||
}
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
PersistentDataContainer data = meta.getPersistentDataContainer();
|
||||
data.set(new NamespacedKey(this.plugin, "range"), PersistentDataType.FLOAT, range);
|
||||
player.getInventory().getItemInMainHand().setItemMeta(meta);
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.CREATE_CUSTOM_RANGE.toString().replace("%custom_range%", Float.toString(range))));
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -88,9 +78,4 @@ public class SetRangeSubCommand extends CommandAPICommand {
|
||||
return item.getType().toString().contains("MUSIC_DISC") && item.getItemMeta().getPersistentDataContainer().has(new NamespacedKey(plugin, "customdisc"));
|
||||
}
|
||||
|
||||
public boolean isCustomGoatHorn(ItemStack item) {
|
||||
if (item==null) return false;
|
||||
return item.getType().toString().contains("GOAT_HORN") && item.getItemMeta().getPersistentDataContainer().has(new NamespacedKey(plugin, "customhorn"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
package me.Navoei.customdiscsplugin.event;
|
||||
|
||||
import me.Navoei.customdiscsplugin.CustomDiscs;
|
||||
import me.Navoei.customdiscsplugin.PlayerManager;
|
||||
import me.Navoei.customdiscsplugin.VoicePlugin;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.TileState;
|
||||
import org.bukkit.block.data.Powerable;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Objects;
|
||||
|
||||
public class GoatHorn implements Listener {
|
||||
|
||||
static CustomDiscs customDiscs = CustomDiscs.getInstance();
|
||||
PlayerManager playerManager = PlayerManager.instance();
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) throws IOException {
|
||||
ItemStack item = event.getItem();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (item == null) return;
|
||||
if (item.getType() != Material.GOAT_HORN) return;
|
||||
|
||||
Block block = event.getClickedBlock();
|
||||
if (player.hasCooldown(Material.GOAT_HORN)) return;
|
||||
|
||||
if (isCustomGoatHorn(event) && ((event.getAction() == Action.RIGHT_CLICK_BLOCK) || (event.getAction() == Action.RIGHT_CLICK_AIR))) {
|
||||
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && !player.isSneaking()) {
|
||||
if ((block.getBlockData() instanceof Powerable) || (block instanceof TileState) && event.useInteractedBlock().equals(Event.Result.ALLOW)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String soundFileName = event.getItem().getItemMeta().getPersistentDataContainer().get(new NamespacedKey(customDiscs, "customhorn"), PersistentDataType.STRING);
|
||||
|
||||
@NotNull PersistentDataContainer persistentDataContainer = event.getItem().getItemMeta().getPersistentDataContainer();
|
||||
|
||||
float range;
|
||||
NamespacedKey customSoundRangeKey = new NamespacedKey(customDiscs, "range");
|
||||
if(persistentDataContainer.has(customSoundRangeKey, PersistentDataType.FLOAT)) {
|
||||
range = Math.min(persistentDataContainer.get(customSoundRangeKey, PersistentDataType.FLOAT), CustomDiscs.getInstance().musicDiscMaxDistance);
|
||||
} else {
|
||||
range = Math.min(CustomDiscs.getInstance().musicDiscDistance, CustomDiscs.getInstance().musicDiscMaxDistance);
|
||||
}
|
||||
|
||||
int hornCooldown;
|
||||
NamespacedKey hornCooldownKey = new NamespacedKey(customDiscs, "horncooldown");
|
||||
if(persistentDataContainer.has(hornCooldownKey, PersistentDataType.INTEGER)) {
|
||||
hornCooldown = Math.min(persistentDataContainer.get(hornCooldownKey, PersistentDataType.INTEGER), CustomDiscs.getInstance().hornMaxCooldown) * 20;
|
||||
} else {
|
||||
hornCooldown = Math.min(Math.round(CustomDiscs.getInstance().hornCooldown) * 20, CustomDiscs.getInstance().hornMaxCooldown) * 20;
|
||||
}
|
||||
|
||||
Path soundFilePath = Path.of(customDiscs.getDataFolder().getPath(), "musicdata", soundFileName);
|
||||
|
||||
if (soundFilePath.toFile().exists()) {
|
||||
|
||||
Component songNameComponent = Objects.requireNonNull(event.getItem().getItemMeta().lore()).get(0).asComponent();
|
||||
String songName = PlainTextComponentSerializer.plainText().serialize(songNameComponent);
|
||||
|
||||
TextComponent customActionBarSongPlaying = Component.text()
|
||||
.content("Now Horn Playing: " + songName)
|
||||
.color(NamedTextColor.GOLD)
|
||||
.build();
|
||||
|
||||
assert VoicePlugin.voicechatServerApi != null;
|
||||
playerManager.playLocationalAudioHorn(VoicePlugin.voicechatServerApi, soundFilePath, player, customActionBarSongPlaying.asComponent(), range);
|
||||
player.setCooldown(Material.GOAT_HORN, hornCooldown);
|
||||
} else {
|
||||
player.sendMessage(NamedTextColor.RED + "Sound file not found.");
|
||||
event.setCancelled(true);
|
||||
throw new FileNotFoundException("Sound file is missing!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isCustomGoatHorn(PlayerInteractEvent e) {
|
||||
if (e.getItem()==null) return false;
|
||||
return e.getItem().getItemMeta().getPersistentDataContainer().has(new NamespacedKey(customDiscs, "customhorn"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,11 +20,7 @@ public enum Lang {
|
||||
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."),
|
||||
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%\"."),
|
||||
NOT_HOLDING_GOATHORN("not-holding-goathorn", "&cYou must hold a goat horn in your main hand."),
|
||||
NOT_HOLDING_MODIFIED_GOATHORN("not-holding-modified-goathorn", "&cYou must hold a modified goat horn in your main hand."),
|
||||
INVALID_COOLDOWN("invalid-cooldown","&cYou need to chose a cooldown between 0 and %cooldown_value%"),
|
||||
CREATE_CUSTOM_GOAT_COOLDOWN("create-custom-goat-cooldown", "&7Your goat horn cooldown is set to: &a\"%custom_goat_cooldown%\".");
|
||||
CREATE_CUSTOM_RANGE("create-custom-range", "&7Your range is set to: &a\"%custom_range%\".");
|
||||
|
||||
private final String path;
|
||||
private final String def;
|
||||
|
||||
@@ -12,12 +12,6 @@ music-disc-volume: 1
|
||||
# The maximum download size in megabytes.
|
||||
max-download-size: 50
|
||||
|
||||
# The default cooldown time for horns in seconds from 1 to the max value of horn-max-cooldown.
|
||||
horn-cooldown: 7
|
||||
|
||||
# The default max cooldown time for horns in seconds (5 minutes by default).
|
||||
horn-max-cooldown: 300
|
||||
|
||||
#Custom Discs Help Page
|
||||
help:
|
||||
- "&8-[&6CustomDiscs Help Page&8]-"
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 199 B |
@@ -16,8 +16,4 @@ 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%\"."
|
||||
not-holding-goathorn: "&cYou must hold a goat horn in your main hand."
|
||||
not-holding-modified-goathorn: "&cYou must hold a modified goat horn in your main hand."
|
||||
invalid-cooldown: "&cYou need to chose a cooldown between 0 and %cooldown_value%"
|
||||
create-custom-goat-cooldown: "&7Your goat horn cooldown is set to: &a\"%custom_goat_cooldown%\"."
|
||||
create-custom-range: "&7Your range is set to: &a\"%custom_range%\"."
|
||||
Reference in New Issue
Block a user