Sets the stat on the given item to the given object, which will be cast to a String @param item The item to set the stat on @param placeholder The placeholder stat to set @param obj The object to set the stat to @return The modified ItemStack, or null if it could not be modified
(ItemStack item, String placeholder, Object obj)
| 161 | * @return The modified ItemStack, or null if it could not be modified |
| 162 | */ |
| 163 | public ItemStack set(ItemStack item, String placeholder, Object obj) { |
| 164 | if (item == null || !item.hasItemMeta() || !item.getItemMeta().hasLore()) { |
| 165 | return null; |
| 166 | } |
| 167 | LorePlaceholder lp = placeholders.get(placeholder); |
| 168 | ItemMeta meta = item.getItemMeta(); |
| 169 | List<String> lore = meta.getLore(); |
| 170 | int line = getLine(item, lp, placeholder); |
| 171 | if (line == -1) { |
| 172 | return null; |
| 173 | } |
| 174 | String str = lore.get(line); |
| 175 | str = str.substring(0, lp.getPosStart()) + obj + str.substring(str.length() - lp.getPosFromEnd()); |
| 176 | lore.set(line, str); |
| 177 | meta.setLore(lore); |
| 178 | item.setItemMeta(meta); |
| 179 | return item; |
| 180 | } |
| 181 | |
| 182 | private static class LorePlaceholder { |
| 183 |
nothing calls this directly
no test coverage detected