mirror of
https://github.com/SPAWNRYS-ban/FUCK-CustomDiscs.git
synced 2025-12-10 05:19:43 +05:00
Fixed bugs related to discs not going to into hoppers. Particles now show for the entire duration of a custom song.
This commit is contained in:
@@ -11,6 +11,6 @@ mod_id=customdiscsplugin
|
||||
# Target an older API to make it compatible with older versions of Simple Voice Chat
|
||||
voicechat_api_version=2.3.3
|
||||
|
||||
plugin_version=2.3
|
||||
plugin_version=2.3.1
|
||||
maven_group=me.Navoei.customdiscsplugin
|
||||
archives_base_name=custom-discs
|
||||
@@ -12,15 +12,26 @@ import me.Navoei.customdiscsplugin.command.CommandManager;
|
||||
import me.Navoei.customdiscsplugin.event.JukeBox;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Hopper;
|
||||
import org.bukkit.block.Jukebox;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.sound.sampled.LineUnavailableException;
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Objects;
|
||||
|
||||
import static me.Navoei.customdiscsplugin.PlayerManager.getLengthSeconds;
|
||||
|
||||
public final class CustomDiscs extends JavaPlugin {
|
||||
|
||||
public static final String PLUGIN_ID = "CustomDiscs";
|
||||
@@ -75,9 +86,12 @@ public final class CustomDiscs extends JavaPlugin {
|
||||
if (!jukebox.getRecord().hasItemMeta()) return;
|
||||
|
||||
if (jukebox.getRecord().getItemMeta().getPersistentDataContainer().has(new NamespacedKey(CustomDiscs.getInstance(), "customdisc"), PersistentDataType.STRING)) {
|
||||
jukebox.stopPlaying();
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
//Spawn particles if there isnt any music playing at this location.
|
||||
ParticleManager.start(jukebox);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -95,4 +109,5 @@ public final class CustomDiscs extends JavaPlugin {
|
||||
public static CustomDiscs getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,17 +4,24 @@ 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.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Jukebox;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
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.PersistentDataType;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
public class HopperManager implements Listener {
|
||||
@@ -51,9 +58,48 @@ public class HopperManager implements Listener {
|
||||
|
||||
if (event.getSource().getLocation() == null) return;
|
||||
if (!event.getSource().getType().equals(InventoryType.JUKEBOX)) return;
|
||||
if (event.getItem().getItemMeta() == null) return;
|
||||
if (!isCustomMusicDisc(event.getItem())) return;
|
||||
|
||||
event.setCancelled(playerManager.isAudioPlayerPlaying(event.getSource().getLocation()));
|
||||
|
||||
}
|
||||
|
||||
public void discToHopper(Block block) {
|
||||
|
||||
if (block == null) return;
|
||||
if (!block.getLocation().getChunk().isLoaded()) return;
|
||||
if (!block.getType().equals(Material.JUKEBOX)) return;
|
||||
if (!block.getRelative(BlockFace.DOWN).getType().equals(Material.HOPPER)) return;
|
||||
|
||||
Block hopperBlock = block.getRelative(BlockFace.DOWN);
|
||||
org.bukkit.block.Hopper hopper = (org.bukkit.block.Hopper) hopperBlock.getState();
|
||||
|
||||
Jukebox jukebox = (Jukebox) block.getState();
|
||||
|
||||
InventoryMoveItemEvent event = new InventoryMoveItemEvent(jukebox.getInventory(), jukebox.getRecord(), hopper.getInventory(), false);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (!event.isCancelled()) {
|
||||
if (!Arrays.toString(hopper.getInventory().getContents()).contains("null")) return;
|
||||
|
||||
hopper.getInventory().setItem(hopper.getInventory().firstEmpty(), jukebox.getRecord());
|
||||
|
||||
block.setType(Material.AIR);
|
||||
block.setType(Material.JUKEBOX);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onChunkLoad(ChunkLoadEvent event) {
|
||||
for (BlockState blockState : event.getChunk().getTileEntities()) {
|
||||
if (blockState instanceof Jukebox jukebox) {
|
||||
if (!PlayerManager.instance().isAudioPlayerPlaying(blockState.getLocation()) && !jukebox.isPlaying()) {
|
||||
discToHopper(blockState.getBlock());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isCustomMusicDisc (ItemStack item) {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package me.Navoei.customdiscsplugin;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.block.Jukebox;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ParticleManager extends BukkitRunnable {
|
||||
|
||||
static PlayerManager playerManager = PlayerManager.instance();
|
||||
static HashMap<Location, ParticleManager> locationParticleManager = new HashMap<>();
|
||||
|
||||
public static void start(Jukebox jukebox) {
|
||||
ParticleManager particleManager = new ParticleManager();
|
||||
particleManager.jukebox = jukebox;
|
||||
if (locationParticleManager.containsKey(jukebox.getLocation())) return;
|
||||
locationParticleManager.put(jukebox.getLocation(), particleManager);
|
||||
locationParticleManager.get(jukebox.getLocation()).runTaskTimer(CustomDiscs.getInstance(), 0, 20);
|
||||
}
|
||||
|
||||
//private float seconds;
|
||||
private Jukebox jukebox;
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (!playerManager.isAudioPlayerPlaying(jukebox.getLocation())) {
|
||||
locationParticleManager.remove(jukebox.getLocation());
|
||||
cancel();
|
||||
} else {
|
||||
//if (!jukebox.isPlaying()) {
|
||||
jukebox.getLocation().getWorld().spawnParticle(Particle.NOTE, jukebox.getLocation().add(0.5, 1.1, 0.5), 1);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -83,6 +83,9 @@ public class PlayerManager {
|
||||
}
|
||||
|
||||
audioPlayer.setOnStopped(() -> {
|
||||
|
||||
Bukkit.getScheduler().runTask(CustomDiscs.getInstance(), () -> HopperManager.instance().discToHopper(block));
|
||||
|
||||
playerMap.remove(id);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package me.Navoei.customdiscsplugin.event;
|
||||
|
||||
import me.Navoei.customdiscsplugin.CustomDiscs;
|
||||
import me.Navoei.customdiscsplugin.ParticleManager;
|
||||
import me.Navoei.customdiscsplugin.PlayerManager;
|
||||
import me.Navoei.customdiscsplugin.VoicePlugin;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
Reference in New Issue
Block a user