|
39 | 39 | import me.wolfyscript.utilities.api.chat.HoverEvent; |
40 | 40 | import me.wolfyscript.utilities.api.inventory.gui.InventoryAPI; |
41 | 41 | import me.wolfyscript.utilities.util.NamespacedKey; |
| 42 | +import net.kyori.adventure.text.Component; |
42 | 43 | import org.bukkit.ChatColor; |
43 | 44 | import org.bukkit.attribute.Attribute; |
44 | 45 | import org.bukkit.attribute.AttributeModifier; |
@@ -180,6 +181,66 @@ public static CollectionEditor<CCCache, String> createLoreChatEditor(InventoryAP |
180 | 181 | itemMeta.setLore(lore); |
181 | 182 | } |
182 | 183 | cache.getItems().getItem().setItemMeta(itemMeta); |
| 184 | + }).setSendInputInfoMessages((guiHandler, player, cache) -> { |
| 185 | + var chat = invAPI.getWolfyUtilities().getChat(); |
| 186 | + chat.sendMessage(player, chat.translated("msg.input.wui_command")); |
| 187 | + chat.sendMessage(player, chat.translated("msg.input.mini_message")); |
| 188 | + }); |
| 189 | + } |
| 190 | + |
| 191 | + public static CollectionEditor<CCCache, net.kyori.adventure.text.Component> createPaperLoreChatEditor(InventoryAPI<CCCache> invAPI) { |
| 192 | + var paperMiniMsg = net.kyori.adventure.text.minimessage.MiniMessage.miniMessage(); |
| 193 | + return new CollectionEditor<CCCache, net.kyori.adventure.text.Component>(invAPI, |
| 194 | + (guiHandler, player, cache) -> { |
| 195 | + var itemMeta = cache.getItems().getItem().getItemMeta(); |
| 196 | + return itemMeta != null && itemMeta.hasLore() ? itemMeta.lore() : List.of(); |
| 197 | + }, |
| 198 | + // This is quite inefficient! We need to convert to the shaded version of Adventure! TODO: v5.0 | No longer shade & relocate Adventure! |
| 199 | + (guiHandler, player, cache, line) -> miniM.deserialize(paperMiniMsg.serialize(line)), |
| 200 | + (guiHandler, player, cache, msg, args) -> paperMiniMsg.deserialize(msg) |
| 201 | + ).onAdd((guiHandler, player, cache, index, entry) -> { |
| 202 | + var itemMeta = cache.getItems().getItem().getItemMeta(); |
| 203 | + List<Component> lore = itemMeta.lore(); |
| 204 | + if (lore == null) { |
| 205 | + lore = new ArrayList<>(); |
| 206 | + } |
| 207 | + if (index >= 0) { |
| 208 | + lore.add(index, entry); |
| 209 | + } else { |
| 210 | + lore.add(entry); |
| 211 | + } |
| 212 | + itemMeta.lore(lore); |
| 213 | + cache.getItems().getItem().setItemMeta(itemMeta); |
| 214 | + }).onRemove((guiHandler, player, cache, index, entry) -> { |
| 215 | + var itemMeta = cache.getItems().getItem().getItemMeta(); |
| 216 | + List<Component> lore = itemMeta.lore(); |
| 217 | + if (lore != null) { |
| 218 | + lore.remove(index); |
| 219 | + itemMeta.lore(lore); |
| 220 | + } |
| 221 | + cache.getItems().getItem().setItemMeta(itemMeta); |
| 222 | + }).onMove((guiHandler, player, cache, fromIndex, toIndex) -> { |
| 223 | + var itemMeta = cache.getItems().getItem().getItemMeta(); |
| 224 | + List<Component> lore = itemMeta.lore(); |
| 225 | + if (lore != null) { |
| 226 | + Component toPrevEntry = lore.get(toIndex); |
| 227 | + lore.set(toIndex, lore.get(fromIndex)); |
| 228 | + lore.set(fromIndex, toPrevEntry); |
| 229 | + itemMeta.lore(lore); |
| 230 | + } |
| 231 | + cache.getItems().getItem().setItemMeta(itemMeta); |
| 232 | + }).onEdit((guiHandler, player, cache, index, previousEntry, newEntry) -> { |
| 233 | + var itemMeta = cache.getItems().getItem().getItemMeta(); |
| 234 | + List<Component> lore = itemMeta.lore(); |
| 235 | + if (lore != null) { |
| 236 | + lore.set(index, newEntry); |
| 237 | + itemMeta.lore(lore); |
| 238 | + } |
| 239 | + cache.getItems().getItem().setItemMeta(itemMeta); |
| 240 | + }).setSendInputInfoMessages((guiHandler, player, cache) -> { |
| 241 | + var chat = invAPI.getWolfyUtilities().getChat(); |
| 242 | + chat.sendMessage(player, chat.translated("msg.input.wui_command")); |
| 243 | + chat.sendMessage(player, chat.translated("msg.input.mini_message")); |
183 | 244 | }); |
184 | 245 | } |
185 | 246 |
|
|
0 commit comments