mirror of
https://github.com/SPAWNRYS-ban/FUCK-CustomDiscs.git
synced 2025-12-10 05:19:43 +05:00
Some Changes
This commit is contained in:
@@ -12,6 +12,6 @@ mod_id=customdiscsplugin
|
||||
voicechat_api_version=2.5.0
|
||||
command_api_version=9.6.0
|
||||
|
||||
plugin_version=4.0
|
||||
plugin_version=4.1
|
||||
maven_group=me.Navoei.customdiscsplugin
|
||||
archives_base_name=custom-discs
|
||||
@@ -18,6 +18,7 @@ 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;
|
||||
|
||||
@@ -82,7 +83,6 @@ public final class CustomDiscs extends JavaPlugin {
|
||||
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"));
|
||||
hornMaxCooldownTicks = (Objects.requireNonNull(getConfig().getInt("horn-max-cooldown")) * 20);
|
||||
|
||||
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
|
||||
@@ -193,12 +193,4 @@ public final class CustomDiscs extends JavaPlugin {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static boolean isMusicDisc(Player p) {
|
||||
return p.getInventory().getItemInMainHand().getType().toString().contains("MUSIC_DISC");
|
||||
}
|
||||
|
||||
public static boolean isGoatHorn(Player p) {
|
||||
return p.getInventory().getItemInMainHand().getType().toString().contains("GOAT_HORN");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ import dev.jorel.commandapi.arguments.ArgumentSuggestions;
|
||||
import dev.jorel.commandapi.arguments.StringArgument;
|
||||
import dev.jorel.commandapi.arguments.TextArgument;
|
||||
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.ShownInTooltip;
|
||||
import me.Navoei.customdiscsplugin.CustomDiscs;
|
||||
import me.Navoei.customdiscsplugin.language.Lang;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -12,11 +15,13 @@ import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.MusicInstrumentMeta;
|
||||
import org.bukkit.inventory.meta.components.JukeboxPlayableComponent;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
@@ -27,8 +32,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
|
||||
public class CreateSubCommand extends CommandAPICommand {
|
||||
private final CustomDiscs plugin;
|
||||
@@ -61,7 +64,10 @@ public class CreateSubCommand extends CommandAPICommand {
|
||||
}
|
||||
|
||||
private int onCommandPlayer(Player player, CommandArguments arguments) {
|
||||
if (!CustomDiscs.isMusicDisc(player) && !CustomDiscs.isGoatHorn(player)) {
|
||||
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
|
||||
if (!isMusicDisc(item) && !isGoatHorn(item)) {
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.NOT_HOLDING_DISC.toString()));
|
||||
return 1;
|
||||
}
|
||||
@@ -92,86 +98,39 @@ public class CreateSubCommand extends CommandAPICommand {
|
||||
|
||||
String song_name = Objects.requireNonNull(arguments.getByClass("song_name", String.class));
|
||||
|
||||
if (CustomDiscs.isMusicDisc(player)) {
|
||||
// IF CD
|
||||
// Sets the lore of the item to the quotes from the command.
|
||||
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);
|
||||
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);
|
||||
|
||||
PersistentDataContainer data = meta.getPersistentDataContainer();
|
||||
data.set(new NamespacedKey(this.plugin, "customdisc"), PersistentDataType.STRING, filename);
|
||||
JukeboxPlayableComponent jpc = meta.getJukeboxPlayable();
|
||||
jpc.setShowInTooltip(false);
|
||||
meta.setJukeboxPlayable(jpc);
|
||||
|
||||
player.getInventory().getItemInMainHand().setItemMeta(meta);
|
||||
} else if (CustomDiscs.isGoatHorn(player)) {
|
||||
// IF HORN
|
||||
int removedHornState = 0;
|
||||
PersistentDataContainer data = meta.getPersistentDataContainer();
|
||||
data.set(new NamespacedKey(this.plugin, "customdisc"), PersistentDataType.STRING, filename);
|
||||
player.getInventory().getItemInMainHand().setItemMeta(meta);
|
||||
|
||||
ItemStack disc = new ItemStack(player.getInventory().getItemInMainHand());
|
||||
ItemMeta theItemMeta = disc.getItemMeta();
|
||||
PersistentDataContainer data = theItemMeta.getPersistentDataContainer();
|
||||
Float retrieveCustomRangeIfSet = data.get(new NamespacedKey(this.plugin, "customsoundrange"), PersistentDataType.FLOAT);
|
||||
if (retrieveCustomRangeIfSet == null) {
|
||||
retrieveCustomRangeIfSet = this.plugin.musicDiscDistance;
|
||||
}
|
||||
} 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);
|
||||
|
||||
if (player.getInventory().getItemInMainHand().getAmount() == 1) {
|
||||
player.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
|
||||
removedHornState = 1;
|
||||
} else {
|
||||
player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount()-1);
|
||||
removedHornState = 1;
|
||||
}
|
||||
if (removedHornState == 1) {
|
||||
var namespaceHorn = new NamespacedKey(this.plugin, "customhorn");
|
||||
var namespaceCustomsoundrange = new NamespacedKey(this.plugin, "customsoundrange");
|
||||
var namespaceCustomhorncooldown = new NamespacedKey(this.plugin, "customhorncoolodwn");
|
||||
|
||||
int setHornCooldown;
|
||||
if(data.has(namespaceCustomhorncooldown, PersistentDataType.INTEGER)) {
|
||||
setHornCooldown = Math.min(data.get(namespaceCustomhorncooldown, PersistentDataType.INTEGER), CustomDiscs.getInstance().hornMaxCooldownTicks);
|
||||
} else {
|
||||
setHornCooldown = Math.min(Math.round(CustomDiscs.getInstance().hornCooldown * 20), CustomDiscs.getInstance().hornMaxCooldownTicks);
|
||||
}
|
||||
|
||||
//TEST COMMAND LOCAL : /give PLAYER minecraft:goat_horn{HideFlags:255,instrument:"",display:{Lore:['{"italic":false,"color":"gray","text":"customName(readQuotes(args))"}']},PublicBukkitValues:{"namespaceHorn":"filename"}}
|
||||
//String command = "minecraft:give "+player.getName()+" minecraft:goat_horn[minecraft:instrument={sound_event:{sound_id:\"intentionally_empty\"},use_duration: 140,range:256F},minecraft:custom_data={PublicBukkitValues:{\""+namespaceHorn+"\":\""+filename+"\"}},minecraft:lore=['{\"bold\":false,\"color\":\"gray\",\"italic\":false,\"text\":\""+song_name+"\",\"underlined\":false}']]";
|
||||
/*String command = "minecraft:give " + player.getName() + " minecraft:goat_horn{"
|
||||
+ "minecraft:instrument:{sound_event:{sound_id:\"intentionally_empty\"},use_duration:140,range:256F},"
|
||||
+ "minecraft:custom_data:{PublicBukkitValues:{\"" + namespaceHorn + "\":\"" + filename + "\"}},"
|
||||
+ "minecraft:lore:[{\"bold\":false,\"color\":\"gray\",\"italic\":false,\"text\":\"" + song_name + "\",\"underlined\":false}]"
|
||||
+ "}";*/
|
||||
//Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||
|
||||
/*1.21.1
|
||||
String itemCommand = "minecraft:give " + player.getName() + " minecraft:goat_horn["
|
||||
+ "minecraft:instrument={sound_event:{sound_id:\"intentionally_empty\"},use_duration:140,range:256F},"
|
||||
+ "minecraft:custom_data={PublicBukkitValues:{\"" + namespaceHorn + "\":\"" + filename + "\",\""+namespaceCustomsoundrange+"\":"+retrieveCustomRangeIfSet+"f,\"" + namespaceCustomhorncooldown + "\":" + setHornCooldown + "}},"
|
||||
+ "minecraft:lore=['{\"bold\":false,\"color\":\"gray\",\"italic\":false,\"text\":\"" + song_name + "\",\"underlined\":false}']"
|
||||
+ "]";
|
||||
*/
|
||||
|
||||
String itemCommand = "minecraft:give " + player.getName() + " minecraft:goat_horn["
|
||||
+ "minecraft:instrument={sound_event:\"intentionally_empty\",use_duration:140,range:256F,description:{\"bold\":false,\"color\":\"gray\",\"italic\":false,\"text\":\"" + song_name + "\",\"underlined\":false}},"
|
||||
+ "minecraft:custom_data={PublicBukkitValues:{\"" + namespaceHorn + "\":\"" + filename + "\",\""+namespaceCustomsoundrange+"\":"+retrieveCustomRangeIfSet+"f,\"" + namespaceCustomhorncooldown + "\":" + setHornCooldown + "}},"
|
||||
+ "minecraft:lore=['{\"bold\":false,\"color\":\"gray\",\"italic\":false,\"text\":\"" + song_name + "\",\"underlined\":false}']"
|
||||
+ "]";
|
||||
meta.addItemFlags(ItemFlag.HIDE_ADDITIONAL_TOOLTIP);
|
||||
|
||||
// Dispatch the command to give the item
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), itemCommand);
|
||||
} else {
|
||||
player.sendMessage("Horn deletion error");
|
||||
}
|
||||
//player.getInventory().getItemInMainHand().subtract();
|
||||
PersistentDataContainer data = meta.getPersistentDataContainer();
|
||||
data.set(new NamespacedKey(this.plugin, "customhorn"), PersistentDataType.STRING, filename);
|
||||
player.getInventory().getItemInMainHand().setItemMeta(meta);
|
||||
} else {
|
||||
// IF ELSE
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.CREATE_FILENAME.toString().replace("%filename%", filename)));
|
||||
@@ -192,4 +151,12 @@ public class CreateSubCommand extends CommandAPICommand {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isMusicDisc(ItemStack item) {
|
||||
return item.getType().toString().contains("MUSIC_DISC");
|
||||
}
|
||||
|
||||
public static boolean isGoatHorn(ItemStack item) {
|
||||
return item.getType().toString().contains("GOAT_HORN");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,15 +3,21 @@ 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;
|
||||
|
||||
@@ -35,52 +41,31 @@ public class SetHornCooldownSubCommand extends CommandAPICommand {
|
||||
}
|
||||
|
||||
private int onCommandPlayer(Player player, CommandArguments arguments) {
|
||||
if (!CustomDiscs.isGoatHorn(player)) {
|
||||
|
||||
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")) {
|
||||
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));
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
//Sets the lore of the item to the quotes from the command.
|
||||
ItemStack disc = new ItemStack(player.getInventory().getItemInMainHand());
|
||||
ItemMeta theItemMeta = disc.getItemMeta();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.getPersistentDataContainer().set(new NamespacedKey(plugin, "horncooldown"), PersistentDataType.INTEGER, goatcooldown.intValue());
|
||||
item.setItemMeta(meta);
|
||||
|
||||
PersistentDataContainer data = theItemMeta.getPersistentDataContainer();
|
||||
|
||||
var namespaceHorn = new NamespacedKey(this.plugin, "customhorn");
|
||||
String retrieveCustomHornFile = data.get(namespaceHorn, PersistentDataType.STRING);
|
||||
if (retrieveCustomHornFile == null || retrieveCustomHornFile.compareTo("null") == 0) {
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.NOT_HOLDING_MODIFIED_GOATHORN.toString()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
var namespaceCustomsoundrange = new NamespacedKey(this.plugin, "customsoundrange");
|
||||
Float retrieveCustomsoundrange = data.get(namespaceCustomsoundrange, PersistentDataType.FLOAT);
|
||||
|
||||
var namespaceCustomhorncooldown = new NamespacedKey(this.plugin, "customhorncoolodwn");
|
||||
int setCustomGoatcooldown;
|
||||
if (goatcooldown == 0) {
|
||||
setCustomGoatcooldown = 1;
|
||||
} else {
|
||||
setCustomGoatcooldown = Math.min(Math.round(goatcooldown * 20), CustomDiscs.getInstance().hornMaxCooldownTicks);
|
||||
}
|
||||
|
||||
String command = "minecraft:item modify entity "+player.getName()+" weapon.mainhand {\"function\":\"minecraft:set_components\",\"components\":{\"minecraft:custom_data\":\"{PublicBukkitValues:{\\\""+namespaceHorn+"\\\":\\\""+retrieveCustomHornFile+"\\\",\\\""+namespaceCustomsoundrange+"\\\":"+retrieveCustomsoundrange+"f,\\\""+namespaceCustomhorncooldown+"\\\":"+setCustomGoatcooldown+"}}\"}}";
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||
|
||||
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.CREATE_CUSTOM_GOAT_COOLDOWN.toString().replace("%custom_goat_cooldown%", Float.toString(goatcooldown))));
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.CREATE_CUSTOM_GOAT_COOLDOWN.toString().replace("%custom_goat_cooldown%", Float.toString(goatcooldown))));
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -90,4 +75,9 @@ public class SetHornCooldownSubCommand extends CommandAPICommand {
|
||||
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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.bukkit.entity.Player;
|
||||
//import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
//import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
@@ -38,52 +39,41 @@ public class SetRangeSubCommand extends CommandAPICommand {
|
||||
}
|
||||
|
||||
private int onCommandPlayer(Player player, CommandArguments arguments) {
|
||||
if (!CustomDiscs.isMusicDisc(player) && !CustomDiscs.isGoatHorn(player)) {
|
||||
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
|
||||
if (!isCustomDisc(item) && !isCustomGoatHorn(item)) {
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.NOT_HOLDING_DISC.toString()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!player.hasPermission("customdiscs.range")) {
|
||||
if (!player.hasPermission("customdiscs.range")) {
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.NO_PERMISSION.toString()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
Float range = Objects.requireNonNull(arguments.getByClass("range", Float.class));
|
||||
Float range = Objects.requireNonNull(arguments.getByClass("range", Float.class));
|
||||
|
||||
if ( range < 1 || range > this.plugin.musicDiscMaxDistance) {
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.INVALID_RANGE.toString().replace("%range_value%", Float.toString(this.plugin.musicDiscMaxDistance))));
|
||||
return 1;
|
||||
}
|
||||
if ( range < 1 || range > this.plugin.musicDiscMaxDistance) {
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.INVALID_RANGE.toString().replace("%range_value%", Float.toString(this.plugin.musicDiscMaxDistance))));
|
||||
return 1;
|
||||
}
|
||||
|
||||
//Sets the lore of the item to the quotes from the command.
|
||||
ItemStack disc = new ItemStack(player.getInventory().getItemInMainHand());
|
||||
ItemMeta theItemMeta = disc.getItemMeta();
|
||||
if (isCustomDisc(item)) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
PersistentDataContainer data = theItemMeta.getPersistentDataContainer();
|
||||
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();
|
||||
|
||||
if (CustomDiscs.isMusicDisc(player)) {
|
||||
data.set(new NamespacedKey(this.plugin, "customsoundrange"), PersistentDataType.FLOAT, range);
|
||||
player.getInventory().getItemInMainHand().setItemMeta(theItemMeta);
|
||||
} else if (CustomDiscs.isGoatHorn(player)) {
|
||||
var namespaceHorn = new NamespacedKey(this.plugin, "customhorn");
|
||||
String retrieveCustomHornFile = data.get(namespaceHorn, PersistentDataType.STRING);
|
||||
if (retrieveCustomHornFile == null || retrieveCustomHornFile.compareTo("null") == 0) {
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.NOT_HOLDING_MODIFIED_GOATHORN.toString()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
Float setCustomHornRange = range;
|
||||
PersistentDataContainer data = meta.getPersistentDataContainer();
|
||||
data.set(new NamespacedKey(this.plugin, "range"), PersistentDataType.FLOAT, range);
|
||||
player.getInventory().getItemInMainHand().setItemMeta(meta);
|
||||
}
|
||||
|
||||
var namespaceCustomsoundrange = new NamespacedKey(this.plugin, "customsoundrange");
|
||||
var namespaceCustomhorncooldown = new NamespacedKey(this.plugin, "customhorncoolodwn");
|
||||
int retrieveCustomhorncooldown = data.get(namespaceCustomhorncooldown, PersistentDataType.INTEGER);
|
||||
|
||||
String command = "minecraft:item modify entity "+player.getName()+" weapon.mainhand {\"function\":\"minecraft:set_components\",\"components\":{\"minecraft:custom_data\":\"{PublicBukkitValues:{\\\""+namespaceHorn+"\\\":\\\""+retrieveCustomHornFile+"\\\",\\\""+namespaceCustomsoundrange+"\\\":"+setCustomHornRange+"f,\\\""+namespaceCustomhorncooldown+"\\\":"+retrieveCustomhorncooldown+"}}\"}}";
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||
|
||||
}
|
||||
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.CREATE_CUSTOM_RANGE.toString().replace("%custom_range%", Float.toString(range))));
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Lang.PREFIX + Lang.CREATE_CUSTOM_RANGE.toString().replace("%custom_range%", Float.toString(range))));
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -93,4 +83,14 @@ public class SetRangeSubCommand extends CommandAPICommand {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public boolean isCustomDisc(ItemStack item) {
|
||||
if (item==null) return false;
|
||||
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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class GoatHorn implements Listener {
|
||||
@NotNull PersistentDataContainer persistentDataContainer = event.getItem().getItemMeta().getPersistentDataContainer();
|
||||
|
||||
float range;
|
||||
NamespacedKey customSoundRangeKey = new NamespacedKey(customDiscs, "customsoundrange");
|
||||
NamespacedKey customSoundRangeKey = new NamespacedKey(customDiscs, "range");
|
||||
if(persistentDataContainer.has(customSoundRangeKey, PersistentDataType.FLOAT)) {
|
||||
range = Math.min(persistentDataContainer.get(customSoundRangeKey, PersistentDataType.FLOAT), CustomDiscs.getInstance().musicDiscMaxDistance);
|
||||
} else {
|
||||
@@ -66,11 +66,11 @@ public class GoatHorn implements Listener {
|
||||
}
|
||||
|
||||
int hornCooldown;
|
||||
NamespacedKey hornCooldownKey = new NamespacedKey(customDiscs, "customhorncoolodwn");
|
||||
NamespacedKey hornCooldownKey = new NamespacedKey(customDiscs, "horncooldown");
|
||||
if(persistentDataContainer.has(hornCooldownKey, PersistentDataType.INTEGER)) {
|
||||
hornCooldown = Math.min(persistentDataContainer.get(hornCooldownKey, PersistentDataType.INTEGER), CustomDiscs.getInstance().hornMaxCooldownTicks);
|
||||
hornCooldown = Math.min(persistentDataContainer.get(hornCooldownKey, PersistentDataType.INTEGER), CustomDiscs.getInstance().hornMaxCooldown) * 20;
|
||||
} else {
|
||||
hornCooldown = Math.min(Math.round(CustomDiscs.getInstance().hornCooldown * 20), CustomDiscs.getInstance().hornMaxCooldownTicks);
|
||||
hornCooldown = Math.min(Math.round(CustomDiscs.getInstance().hornCooldown) * 20, CustomDiscs.getInstance().hornMaxCooldown) * 20;
|
||||
}
|
||||
|
||||
Path soundFilePath = Path.of(customDiscs.getDataFolder().getPath(), "musicdata", soundFileName);
|
||||
|
||||
@@ -52,7 +52,7 @@ public class JukeBox implements Listener{
|
||||
|
||||
PersistentDataContainer persistentDataContainer = event.getItem().getItemMeta().getPersistentDataContainer();
|
||||
float range = CustomDiscs.getInstance().musicDiscDistance;
|
||||
NamespacedKey customSoundRangeKey = new NamespacedKey(customDiscs, "customsoundrange");
|
||||
NamespacedKey customSoundRangeKey = new NamespacedKey(customDiscs, "range");
|
||||
|
||||
if(persistentDataContainer.has(customSoundRangeKey, PersistentDataType.FLOAT)) {
|
||||
range = Math.min(persistentDataContainer.get(customSoundRangeKey, PersistentDataType.FLOAT), CustomDiscs.getInstance().musicDiscMaxDistance);
|
||||
|
||||
Reference in New Issue
Block a user