mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Use new ItemStack#displayName Paper API
This commit is contained in:
1 parent
f3a734601e
commit
b2f5b2c605
4 files changed
+6
-33
No files matched your search
@@ -12,9 +12,6 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static java.util.Objects.requireNonNullElseGet;
|
||||
import static net.kyori.adventure.text.Component.translatable;
|
||||
|
||||
public final class CarbonPlayerBukkit extends CarbonPlayerCommon {
|
||||
|
||||
public CarbonPlayerBukkit(
|
||||
@@ -83,10 +80,7 @@ public final class CarbonPlayerBukkit extends CarbonPlayerCommon {
|
||||
return Component.empty();
|
||||
}
|
||||
|
||||
final Component displayName = requireNonNullElseGet(itemStack.getItemMeta().displayName(), () ->
|
||||
translatable(itemStack.getType().getTranslationKey()));
|
||||
|
||||
return this.createItemHoverComponent(displayName, itemStack);
|
||||
return itemStack.displayName();
|
||||
}
|
||||
|
||||
}
|
||||
+4
-4
@@ -18,11 +18,11 @@ import java.util.regex.Pattern;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
|
||||
public final class PlaceholderAPIMiniMessageSerializer {
|
||||
public final class PlaceholderAPIMiniMessageParser {
|
||||
|
||||
private final MiniMessage miniMessage;
|
||||
|
||||
private PlaceholderAPIMiniMessageSerializer(final @NonNull MiniMessage miniMessage) {
|
||||
private PlaceholderAPIMiniMessageParser(final @NonNull MiniMessage miniMessage) {
|
||||
this.miniMessage = miniMessage;
|
||||
}
|
||||
|
||||
@@ -78,8 +78,8 @@ public final class PlaceholderAPIMiniMessageSerializer {
|
||||
return this.miniMessage.parse(builder.toString(), templates);
|
||||
}
|
||||
|
||||
public static @NonNull PlaceholderAPIMiniMessageSerializer create(final @NonNull MiniMessage backingInstance) {
|
||||
return new PlaceholderAPIMiniMessageSerializer(backingInstance);
|
||||
public static @NonNull PlaceholderAPIMiniMessageParser create(final @NonNull MiniMessage backingInstance) {
|
||||
return new PlaceholderAPIMiniMessageParser(backingInstance);
|
||||
}
|
||||
|
||||
private static boolean containsLegacyColorCodes(final @NonNull String string) {
|
||||
@@ -4,9 +4,6 @@ import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.event.HoverEventSource;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
@@ -14,7 +11,6 @@ import java.util.UUID;
|
||||
|
||||
import static java.util.Objects.requireNonNullElseGet;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.WHITE;
|
||||
|
||||
public abstract class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Single {
|
||||
|
||||
@@ -60,19 +56,4 @@ public abstract class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudi
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
protected final @NonNull Component createItemHoverComponent(
|
||||
final @NonNull Component displayName,
|
||||
final @NonNull HoverEventSource<HoverEvent.ShowItem> itemStack
|
||||
) {
|
||||
final TextComponent.Builder builder = text(); // Empty root - prevents style leaking.
|
||||
|
||||
builder.hoverEvent(itemStack); // Let this be inherited by all coming components.
|
||||
|
||||
builder.append(text("[", WHITE));
|
||||
builder.append(displayName);
|
||||
builder.append(text("]", WHITE));
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -76,10 +76,8 @@ public final class CarbonPlayerSponge extends CarbonPlayerCommon {
|
||||
return Component.empty();
|
||||
}
|
||||
|
||||
final Component displayName = itemStack.get(Keys.DISPLAY_NAME)
|
||||
return itemStack.get(Keys.DISPLAY_NAME)
|
||||
.orElse(itemStack.type().asComponent());
|
||||
|
||||
return this.createItemHoverComponent(displayName, itemStack.createSnapshot());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user