mirror of
https://github.com/SPAWNRYS-ban/FUCK-CustomDiscs.git
synced 2025-12-10 13:30:24 +05:00
File Checks
When inserted into jukebox, the plugin will check if a file exists.
This commit is contained in:
@@ -26,9 +26,11 @@ dependencies {
|
||||
// Use this dependency if you don't want to compile bukkit
|
||||
implementation "io.papermc.paper:paper-api:${bukkit_version}"
|
||||
implementation "de.maxhenkel.voicechat:voicechat-api:${voicechat_api_version}"
|
||||
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven { url "https://repo.dmulloy2.net/repository/public/" }
|
||||
mavenCentral()
|
||||
maven {
|
||||
name = "henkelmax.public"
|
||||
|
||||
@@ -9,5 +9,5 @@ bukkit_version=1.19-R0.1-SNAPSHOT
|
||||
voicechat_api_version=2.2.22
|
||||
|
||||
plugin_version=1.0.0
|
||||
maven_group=na.Navoei.customdiscsplugin
|
||||
maven_group=me.Navoei.customdiscsplugin
|
||||
archives_base_name=custom-discs
|
||||
@@ -1,14 +1,14 @@
|
||||
package na.Navoei.customdiscsplugin;
|
||||
package me.Navoei.customdiscsplugin;
|
||||
|
||||
import de.maxhenkel.voicechat.api.BukkitVoicechatService;
|
||||
import na.Navoei.customdiscsplugin.command.CustomDisc;
|
||||
import me.Navoei.customdiscsplugin.command.CustomDisc;
|
||||
import me.Navoei.customdiscsplugin.event.JukeBox;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
|
||||
public final class CustomDiscs extends JavaPlugin {
|
||||
|
||||
@@ -17,7 +17,7 @@ public final class CustomDiscs extends JavaPlugin {
|
||||
static CustomDiscs instance;
|
||||
|
||||
@Nullable
|
||||
private PlayMusic voicechatPlugin;
|
||||
private VoicePlugin voicechatPlugin;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@@ -39,14 +39,14 @@ public final class CustomDiscs extends JavaPlugin {
|
||||
}
|
||||
|
||||
if (service != null) {
|
||||
voicechatPlugin = new PlayMusic();
|
||||
voicechatPlugin = new VoicePlugin();
|
||||
service.registerPlugin(voicechatPlugin);
|
||||
LOGGER.info("Successfully registered CustomDiscs plugin");
|
||||
} else {
|
||||
LOGGER.info("Failed to register CustomDiscs plugin");
|
||||
}
|
||||
|
||||
|
||||
getServer().getPluginManager().registerEvents(new JukeBox(), this);
|
||||
getCommand("customdisc").setExecutor(command);
|
||||
|
||||
}
|
||||
@@ -1,10 +1,19 @@
|
||||
package na.Navoei.customdiscsplugin;
|
||||
package me.Navoei.customdiscsplugin;
|
||||
|
||||
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 PlayMusic implements VoicechatPlugin {
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class VoicePlugin implements VoicechatPlugin {
|
||||
|
||||
public static VoicechatApi voicechatApi;
|
||||
|
||||
@Nullable
|
||||
public static VoicechatServerApi voicechatServerApi;
|
||||
|
||||
/**
|
||||
* @return the unique ID for this voice chat plugin
|
||||
@@ -21,7 +30,7 @@ public class PlayMusic implements VoicechatPlugin {
|
||||
*/
|
||||
@Override
|
||||
public void initialize(final VoicechatApi api) {
|
||||
|
||||
VoicePlugin.voicechatApi = api;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -31,7 +40,14 @@ public class PlayMusic implements VoicechatPlugin {
|
||||
*/
|
||||
@Override
|
||||
public void registerEvents(final EventRegistration registration) {
|
||||
|
||||
registration.registerEvent(VoicechatServerStartedEvent.class, this::onServerStarted);
|
||||
}
|
||||
|
||||
public void onServerStarted(final VoicechatServerStartedEvent event) {
|
||||
VoicePlugin.voicechatServerApi = event.getVoicechat();
|
||||
}
|
||||
|
||||
public void playAudio() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,18 @@
|
||||
package na.Navoei.customdiscsplugin.command;
|
||||
package me.Navoei.customdiscsplugin.command;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import na.Navoei.customdiscsplugin.CustomDiscs;
|
||||
import me.Navoei.customdiscsplugin.CustomDiscs;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeModifier;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
@@ -98,6 +100,7 @@ public class CustomDisc implements CommandExecutor {
|
||||
itemLore.add(customLoreFile);
|
||||
meta.lore(itemLore);
|
||||
meta.addItemFlags(ItemFlag.values());
|
||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
p.getInventory().getItemInMainHand().setItemMeta(meta);
|
||||
|
||||
|
||||
75
src/main/java/me/Navoei/customdiscsplugin/event/JukeBox.java
Normal file
75
src/main/java/me/Navoei/customdiscsplugin/event/JukeBox.java
Normal file
@@ -0,0 +1,75 @@
|
||||
package me.Navoei.customdiscsplugin.event;
|
||||
|
||||
import me.Navoei.customdiscsplugin.CustomDiscs;
|
||||
import me.Navoei.customdiscsplugin.VoicePlugin;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Objects;
|
||||
|
||||
public class JukeBox implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInsert(PlayerInteractEvent event) throws UnsupportedAudioFileException, IOException {
|
||||
|
||||
if (event.getAction().isRightClick() && isCustomMusicDisc(event.getPlayer()) && Objects.requireNonNull(event.getClickedBlock()).getType().equals(Material.JUKEBOX)) {
|
||||
|
||||
Component soundFileComponent = Objects.requireNonNull(event.getPlayer().getInventory().getItemInMainHand().getItemMeta().lore()).get(1).asComponent();
|
||||
String soundFileName = PlainTextComponentSerializer.plainText().serialize(soundFileComponent);
|
||||
|
||||
Path soundFilePath = Path.of(CustomDiscs.getInstance().getDataFolder() + "\\musicdata\\" + soundFileName);
|
||||
if (soundFilePath.toFile().exists()) {
|
||||
Component songNameComponent = Objects.requireNonNull(event.getPlayer().getInventory().getItemInMainHand().getItemMeta().lore()).get(0).asComponent();
|
||||
String songName = PlainTextComponentSerializer.plainText().serialize(songNameComponent);
|
||||
event.getPlayer().sendMessage(ChatColor.GOLD + "Now playing: " + songName);
|
||||
|
||||
//VoicePlugin.voicechatServerApi.createAudioPlayer();
|
||||
|
||||
} else {
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "Sound file not found.");
|
||||
event.setCancelled(true);
|
||||
throw new FileNotFoundException("ERROR: Sound file is missing!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isCustomMusicDisc(Player p) {
|
||||
|
||||
if (
|
||||
p.getInventory().getItemInMainHand().hasItemFlag(ItemFlag.HIDE_ENCHANTS) &&
|
||||
(
|
||||
p.getInventory().getItemInMainHand().getType().equals(Material.MUSIC_DISC_13) ||
|
||||
p.getInventory().getItemInMainHand().getType().equals(Material.MUSIC_DISC_CAT) ||
|
||||
p.getInventory().getItemInMainHand().getType().equals(Material.MUSIC_DISC_BLOCKS) ||
|
||||
p.getInventory().getItemInMainHand().getType().equals(Material.MUSIC_DISC_CHIRP) ||
|
||||
p.getInventory().getItemInMainHand().getType().equals(Material.MUSIC_DISC_FAR) ||
|
||||
p.getInventory().getItemInMainHand().getType().equals(Material.MUSIC_DISC_MALL) ||
|
||||
p.getInventory().getItemInMainHand().getType().equals(Material.MUSIC_DISC_MELLOHI) ||
|
||||
p.getInventory().getItemInMainHand().getType().equals(Material.MUSIC_DISC_STAL) ||
|
||||
p.getInventory().getItemInMainHand().getType().equals(Material.MUSIC_DISC_STRAD) ||
|
||||
p.getInventory().getItemInMainHand().getType().equals(Material.MUSIC_DISC_WARD) ||
|
||||
p.getInventory().getItemInMainHand().getType().equals(Material.MUSIC_DISC_11) ||
|
||||
p.getInventory().getItemInMainHand().getType().equals(Material.MUSIC_DISC_WAIT) ||
|
||||
p.getInventory().getItemInMainHand().getType().equals(Material.MUSIC_DISC_OTHERSIDE) ||
|
||||
p.getInventory().getItemInMainHand().getType().equals(Material.MUSIC_DISC_5) ||
|
||||
p.getInventory().getItemInMainHand().getType().equals(Material.MUSIC_DISC_PIGSTEP)
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
name: CustomDiscs
|
||||
version: ${version}
|
||||
main: na.Navoei.customdiscsplugin.CustomDiscs
|
||||
main: me.Navoei.customdiscsplugin.CustomDiscs
|
||||
api-version: ${bukkit_api_version}
|
||||
prefix: CustomDiscs
|
||||
authors: [ "Navoei" ]
|
||||
|
||||
Reference in New Issue
Block a user