mirror of
https://github.com/itHotL/PlayerStats.git
synced 2024-11-29 13:05:32 +01:00
Started implementing more subtle rainbow decorations
This commit is contained in:
parent
022fb7a519
commit
fc57f33e17
@ -71,5 +71,6 @@
|
||||
<properties>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
</project>
|
||||
|
1
pom.xml
1
pom.xml
@ -9,6 +9,7 @@
|
||||
<version>1.3</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
</properties>
|
||||
|
@ -128,17 +128,16 @@ public class MessageFactory {
|
||||
|
||||
public TextComponent usageExamples(boolean isConsoleSender) {
|
||||
TextComponent spaces = text(" "); //4 spaces
|
||||
TextComponent underscores = text("_____________").color(TextColor.fromHexString("#6E3485"));
|
||||
TextComponent arrow = text("→ ").color(NamedTextColor.GOLD);
|
||||
TextColor accentColor = TextColor.fromHexString("#FFE339");
|
||||
|
||||
if (isConsoleSender) {
|
||||
if (isConsoleSender && Bukkit.getName().equalsIgnoreCase("CraftBukkit")) {
|
||||
arrow = text("-> ").color(NamedTextColor.GOLD);
|
||||
accentColor = NamedTextColor.YELLOW;
|
||||
}
|
||||
|
||||
return Component.newline()
|
||||
.append(underscores).append(spaces).append(pluginPrefix()).append(spaces).append(underscores)
|
||||
.append(getPrefixAsTitle(isConsoleSender))
|
||||
.append(newline())
|
||||
.append(text("Examples: ").color(NamedTextColor.GOLD))
|
||||
.append(newline())
|
||||
@ -166,14 +165,9 @@ public class MessageFactory {
|
||||
return singleStat.build();
|
||||
}
|
||||
|
||||
public TextComponent formatTopStats(LinkedHashMap<String, Integer> topStats, String statName, String subStatEntryName) {
|
||||
public TextComponent formatTopStats(@NotNull LinkedHashMap<String, Integer> topStats, String statName, String subStatEntryName, boolean isConsoleSender) {
|
||||
TextComponent.Builder topList = Component.text();
|
||||
|
||||
topList.append(newline()).append(pluginPrefix())
|
||||
.append(titleComponent(Query.TOP, "Top")).append(space())
|
||||
.append(titleNumberComponent(topStats.size())).append(space())
|
||||
.append(statNameComponent(Query.TOP, statName)).append(space())
|
||||
.append(subStatNameComponent(Query.TOP, subStatEntryName));
|
||||
topList.append(getTopStatTitle(topStats.size(), statName, subStatEntryName, isConsoleSender));
|
||||
|
||||
boolean useDots = config.useDots();
|
||||
Set<String> playerNames = topStats.keySet();
|
||||
@ -191,11 +185,14 @@ public class MessageFactory {
|
||||
topList.append(space());
|
||||
|
||||
int dots = (int) Math.round((130.0 - font.getWidth(count + ". " + playerName))/2);
|
||||
if (config.playerNameIsBold()) {
|
||||
if (isConsoleSender) {
|
||||
dots = (int) Math.round((130.0 - font.getWidth(count + ". " + playerName))/6) + 7;
|
||||
}
|
||||
else if (config.playerNameIsBold()) {
|
||||
dots = (int) Math.round((130.0 - font.getWidth(count + ". ") - (font.getWidth(playerName) * 1.19))/2);
|
||||
}
|
||||
if (dots >= 1) {
|
||||
topList.append(dotsComponent(".".repeat(dots)));
|
||||
topList.append(dotsComponent(".".repeat(dots), isConsoleSender));
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -221,22 +218,28 @@ public class MessageFactory {
|
||||
return serverStat.build();
|
||||
}
|
||||
|
||||
//returns the type of the substatistic in String-format, or null if this statistic is not of type block, item or entity
|
||||
private String getSubStatTypeName(Statistic.Type statType) {
|
||||
String subStat;
|
||||
if (statType == Statistic.Type.BLOCK) {
|
||||
subStat = "block";
|
||||
protected TextComponent getPrefixAsTitle(boolean isConsoleSender) {
|
||||
String underscores = "____________"; //12 underscores for both console and in-game
|
||||
TextColor underscoreColor = TextColor.fromHexString("#6E3485"); //a dark shade of purple
|
||||
|
||||
if (isConsoleSender && Bukkit.getName().equalsIgnoreCase("CraftBukkit")) {
|
||||
underscoreColor = NamedTextColor.DARK_PURPLE;
|
||||
}
|
||||
else if (statType == Statistic.Type.ITEM) {
|
||||
subStat = "item";
|
||||
}
|
||||
else if (statType == Statistic.Type.ENTITY) {
|
||||
subStat = "entity";
|
||||
}
|
||||
else {
|
||||
subStat = null;
|
||||
}
|
||||
return subStat;
|
||||
|
||||
return text(underscores).color(underscoreColor)
|
||||
.append(text(" ")) //4 spaces
|
||||
.append(pluginPrefix())
|
||||
.append(text(" ")) //3 spaces (since prefix already has one)
|
||||
.append(text(underscores));
|
||||
}
|
||||
|
||||
protected TextComponent getTopStatTitle(int topLength, String statName, String subStatEntryName, boolean isConsoleSender) {
|
||||
return Component.newline()
|
||||
.append(pluginPrefix())
|
||||
.append(titleComponent(Query.TOP, "Top")).append(space())
|
||||
.append(titleNumberComponent(topLength)).append(space())
|
||||
.append(statNameComponent(Query.TOP, statName)).append(space())
|
||||
.append(subStatNameComponent(Query.TOP, subStatEntryName));
|
||||
}
|
||||
|
||||
protected TextComponent playerNameComponent(Query selection, String playerName) {
|
||||
@ -245,7 +248,7 @@ public class MessageFactory {
|
||||
getStyleFromString(config.getPlayerNameFormatting(selection, true)));
|
||||
}
|
||||
|
||||
protected TextComponent statNameComponent(Query selection, String statName) {
|
||||
protected TextComponent statNameComponent(Query selection, @NotNull String statName) {
|
||||
return getComponent(statName.toLowerCase().replace("_", " "),
|
||||
getColorFromString(config.getStatNameFormatting(selection, false)),
|
||||
getStyleFromString(config.getStatNameFormatting(selection, true)));
|
||||
@ -295,7 +298,7 @@ public class MessageFactory {
|
||||
getStyleFromString(config.getRankNumberFormatting(true)));
|
||||
}
|
||||
|
||||
protected TextComponent dotsComponent(String dots) {
|
||||
protected TextComponent dotsComponent(String dots, boolean isConsoleSender) {
|
||||
return getComponent(dots,
|
||||
getColorFromString(config.getDotsFormatting(false)),
|
||||
getStyleFromString(config.getDotsFormatting(true)));
|
||||
@ -327,7 +330,7 @@ public class MessageFactory {
|
||||
return names.value(textColor);
|
||||
}
|
||||
|
||||
private @Nullable TextDecoration getStyleFromString(String configString) {
|
||||
private @Nullable TextDecoration getStyleFromString(@NotNull String configString) {
|
||||
if (configString.equalsIgnoreCase("none")) {
|
||||
return null;
|
||||
}
|
||||
@ -340,23 +343,32 @@ public class MessageFactory {
|
||||
}
|
||||
}
|
||||
|
||||
protected TextComponent getHelpMsgTitle(boolean isConsoleSender) {
|
||||
String underscores = isConsoleSender ? "___________" : "____________"; //11 underscores for console, 12 for in-game chat
|
||||
return text(underscores).color(TextColor.fromHexString("#6E3485")) //a dark shade of purple
|
||||
.append(text(" ")) //4 spaces
|
||||
.append(pluginPrefix())
|
||||
.append(text(" ")) //3 spaces (since prefix already has one)
|
||||
.append(text(underscores));
|
||||
//returns the type of the substatistic in String-format, or null if this statistic is not of type block, item or entity
|
||||
private String getSubStatTypeName(Statistic.Type statType) {
|
||||
String subStat;
|
||||
if (statType == Statistic.Type.BLOCK) {
|
||||
subStat = "block";
|
||||
}
|
||||
else if (statType == Statistic.Type.ITEM) {
|
||||
subStat = "item";
|
||||
}
|
||||
else if (statType == Statistic.Type.ENTITY) {
|
||||
subStat = "entity";
|
||||
}
|
||||
else {
|
||||
subStat = null;
|
||||
}
|
||||
return subStat;
|
||||
}
|
||||
|
||||
//returns the usage-explanation with hovering text
|
||||
private TextComponent helpMsgHover() {
|
||||
private @NotNull TextComponent helpMsgHover() {
|
||||
TextComponent spaces = text(" "); //4 spaces
|
||||
TextComponent arrow = text("→ ").color(NamedTextColor.GOLD); //alt + 26
|
||||
TextColor arguments = NamedTextColor.YELLOW;
|
||||
|
||||
return Component.newline()
|
||||
.append(getHelpMsgTitle(false))
|
||||
.append(getPrefixAsTitle(false))
|
||||
.append(newline())
|
||||
.append(text("Hover over the arguments for more information!").color(NamedTextColor.GRAY).decorate(TextDecoration.ITALIC))
|
||||
.append(newline())
|
||||
@ -409,21 +421,21 @@ public class MessageFactory {
|
||||
|
||||
//returns the usage-explanation without any hovering text
|
||||
//if BukkitVersion is CraftBukkit, this doesn't use unicode symbols or hex colors
|
||||
private TextComponent helpMsgPlain(boolean isConsoleSender) {
|
||||
private @NotNull TextComponent helpMsgPlain(boolean isConsoleSender) {
|
||||
TextComponent spaces = text(" "); //4 spaces
|
||||
TextComponent arrow = text("→ ").color(NamedTextColor.GOLD); //alt + 26;
|
||||
TextComponent bullet = text("• ").color(NamedTextColor.GOLD); //alt + 7
|
||||
TextColor arguments = NamedTextColor.YELLOW;
|
||||
TextColor accentColor = accentColor2;
|
||||
|
||||
if (isConsoleSender && Bukkit.getVersion().equalsIgnoreCase("CraftBukkit")) {
|
||||
if (isConsoleSender && Bukkit.getName().equalsIgnoreCase("CraftBukkit")) {
|
||||
arrow = text("-> ").color(NamedTextColor.GOLD);
|
||||
bullet = text("* ").color(NamedTextColor.GOLD);
|
||||
accentColor = NamedTextColor.GOLD;
|
||||
}
|
||||
|
||||
return Component.newline()
|
||||
.append(getHelpMsgTitle(isConsoleSender))
|
||||
.append(getPrefixAsTitle(isConsoleSender))
|
||||
.append(newline())
|
||||
.append(text("Type \"/statistic examples\" to see examples!").color(NamedTextColor.GRAY).decorate(TextDecoration.ITALIC))
|
||||
.append(newline())
|
||||
|
@ -2,8 +2,12 @@ package com.gmail.artemis.the.gr8.playerstats.msg;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.config.ConfigHandler;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.Query;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.map.MinecraftFont;
|
||||
|
||||
import static net.kyori.adventure.text.Component.*;
|
||||
|
||||
@ -18,13 +22,56 @@ public class PrideMessageFactory extends MessageFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TextComponent getHelpMsgTitle(boolean isConsoleSender) {
|
||||
return text().append(MiniMessage.miniMessage().deserialize("<rainbow:16>____________ [PlayerStats] ____________</rainbow>")).build();
|
||||
protected TextComponent getPrefixAsTitle(boolean isConsoleSender) {
|
||||
if (isConsoleSender && Bukkit.getName().equalsIgnoreCase("CraftBukkit")) {
|
||||
return super.getPrefixAsTitle(true);
|
||||
}
|
||||
else {
|
||||
String underscores = "____________"; //12 underscores
|
||||
String title = "<rainbow:16>" + underscores + " [PlayerStats] " + underscores + "</rainbow>";
|
||||
return text()
|
||||
.append(MiniMessage.miniMessage().deserialize(title))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TextComponent dotsComponent(String dots) {
|
||||
String tag = "<rainbow:" + config.getRainbowPhase() + ">";
|
||||
return text().append(MiniMessage.miniMessage().deserialize((tag + dots))).build();
|
||||
protected TextComponent getTopStatTitle(int topLength, String statName, String subStatEntryName, boolean isConsoleSender) {
|
||||
if (isConsoleSender && Bukkit.getName().equalsIgnoreCase("CraftBukkit")) {
|
||||
return super.getTopStatTitle(topLength, statName, subStatEntryName, true);
|
||||
}
|
||||
else {
|
||||
MinecraftFont font = new MinecraftFont();
|
||||
TextComponent prefixTitle = getPrefixAsTitle(false);
|
||||
TextComponent statTitle = Component.text()
|
||||
.append(titleComponent(Query.TOP, "Top")).append(space())
|
||||
.append(titleNumberComponent(topLength)).append(space())
|
||||
.append(statNameComponent(Query.TOP, statName)).append(space())
|
||||
.append(subStatNameComponent(Query.TOP, subStatEntryName))
|
||||
.build();
|
||||
|
||||
if (font.getWidth(prefixTitle.content()) > font.getWidth(statTitle.content())) {
|
||||
|
||||
}
|
||||
|
||||
return Component.newline()
|
||||
.append(getPrefixAsTitle(false))
|
||||
.append(newline())
|
||||
.append(titleComponent(Query.TOP, "Top")).append(space())
|
||||
.append(titleNumberComponent(topLength)).append(space())
|
||||
.append(statNameComponent(Query.TOP, statName)).append(space())
|
||||
.append(subStatNameComponent(Query.TOP, subStatEntryName));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TextComponent dotsComponent(String dots, boolean isConsoleSender) {
|
||||
if (isConsoleSender && Bukkit.getName().equalsIgnoreCase("CraftBukkit")) {
|
||||
return super.dotsComponent(dots, true);
|
||||
}
|
||||
else {
|
||||
String tag = "<rainbow:" + config.getRainbowPhase() + ">";
|
||||
return text().append(MiniMessage.miniMessage().deserialize((tag + dots))).build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import com.google.common.collect.ImmutableList;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -79,7 +80,7 @@ public class StatThread extends Thread {
|
||||
try {
|
||||
if (selection == Query.TOP) {
|
||||
adventure.sender(sender).sendMessage(messageFactory.formatTopStats(
|
||||
getTopStats(), statName, subStatEntry));
|
||||
getTopStats(), statName, subStatEntry, sender instanceof ConsoleCommandSender));
|
||||
}
|
||||
else {
|
||||
adventure.sender(sender).sendMessage(messageFactory.formatServerStat(
|
||||
|
@ -25,7 +25,7 @@ number-of-days-since-last-joined: 0
|
||||
# The festive formatting automatically stops when the holiday/event is over
|
||||
# Changing this setting requires a server restart to take effect!
|
||||
enable-festive-formatting: true
|
||||
rainbow-phase:
|
||||
rainbow-phase: 5
|
||||
|
||||
# Use hover-text for additional info in the usage explanation (set "false" to disable)
|
||||
enable-hover-text: true
|
||||
@ -36,11 +36,11 @@ use-dots: true
|
||||
# The maximum number of results displayed in the top list
|
||||
top-list-max-size: 10
|
||||
|
||||
# The title above the top list (the x is translated to the list-max-size, by default 10)
|
||||
# The title above the top list (this will become 'Top 10 animals bred', for example)
|
||||
top-list-title: 'Top [x]'
|
||||
|
||||
# The text you want displayed for a total-on-this-server statistic
|
||||
# This will be put on the same line ('Total on this server: [x] animals bred', for example)
|
||||
# The title in front of a total-on-this-server statistic
|
||||
# This will become 'Total on this server: [n] animals bred', for example
|
||||
total-server-stat-title: 'Total on'
|
||||
your-server-name: 'this server'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user