Merge pull request #97 from Protonull/more-chat-updates

Some more chat utilities
This commit is contained in:
wingzero54
2021-05-27 09:58:45 -05:00
committed by GitHub
2 changed files with 68 additions and 0 deletions

View File

@@ -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();

View File

@@ -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("<null>")
.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();
}
}