forked from Upstream/CommandPanels
recursive nbt
This commit is contained in:
parent
47aabb03b2
commit
43dbaafc94
src/me/rockyhawk/commandpanels
@ -194,12 +194,8 @@ public class ItemCreation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(addNBT && itemSection.contains("nbt")){
|
if(addNBT && itemSection.contains("nbt")){
|
||||||
for(String key : Objects.requireNonNull(itemSection.getConfigurationSection("nbt")).getKeys(true)){
|
|
||||||
if(itemSection.isConfigurationSection("nbt." + key)){
|
plugin.nbt.applyNBTRecursively("", itemSection, s, p, panel, position);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
s = plugin.nbt.setNBT(s,key,plugin.tex.attachPlaceholders(panel, position, p, Objects.requireNonNull(itemSection.getString("nbt." + key)))); //itemSection.getString("nbt." + key));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (itemSection.contains("enchanted")) {
|
if (itemSection.contains("enchanted")) {
|
||||||
try {
|
try {
|
||||||
|
@ -3,9 +3,15 @@ package me.rockyhawk.commandpanels.ioclasses.nbt;
|
|||||||
import de.tr7zw.changeme.nbtapi.NBT;
|
import de.tr7zw.changeme.nbtapi.NBT;
|
||||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||||
import me.rockyhawk.commandpanels.CommandPanels;
|
import me.rockyhawk.commandpanels.CommandPanels;
|
||||||
|
import me.rockyhawk.commandpanels.api.Panel;
|
||||||
|
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class NBTManager {
|
public class NBTManager {
|
||||||
CommandPanels plugin;
|
CommandPanels plugin;
|
||||||
public NBTManager(CommandPanels pl) {
|
public NBTManager(CommandPanels pl) {
|
||||||
@ -36,4 +42,18 @@ public class NBTManager {
|
|||||||
if(!nbti.hasNBTData()) return "";
|
if(!nbti.hasNBTData()) return "";
|
||||||
return nbti.getString(key);
|
return nbti.getString(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void applyNBTRecursively(String path, ConfigurationSection section, ItemStack s, Player p, Panel panel, PanelPosition position) {
|
||||||
|
for (String key : section.getKeys(true)) {
|
||||||
|
String fullPath = path.isEmpty() ? key : path + "." + key;
|
||||||
|
if (section.isConfigurationSection(key)) {
|
||||||
|
// Recursive call for nested sections
|
||||||
|
applyNBTRecursively(fullPath, section.getConfigurationSection(key), s, p, panel, position);
|
||||||
|
} else {
|
||||||
|
// Set the NBT tag at this level
|
||||||
|
String value = plugin.tex.attachPlaceholders(panel, position, p, section.getString(key));
|
||||||
|
s = plugin.nbt.setNBT(s, fullPath, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user