mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Share some item hover code
This commit is contained in:
1 parent
8d1833bd43
commit
dd5aca28fb
3 files changed
+31
-29
No files matched your search
@@ -4,7 +4,6 @@ import io.papermc.lib.PaperLib;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.events.CarbonEventHandler;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
@@ -19,9 +18,7 @@ import java.util.logging.Level;
|
||||
|
||||
import static java.util.Objects.requireNonNullElseGet;
|
||||
import static net.kyori.adventure.text.Component.empty;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.Component.translatable;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.WHITE;
|
||||
|
||||
public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
private final Logger logger = LogManager.getLogger("CarbonChat");
|
||||
@@ -60,7 +57,7 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Component createComponent(final @NonNull UUID uuid) {
|
||||
public @NonNull Component createItemHoverComponent(final @NonNull UUID uuid) {
|
||||
final Player player = Bukkit.getPlayer(uuid); // This is temporary (it's not)
|
||||
|
||||
if (player == null) {
|
||||
@@ -91,19 +88,10 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
return empty();
|
||||
}
|
||||
|
||||
final TextComponent.Builder builder = text();
|
||||
final Component displayName = requireNonNullElseGet(itemStack.getItemMeta().displayName(), () ->
|
||||
translatable(itemStack.getType().getTranslationKey()));
|
||||
|
||||
builder.hoverEvent(itemStack); // Let this be inherited by all coming components.
|
||||
builder.append(text("[", WHITE));
|
||||
|
||||
final Component displayName = itemStack.getItemMeta().displayName();
|
||||
|
||||
builder.append(requireNonNullElseGet(displayName, () ->
|
||||
translatable(itemStack.getType().getTranslationKey())));
|
||||
|
||||
builder.append(text("]", WHITE));
|
||||
|
||||
return builder.build();
|
||||
return createItemHoverComponent(displayName, itemStack);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user