From 260fad2d4a358f0b358faccf5533e67da38baa97 Mon Sep 17 00:00:00 2001 From: Artemis-the-gr8 Date: Fri, 28 Oct 2022 12:00:26 +0200 Subject: [PATCH] Made sharerName have a random rainbow gradient in rainbow mode --- .../msg/components/PrideComponentFactory.java | 55 +++++++++++-------- .../msg/msgutils/EasterEggProvider.java | 27 --------- 2 files changed, 33 insertions(+), 49 deletions(-) diff --git a/src/main/java/com/artemis/the/gr8/playerstats/msg/components/PrideComponentFactory.java b/src/main/java/com/artemis/the/gr8/playerstats/msg/components/PrideComponentFactory.java index af965af..2f51434 100644 --- a/src/main/java/com/artemis/the/gr8/playerstats/msg/components/PrideComponentFactory.java +++ b/src/main/java/com/artemis/the/gr8/playerstats/msg/components/PrideComponentFactory.java @@ -2,7 +2,6 @@ package com.artemis.the.gr8.playerstats.msg.components; import com.artemis.the.gr8.playerstats.config.ConfigHandler; -import com.artemis.the.gr8.playerstats.msg.msgutils.EasterEggProvider; import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.minimessage.MiniMessage; import org.jetbrains.annotations.Contract; @@ -17,45 +16,39 @@ import static net.kyori.adventure.text.Component.*; */ public class PrideComponentFactory extends ComponentFactory { + private final Random random; + public PrideComponentFactory(ConfigHandler config) { super(config); + random = new Random(); } @Override public TextComponent getExampleName() { - return text() - .append(EasterEggProvider.getFestiveName("Artemis_the_gr8")) - .build(); + return deserialize("Artemis_the_gr8"); } @Override public TextComponent sharerName(String sharerName) { - return text() - .append(EasterEggProvider.getFestiveName(sharerName)) - .build(); + return deserialize(decorateWithRandomGradient(sharerName)); } @Override + //12 underscores public TextComponent pluginPrefixAsTitle() { - String title = "____________ [PlayerStats] ____________"; //12 underscores - return text() - .append(MiniMessage.miniMessage().deserialize(title)) - .build(); + return deserialize("____________ [PlayerStats] ____________"); } @Override public TextComponent pluginPrefix() { - Random randomizer = new Random(); - if (randomizer.nextBoolean()) { + if (random.nextBoolean()) { return backwardsPluginPrefixComponent(); } return rainbowPrefix(); } public TextComponent rainbowPrefix() { - return text() - .append(MiniMessage.miniMessage() - .deserialize("<#f74040>[" + + return deserialize("<#f74040>[" + "<#F54D39>P" + "<#F16E28>l" + "<#ee8a19>a" + @@ -67,15 +60,12 @@ public class PrideComponentFactory extends ComponentFactory { "<#01c1a7>a" + "<#1F8BEB>t" + "<#3341E6>s" + - "<#631ae6>]")) - .build(); + "<#631ae6>]"); } @Contract(" -> new") private @NotNull TextComponent backwardsPluginPrefixComponent() { - return text() - .append(MiniMessage.miniMessage() - .deserialize("<#631ae6>[" + + return deserialize("<#631ae6>[" + "<#3341E6>P" + "<#1F8BEB>l" + "<#01c1a7>a" + @@ -87,7 +77,28 @@ public class PrideComponentFactory extends ComponentFactory { "<#ee8a19>a" + "<#f67824>t" + "<#f76540>s" + - "<#f74040>]")) + "<#f74040>]"); + } + + private @NotNull String decorateWithRandomGradient(@NotNull String input) { + String colorString = switch (random.nextInt(9)) { + case 0 -> ""; + case 1 -> ""; + case 2 -> ""; + case 3 -> ""; + case 4 -> ""; + case 5 -> ""; + case 6 -> ""; + case 7 -> ""; + default -> ""; + }; + return colorString + input + ""; + } + + @Contract("_ -> new") + private @NotNull TextComponent deserialize(String input) { + return text() + .append(MiniMessage.miniMessage().deserialize(input)) .build(); } } \ No newline at end of file diff --git a/src/main/java/com/artemis/the/gr8/playerstats/msg/msgutils/EasterEggProvider.java b/src/main/java/com/artemis/the/gr8/playerstats/msg/msgutils/EasterEggProvider.java index e52de7e..c908020 100644 --- a/src/main/java/com/artemis/the/gr8/playerstats/msg/msgutils/EasterEggProvider.java +++ b/src/main/java/com/artemis/the/gr8/playerstats/msg/msgutils/EasterEggProvider.java @@ -27,10 +27,6 @@ public final class EasterEggProvider { random = new Random(); } - public static @NotNull Component getFestiveName(String playerName) { - return MiniMessage.miniMessage().deserialize(decorateWithRandomGradient(playerName)); - } - public static @Nullable Component getPlayerName(@NotNull Player player) { int sillyNumber = getSillyNumber(); String playerName = null; @@ -102,29 +98,6 @@ public final class EasterEggProvider { } } - private static @NotNull String decorateWithRandomGradient(String input) { - String colorString = switch (random.nextInt(9)) { - case 0 -> { - if (input.equalsIgnoreCase("Artemis_the_gr8")) { - yield ""; - } - else { - yield ""; - } - } - case 1 -> ""; - case 2 -> ""; - case 3 -> ""; - case 4 -> ""; - case 5 -> ""; - case 6 -> ""; - case 7 -> ""; - case 8 -> ""; - default -> ""; - }; - return colorString + input + ""; - } - private static int getSillyNumber() { return random.nextInt(100); }