Skip to content

Commit

Permalink
Implement item metadata check in PreShopCreation
Browse files Browse the repository at this point in the history
The ItemChecker class now includes functionality to handle item metadata during PreShopCreation. It adds a check for itemStack's metadata, strips any color from displayName if it exists or adds italics to itemName if the metadata is unique. This ensures correct preprocessing of items with metadata.
  • Loading branch information
Feli499 committed Jan 1, 2024
1 parent 05c2450 commit 41e733a
Showing 1 changed file with 12 additions and 0 deletions.
Expand Up @@ -2,10 +2,12 @@

import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.INVALID_ITEM;

import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import com.Acrobot.Breeze.Utils.MaterialUtil;
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
Expand All @@ -29,6 +31,16 @@ public static void onPreShopCreation(PreShopCreationEvent event) {
event.setOutcome(INVALID_ITEM);
return;
}

if (itemStack.hasItemMeta()) {
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta.hasDisplayName()) {
itemName = ChatColor.stripColor(itemMeta.getDisplayName());
} else if (!itemMeta.equals(new ItemStack(itemStack.getType()).getItemMeta())) {
itemName = ChatColor.ITALIC + itemName;
}
}

event.setItemLine(itemName);
}
}

0 comments on commit 41e733a

Please sign in to comment.