From c09f6c62ee897608cd808ebe29c27ef0d74c8450 Mon Sep 17 00:00:00 2001 From: insanj Date: Mon, 8 Apr 2019 21:05:25 -0400 Subject: [PATCH] finalize text formatting w hover, color, bold wiring --- .../com/insanj/pride/PrideEntityTracker.java | 56 +++++++++++++++---- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/plugin/src/main/java/com/insanj/pride/PrideEntityTracker.java b/plugin/src/main/java/com/insanj/pride/PrideEntityTracker.java index 674649d..6fd990c 100644 --- a/plugin/src/main/java/com/insanj/pride/PrideEntityTracker.java +++ b/plugin/src/main/java/com/insanj/pride/PrideEntityTracker.java @@ -49,6 +49,7 @@ import net.minecraft.text.TextComponent; import net.minecraft.text.TextFormat; import net.minecraft.text.TranslatableTextComponent; +import net.minecraft.text.event.HoverEvent; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; @@ -121,6 +122,8 @@ public void run() { double distanceBetween = Math.abs(Math.abs(areaPos.getX() - pos.getX()) + Math.abs(areaPos.getY() - pos.getY()) + Math.abs(areaPos.getZ() - pos.getZ())); if (distanceBetween <= areaDetectionDistance) { + String areaDescription = String.format("x: %d, y: %d, z: %d", (Integer)areaPos.getX(), (Integer)areaPos.getY(), (Integer)areaPos.getZ()); + // activate! if (tracker.currentlyActivatedAreas.get(playerName) == null) { ArrayList playerActivatedAreas = new ArrayList(); @@ -128,8 +131,8 @@ public void run() { tracker.currentlyActivatedAreas.put(playerName, playerActivatedAreas); - sendServerMessage(server, String.format("%s is entering %s!", playerName, areaName)); - sendPlayerMessage(player, String.format("Welcome to the\n%s", areaName)); + sendServerMessage(server, playerName, areaName, areaDescription); + sendPlayerMessage(player, areaName); } // activate! @@ -139,8 +142,8 @@ else if (tracker.currentlyActivatedAreas.get(playerName).contains(areaName) == f tracker.currentlyActivatedAreas.put(playerName, playerActivatedAreas); - sendServerMessage(server, String.format("%s is entering %s!", playerName, areaName)); - sendPlayerMessage(player, String.format("Welcome to the\n%s", areaName)); + sendServerMessage(server, playerName, areaName, areaDescription); + sendPlayerMessage(player, areaName); } } @@ -155,17 +158,50 @@ else if (tracker.currentlyActivatedAreas.get(playerName).contains(areaName) == f } } - private void sendPlayerMessage(ServerPlayerEntity player, String message) { - player.addChatMessage(new StringTextComponent(message), true); + private void sendPlayerMessage(ServerPlayerEntity player, String areaName) { + StringTextComponent component = new StringTextComponent(areaName); + + Style style = new Style(); + style.setColor(TextFormat.GOLD); + style.setBold(true); + component.setStyle(style); + + player.addChatMessage(component, true); } - private void sendServerMessage(MinecraftServer server, String message) { - StringTextComponent component = new StringTextComponent(message); - component.setStyle(new Style().setColor(TextFormat.BLUE)); + private void sendServerMessage(MinecraftServer server, String playerName, String areaName, String areaDescription) { + StringTextComponent playerComponent = new StringTextComponent(playerName); + Style playerComponentStyle = new Style(); + playerComponentStyle.setColor(TextFormat.BLUE); + playerComponent.setStyle(playerComponentStyle); + + StringTextComponent fillerComponent = new StringTextComponent(" is entering "); + Style fillerComponentStyle = new Style(); + fillerComponentStyle.setColor(TextFormat.WHITE); + fillerComponent.setStyle(fillerComponentStyle); + + StringTextComponent areaComponent = new StringTextComponent(areaName); + Style areaComponentStyle = new Style(); + areaComponentStyle.setColor(TextFormat.GOLD); + areaComponentStyle.setBold(true); + + StringTextComponent areaDescriptionComponent = new StringTextComponent(areaDescription); + HoverEvent areaHoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, areaDescriptionComponent); + areaComponentStyle.setHoverEvent(areaHoverEvent); + + areaComponent.setStyle(areaComponentStyle); + + StringTextComponent punctuationComponent = new StringTextComponent("!"); + Style punctuationComponentStyle = new Style(); + punctuationComponentStyle.setColor(TextFormat.WHITE); + punctuationComponentStyle.setBold(false); + punctuationComponent.setStyle(punctuationComponentStyle); + + TextComponent concatComponent = playerComponent.append(fillerComponent).append(areaComponent).append(punctuationComponent); Set players = (Set)PlayerStream.all(server).collect(Collectors.toSet()); for (ServerPlayerEntity player : players) { - player.addChatMessage(component, false); + player.addChatMessage(concatComponent, false); } } }).start();