Finished stat-result feedback message and made it hover with actual stat-result for sharer

This commit is contained in:
Artemis-the-gr8 2022-07-17 16:34:29 +02:00
parent 644a9c0e0b
commit 16b1350948
5 changed files with 129 additions and 25 deletions

View File

@ -16,7 +16,7 @@ import net.kyori.adventure.text.format.TextColor;
public enum PluginColor {
GRAY (NamedTextColor.GRAY), //#AAAAAA
DARK_PURPLE (TextColor.fromHexString("#6E3485")),
LIGHT_PURPLE (TextColor.fromHexString("#9876AA")),
LIGHT_PURPLE (TextColor.fromHexString("#845EC2")),
MEDIUM_BLUE (TextColor.fromHexString("#55AAFF")),
LIGHT_BLUE (TextColor.fromHexString("#55C6FF")),
GOLD (NamedTextColor.GOLD), //#FFAA00

View File

@ -305,19 +305,25 @@ public class ComponentFactory {
.color(HOVER_ACCENT))));
}
public TextComponent sharedMessageComponent(String playerName) {
if (playerName == null) {
return surroundingBracketComponent(
text("Shared!")
.color(CLICKED_MSG));
} else {
return surroundingBracketComponent(
text("Shared by ")
.color(CLICKED_MSG)
.append(text(playerName)
.color(MSG_ACCENT))
.append(text("!")));
}
public TextComponent messageSharedComponent() {
return surroundingBracketComponent(
text("Shared!")
.color(CLICKED_MSG));
}
public TextComponent messageSharedComponent(String playerName) {
return messageSharedComponent(
text(playerName)
.color(MSG_ACCENT));
}
public TextComponent messageSharedComponent(Component playerName) {
return surroundingBracketComponent(
text("Shared by")
.color(CLICKED_MSG)
.append(space())
.append(playerName)
.append(text("!")));
}
private TextComponent surroundingBracketComponent(TextComponent component) {

View File

@ -198,11 +198,15 @@ public class MessageWriter {
TextComponent list = getTopStatList(topStats, request);
return shareCode -> {
TextComponent.Builder topBuilder = Component.text().append(title);
if (shareCode != null) {
TextComponent.Builder topBuilder = Component.text();
if (shareCode != null) { //if we're adding a share-button
TextComponent newLineTitle = newline().append(title);
topBuilder
.append(newLineTitle)
.append(space())
.append(componentFactory.shareButtonComponent(shareCode));
} else {
topBuilder.append(title);
}
topBuilder.append(list);
return topBuilder.build();
@ -211,18 +215,26 @@ public class MessageWriter {
//TODO add fancy hover-text with sharedResults
public TextComponent messageShared(TextComponent statResults) {
return componentFactory.sharedMessageComponent(null);
//.hoverEvent(HoverEvent.showText(statResults));
return componentFactory.messageSharedComponent()
.hoverEvent(HoverEvent.showText(statResults));
}
public TextComponent addSharedSignature(TextComponent statResults, String playerName) {
return statResults.append(newline())
.append(componentFactory.sharedMessageComponent(playerName));
.append(componentFactory.messageSharedComponent(playerName));
}
public TextComponent addSharedSignature(TextComponent statResults, Component playerName) {
return statResults.append(newline())
.append(componentFactory.messageSharedComponent(playerName));
}
public TextComponent startWithNewLine(TextComponent component) {
return newline().append(component);
}
private TextComponent getTopStatsTitle(StatRequest request, int statListSize) {
return Component.text()
.append(newline())
.append(componentFactory.pluginPrefixComponent()).append(space())
.append(componentFactory.titleComponent(config.getTopStatsTitle(), Target.TOP)).append(space())
.append(componentFactory.titleNumberComponent(statListSize)).append(space())

View File

@ -5,12 +5,15 @@ import com.gmail.artemis.the.gr8.playerstats.ShareManager;
import com.gmail.artemis.the.gr8.playerstats.config.ConfigHandler;
import com.gmail.artemis.the.gr8.playerstats.enums.StandardMessage;
import com.gmail.artemis.the.gr8.playerstats.models.StatRequest;
import com.gmail.artemis.the.gr8.playerstats.msg.msgutils.EasterEggProvider;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.Statistic;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.EnumMap;
@ -76,11 +79,23 @@ public class OutputManager {
}
public void shareStatResults(CommandSender sender, @NotNull TextComponent statResult) {
adventure.players()
.filterAudience(player -> !player.get(Identity.NAME)
.orElse("").equalsIgnoreCase(sender.getName())).sendMessage(
msg.addSharedSignature(statResult, sender.getName()));
adventure.sender(sender).sendMessage(msg.messageShared(statResult));
if (sender instanceof Player player) {
TextComponent totalResult;
Component playerName = EasterEggProvider.getPlayerName(player);
if (playerName == null) {
totalResult = msg.addSharedSignature(statResult, sender.getName());
} else {
totalResult = msg.addSharedSignature(statResult, playerName);
}
totalResult = msg.startWithNewLine(totalResult);
adventure.players()
.filterAudience(onlinePlayer -> !onlinePlayer.get(Identity.NAME)
.orElse("").equalsIgnoreCase(sender.getName())).sendMessage(totalResult);
adventure.sender(sender).sendMessage(msg.messageShared(statResult));
}
}
public void sendPlayerStat(StatRequest request, int playerStat) {

View File

@ -0,0 +1,71 @@
package com.gmail.artemis.the.gr8.playerstats.msg.msgutils;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.entity.Player;
import java.util.Random;
//This class is just for fun, and adds some silly names for players on my server.
//It does not impact the rest of the plugin, and will only be used for the players mentioned in here.
public class EasterEggProvider {
private static final Random random;
static{
random = new Random();
}
public static Component getPlayerName(Player player) {
int sillyNumber = getSillyNumber();
String playerName = null;
switch (player.getUniqueId().toString()) {
case "8fb811dc-2ceb-4528-9951-cf803e0550a1" -> {
if (sillyNumberIsBetween(sillyNumber, 0, 20)) {
playerName = "<bold><#7d330e><#D17300>b</#D17300>e<#D17300>e</#D17300> b<#D17300>o</#D17300>i";
}
}
case "b7d2e46f-cc89-434c-9757-f71a681e168a" -> {
if (sillyNumberIsBetween(sillyNumber, 0, 20)) {
playerName = "<gradient:#7402d1:#e31bc5:#7402d1>purple slime</gradient>";
}
}
case "46dd0c5a-2b51-4ee6-80e8-29deca6dedc1" -> {
if (sillyNumberIsBetween(sillyNumber, 0, 20)) {
playerName = "<gradient:#f74040:#FF6600:#f74040>fire demon</gradient>";
}
else if (sillyNumberIsBetween(sillyNumber, 69, 69)) {
playerName = "<gradient:blue:#b01bd1:blue>best admin</gradient>";
}
}
case "0dc5336b-acd2-4dc3-a5e9-0aa9b8f113f7" -> {
if (sillyNumberIsBetween(sillyNumber, 0, 20)) {
playerName = "<gradient:#f73bdb:#fc8bec:#f73bdb>an UwU sister</gradient>";
}
}
case "10dd9f02-5ec2-4f60-816c-48bb9e2ddf47" -> {
if (sillyNumberIsBetween(sillyNumber, 0, 20)) {
playerName = "<gradient:gold:#fc7f03:-1>gottem</gradient>";
}
}
case "e4c5dfef-bbcc-4012-9f74-879d28fff431" -> {
if (sillyNumberIsBetween(sillyNumber, 69, 69)) {
playerName = "<gradient:blue:#03befc:blue>nice admin</gradient>";
}
}
}
if (playerName == null) {
return null;
} else {
return MiniMessage.miniMessage().deserialize(playerName);
}
}
private static int getSillyNumber() {
return random.nextInt(100);
}
private static boolean sillyNumberIsBetween(int sillyNumber, int lowerBound, int upperBound) {
return sillyNumber >= lowerBound && sillyNumber <= upperBound;
}
}