Command Lore

Command now sets the lore for the disc.
This commit is contained in:
Navoei
2022-07-08 00:29:20 -05:00
parent c255e5821f
commit 6e8d345776
2 changed files with 125 additions and 8 deletions

View File

@@ -2,8 +2,13 @@ package na.Navoei.customdiscsplugin;
import de.maxhenkel.voicechat.api.VoicechatApi;
import de.maxhenkel.voicechat.api.VoicechatPlugin;
import de.maxhenkel.voicechat.api.audiochannel.AudioChannel;
import de.maxhenkel.voicechat.api.audiochannel.AudioPlayer;
import de.maxhenkel.voicechat.api.events.Event;
import de.maxhenkel.voicechat.api.events.EventRegistration;
import java.util.function.Consumer;
public class PlayMusic implements VoicechatPlugin {
/**
@@ -20,7 +25,7 @@ public class PlayMusic implements VoicechatPlugin {
* @param api the voice chat API
*/
@Override
public void initialize(VoicechatApi api) {
public void initialize(final VoicechatApi api) {
}
@@ -30,8 +35,12 @@ public class PlayMusic implements VoicechatPlugin {
* @param registration the event registration
*/
@Override
public void registerEvents(EventRegistration registration) {
// TODO register your events
public void registerEvents(final EventRegistration registration) {
}
public void playSoundFile() {
}
}

View File

@@ -1,13 +1,25 @@
package na.Navoei.customdiscsplugin.command;
import
import na.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.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
public class CustomDisc implements CommandExecutor {
@@ -23,17 +35,113 @@ public class CustomDisc implements CommandExecutor {
// /customdisc wewontbealone "We wont be alone"
if (command.getName().equalsIgnoreCase("customdisc")) {
if (args.length == 2) {
if (isMusicDisc(p)) {
if (args.length >= 2) {
//Find file, if file not there then say "file not there"
String filename = args[0];
p.sendMessage("Your filename is:" + args[0]);
p.sendMessage("Your custom name is " + args[1]);
//Reads the command for quotations.
ArrayList<String> quotes = new ArrayList<>();
String temp = "";
boolean inQuotes = false;
for (String s : args) {
if (s.startsWith("\"") && s.endsWith("\"")) {
temp += s.substring(1, s.length()-1);
quotes.add(temp);
} else if (s.startsWith("\"")) {
temp += s.substring(1);
quotes.add(temp);
inQuotes = true;
} else if (s.endsWith("\"")) {
temp += s.substring(0, s.length()-1);
quotes.add(temp);
inQuotes = false;
} else if (inQuotes) {
temp += s;
quotes.add(temp);
}
temp = "";
}
//Sets the lore of the item to the quotes from the command.
ItemStack disc = new ItemStack(p.getInventory().getItemInMainHand());
ItemMeta meta = disc.getItemMeta();
@Nullable List<Component> itemLore = new ArrayList<>();
final TextComponent customLoreSong = Component.text()
.decoration(TextDecoration.ITALIC, false)
.content(customName(quotes))
.color(NamedTextColor.GRAY)
.build();
itemLore.add(customLoreSong);
final TextComponent customLoreFile = Component.text()
.content(filename)
.color(NamedTextColor.DARK_GRAY)
.build();
itemLore.add(customLoreFile);
meta.lore(itemLore);
meta.addItemFlags(ItemFlag.values());
p.getInventory().getItemInMainHand().setItemMeta(meta);
p.sendMessage("Your filename is: " + filename);
p.sendMessage("Your custom name is: " + customName(quotes));
return true;
} else {
p.sendMessage(ChatColor.RED + "Insufficient arguments! ( /customdisc <filename> [\"customname\"] )");
return true;
}
} else {
p.sendMessage(ChatColor.RED + "Incorrect arguments! ( /customdisc <filename> [customname] )");
p.sendMessage(ChatColor.RED + "You are not holding a music disc in your main hand!");
}
}
return false;
}
private String customName(ArrayList<String> q) {
StringBuffer sb = new StringBuffer();
for (String s : q) {
sb.append(s);
sb.append(" ");
}
if (sb.isEmpty()) {
return sb.toString();
} else {
return sb.toString().substring(0, sb.length()-1);
}
}
private boolean isMusicDisc(Player p) {
if ( 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;
}
}