Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'java'
id "com.gradleup.shadow" version "9.2.2"
id "com.gradleup.shadow" version "9.3.1"
}

java {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ mod_id=customdiscsplugin
voicechat_api_version=2.6.0
command_api_version=11.1.0

plugin_version=5.1.4
plugin_version=5.1.5
maven_group=me.Navoei.customdiscsplugin
archives_base_name=custom-discs
10 changes: 5 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Custom Discs v5.1.3
# Custom Discs v5.1.5
### For Paper and Folia
### 1.21.7 to 1.21.11

Expand All @@ -10,7 +10,7 @@ A Paper fork of henkelmax's Audio Player. Special thanks to Athar42 for maintain
- Music files should go into ```plugins/CustomDiscs/musicdata/```
- Music files must be in the ```.wav```, ```.flac```, or ```.mp3``` format.

Join the discord for support: https://discord.gg/YJpqruvZ97. The issues section in this repository has been closed.
Join the discord for support: https://discord.gg/rJtBRmRFCr. The issues section in this repository has been closed.

Downloading Files:
- To download a file use the command ```/cd download <url> <filename.extension>```.
Expand Down Expand Up @@ -52,9 +52,9 @@ Versions support matrix :
| **1.21.4** | Paper | 4.2 - 4.4 | [4.4](https://github.com/Navoei/CustomDiscs/releases/tag/v4.4) |
| **1.21.5** | Paper | 4.4 | [4.4](https://github.com/Navoei/CustomDiscs/releases/tag/v4.4) |
| **1.21.6, 1.21.7-8** | Paper | 4.5 | [4.5](https://github.com/Navoei/CustomDiscs/releases/tag/v4.5) |
| **1.21.7-9, 1.21.8**<br>**1.21.8** | Paper<br>Folia | 5.0 - 5.1.3<br>5.1.1 - 5.1.3 | [5.1.3](https://modrinth.com/plugin/customdiscs-plugin/version/5.1.3) |
| **1.21.9, 1.21.10**<br>**1.21.9, 1.21.10** | Paper<br>Folia | 5.1.2 - 5.1.3<br>5.1.2 - 5.1.3 | [5.1.3](https://modrinth.com/plugin/customdiscs-plugin/version/5.1.3) |
| **1.21.11**<br>**1.21.11** | Paper<br>Folia | 5.1.3 - 5.1.4<br>5.1.3 - 5.1.4 | [5.1.4](https://modrinth.com/plugin/customdiscs-plugin/version/5.1.4) |
| **1.21.7-9, 1.21.8**<br>**1.21.8** | Paper<br>Folia | 5.0 - 5.1.5<br>5.1.1 - 5.1.5 | [5.1.5](https://modrinth.com/plugin/customdiscs-plugin/version/5.1.5) |
| **1.21.9, 1.21.10**<br>**1.21.9, 1.21.10** | Paper<br>Folia | 5.1.2 - 5.1.5<br>5.1.2 - 5.1.5 | [5.1.5](https://modrinth.com/plugin/customdiscs-plugin/version/5.1.5) |
| **1.21.11**<br>**1.21.11** | Paper<br>Folia | 5.1.3 - 5.1.5<br>5.1.3 - 5.1.5 | [5.1.5](https://modrinth.com/plugin/customdiscs-plugin/version/5.1.5) |

https://user-images.githubusercontent.com/64107368/178426026-c454ac66-5133-4f3a-9af9-7f674e022423.mp4

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/Navoei/customdiscsplugin/CustomDiscs.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ public void onEnable() {
.clickEvent(ClickEvent.openUrl("https://github.com/Navoei/CustomDiscs"))
.hoverEvent(HoverEvent.showText(Component.text("Click to open CustomDiscs' GitHub page")))),
LegacyComponentAmpersand.deserialize("&aDiscord&7: ")
.append(Component.text("https://discord.gg/YJpqruvZ97")
.append(Component.text("https://discord.gg/rJtBRmRFCr")
.color(NamedTextColor.BLUE)
.decorate(TextDecoration.UNDERLINED)
.clickEvent(ClickEvent.openUrl("https://discord.gg/YJpqruvZ97"))
.clickEvent(ClickEvent.openUrl("https://discord.gg/rJtBRmRFCr"))
.hoverEvent(HoverEvent.showText(Component.text("Click to join our Discord !"))))
};

Expand Down
44 changes: 28 additions & 16 deletions src/main/java/me/Navoei/customdiscsplugin/HopperManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.NamespacedKey;
import org.bukkit.persistence.PersistentDataType;

import java.nio.file.Path;
import java.util.Objects;
import java.util.List;
import java.util.Optional;
import java.util.logging.Logger;

Expand All @@ -43,18 +45,27 @@ public void onJukeboxInsertFromHopper(InventoryMoveItemEvent event) {
if (debugModeResult) {
pluginLogger.info("DEBUG - HopperManager -> Enter : onJukeboxInsertFromHopper");
}
if (event.getDestination().getLocation() == null) return;
if (!event.getDestination().getType().equals(InventoryType.JUKEBOX)) return;
if (!TypeChecker.isCustomMusicDisc(event.getItem())) return;

Component songNameComponent = Objects.requireNonNull(event.getItem().getItemMeta().lore()).get(0).asComponent();
Inventory destinationInventory = event.getDestination();

if (destinationInventory.getLocation() == null) return;
if (!destinationInventory.getType().equals(InventoryType.JUKEBOX)) return;

ItemStack eventItemStack = event.getItem();

if (!TypeChecker.isCustomMusicDisc(eventItemStack)) return;

ItemMeta discMeta = eventItemStack.getItemMeta();

List<Component> discLore = discMeta.lore();
if (discLore == null || discLore.isEmpty()) return;
Component songNameComponent = discLore.getFirst().asComponent();
String songName = PlainTextComponentSerializer.plainText().serialize(songNameComponent);
Component customActionBarSongPlaying = LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.NOW_PLAYING.toString().replace("%song_name%", songName));

ItemMeta discMeta = event.getItem().getItemMeta();
String soundFileName = discMeta.getPersistentDataContainer().get(new NamespacedKey(customDiscs, "customdisc"), PersistentDataType.STRING);

PersistentDataContainer persistentDataContainer = event.getItem().getItemMeta().getPersistentDataContainer();
PersistentDataContainer persistentDataContainer = discMeta.getPersistentDataContainer();
float range = CustomDiscs.getInstance().musicDiscDistance;
NamespacedKey customSoundRangeKey = new NamespacedKey(customDiscs, "range");

Expand All @@ -63,14 +74,13 @@ public void onJukeboxInsertFromHopper(InventoryMoveItemEvent event) {
range = Math.min(soundRange, CustomDiscs.getInstance().musicDiscMaxDistance);
}

if (!event.getItem().hasData(DataComponentTypes.TOOLTIP_DISPLAY) || !event.getItem().getData(DataComponentTypes.TOOLTIP_DISPLAY).hiddenComponents().contains(DataComponentTypes.JUKEBOX_PLAYABLE)) {
event.getItem().setData(DataComponentTypes.TOOLTIP_DISPLAY, TooltipDisplay.tooltipDisplay().addHiddenComponents(DataComponentTypes.JUKEBOX_PLAYABLE).build());
if (!eventItemStack.hasData(DataComponentTypes.TOOLTIP_DISPLAY) || !eventItemStack.getData(DataComponentTypes.TOOLTIP_DISPLAY).hiddenComponents().contains(DataComponentTypes.JUKEBOX_PLAYABLE)) {
eventItemStack.setData(DataComponentTypes.TOOLTIP_DISPLAY, TooltipDisplay.tooltipDisplay().addHiddenComponents(DataComponentTypes.JUKEBOX_PLAYABLE).build());
}

Path soundFilePath = Path.of(customDiscs.getDataFolder().getPath(), "musicdata", soundFileName);
assert VoicePlugin.voicechatServerApi != null;
playerManager.playAudio(VoicePlugin.voicechatServerApi, soundFilePath, event.getDestination().getLocation().getBlock(), customActionBarSongPlaying, range);

playerManager.playAudio(VoicePlugin.voicechatServerApi, soundFilePath, destinationInventory.getLocation().getBlock(), customActionBarSongPlaying, range);
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
Expand All @@ -79,21 +89,23 @@ public void onJukeboxEjectToHopperMinecart(InventoryMoveItemEvent event) {
pluginLogger.info("DEBUG - HopperManager -> Enter : onJukeboxEjectToHopper");
}

Inventory sourceInventory = event.getSource();

if (sourceInventory.getLocation() == null) return;
if (!sourceInventory.getType().equals(InventoryType.JUKEBOX)) return;
if (!TypeChecker.isCustomMusicDisc(event.getItem())) return;
if (event.getSource().getLocation() == null) return;
if (!event.getSource().getType().equals(InventoryType.JUKEBOX)) return;

if (ServerVersionChecker.isPaperAPI()) {
if (!(event.getDestination().getHolder(false) instanceof HopperMinecart)) return;

InventoryHolder holderSource = event.getSource().getHolder(false);
InventoryHolder holderSource = sourceInventory.getHolder(false);
if (holderSource instanceof BlockState) {
playerManager.stopDisc(((BlockState) holderSource).getBlock());
}
} else {
if (!(event.getDestination().getHolder() instanceof HopperMinecart)) return;

InventoryHolder holderSource = event.getSource().getHolder();
InventoryHolder holderSource = sourceInventory.getHolder();
if (holderSource instanceof BlockState) {
playerManager.stopDisc(((BlockState) holderSource).getBlock());
}
Expand All @@ -107,7 +119,7 @@ public void onChunkLoad(ChunkLoadEvent event) {
}
for (BlockState blockState : event.getChunk().getTileEntities()) {
if (blockState instanceof Jukebox jukebox) {
if (!jukebox.hasRecord()) return;
if (!jukebox.hasRecord()) continue;
if (!PlayerManager.instance().isAudioPlayerPlaying(blockState.getLocation()) && TypeChecker.isCustomMusicDisc(jukebox.getRecord())) {
jukebox.stopPlaying();
}
Expand Down
137 changes: 132 additions & 5 deletions src/main/java/me/Navoei/customdiscsplugin/event/HeadPlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import me.Navoei.customdiscsplugin.PlayerManager;
import me.Navoei.customdiscsplugin.VoicePlugin;
import me.Navoei.customdiscsplugin.language.Lang;
import me.Navoei.customdiscsplugin.utils.TypeChecker;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
Expand All @@ -14,22 +15,31 @@
import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.Skull;
import org.bukkit.entity.Item;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.NotePlayEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;

import javax.annotation.Nullable;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class HeadPlay implements Listener{
Expand All @@ -45,10 +55,10 @@ public void onNotePlay(NotePlayEvent event) throws IOException {

if (noteBlock.getType() != Material.NOTE_BLOCK) return;

if (PlayerManager.instance().isAudioPlayerPlaying(noteBlock.getLocation())) return;
if (PlayerManager.instance().isAudioPlayerPlaying(noteBlock.getLocation())) playerManager.stopDisc(noteBlock);

Block headBlock = noteBlock.getRelative(BlockFace.UP);
if (headBlock.getType() != Material.PLAYER_HEAD) return;
if (!TypeChecker.isHead(headBlock.getType())) return;

Skull skull = (Skull) headBlock.getState();
PersistentDataContainer persistentDataContainer = skull.getPersistentDataContainer();
Expand Down Expand Up @@ -88,16 +98,15 @@ public void onNotePlay(NotePlayEvent event) throws IOException {
public void onHeadPlace(BlockPlaceEvent event) {
ItemStack item = event.getItemInHand();

if (item.getType() != Material.PLAYER_HEAD) return;
if (!TypeChecker.isHead(item.getType())) return;
if (!(item.getItemMeta() instanceof SkullMeta meta)) return;

PersistentDataContainer itemPDC = meta.getPersistentDataContainer();
if (!itemPDC.has(new NamespacedKey(customDiscs, "customhead"), PersistentDataType.STRING)) return;

Block block = event.getBlockPlaced();
if (!TypeChecker.isHead(block.getType()) && !TypeChecker.isWallHead(block.getType())) return;
Bukkit.getRegionScheduler().runDelayed(customDiscs, block.getLocation(), task -> {
if (block.getType() != Material.PLAYER_HEAD && block.getType() != Material.PLAYER_WALL_HEAD) return;

Skull skull = (Skull) block.getState();
PersistentDataContainer blockPDC = skull.getPersistentDataContainer();

Expand All @@ -124,4 +133,122 @@ public void onHeadPlace(BlockPlaceEvent event) {
}, 1L);
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onHeadBreak(BlockBreakEvent event) {
Block block = event.getBlock();
if (!TypeChecker.isHead(block.getType()) && !TypeChecker.isWallHead(block.getType())) return;

Skull headSkull = (Skull) block.getState();

PersistentDataContainer headPDC = headSkull.getPersistentDataContainer();
if (!headPDC.has(new NamespacedKey(customDiscs, "customhead"), PersistentDataType.STRING)) return;

Block noteblockBlockChecker = block.getRelative(BlockFace.DOWN);

if (noteblockBlockChecker.getType() != Material.NOTE_BLOCK) return;

playerManager.stopDisc(noteblockBlockChecker);
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onHeadDrop(BlockDropItemEvent event) {
BlockState blockState = event.getBlockState();

if (!(blockState instanceof Skull skull)) return;

PersistentDataContainer blockPDC = skull.getPersistentDataContainer();

NamespacedKey headKey = new NamespacedKey(customDiscs, "customhead");
NamespacedKey loreKey = new NamespacedKey(customDiscs, "headlore");
NamespacedKey rangeKey = new NamespacedKey(customDiscs, "range");

for (Item itemEntity : event.getItems()) {
ItemStack droppedStack = itemEntity.getItemStack();
if (!TypeChecker.isHead(droppedStack.getType()) && !TypeChecker.isWallHead(droppedStack.getType())) continue;

ItemMeta droppedMeta = droppedStack.getItemMeta();
if (droppedMeta == null) continue;

PersistentDataContainer droppedItemPDC = droppedMeta.getPersistentDataContainer();

String customHeadRetrieved = blockPDC.get(headKey, PersistentDataType.STRING);
if (customHeadRetrieved != null) {
droppedItemPDC.set(headKey, PersistentDataType.STRING, customHeadRetrieved);
}

String loreRetrieved = blockPDC.get(loreKey, PersistentDataType.STRING);
if (loreRetrieved != null) {
droppedItemPDC.set(loreKey, PersistentDataType.STRING, loreRetrieved);

Component deserialized = GsonComponentSerializer.gson().deserialize(loreRetrieved);
@Nullable List<Component> itemLore = new ArrayList<>();
itemLore.add(deserialized);
droppedMeta.lore(itemLore);
}

Float rangeRetrieved = blockPDC.get(rangeKey, PersistentDataType.FLOAT);
if (rangeRetrieved != null) {
droppedItemPDC.set(rangeKey, PersistentDataType.FLOAT, rangeRetrieved);
}

droppedStack.setItemMeta(droppedMeta);
}
}

//TODO: To rework someday, so that it retain custom_data infos
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onHeadExplode(EntityExplodeEvent event) {
for (Block explodedBlock : event.blockList()) {
if (TypeChecker.isHead(explodedBlock.getType()) || TypeChecker.isWallHead(explodedBlock.getType())) {
Skull headSkull = (Skull) explodedBlock.getState();

PersistentDataContainer headPDC = headSkull.getPersistentDataContainer();
if (!headPDC.has(new NamespacedKey(customDiscs, "customhead"), PersistentDataType.STRING)) return;

Block noteblockBlockChecker = explodedBlock.getRelative(BlockFace.DOWN);

if (noteblockBlockChecker.getType() != Material.NOTE_BLOCK) continue;

playerManager.stopDisc(noteblockBlockChecker);
}
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onNoteblockHeadBreak(BlockBreakEvent event) {
Block block = event.getBlock();

if (block.getType() != Material.NOTE_BLOCK) return;

Block headBlockChecker = block.getRelative(BlockFace.UP);

if (!TypeChecker.isHead(headBlockChecker.getType())) return;

Skull headSkull = (Skull) headBlockChecker.getState();

PersistentDataContainer headPDC = headSkull.getPersistentDataContainer();
if (!headPDC.has(new NamespacedKey(customDiscs, "customhead"), PersistentDataType.STRING)) return;

playerManager.stopDisc(block);
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onNoteblockHeadExplode(EntityExplodeEvent event) {
for (Block explodedBlock : event.blockList()) {
if (explodedBlock.getType() == Material.NOTE_BLOCK) {

Block headBlockChecker = explodedBlock.getRelative(BlockFace.UP);

if (!TypeChecker.isHead(headBlockChecker.getType())) continue;

Skull headSkull = (Skull) headBlockChecker.getState();

PersistentDataContainer headPDC = headSkull.getPersistentDataContainer();
if (!headPDC.has(new NamespacedKey(customDiscs, "customhead"), PersistentDataType.STRING)) continue;

playerManager.stopDisc(explodedBlock);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void onJukeboxExplode(EntityExplodeEvent event) {
for (Block explodedBlock : event.blockList()) {
if (explodedBlock.getType() == Material.JUKEBOX) {
Jukebox jukebox = (Jukebox) explodedBlock.getState();
if (!isCustomMusicDisc(jukebox.getRecord())) return;
if (!isCustomMusicDisc(jukebox.getRecord())) continue;
playerManager.stopDisc(explodedBlock);
}
}
Expand Down
Loading