Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,17 @@ public final class XItemStack {
SUPPORTS_Inventory_getStorageContents,
SUPPORTS_CUSTOM_MODEL_DATA,
SUPPORTS_ADVANCED_CUSTOM_MODEL_DATA,
SUPPORTS_ITEM_MODEL;
SUPPORTS_ITEM_MODEL,
SUPPORTS_ITEM_NAME;

static {
boolean supportsPotionColor = false,
supportsUnbreakable = false,
supportsGetStorageContents = false,
supportSCustomModelData = false,
supportsAdvancedCustomModelData = false,
supportsItemModel = false;
supportsItemModel = false,
supportsItemName = false;


try {
Expand All @@ -129,6 +131,12 @@ public final class XItemStack {
} catch (NoSuchMethodException ignored) {
}

try {
ItemMeta.class.getDeclaredMethod("setItemName", String.class);
supportsItemName = true;
} catch (NoSuchMethodException ignored) {
}

try {
Class.forName("org.bukkit.inventory.meta.PotionMeta").getMethod("setColor", Color.class);
supportsPotionColor = true;
Expand All @@ -147,6 +155,7 @@ public final class XItemStack {
SUPPORTS_CUSTOM_MODEL_DATA = supportSCustomModelData;
SUPPORTS_ADVANCED_CUSTOM_MODEL_DATA = supportsAdvancedCustomModelData;
SUPPORTS_ITEM_MODEL = supportsItemModel;
SUPPORTS_ITEM_NAME = supportsItemName;
}

private interface MetaHandler<M extends ItemMeta> {
Expand Down Expand Up @@ -463,6 +472,11 @@ public void handle() {
if (meta.hasLore())
config.set("lore", meta.getLore().stream().map(translator).collect(Collectors.toList()));

if (SUPPORTS_ITEM_NAME && meta.hasItemName()) {
String itemName = meta.getItemName();
config.set("item-name", translator.apply(itemName));
}

customModelData();
if (SUPPORTS_UNBREAKABLE) {
if (meta.isUnbreakable()) config.set("unbreakable", true);
Expand Down Expand Up @@ -805,6 +819,7 @@ public ItemStack parse() {
getOrCreateMeta();
handleDurability();
displayName();
itemName();
unbreakable();
customModelData();
lore();
Expand Down Expand Up @@ -969,6 +984,19 @@ private void displayName() {
meta.setDisplayName(" "); // For GUI easy access configuration purposes
}

private void itemName() {
if (!SUPPORTS_ITEM_NAME)
return;

String itemName = config.getString("item-name");
if (!Strings.isNullOrEmpty(itemName)) {
String translated = translator.apply(itemName);
meta.setItemName(translated);
} else if (itemName != null && itemName.isEmpty()) {
meta.setItemName(" ");
}
}

private void itemFlags() {
List<String> flags = config.getStringList("flags");
if (!flags.isEmpty()) {
Expand Down
Loading