diff --git a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/chat/ChatUtils.java b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/chat/ChatUtils.java index d3c1aaea8..f6afad8f1 100644 --- a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/chat/ChatUtils.java +++ b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/chat/ChatUtils.java @@ -199,6 +199,7 @@ public final class ChatUtils { final var content = component instanceof net.kyori.adventure.text.TextComponent ? ((net.kyori.adventure.text.TextComponent) component).content() : null; return StringUtils.isEmpty(content) + && !component.children().isEmpty() && component.clickEvent() == null && component.hoverEvent() == null && !component.hasStyling(); diff --git a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/chat/Componentify.java b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/chat/Componentify.java new file mode 100644 index 000000000..744bc8262 --- /dev/null +++ b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/chat/Componentify.java @@ -0,0 +1,67 @@ +package vg.civcraft.mc.civmodcore.chat; + +import javax.annotation.Nonnull; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.event.HoverEvent; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.Location; + +public final class Componentify { + + private static Component INTERNAL_addLocationWorld(final Location location) { + if (location.isWorldLoaded()) { + return Component.text(location.getWorld().getName()) + .hoverEvent(HoverEvent.showText(Component.text("World name"))); + } + else { + return Component.text("") + .color(NamedTextColor.RED) + .hoverEvent(HoverEvent.showText(Component.text("World not specified / loaded"))); + } + } + + public static Component fullLocation(@Nonnull final Location location) { + final var component = Component.text(); + component.append(INTERNAL_addLocationWorld(location)); + component.append(Component.space()); + component.append(Component.text(location.getX()) + .color(NamedTextColor.RED) + .hoverEvent(HoverEvent.showText(Component.text("X")))); + component.append(Component.space()); + component.append(Component.text(location.getY()) + .color(NamedTextColor.GREEN) + .hoverEvent(HoverEvent.showText(Component.text("Y")))); + component.append(Component.space()); + component.append(Component.text(location.getZ()) + .color(NamedTextColor.BLUE) + .hoverEvent(HoverEvent.showText(Component.text("Z")))); + component.append(Component.space()); + component.append(Component.text(location.getYaw()) + .color(NamedTextColor.GOLD) + .hoverEvent(HoverEvent.showText(Component.text("Yaw")))); + component.append(Component.space()); + component.append(Component.text(location.getPitch()) + .color(NamedTextColor.AQUA) + .hoverEvent(HoverEvent.showText(Component.text("Pitch")))); + return component.build(); + } + + public static Component blockLocation(@Nonnull final Location location) { + final var component = Component.text(); + component.append(INTERNAL_addLocationWorld(location)); + component.append(Component.space()); + component.append(Component.text(location.getBlockX()) + .color(NamedTextColor.RED) + .hoverEvent(HoverEvent.showText(Component.text("Block X")))); + component.append(Component.space()); + component.append(Component.text(location.getBlockY()) + .color(NamedTextColor.GREEN) + .hoverEvent(HoverEvent.showText(Component.text("Block X")))); + component.append(Component.space()); + component.append(Component.text(location.getBlockZ()) + .color(NamedTextColor.BLUE) + .hoverEvent(HoverEvent.showText(Component.text("Block X")))); + return component.build(); + } + +}