diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index c6b5de1..276b6a6 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -6,11 +6,6 @@
-
-
-
-
-
@@ -21,11 +16,21 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/resource/config.yml b/resource/config.yml
index d9fb99f..784b73d 100644
--- a/resource/config.yml
+++ b/resource/config.yml
@@ -37,7 +37,7 @@ input:
- '&aEnter Input for Command'
- '&cType &4%cp-args% &cto Cancel the command'
hexcodes:
- start_tag: '#'
+ start_tag: ''
end_tag: ''
placeholders:
primary:
diff --git a/resource/plugin.yml b/resource/plugin.yml
index 7e338f4..8a2e0f8 100644
--- a/resource/plugin.yml
+++ b/resource/plugin.yml
@@ -1,4 +1,4 @@
-version: 3.21.3.4
+version: 3.21.4.0
main: me.rockyhawk.commandpanels.CommandPanels
name: CommandPanels
author: RockyHawk
diff --git a/src/me/rockyhawk/commandpanels/CommandPanels.java b/src/me/rockyhawk/commandpanels/CommandPanels.java
index 1cbb944..7d113f5 100644
--- a/src/me/rockyhawk/commandpanels/CommandPanels.java
+++ b/src/me/rockyhawk/commandpanels/CommandPanels.java
@@ -5,7 +5,7 @@ import io.lumine.mythic.lib.api.item.NBTItem;
import me.rockyhawk.commandpanels.api.CommandPanelsAPI;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.classresources.ExecuteOpenVoids;
-import me.rockyhawk.commandpanels.classresources.SerializerUtils;
+import me.rockyhawk.commandpanels.classresources.MiniMessageUtils;
import me.rockyhawk.commandpanels.classresources.customheads.GetCustomHeads;
import me.rockyhawk.commandpanels.classresources.HasSections;
import me.rockyhawk.commandpanels.classresources.ItemCreation;
@@ -99,6 +99,8 @@ public class CommandPanels extends JavaPlugin{
public CreateText tex = new CreateText(this);
public HexColours hex = new HexColours(this);
+ public MiniMessageUtils miniMessage = null;
+
public ExecuteOpenVoids openVoids = new ExecuteOpenVoids(this);
public ItemCreation itemCreate = new ItemCreation(this);
public HasSections has = new HasSections(this);
@@ -194,6 +196,14 @@ public class CommandPanels extends JavaPlugin{
this.getServer().getPluginManager().registerEvents(new legacyPlayerEvent(this), this);
}
+ try {
+ // Check for a class that exists only in Paper
+ Class.forName("com.destroystokyo.paper.PaperConfig");
+ miniMessage = new MiniMessageUtils(this);
+ } catch (ClassNotFoundException ignore) {
+ //do not initialise miniMessage
+ }
+
this.getServer().getPluginManager().registerEvents(inputUtils, this);
this.getServer().getPluginManager().registerEvents(panelDataPlayers, this);
this.getServer().getPluginManager().registerEvents(new UtilsPanelsLoader(this), this);
@@ -359,12 +369,7 @@ public class CommandPanels extends JavaPlugin{
}
}
if (customName != null) {
- if(SerializerUtils.isPaperServer()){
- renamedMeta.setDisplayName(SerializerUtils.doMiniMessageLegacy(customName));
- } else {
- renamedMeta.setDisplayName(customName);
- }
-
+ renamedMeta.setDisplayName(customName);
}
List re_lore;
@@ -378,11 +383,7 @@ public class CommandPanels extends JavaPlugin{
}else{
re_lore = lore;
}
- if(SerializerUtils.isPaperServer()){
- renamedMeta.setLore(SerializerUtils.doMiniMessageLegacy(re_lore));
- } else {
- renamedMeta.setLore(splitListWithEscape(re_lore));
- }
+ renamedMeta.setLore(splitListWithEscape(re_lore));
}
renamed.setItemMeta(renamedMeta);
} catch (Exception ignored) {}
diff --git a/src/me/rockyhawk/commandpanels/Utils.java b/src/me/rockyhawk/commandpanels/Utils.java
index 68c0b93..ebc5593 100644
--- a/src/me/rockyhawk/commandpanels/Utils.java
+++ b/src/me/rockyhawk/commandpanels/Utils.java
@@ -87,23 +87,24 @@ public class Utils implements Listener {
panel = plugin.openPanels.getOpenPanel(p.getName(),position);
//this loops through all the items in the panel
- boolean foundSlot = false;
- for(String slot : Objects.requireNonNull(panel.getConfig().getConfigurationSection("item")).getKeys(false)){
+ String foundSlot = null;
+ for(String item : Objects.requireNonNull(panel.getConfig().getConfigurationSection("item")).getKeys(false)){
+ String slot = plugin.tex.placeholdersNoColour(panel, position, p, item);
if (slot.equals(Integer.toString(clickedSlot))) {
- foundSlot = true;
+ foundSlot = item;
break;
}
}
- if(!foundSlot){
+ if(foundSlot == null){
e.setCancelled(true);
return;
}
//get the section of the slot that was clicked
- String section = plugin.has.hasSection(panel,position,panel.getConfig().getConfigurationSection("item." + clickedSlot), p);
+ String section = plugin.has.hasSection(panel,position,panel.getConfig().getConfigurationSection("item." + foundSlot), p);
- if(panel.getConfig().contains("item." + clickedSlot + section + ".itemType")){
- if(panel.getConfig().getStringList("item." + clickedSlot + section + ".itemType").contains("placeable")){
+ if(panel.getConfig().contains("item." + foundSlot + section + ".itemType")){
+ if(panel.getConfig().getStringList("item." + foundSlot + section + ".itemType").contains("placeable")){
//skip if the item is a placeable
e.setCancelled(false);
return;
@@ -115,13 +116,13 @@ public class Utils implements Listener {
p.updateInventory();
//if an item has an area for input instead of commands
- if(panel.getConfig().contains("item." + clickedSlot + section + ".player-input")) {
- plugin.inputUtils.playerInput.put(p,new PlayerInput(panel,panel.getConfig().getStringList("item." + clickedSlot + section + ".player-input"),e.getClick()));
+ if(panel.getConfig().contains("item." + foundSlot + section + ".player-input")) {
+ plugin.inputUtils.playerInput.put(p,new PlayerInput(panel,panel.getConfig().getStringList("item." + foundSlot + section + ".player-input"),e.getClick()));
plugin.inputUtils.sendMessage(panel,position,p);
}
- if(panel.getConfig().contains("item." + clickedSlot + section + ".commands")) {
- List commands = panel.getConfig().getStringList("item." + clickedSlot + section + ".commands");
+ if(panel.getConfig().contains("item." + foundSlot + section + ".commands")) {
+ List commands = panel.getConfig().getStringList("item." + foundSlot + section + ".commands");
if (!commands.isEmpty()) {
for (int i = 0; commands.size() > i; i++) {
try {
@@ -130,9 +131,9 @@ public class Utils implements Listener {
commands.set(i, commands.get(i).replaceAll("%cp-clicked%", "AIR"));
}
}
- if (panel.getConfig().contains("item." + clickedSlot + section + ".multi-paywall")) {
+ if (panel.getConfig().contains("item." + foundSlot + section + ".multi-paywall")) {
plugin.commandRunner.runMultiPaywall(panel,position,p,
- panel.getConfig().getStringList("item." + clickedSlot + section + ".multi-paywall"),
+ panel.getConfig().getStringList("item." + foundSlot + section + ".multi-paywall"),
commands,e.getClick());
} else {
plugin.commandRunner.runCommands(panel, position, p, commands, e.getClick());
diff --git a/src/me/rockyhawk/commandpanels/classresources/ItemCreation.java b/src/me/rockyhawk/commandpanels/classresources/ItemCreation.java
index dbcd5fb..177ae4f 100644
--- a/src/me/rockyhawk/commandpanels/classresources/ItemCreation.java
+++ b/src/me/rockyhawk/commandpanels/classresources/ItemCreation.java
@@ -1,5 +1,6 @@
package me.rockyhawk.commandpanels.classresources;
+import dev.lone.itemsadder.api.CustomStack;
import me.arcaniax.hdb.api.HeadDatabaseAPI;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
@@ -94,6 +95,16 @@ public class ItemCreation {
}
}
+ //ItemsAdder support, needs namespaceID (eg, money:coin)
+ if (matraw.split("\\s")[0].equalsIgnoreCase("itemsadder=")) {
+ String namespaceID = matraw.split("\\s")[1];
+ CustomStack stack = CustomStack.getInstance(namespaceID);
+ if(stack != null) {
+ s = stack.getItemStack().clone();
+ normalCreation = false;
+ }
+ }
+
//creates custom MMOItems items
if(matraw.split("\\s")[0].equalsIgnoreCase("mmo=") && plugin.getServer().getPluginManager().isPluginEnabled("MMOItems")){
String itemType = matraw.split("\\s")[1];
diff --git a/src/me/rockyhawk/commandpanels/classresources/MiniMessageUtils.java b/src/me/rockyhawk/commandpanels/classresources/MiniMessageUtils.java
new file mode 100644
index 0000000..5b23f25
--- /dev/null
+++ b/src/me/rockyhawk/commandpanels/classresources/MiniMessageUtils.java
@@ -0,0 +1,60 @@
+package me.rockyhawk.commandpanels.classresources;
+
+import me.rockyhawk.commandpanels.CommandPanels;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.format.TextDecoration;
+import net.kyori.adventure.text.minimessage.MiniMessage;
+import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class MiniMessageUtils {
+
+ CommandPanels plugin;
+ public MiniMessageUtils(CommandPanels pl) {
+ this.plugin = pl;
+ }
+
+ /*
+ MiniMessage is used here as an alternative to the standard Minecraft colour codes &
+ As MiniMessage does not accept legacy colour codes at any point, which is
+ a possibility when using Minecraft colour codes, running a try/catch allows for
+ MiniMessage to be used anywhere and ignored when legacy colour codes are found.
+ */
+
+ public String doMiniMessageLegacy(String string) {
+ MiniMessage miniMessage = MiniMessage.miniMessage();
+ try {
+ Component component = miniMessage.deserialize(string);
+ return LegacyComponentSerializer.builder()
+ .character('&')
+ .hexColors()
+ .build()
+ .serialize(component);
+ }catch (Exception e){
+ return string;
+ }
+ }
+
+ public List doMiniMessageLegacy(List strings) {
+ return strings.stream()
+ .map(this::doMiniMessageLegacy)
+ .collect(Collectors.toList());
+ }
+
+ public Component doMiniMessage(String string) {
+ LegacyComponentSerializer legacyComponentSerializer = LegacyComponentSerializer.builder().hexColors().character('&').build();
+ Component component = legacyComponentSerializer.deserialize(string.replace('§', '&'));
+
+ return MiniMessage.miniMessage().deserialize(MiniMessage.miniMessage().serialize(component.decoration(TextDecoration.ITALIC, false))
+ .replace("\\<", "<").replace("\\", "").replace("\n", "
")).decoration(TextDecoration.ITALIC, false);
+
+ }
+
+ public List doMiniMessage(List strings) {
+ return strings.stream()
+ .map(this::doMiniMessage)
+ .collect(Collectors.toList());
+ }
+}
diff --git a/src/me/rockyhawk/commandpanels/classresources/SerializerUtils.java b/src/me/rockyhawk/commandpanels/classresources/SerializerUtils.java
deleted file mode 100644
index aee2906..0000000
--- a/src/me/rockyhawk/commandpanels/classresources/SerializerUtils.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package me.rockyhawk.commandpanels.classresources;
-
-import net.kyori.adventure.text.Component;
-import net.kyori.adventure.text.format.TextDecoration;
-import net.kyori.adventure.text.minimessage.MiniMessage;
-import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
-import org.bukkit.Bukkit;
-
-import java.util.List;
-import java.util.stream.Collectors;
-
-public class SerializerUtils {
-
- static LegacyComponentSerializer legacyComponentSerializer;
-
- //public static Component serializeText(String msg){
- // return MiniMessage.miniMessage().deserialize(msg);
- //}
-
- public static boolean isPaperServer(){
- try {
- // Check for a class that exists only in Paper
- Class.forName("com.destroystokyo.paper.PaperConfig");
- return true;
- } catch (ClassNotFoundException e) {
- // The class was not found, indicating a non-Paper server
- return false;
- }
- }
-
- public static Component doMiniMessage(String string) {
- legacyComponentSerializer = LegacyComponentSerializer.builder().hexColors().character('&').build();
- Component component = legacyComponentSerializer.deserialize(string.replace('§', '&'));
-
- return MiniMessage.miniMessage().deserialize(MiniMessage.miniMessage().serialize(component.decoration(TextDecoration.ITALIC, false))
- .replace("\\<", "<").replace("\\", "").replace("\n", "
")).decoration(TextDecoration.ITALIC, false);
- }
-
- public static List doMiniMessage(List strings) {
- return strings.stream()
- .map(SerializerUtils::doMiniMessage)
- .collect(Collectors.toList());
- }
-
- public static String doMiniMessageLegacy(String string) {
- MiniMessage miniMessage = MiniMessage.miniMessage();
- Component component = miniMessage.deserialize(string);
-
- Bukkit.getLogger().info("Component: " + component);
-
- String legacyText = LegacyComponentSerializer.builder()
- .character('&')
- .hexColors()
- .build()
- .serialize(component);
-
- Bukkit.getLogger().info("Legacy: " + legacyText);
-
- Bukkit.getLogger().info("Convert: " + convertHexCodes(legacyText));
-
- return convertHexCodes(legacyText);
- }
-
- public static List doMiniMessageLegacy(List strings) {
- return strings.stream()
- .map(SerializerUtils::doMiniMessageLegacy)
- .collect(Collectors.toList());
- }
-
- // Helper method to convert &x&F&F&F&F&F&F to FFFFFF format
- private static String convertHexCodes(String text) {
- StringBuilder result = new StringBuilder();
- char[] chars = text.toCharArray();
-
- for (int i = 0; i < chars.length; i++) {
- // Check for the start of a hex color code (&x pattern)
- if (chars[i] == '&' && i + 1 < chars.length && chars[i + 1] == 'x' && i + 13 <= chars.length) {
- // Found a hex color code
- StringBuilder hexCode = new StringBuilder("");
- for (int j = 2; j < 14; j += 2) {
- hexCode.append(chars[i + j]);
- }
- result.append(hexCode.toString());
- i += 13; // Skip the next 12 characters (full hex code)
- } else {
- result.append(chars[i]);
- }
- }
-
- return result.toString();
- }
-}
diff --git a/src/me/rockyhawk/commandpanels/classresources/placeholders/CreateText.java b/src/me/rockyhawk/commandpanels/classresources/placeholders/CreateText.java
index e0e073a..ceb1cbf 100644
--- a/src/me/rockyhawk/commandpanels/classresources/placeholders/CreateText.java
+++ b/src/me/rockyhawk/commandpanels/classresources/placeholders/CreateText.java
@@ -86,6 +86,9 @@ public class CreateText {
//regular string papi, but only colours so Player doesn't need to be there
public String colour(String setpapi) {
try {
+ if(plugin.miniMessage != null){
+ setpapi = plugin.miniMessage.doMiniMessageLegacy(setpapi);
+ }
setpapi = ChatColor.translateAlternateColorCodes('&', setpapi);
setpapi = plugin.hex.translateHexColorCodes(setpapi);
return setpapi;
@@ -108,7 +111,11 @@ public class CreateText {
public String placeholders(Panel panel, PanelPosition position, Player p, String setpapi) {
try {
setpapi = attachPlaceholders(panel,position, p,setpapi);
- setpapi = plugin.hex.translateHexColorCodes(ChatColor.translateAlternateColorCodes('&', setpapi));
+ if(plugin.miniMessage != null){
+ setpapi = plugin.miniMessage.doMiniMessageLegacy(setpapi);
+ }
+ setpapi = ChatColor.translateAlternateColorCodes('&', setpapi);
+ setpapi = plugin.hex.translateHexColorCodes(setpapi);
return setpapi;
}catch(NullPointerException e){
return setpapi;
diff --git a/src/me/rockyhawk/commandpanels/classresources/placeholders/HexColours.java b/src/me/rockyhawk/commandpanels/classresources/placeholders/HexColours.java
index eadfe39..2cae35b 100644
--- a/src/me/rockyhawk/commandpanels/classresources/placeholders/HexColours.java
+++ b/src/me/rockyhawk/commandpanels/classresources/placeholders/HexColours.java
@@ -35,7 +35,7 @@ public class HexColours {
}
//automatically format regex to escape special characters
- public String formatRegex(String path){
+ private String formatRegex(String path){
String inputString = plugin.config.getString(path);
final String[] metaCharacters = {"\\","^","$","{","}","[","]","(",")",".","*","+","?","|","<",">","-","&","%"};
diff --git a/src/me/rockyhawk/commandpanels/commandtags/tags/standard/BasicTags.java b/src/me/rockyhawk/commandpanels/commandtags/tags/standard/BasicTags.java
index 96080ee..7da223c 100644
--- a/src/me/rockyhawk/commandpanels/commandtags/tags/standard/BasicTags.java
+++ b/src/me/rockyhawk/commandpanels/commandtags/tags/standard/BasicTags.java
@@ -2,7 +2,7 @@ package me.rockyhawk.commandpanels.commandtags.tags.standard;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.PanelCommandEvent;
-import me.rockyhawk.commandpanels.classresources.SerializerUtils;
+import me.rockyhawk.commandpanels.classresources.MiniMessageUtils;
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
import me.rockyhawk.commandpanels.openpanelsmanager.PanelOpenType;
@@ -140,7 +140,7 @@ public class BasicTags implements Listener {
//do mini message if conditions are met
if (plugin.legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_18)) {
Audience player = (Audience) e.p; // Needed because the basic Player from the Event can't send Paper's Components
- Component parsedText = SerializerUtils.doMiniMessage(String.join(" ", e.args));
+ Component parsedText = plugin.miniMessage.doMiniMessage(String.join(" ", e.args));
player.sendMessage(parsedText);
} else {
plugin.tex.sendString(e.p, plugin.tag + ChatColor.RED + "MiniMessage-Feature needs Paper 1.18 or newer to work!");
diff --git a/src/me/rockyhawk/commandpanels/interactives/Commandpanelrefresher.java b/src/me/rockyhawk/commandpanels/interactives/Commandpanelrefresher.java
index f91c15a..1b2ef38 100644
--- a/src/me/rockyhawk/commandpanels/interactives/Commandpanelrefresher.java
+++ b/src/me/rockyhawk/commandpanels/interactives/Commandpanelrefresher.java
@@ -22,6 +22,10 @@ public class Commandpanelrefresher implements Listener {
}
@EventHandler
public void onPanelOpen(PanelOpenedEvent e){ //Handles when Players open inventory
+ if(e.isCancelled()){
+ return;
+ }
+
if (plugin.config.contains("config.refresh-panels")) {
if (Objects.requireNonNull(plugin.config.getString("config.refresh-panels")).trim().equalsIgnoreCase("false")) {
return;
diff --git a/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenGUI.java b/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenGUI.java
index 28593aa..0845c37 100644
--- a/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenGUI.java
+++ b/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenGUI.java
@@ -9,7 +9,6 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
-import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@@ -50,11 +49,9 @@ public class OpenGUI {
Set itemList = pconfig.getConfigurationSection("item").getKeys(false);
HashSet takenSlots = new HashSet<>();
for (String item : itemList) {
- item = plugin.tex.attachPlaceholders(panel,position,p,item);
- Bukkit.getLogger().info("formatted number: " + item);
- String section = "";
+ String section;
//openType needs to not be 3 so the editor won't include hasperm and hasvalue, etc items
- section = plugin.has.hasSection(panel,position,pconfig.getConfigurationSection("item." + Integer.parseInt(item)), p);
+ section = plugin.has.hasSection(panel,position,pconfig.getConfigurationSection("item." + item), p);
//This section is for animations below here: VISUAL ONLY
//check for if there is animations inside the items section
@@ -72,17 +69,16 @@ public class OpenGUI {
//this is for contents in the itemType section
if (pconfig.getStringList("item." + item + section + ".itemType").contains("placeable") && openType == PanelOpenType.Refresh) {
//keep item the same, openType == 0 meaning panel is refreshing
- setItem(p.getOpenInventory().getItem(Integer.parseInt(item)),Integer.parseInt(item),i,p,position);
- takenSlots.add(Integer.parseInt(item));
+ setItem(p.getOpenInventory().getItem(Integer.parseInt(plugin.tex.placeholdersNoColour(panel,position,p,item))), item, i, p, position);
+ takenSlots.add(Integer.parseInt(plugin.tex.placeholdersNoColour(panel,position,p,item)));
continue;
}
}
try {
//place item into the GUI
- setItem(s,Integer.parseInt(item),i,p,position);
- takenSlots.add(Integer.parseInt(item));
- //i.setItem(Integer.parseInt(item), s);
+ setItem(s,item,i,p,position);
+ takenSlots.add(Integer.parseInt(plugin.tex.placeholdersNoColour(panel,position,p,item)));
//only place duplicate items in without the editor mode. These are merely visual and will not carry over commands
if(pconfig.contains("item." + item + section + ".duplicate")) {
try {
@@ -194,6 +190,12 @@ public class OpenGUI {
return 9;
}
}
+
+ //allows for a string to be used instead of integer, for placeholders
+ private void setItem(ItemStack item, String slotName, Inventory inv, Player p, PanelPosition position) throws ArrayIndexOutOfBoundsException{
+ int slot = Integer.parseInt(plugin.tex.placeholdersNoColour(null, position, p, slotName));
+ setItem(item, slot, inv, p, position);
+ }
private void setItem(ItemStack item, int slot, Inventory inv, Player p, PanelPosition position) throws ArrayIndexOutOfBoundsException{
if(position == PanelPosition.Top){
inv.setItem(slot, item);