diff --git a/pom.xml b/pom.xml index 62c40482f..4b07d4564 100644 --- a/pom.xml +++ b/pom.xml @@ -260,6 +260,10 @@ onarandombox http://repo.onarandombox.com/content/groups/public + + sonatype-oss + https://oss.sonatype.org/content/repositories/snapshots/ + @@ -677,5 +681,10 @@ adventure-text-minimessage 4.0.0-SNAPSHOT + + net.kyori + adventure-platform-bukkit + 4.0.0-SNAPSHOT + diff --git a/src/main/java/org/maxgamer/quickshop/util/ItemNMS.java b/src/main/java/org/maxgamer/quickshop/util/ItemNMS.java index dffb4e7e5..b2f6190e1 100644 --- a/src/main/java/org/maxgamer/quickshop/util/ItemNMS.java +++ b/src/main/java/org/maxgamer/quickshop/util/ItemNMS.java @@ -1,6 +1,5 @@ /* * This file is a part of project QuickShop, the name is ItemNMS.java - * Copyright (C) Ghost_chu * Copyright (C) PotatoCraft Studio and contributors * * This program is free software: you can redistribute it and/or modify it @@ -86,4 +85,26 @@ public abstract class ItemNMS { return nbtTagCompound.toString(); } + /** + * Save ItemStack to Json through the NMS. + * + * @param bStack ItemStack + * @return The json for ItemStack. + * @throws InvocationTargetException throws + * @throws IllegalAccessException throws + * @throws NoSuchMethodException throws + * @throws InstantiationException throws + */ + @Nullable + public static Object saveItemStackToMojang(@NotNull ItemStack bStack) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException { + if (bStack.getType() == Material.AIR) { + return null; + } + Object mcStack = craftItemStack_asNMSCopyMethod.invoke(null, bStack); + Object nbtTagCompound = nbtTagCompoundClass.getDeclaredConstructor().newInstance(); + + itemStack_saveMethod.invoke(mcStack, nbtTagCompound); + return nbtTagCompound.toString(); + } + } diff --git a/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java b/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java index 060296b76..c14643c44 100644 --- a/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java +++ b/src/main/java/org/maxgamer/quickshop/util/MsgUtil.java @@ -23,10 +23,13 @@ import com.google.common.collect.Maps; import lombok.Getter; import lombok.SneakyThrows; import me.clip.placeholderapi.PlaceholderAPI; -import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.chat.ComponentBuilder; -import net.md_5.bungee.api.chat.HoverEvent; -import net.md_5.bungee.api.chat.TextComponent; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.key.Key; +import net.kyori.adventure.platform.bukkit.BukkitAudiences; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.ComponentBuilder; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.event.HoverEvent; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -89,6 +92,7 @@ public class MsgUtil { @Getter private static YamlConfiguration potioni18n; private static IFile builtInLang; + private static final BukkitAudiences audiences = BukkitAudiences.create(QuickShop.getInstance()); /** * Deletes any messages that are older than a week in the database, to save on space. @@ -152,10 +156,13 @@ public class MsgUtil { return; } - Util.debugLog(left); - Util.debugLog(json); - Util.debugLog(right); - TextComponent centerItem = new TextComponent(left + Util.getItemStackName(itemStack) + right); +// Util.debugLog(left); +// Util.debugLog(json); +// Util.debugLog(right); + Audience audience = audiences.player(player); + Component.text(left + Util.getItemStackName(itemStack) + right) + Component.text(json).hoverEvent(HoverEvent.showItem(Key.of(itemStack.getData().getItemType().getKey()))) + TextComponent centerItem = Component.se; ComponentBuilder cBuilder = new ComponentBuilder(json); centerItem.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, cBuilder.create())); //FIXME: Update this when drop 1.15 supports player.spigot().sendMessage(centerItem); @@ -1011,9 +1018,11 @@ public class MsgUtil { @NotNull ItemStack itemStack, @NotNull Player player, @NotNull String normalText) { - player.spigot().sendMessage(getItemholochat(shop, itemStack, player, normalText)); + getItemholochat(shop, itemStack, player, normalText). + player.spigot().sendMessage(getItemholochat(shop, itemStack, player, normalText)); } + @NotNull public static TextComponent getItemholochat( @NotNull Shop shop, @@ -1022,7 +1031,8 @@ public class MsgUtil { @NotNull String normalText) { try { if (errorComponent == null) { - errorComponent = new TextComponent(getMessage("menu.item-holochat-error", player)); + Component.text(getMessage("menu.item-holochat-error", player)). + errorComponent = new TextComponent(); } String json = ItemNMS.saveJsonfromNMS(itemStack); if (json == null) {