|
37 | 37 | */ |
38 | 38 | public class ItemUtils { |
39 | 39 |
|
40 | | - public static final ItemStack PLAYER_HEAD_ITEM; |
41 | | - |
42 | | - static { |
43 | | - PLAYER_HEAD_ITEM = XMaterial.PLAYER_HEAD.parseItem(); |
44 | | - } |
45 | | - |
46 | | - private ItemUtils() { |
47 | | - } |
48 | | - |
49 | | - public static boolean isNamed(ItemStack stack) { |
50 | | - return stack != null && stack.hasItemMeta() && stack.getItemMeta().hasDisplayName(); |
51 | | - } |
52 | | - |
53 | | - /** |
54 | | - * Checks if the given 2 items have the same display name, lore and amount. |
55 | | - * |
56 | | - * @param first the first item to check |
57 | | - * @param second the second item to check |
58 | | - * @return {@code true} if the given 2 items are equals and both are same amount, |
59 | | - * otherwise {@code false} |
60 | | - */ |
61 | | - public static boolean isSameItems(ItemStack first, ItemStack second) { |
62 | | - return isSameItemsWithoutAmount(first, second) && first.getAmount() == second.getAmount(); |
63 | | - } |
64 | | - |
65 | | - /** |
66 | | - * Checks if the given 2 items have the same display name and lore. |
67 | | - * |
68 | | - * @param first the first item to check |
69 | | - * @param second the second item to check |
70 | | - * @return {@code true} if the given 2 items are equals, may not be same amount |
71 | | - */ |
72 | | - public static boolean isSameItemsWithoutAmount(ItemStack first, ItemStack second) { |
73 | | - if (first == null || second == null) { |
74 | | - return false; |
75 | | - } |
76 | | - |
77 | | - if (first.getType() != second.getType()) { |
78 | | - return false; |
79 | | - } |
80 | | - |
81 | | - ItemMeta firstMeta = first.getItemMeta(); |
82 | | - ItemMeta secondMeta = second.getItemMeta(); |
83 | | - |
84 | | - return Objects.equals(firstMeta.getDisplayName(), secondMeta.getDisplayName()) && |
85 | | - Objects.equals(firstMeta.getLore(), secondMeta.getLore()); |
86 | | - } |
87 | | - |
88 | | - public static ItemStack getSkull(String url) { |
89 | | - return XSkull.of(PLAYER_HEAD_ITEM.clone()) |
90 | | - .profile(Profileable.detect(url)) |
91 | | - .applyAsync() |
92 | | - .join(); |
93 | | - } |
94 | | - |
95 | | - public static SkullMeta setPlayerHead(Player player, SkullMeta meta) { |
96 | | - if (XReflection.supports(12)) { |
97 | | - meta.setOwningPlayer(player); |
98 | | - } else if (Bukkit.getServer().getVersion().contains("Paper") && player.getPlayerProfile().hasTextures()) { |
99 | | - meta.setPlayerProfile(player.getPlayerProfile()); |
100 | | - } else { |
101 | | - meta.setOwner(player.getName()); |
102 | | - } |
103 | | - |
104 | | - return meta; |
105 | | - } |
| 40 | + public static final ItemStack PLAYER_HEAD_ITEM; |
| 41 | + |
| 42 | + static { |
| 43 | + PLAYER_HEAD_ITEM = XMaterial.PLAYER_HEAD.parseItem(); |
| 44 | + } |
| 45 | + |
| 46 | + private ItemUtils() { |
| 47 | + } |
| 48 | + |
| 49 | + public static boolean isNamed(ItemStack stack) { |
| 50 | + return stack != null && stack.hasItemMeta() && stack.getItemMeta().hasDisplayName(); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Checks if the given 2 items have the same display name, lore and amount. |
| 55 | + * |
| 56 | + * @param first the first item to check |
| 57 | + * @param second the second item to check |
| 58 | + * @return {@code true} if the given 2 items are equals and both are same amount, |
| 59 | + * otherwise {@code false} |
| 60 | + */ |
| 61 | + public static boolean isSameItems(ItemStack first, ItemStack second) { |
| 62 | + return isSameItemsWithoutAmount(first, second) && first.getAmount() == second.getAmount(); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Checks if the given 2 items have the same display name and lore. |
| 67 | + * |
| 68 | + * @param first the first item to check |
| 69 | + * @param second the second item to check |
| 70 | + * @return {@code true} if the given 2 items are equals, may not be same amount |
| 71 | + */ |
| 72 | + public static boolean isSameItemsWithoutAmount(ItemStack first, ItemStack second) { |
| 73 | + if (first == null || second == null) { |
| 74 | + return false; |
| 75 | + } |
| 76 | + |
| 77 | + if (first.getType() != second.getType()) { |
| 78 | + return false; |
| 79 | + } |
| 80 | + |
| 81 | + ItemMeta firstMeta = first.getItemMeta(); |
| 82 | + ItemMeta secondMeta = second.getItemMeta(); |
| 83 | + |
| 84 | + return Objects.equals(firstMeta.getDisplayName(), secondMeta.getDisplayName()) && |
| 85 | + Objects.equals(firstMeta.getLore(), secondMeta.getLore()); |
| 86 | + } |
| 87 | + |
| 88 | + public static ItemStack getSkull(String url) { |
| 89 | + return XSkull.of(PLAYER_HEAD_ITEM.clone()) |
| 90 | + .profile(Profileable.detect(url)) |
| 91 | + .applyAsync() |
| 92 | + .join(); |
| 93 | + } |
| 94 | + |
| 95 | + public static SkullMeta setPlayerHead(Player player, SkullMeta meta) { |
| 96 | + try { |
| 97 | + meta.setOwningPlayer(player); |
| 98 | + } catch (Throwable throwable) { |
| 99 | + if (Bukkit.getServer().getVersion().contains("Paper") && player.getPlayerProfile().hasTextures()) { |
| 100 | + meta.setPlayerProfile(player.getPlayerProfile()); |
| 101 | + } else { |
| 102 | + meta.setOwner(player.getName()); |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + return meta; |
| 107 | + } |
106 | 108 | } |
0 commit comments