65 lines
1.8 KiB
Java
65 lines
1.8 KiB
Java
package com.Acrobot.ChestShop.Utils;
|
|
|
|
import com.Acrobot.Breeze.Utils.InventoryUtil;
|
|
import com.Acrobot.ChestShop.ChestShop;
|
|
import com.Acrobot.ChestShop.Events.ItemStringQueryEvent;
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import static com.Acrobot.Breeze.Utils.MaterialUtil.MAXIMUM_SIGN_WIDTH;
|
|
|
|
public class ItemUtil {
|
|
|
|
/**
|
|
* Get a list with item information
|
|
*
|
|
* @param items The items to get the information from
|
|
* @return The list, including the amount and names of the items
|
|
*/
|
|
public static String getItemList(ItemStack[] items) {
|
|
ItemStack[] mergedItems = InventoryUtil.mergeSimilarStacks(items);
|
|
|
|
List<String> itemText = new ArrayList<>();
|
|
|
|
for (ItemStack item : mergedItems) {
|
|
itemText.add(item.getAmount() + " " + getName(item));
|
|
}
|
|
|
|
return String.join(", ", itemText);
|
|
}
|
|
|
|
/**
|
|
* Returns item's name
|
|
*
|
|
* @param itemStack ItemStack to name
|
|
* @return ItemStack's name
|
|
*/
|
|
public static String getName(ItemStack itemStack) {
|
|
return getName(itemStack, 0);
|
|
}
|
|
|
|
|
|
/**
|
|
* Returns item's name, with a maximum width
|
|
*
|
|
* @param itemStack ItemStack to name
|
|
* @param maxWidth The max width that the name should have; 0 or below if it should be unlimited
|
|
* @return ItemStack's name
|
|
*/
|
|
public static String getName(ItemStack itemStack, int maxWidth) {
|
|
return ChestShop.callEvent(new ItemStringQueryEvent(itemStack, maxWidth)).getItemString();
|
|
}
|
|
|
|
/**
|
|
* Returns item's name, just like on the sign
|
|
*
|
|
* @param itemStack ItemStack to name
|
|
* @return ItemStack's name
|
|
*/
|
|
public static String getSignName(ItemStack itemStack) {
|
|
return getName(itemStack, MAXIMUM_SIGN_WIDTH);
|
|
}
|
|
}
|