From 5dbc4575827be6f4fe5b79d912b764c22e003518 Mon Sep 17 00:00:00 2001 From: sub-kek Date: Sat, 31 Aug 2024 23:20:48 +0300 Subject: [PATCH] Fix playing after eject for "Standard" discs --- .../{VoicePlugin.java => CDVoiceAddon.java} | 20 ++++--- .../subkek/customdiscs/CustomDiscs.java | 18 +++---- .../subkek/customdiscs/LavaPlayerManager.java | 25 ++++----- ...rticleManager.java => PhysicsManager.java} | 52 ++++++++++--------- .../subkek/customdiscs/PlayerManager.java | 37 +++++++------ .../command/subcommand/CreateSubCommand.java | 2 +- .../subcommand/CreateYtSubCommand.java | 2 +- .../subkek/customdiscs/config/CDConfig.java | 2 +- .../customdiscs/event/HopperHandler.java | 30 +++-------- .../customdiscs/event/JukeboxHandler.java | 4 -- .../subkek/customdiscs/language/Language.java | 2 +- .../subkek/customdiscs/util/PlayUtil.java | 4 +- 12 files changed, 91 insertions(+), 107 deletions(-) rename src/main/java/io/github/subkek/customdiscs/{VoicePlugin.java => CDVoiceAddon.java} (77%) rename src/main/java/io/github/subkek/customdiscs/{particle/ParticleManager.java => PhysicsManager.java} (60%) diff --git a/src/main/java/io/github/subkek/customdiscs/VoicePlugin.java b/src/main/java/io/github/subkek/customdiscs/CDVoiceAddon.java similarity index 77% rename from src/main/java/io/github/subkek/customdiscs/VoicePlugin.java rename to src/main/java/io/github/subkek/customdiscs/CDVoiceAddon.java index 70b3156..e50e174 100644 --- a/src/main/java/io/github/subkek/customdiscs/VoicePlugin.java +++ b/src/main/java/io/github/subkek/customdiscs/CDVoiceAddon.java @@ -6,17 +6,25 @@ import de.maxhenkel.voicechat.api.VolumeCategory; import de.maxhenkel.voicechat.api.events.EventRegistration; import de.maxhenkel.voicechat.api.events.VoicechatServerStartedEvent; +import lombok.Getter; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.net.URL; import java.util.Enumeration; -public class VoicePlugin implements VoicechatPlugin { - public static String MUSIC_DISC_CATEGORY = "music_discs"; +@Getter +public class CDVoiceAddon implements VoicechatPlugin { + public static final String MUSIC_DISC_CATEGORY = "music_discs"; - public static VoicechatServerApi voicechatApi; - public static VolumeCategory musicDiscs; + private VoicechatServerApi voicechatApi; + private VolumeCategory musicDiscsCategory; + + private static CDVoiceAddon instance; + public static CDVoiceAddon getInstance() { + if (instance == null) return instance = new CDVoiceAddon(); + return instance; + } @Override public String getPluginId() { @@ -31,12 +39,12 @@ public void initialize(VoicechatApi api) { @Override public void registerEvents(EventRegistration registration) { registration.registerEvent(VoicechatServerStartedEvent.class, event -> { - musicDiscs = voicechatApi.volumeCategoryBuilder() + musicDiscsCategory = voicechatApi.volumeCategoryBuilder() .setId(MUSIC_DISC_CATEGORY) .setName("Music Discs") .setIcon(getMusicDiscIcon()) .build(); - voicechatApi.registerVolumeCategory(musicDiscs); + voicechatApi.registerVolumeCategory(musicDiscsCategory); }); } diff --git a/src/main/java/io/github/subkek/customdiscs/CustomDiscs.java b/src/main/java/io/github/subkek/customdiscs/CustomDiscs.java index ef46b19..5aa20f2 100644 --- a/src/main/java/io/github/subkek/customdiscs/CustomDiscs.java +++ b/src/main/java/io/github/subkek/customdiscs/CustomDiscs.java @@ -17,13 +17,11 @@ import io.github.subkek.customdiscs.event.JukeboxHandler; import io.github.subkek.customdiscs.language.YamlLanguage; import io.github.subkek.customdiscs.metrics.BStatsLink; -import io.github.subkek.customdiscs.particle.ParticleManager; import io.github.subkek.customdiscs.util.Formatter; import io.github.subkek.customdiscs.util.LegacyUtil; import lombok.Getter; import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.text.Component; -import org.apache.commons.lang.exception.ExceptionUtils; import org.bukkit.block.Jukebox; import org.bukkit.command.CommandSender; import org.bukkit.plugin.java.JavaPlugin; @@ -35,8 +33,7 @@ import java.io.StringWriter; public class CustomDiscs extends JavaPlugin { - public static final String PLUGIN_ID = "CustomDiscs"; - private VoicePlugin voicechatPlugin; + public static final String PLUGIN_ID = "customdiscs"; @Getter private YamlLanguage language = new YamlLanguage(); @Getter @@ -47,6 +44,7 @@ public class CustomDiscs extends JavaPlugin { @Getter private BukkitAudiences audience; public int discsPlayed = 0; + private boolean voicechatAddonRegistered = false; public static CustomDiscs getPlugin() { return getPlugin(CustomDiscs.class); @@ -92,7 +90,7 @@ public void onPacketSending(PacketEvent event) { if (LegacyUtil.isCustomDisc(jukebox.getRecord()) || LegacyUtil.isCustomYouTubeDisc(jukebox.getRecord())) { event.setCancelled(true); - ParticleManager.getInstance().start(jukebox); + PhysicsManager.getInstance().start(jukebox); } } } @@ -103,8 +101,8 @@ private void registerVoicechatHook() { BukkitVoicechatService service = getServer().getServicesManager().load(BukkitVoicechatService.class); if (service != null) { - voicechatPlugin = new VoicePlugin(); - service.registerPlugin(voicechatPlugin); + service.registerPlugin(CDVoiceAddon.getInstance()); + voicechatAddonRegistered = true; info("Successfully enabled voicechat hook"); } else { error("Failed to enable voicechat hook"); @@ -126,10 +124,10 @@ public void onDisable() { LavaPlayerManager.getInstance().stopPlayingAll(); LavaPlayerManager.getInstance().save(); - PlayerManager.getInstance().stopAll(); + PlayerManager.getInstance().stopPlayingAll(); - if (voicechatPlugin != null) { - getServer().getServicesManager().unregister(voicechatPlugin); + if (voicechatAddonRegistered) { + getServer().getServicesManager().unregister(CDVoiceAddon.getInstance()); CustomDiscs.info("Successfully disabled CustomDiscs plugin"); } diff --git a/src/main/java/io/github/subkek/customdiscs/LavaPlayerManager.java b/src/main/java/io/github/subkek/customdiscs/LavaPlayerManager.java index b4ce22b..b3f0741 100644 --- a/src/main/java/io/github/subkek/customdiscs/LavaPlayerManager.java +++ b/src/main/java/io/github/subkek/customdiscs/LavaPlayerManager.java @@ -15,9 +15,7 @@ import de.maxhenkel.voicechat.api.audiochannel.LocationalAudioChannel; import dev.lavalink.youtube.YoutubeAudioSourceManager; import dev.lavalink.youtube.http.YoutubeOauth2Handler; -import io.github.subkek.customdiscs.event.HopperHandler; import net.kyori.adventure.text.Component; -import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -28,12 +26,17 @@ import java.util.concurrent.TimeUnit; public class LavaPlayerManager { - private static LavaPlayerManager instance; private final CustomDiscs plugin = CustomDiscs.getPlugin(); private final AudioPlayerManager lavaPlayerManager = new DefaultAudioPlayerManager(); private final Map playerMap = new HashMap<>(); File refreshTokenFile = new File(plugin.getDataFolder(), ".youtube-token"); + private static LavaPlayerManager instance; + public static LavaPlayerManager getInstance() { + if (instance == null) return instance = new LavaPlayerManager(); + return instance; + } + public LavaPlayerManager() { YoutubeAudioSourceManager source = new YoutubeAudioSourceManager(false); if (plugin.getCDConfig().isYoutubeOauth2()) { @@ -70,13 +73,6 @@ public LavaPlayerManager() { lavaPlayerManager.registerSourceManager(source); } - public static LavaPlayerManager getInstance() { - if (Objects.isNull(instance)) { - instance = new LavaPlayerManager(); - } - return instance; - } - public void save() { for (AudioSourceManager manager : lavaPlayerManager.getSourceManagers()) { if (!(manager instanceof YoutubeAudioSourceManager)) continue; @@ -99,16 +95,17 @@ public void save() { } } - public void playLocationalAudioYoutube(Block block, VoicechatServerApi api, String ytUrl, Component actionbarComponent) { + public void play(Block block, String ytUrl, Component actionbarComponent) { UUID uuid = UUID.nameUUIDFromBytes(block.getLocation().toString().getBytes()); CustomDiscs.debug("LavaPlayer UUID is {0}", uuid); if (playerMap.containsKey(uuid)) stopPlaying(uuid); + VoicechatServerApi api = CDVoiceAddon.getInstance().getVoicechatApi(); + LavaPlayer lavaPlayer = new LavaPlayer(); playerMap.put(uuid, lavaPlayer); lavaPlayer.ytUrl = ytUrl; - lavaPlayer.block = block; lavaPlayer.playerUUID = uuid; lavaPlayer.audioChannel = api.createLocationalAudioChannel( UUID.randomUUID(), @@ -122,7 +119,7 @@ public void playLocationalAudioYoutube(Block block, VoicechatServerApi api, Str if (lavaPlayer.audioChannel == null) return; - lavaPlayer.audioChannel.setCategory(VoicePlugin.MUSIC_DISC_CATEGORY); + lavaPlayer.audioChannel.setCategory(CDVoiceAddon.MUSIC_DISC_CATEGORY); lavaPlayer.audioChannel.setDistance(plugin.getCDConfig().getMusicDiscDistance()); lavaPlayer.playersInRange = api.getPlayersInRange( @@ -159,7 +156,6 @@ public void stopPlaying(UUID uuid) { lavaPlayer.trackFuture.complete(null); lavaPlayer.audioPlayer.destroy(); lavaPlayer.lavaPlayerThread.interrupt(); - HopperHandler.getInstance().discToHopper(lavaPlayer.block); } else { CustomDiscs.debug( "Couldn't find LavaPlayer {0} to stop", @@ -184,7 +180,6 @@ private class LavaPlayer { private UUID playerUUID; private AudioPlayer audioPlayer; private final Thread lavaPlayerThread = new Thread(this::startTrackJob, "LavaPlayerThread"); - private Block block; private void startTrackJob() { try { diff --git a/src/main/java/io/github/subkek/customdiscs/particle/ParticleManager.java b/src/main/java/io/github/subkek/customdiscs/PhysicsManager.java similarity index 60% rename from src/main/java/io/github/subkek/customdiscs/particle/ParticleManager.java rename to src/main/java/io/github/subkek/customdiscs/PhysicsManager.java index fd17c53..70f67a9 100644 --- a/src/main/java/io/github/subkek/customdiscs/particle/ParticleManager.java +++ b/src/main/java/io/github/subkek/customdiscs/PhysicsManager.java @@ -1,29 +1,29 @@ -package io.github.subkek.customdiscs.particle; +package io.github.subkek.customdiscs; import com.tcoded.folialib.wrapper.task.WrappedTask; -import io.github.subkek.customdiscs.CustomDiscs; -import io.github.subkek.customdiscs.LavaPlayerManager; -import io.github.subkek.customdiscs.PlayerManager; -import io.github.subkek.customdiscs.util.LegacyUtil; import lombok.Data; +import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.block.Jukebox; -import java.util.*; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; -public class ParticleManager { - private static ParticleManager instance; +public class PhysicsManager { private final CustomDiscs plugin = CustomDiscs.getPlugin(); - private final Map locationParticleManager = new HashMap<>(); + private final Map jukeboxMap = new HashMap<>(); - public static ParticleManager getInstance() { - if (instance == null) return instance = new ParticleManager(); + private static PhysicsManager instance; + public static PhysicsManager getInstance() { + if (instance == null) return instance = new PhysicsManager(); return instance; } public ParticleJukebox get(Block block) { UUID uuid = UUID.nameUUIDFromBytes(block.getLocation().toString().getBytes()); - ParticleJukebox particleJukebox = locationParticleManager.get(uuid); + ParticleJukebox particleJukebox = jukeboxMap.get(uuid); if (particleJukebox == null) throw new IllegalStateException("This ParticleJukebox doesn't exists cannot get"); return particleJukebox; @@ -34,7 +34,7 @@ public record NeedUpdate(boolean returnForced, boolean value) { public NeedUpdate isNeedUpdate(Block block) { UUID uuid = UUID.nameUUIDFromBytes(block.getLocation().toString().getBytes()); - ParticleJukebox particleJukebox = locationParticleManager.get(uuid); + ParticleJukebox particleJukebox = jukeboxMap.get(uuid); if (particleJukebox == null) { CustomDiscs.debug("ParticleManager return value false because ParticleJukebox is null"); return new NeedUpdate(true, false); @@ -42,33 +42,35 @@ public NeedUpdate isNeedUpdate(Block block) { return new NeedUpdate(false, particleJukebox.isNeedUpdate()); } - public void setNeedUpdate(Block block, boolean value) { - UUID uuid = UUID.nameUUIDFromBytes(block.getLocation().toString().getBytes()); - ParticleJukebox particleJukebox = locationParticleManager.get(uuid); + private void discToHopper(Block block) { + if (!plugin.getCDConfig().isAllowHoppers()) return; + if (!plugin.isEnabled()) return; + if (!block.getLocation().getChunk().isLoaded()) return; + if (!block.getType().equals(Material.JUKEBOX)) return; - if (particleJukebox == null) - throw new IllegalStateException("This ParticleJukebox doesn't exists cannot set NeedUpdate value"); + Block possibleHopper = block.getRelative(BlockFace.DOWN); + if (!possibleHopper.getType().equals(Material.HOPPER)) return; - particleJukebox.setNeedUpdate(value); + CustomDiscs.debug("Attempting to send a disk to the hopper using a hopper update."); } - public void stop(Block block) { + private void stop(Block block) { UUID uuid = UUID.nameUUIDFromBytes(block.getLocation().toString().getBytes()); - if (locationParticleManager.containsKey(uuid)) { - ParticleJukebox particleJukebox = locationParticleManager.remove(uuid); + if (jukeboxMap.containsKey(uuid)) { + ParticleJukebox particleJukebox = jukeboxMap.remove(uuid); particleJukebox.task.cancel(); Jukebox jukebox = (Jukebox) block.getState(); - jukebox.update(); jukebox.stopPlaying(); + discToHopper(block); } } public void start(Jukebox jukebox) { UUID uuid = UUID.nameUUIDFromBytes(jukebox.getLocation().toString().getBytes()); - if (locationParticleManager.containsKey(uuid)) return; + if (jukeboxMap.containsKey(uuid)) return; ParticleJukebox particleJukebox = new ParticleJukebox(); - locationParticleManager.put(uuid, particleJukebox); + jukeboxMap.put(uuid, particleJukebox); plugin.getFoliaLib().getScheduler().runAtLocationTimer(jukebox.getLocation(), task -> { particleJukebox.setTask(task); diff --git a/src/main/java/io/github/subkek/customdiscs/PlayerManager.java b/src/main/java/io/github/subkek/customdiscs/PlayerManager.java index 8ea16da..0700170 100644 --- a/src/main/java/io/github/subkek/customdiscs/PlayerManager.java +++ b/src/main/java/io/github/subkek/customdiscs/PlayerManager.java @@ -4,11 +4,9 @@ import de.maxhenkel.voicechat.api.VoicechatServerApi; import de.maxhenkel.voicechat.api.audiochannel.AudioPlayer; import de.maxhenkel.voicechat.api.audiochannel.LocationalAudioChannel; -import io.github.subkek.customdiscs.event.HopperHandler; import javazoom.spi.mpeg.sampled.convert.MpegFormatConversionProvider; import javazoom.spi.mpeg.sampled.file.MpegAudioFileReader; import net.kyori.adventure.text.Component; -import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.jflac.sound.spi.Flac2PcmAudioInputStream; @@ -21,6 +19,8 @@ import java.io.IOException; import java.nio.file.Path; import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.atomic.AtomicReference; public class PlayerManager { private static final AudioFormat FORMAT = new AudioFormat( @@ -32,29 +32,26 @@ public class PlayerManager { 48000F, false ); - private static PlayerManager instance; private final CustomDiscs plugin = CustomDiscs.getPlugin(); private final Map playerMap = new HashMap<>(); + private static PlayerManager instance; public static PlayerManager getInstance() { - if (instance == null) { - instance = new PlayerManager(); - } + if (instance == null) return instance = new PlayerManager(); return instance; } - public void playLocationalAudio(Path soundFilePath, Block block, Component actionbarComponent) { + public void play(Path soundFilePath, Block block, Component actionbarComponent) { UUID uuid = UUID.nameUUIDFromBytes(block.getLocation().toString().getBytes()); CustomDiscs.debug("Player UUID is {0}", uuid); if (playerMap.containsKey(uuid)) stopPlaying(uuid); CustomDiscs.debug("Player {0} not already exists", uuid); - VoicechatServerApi api = VoicePlugin.voicechatApi; + VoicechatServerApi api = CDVoiceAddon.getInstance().getVoicechatApi(); DiscPlayer discPlayer = new DiscPlayer(); playerMap.put(uuid, discPlayer); - discPlayer.block = block; discPlayer.soundFilePath = soundFilePath; discPlayer.playerUUID = uuid; discPlayer.audioChannel = api.createLocationalAudioChannel( @@ -69,7 +66,7 @@ public void playLocationalAudio(Path soundFilePath, Block block, Component actio if (discPlayer.audioChannel == null) return; - discPlayer.audioChannel.setCategory(VoicePlugin.MUSIC_DISC_CATEGORY); + discPlayer.audioChannel.setCategory(CDVoiceAddon.MUSIC_DISC_CATEGORY); discPlayer.audioChannel.setDistance(plugin.getCDConfig().getMusicDiscDistance()); discPlayer.playersInRange = api.getPlayersInRange( @@ -91,11 +88,15 @@ public void playLocationalAudio(Path soundFilePath, Block block, Component actio } private AudioPlayer playChannel(DiscPlayer discPlayer) { - VoicechatServerApi api = VoicePlugin.voicechatApi; + VoicechatServerApi api = CDVoiceAddon.getInstance().getVoicechatApi(); try { short[] audio = readSoundFile(discPlayer.soundFilePath); AudioPlayer audioPlayer = api.createAudioPlayer(discPlayer.audioChannel, api.createEncoder(), audio); + if (discPlayer.audioPlayerThread.isInterrupted()) { + CustomDiscs.debug("Player {0} return AudioPlayer null because thread interrupted", discPlayer.playerUUID); + return null; + } audioPlayer.startPlaying(); return audioPlayer; } catch (Exception e) { @@ -108,7 +109,7 @@ private AudioPlayer playChannel(DiscPlayer discPlayer) { } private short[] readSoundFile(Path file) throws UnsupportedAudioFileException, IOException { - return VoicePlugin.voicechatApi.getAudioConverter().bytesToShorts(convertFormat(file)); + return CDVoiceAddon.getInstance().getVoicechatApi().getAudioConverter().bytesToShorts(convertFormat(file)); } private byte[] convertFormat(Path file) throws UnsupportedAudioFileException, IOException { @@ -183,7 +184,6 @@ public void stopPlaying(UUID uuid) { playerMap.remove(uuid); discPlayer.audioPlayerThread.interrupt(); - HopperHandler.getInstance().discToHopper(discPlayer.block); } } else { CustomDiscs.debug( @@ -192,7 +192,7 @@ public void stopPlaying(UUID uuid) { } } - public void stopAll() { + public void stopPlayingAll() { Set.copyOf(playerMap.keySet()).forEach(this::stopPlaying); } @@ -217,14 +217,18 @@ private class DiscPlayer { private UUID playerUUID; private final Thread audioPlayerThread = new Thread(this::startTrackJob, "AudioPlayerThread"); private AudioPlayer audioPlayer; - private Block block; private void startTrackJob() { try { audioPlayer = playChannel(this); + if (audioPlayerThread.isInterrupted()) { + CustomDiscs.debug("Player {0} got interrupt, return", playerUUID); + return; + } + if (audioPlayer == null) { - CustomDiscs.debug("Player excepted AudioPlayer is null"); + CustomDiscs.debug("Player {0} excepted AudioPlayer is null", playerUUID); stopPlaying(playerUUID); return; } @@ -237,7 +241,6 @@ private void startTrackJob() { playerMap.remove(playerUUID); audioPlayerThread.interrupt(); - HopperHandler.getInstance().discToHopper(block); }); } catch (Throwable e) { for (ServerPlayer serverPlayer : playersInRange) { diff --git a/src/main/java/io/github/subkek/customdiscs/command/subcommand/CreateSubCommand.java b/src/main/java/io/github/subkek/customdiscs/command/subcommand/CreateSubCommand.java index d21c9ed..d5dc5a1 100644 --- a/src/main/java/io/github/subkek/customdiscs/command/subcommand/CreateSubCommand.java +++ b/src/main/java/io/github/subkek/customdiscs/command/subcommand/CreateSubCommand.java @@ -6,8 +6,8 @@ import dev.jorel.commandapi.executors.CommandArguments; import io.github.subkek.customdiscs.CustomDiscs; import io.github.subkek.customdiscs.Keys; -import io.github.subkek.customdiscs.util.LegacyUtil; import io.github.subkek.customdiscs.command.AbstractSubCommand; +import io.github.subkek.customdiscs.util.LegacyUtil; import net.kyori.adventure.platform.bukkit.BukkitComponentSerializer; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; diff --git a/src/main/java/io/github/subkek/customdiscs/command/subcommand/CreateYtSubCommand.java b/src/main/java/io/github/subkek/customdiscs/command/subcommand/CreateYtSubCommand.java index 44de480..3dbbcf2 100644 --- a/src/main/java/io/github/subkek/customdiscs/command/subcommand/CreateYtSubCommand.java +++ b/src/main/java/io/github/subkek/customdiscs/command/subcommand/CreateYtSubCommand.java @@ -4,8 +4,8 @@ import dev.jorel.commandapi.executors.CommandArguments; import io.github.subkek.customdiscs.CustomDiscs; import io.github.subkek.customdiscs.Keys; -import io.github.subkek.customdiscs.util.LegacyUtil; import io.github.subkek.customdiscs.command.AbstractSubCommand; +import io.github.subkek.customdiscs.util.LegacyUtil; import net.kyori.adventure.platform.bukkit.BukkitComponentSerializer; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; diff --git a/src/main/java/io/github/subkek/customdiscs/config/CDConfig.java b/src/main/java/io/github/subkek/customdiscs/config/CDConfig.java index b6224fd..b3bc836 100644 --- a/src/main/java/io/github/subkek/customdiscs/config/CDConfig.java +++ b/src/main/java/io/github/subkek/customdiscs/config/CDConfig.java @@ -1,8 +1,8 @@ package io.github.subkek.customdiscs.config; import io.github.subkek.customdiscs.CustomDiscs; -import io.github.subkek.customdiscs.util.Formatter; import io.github.subkek.customdiscs.language.Language; +import io.github.subkek.customdiscs.util.Formatter; import lombok.Getter; import lombok.RequiredArgsConstructor; import org.simpleyaml.configuration.comments.CommentType; diff --git a/src/main/java/io/github/subkek/customdiscs/event/HopperHandler.java b/src/main/java/io/github/subkek/customdiscs/event/HopperHandler.java index e8da846..9311f94 100644 --- a/src/main/java/io/github/subkek/customdiscs/event/HopperHandler.java +++ b/src/main/java/io/github/subkek/customdiscs/event/HopperHandler.java @@ -2,13 +2,12 @@ import io.github.subkek.customdiscs.CustomDiscs; import io.github.subkek.customdiscs.LavaPlayerManager; +import io.github.subkek.customdiscs.PhysicsManager; import io.github.subkek.customdiscs.PlayerManager; -import io.github.subkek.customdiscs.particle.ParticleManager; import io.github.subkek.customdiscs.util.LegacyUtil; import io.github.subkek.customdiscs.util.PlayUtil; import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -17,7 +16,6 @@ public class HopperHandler implements Listener { private static HopperHandler instance; - private final CustomDiscs plugin = CustomDiscs.getPlugin(); private final PlayerManager playerManager = PlayerManager.getInstance(); private final LavaPlayerManager lavaPlayerManager = LavaPlayerManager.getInstance(); @@ -46,7 +44,7 @@ public void onJukeboxInsertFromHopper(InventoryMoveItemEvent event) { PlayUtil.playStandard(block, event.getItem()); if (isYouTubeCustomDisc) - PlayUtil. playLava(block, event.getItem()); + PlayUtil.playLava(block, event.getItem()); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -63,21 +61,6 @@ public void onJukeboxEjectToHopper(InventoryMoveItemEvent event) { if (!event.isCancelled()) CustomDiscs.debug("Jukebox eject by hopper event"); } - public void discToHopper(Block block) { - if (!plugin.getCDConfig().isAllowHoppers()) return; - if (!plugin.isEnabled()) return; - if (!block.getLocation().getChunk().isLoaded()) return; - - plugin.getFoliaLib().getScheduler().runAtLocation(block.getLocation(), task -> { - if (!block.getType().equals(Material.JUKEBOX)) return; - - Block possibleHopper = block.getRelative(BlockFace.DOWN); - if (!possibleHopper.getType().equals(Material.HOPPER)) return; - - CustomDiscs.debug("Attempting to send a disk to the hopper using a hopper update."); - }); - } - @EventHandler public void onPhysics(BlockPhysicsEvent event) { if (!event.getSourceBlock().getType().equals(Material.JUKEBOX)) return; @@ -86,20 +69,19 @@ public void onPhysics(BlockPhysicsEvent event) { if (!LavaPlayerManager.getInstance().isPlaying(block) && !PlayerManager.getInstance().isPlaying(block)) return; - ParticleManager.NeedUpdate needUpdate = ParticleManager.getInstance().isNeedUpdate(block); + PhysicsManager.NeedUpdate needUpdate = PhysicsManager.getInstance().isNeedUpdate(block); boolean reallyNeed = false; - ParticleManager.ParticleJukebox particleJukebox = null; + PhysicsManager.ParticleJukebox particleJukebox = null; long time = block.getWorld().getTime(); if (!needUpdate.returnForced()) { - particleJukebox = ParticleManager.getInstance().get(block); - + particleJukebox = PhysicsManager.getInstance().get(block); reallyNeed = particleJukebox.getLastUpdateTick() == time; } if (needUpdate.value() || reallyNeed) { - ParticleManager.getInstance().setNeedUpdate(block, false); assert particleJukebox != null; + particleJukebox.setNeedUpdate(false); particleJukebox.setLastUpdateTick(time); CustomDiscs.debug("Updating physics on {0} by jukebox", event.getBlock().getType()); return; diff --git a/src/main/java/io/github/subkek/customdiscs/event/JukeboxHandler.java b/src/main/java/io/github/subkek/customdiscs/event/JukeboxHandler.java index ecb4f8c..f08c99d 100644 --- a/src/main/java/io/github/subkek/customdiscs/event/JukeboxHandler.java +++ b/src/main/java/io/github/subkek/customdiscs/event/JukeboxHandler.java @@ -3,7 +3,6 @@ import io.github.subkek.customdiscs.CustomDiscs; import io.github.subkek.customdiscs.LavaPlayerManager; import io.github.subkek.customdiscs.PlayerManager; -import io.github.subkek.customdiscs.particle.ParticleManager; import io.github.subkek.customdiscs.util.LegacyUtil; import io.github.subkek.customdiscs.util.PlayUtil; import org.bukkit.Material; @@ -15,14 +14,11 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; public class JukeboxHandler implements Listener { - private final CustomDiscs plugin = CustomDiscs.getPlugin(); - private static ItemStack getItemStack(PlayerInteractEvent event, Player player) { ItemStack itemInvolvedInEvent; if (event.getMaterial().equals(Material.AIR)) { diff --git a/src/main/java/io/github/subkek/customdiscs/language/Language.java b/src/main/java/io/github/subkek/customdiscs/language/Language.java index 2cb223e..cc9112f 100644 --- a/src/main/java/io/github/subkek/customdiscs/language/Language.java +++ b/src/main/java/io/github/subkek/customdiscs/language/Language.java @@ -20,6 +20,6 @@ public static String getAllSeparatedComma() { for (Language language : values()) { labels.add(language.getLabel()); } - return String.join(",", labels); + return String.join(", ", labels); } } diff --git a/src/main/java/io/github/subkek/customdiscs/util/PlayUtil.java b/src/main/java/io/github/subkek/customdiscs/util/PlayUtil.java index 7efc098..705df63 100644 --- a/src/main/java/io/github/subkek/customdiscs/util/PlayUtil.java +++ b/src/main/java/io/github/subkek/customdiscs/util/PlayUtil.java @@ -28,7 +28,7 @@ public static void playStandard(Block block, ItemStack disc) { Component customActionBarSongPlaying = plugin.getLanguage().component("now-playing", songName); - PlayerManager.getInstance().playLocationalAudio(soundFilePath, block, customActionBarSongPlaying); + PlayerManager.getInstance().play(soundFilePath, block, customActionBarSongPlaying); } } @@ -45,6 +45,6 @@ public static void playLava(Block block, ItemStack disc) { Component customActionBarSongPlaying = plugin.getLanguage().component("now-playing", songName); - LavaPlayerManager.getInstance().playLocationalAudioYoutube(block, VoicePlugin.voicechatApi, soundLink, customActionBarSongPlaying); + LavaPlayerManager.getInstance().play(block, soundLink, customActionBarSongPlaying); } }