Release v1.3!

This commit is contained in:
Artemis-the-gr8 2022-06-17 12:40:34 +02:00
parent 5790c697a3
commit b316d6f3a5
9 changed files with 77 additions and 166 deletions

View File

@ -136,18 +136,19 @@ public class StatCommand implements CommandExecutor {
//call this method when isValidStatRequest has returned false to get a relevant error-message
private TextComponent getRelevantFeedback(@NotNull StatRequest request) {
boolean isConsoleSender = request.getCommandSender() instanceof ConsoleCommandSender;
if (request.getStatName() == null) {
return messageFactory.missingStatName();
return messageFactory.missingStatName(isConsoleSender);
}
else if (request.getStatType() != Statistic.Type.UNTYPED && request.getSubStatEntry() == null) {
return messageFactory.missingSubStatName(request.getStatType());
return messageFactory.missingSubStatName(request.getStatType(), isConsoleSender);
}
else if (!EnumHandler.isValidStatEntry(request.getStatType(), request.getSubStatEntry())){
return messageFactory.wrongSubStatType(request.getStatType(), request.getSubStatEntry());
return messageFactory.wrongSubStatType(request.getStatType(), request.getSubStatEntry(), isConsoleSender);
}
else if (request.getSelection() == Query.PLAYER && request.getPlayerName() == null) {
return messageFactory.missingPlayerName();
return messageFactory.missingPlayerName(isConsoleSender);
}
return messageFactory.unknownError();
return messageFactory.unknownError(isConsoleSender);
}
}

View File

@ -65,12 +65,6 @@ public class ConfigHandler {
return config.getBoolean("enable-festive-formatting", true);
}
/** Gets a String representation of an integer (with or without "!" in front of it) that can determine rainbow phase in Adventure.
<p>Default: ""</p>*/
public String getRainbowPhase() {
return config.getString("rainbow-phase", "");
}
/** Whether or not to use HoverComponents in the usage explanation.
<p>Default: true</p>*/
public boolean useHoverText() {
@ -91,9 +85,10 @@ public class ConfigHandler {
/** Returns a String that represents the title for a top statistic.
<p>Default: "Top"</p>*/
public String getTopStatsTitel() {
public String getTopStatsTitle() {
return config.getString("top-list-title", "Top");
}
/** Returns a String that represents the title for a server stat.
<p>Default: "Total on"</p> */
public String getServerTitle() {
@ -247,6 +242,7 @@ public class ConfigHandler {
private void checkConfigVersion() {
if (!config.contains("config-version") || config.getInt("config-version") != configVersion) {
new ConfigUpdateHandler(plugin, configFile, configVersion);
reloadConfig();
}
}
}

View File

@ -13,6 +13,7 @@ public class ConfigUpdateHandler {
/** Add new key-value pairs to the config without losing comments, using <a href="https://github.com/tchristofferson/Config-Updater">tchristofferson's Config-Updater</a> */
public ConfigUpdateHandler(Main plugin, File configFile, int configVersion) {
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(configFile);
updateTopListDefault(configuration);
configuration.set("config-version", configVersion);
try {
configuration.save(configFile);
@ -23,4 +24,11 @@ public class ConfigUpdateHandler {
e.printStackTrace();
}
}
private void updateTopListDefault(YamlConfiguration configuration) {
String oldTitle = configuration.getString("top-list-title");
if (oldTitle != null && oldTitle.equalsIgnoreCase("Top [x]")) {
configuration.set("top-list-title", "Top");
}
}
}

View File

@ -37,7 +37,7 @@ public class MessageFactory {
accentColor2 = TextColor.fromHexString("#FFD52B");
}
protected TextComponent pluginPrefix() {
protected TextComponent pluginPrefix(boolean isConsoleSender) {
return text("[")
.color(NamedTextColor.GRAY)
.append(text("PlayerStats").color(NamedTextColor.GOLD))
@ -45,63 +45,63 @@ public class MessageFactory {
.append(space());
}
public TextComponent reloadedConfig() {
return pluginPrefix()
public TextComponent reloadedConfig(boolean isConsoleSender) {
return pluginPrefix(isConsoleSender)
.append(text("Config reloaded!")
.color(NamedTextColor.GREEN));
}
public TextComponent stillReloading() {
return pluginPrefix()
public TextComponent stillReloading(boolean isConsoleSender) {
return pluginPrefix(isConsoleSender)
.append(text("The plugin is still (re)loading, your request will be processed when it is done!")
.color(msgColor));
}
public TextComponent partiallyReloaded() {
return pluginPrefix()
public TextComponent partiallyReloaded(boolean isConsoleSender) {
return pluginPrefix(isConsoleSender)
.append(text("The reload process was interrupted. If you notice unexpected behavior, please reload PlayerStats again to fix it!")
.color(msgColor));
}
public TextComponent waitAMoment(boolean longWait) {
return longWait ? pluginPrefix()
public TextComponent waitAMoment(boolean longWait, boolean isConsoleSender) {
return longWait ? pluginPrefix(isConsoleSender)
.append(text("Calculating statistics, this may take a minute...")
.color(msgColor))
: pluginPrefix()
: pluginPrefix(isConsoleSender)
.append(text("Calculating statistics, this may take a few moments...")
.color(msgColor));
}
public TextComponent formatExceptions(@NotNull String exception) {
return pluginPrefix()
public TextComponent formatExceptions(@NotNull String exception, boolean isConsoleSender) {
return pluginPrefix(isConsoleSender)
.append(text(exception)
.color(msgColor));
}
public TextComponent missingStatName() {
return pluginPrefix()
public TextComponent missingStatName(boolean isConsoleSender) {
return pluginPrefix(isConsoleSender)
.append(text("Please provide a valid statistic name!")
.color(msgColor));
}
public TextComponent missingSubStatName(Statistic.Type statType) {
public TextComponent missingSubStatName(Statistic.Type statType, boolean isConsoleSender) {
String subStat = getSubStatTypeName(statType) == null ? "sub-statistic" : getSubStatTypeName(statType);
return pluginPrefix()
return pluginPrefix(isConsoleSender)
.append(text("Please add a valid ")
.append(text(subStat))
.append(text(" to look up this statistic!"))
.color(msgColor));
}
public TextComponent missingPlayerName() {
return pluginPrefix()
public TextComponent missingPlayerName(boolean isConsoleSender) {
return pluginPrefix(isConsoleSender)
.append(text("Please specify a valid player-name!")
.color(msgColor));
}
public TextComponent wrongSubStatType(Statistic.Type statType, String subStatEntry) {
public TextComponent wrongSubStatType(Statistic.Type statType, String subStatEntry, boolean isConsoleSender) {
String subStat = getSubStatTypeName(statType) == null ? "sub-statistic for this statistic" : getSubStatTypeName(statType);
return pluginPrefix()
return pluginPrefix(isConsoleSender)
.append(text("\"")
.append(text(subStatEntry))
.append(text("\""))
@ -111,8 +111,8 @@ public class MessageFactory {
.color(msgColor));
}
public TextComponent unknownError() {
return pluginPrefix()
public TextComponent unknownError(boolean isConsoleSender) {
return pluginPrefix(isConsoleSender)
.append(text("Something went wrong with your request, please try again or see /statistic for a usage explanation!")
.color(msgColor));
}
@ -192,7 +192,7 @@ public class MessageFactory {
dots = (int) Math.round((130.0 - font.getWidth(count + ". ") - (font.getWidth(playerName) * 1.19))/2);
}
if (dots >= 1) {
topList.append(dotsComponent(".".repeat(dots), isConsoleSender));
topList.append(dotsComponent(".".repeat(dots)));
}
}
else {
@ -228,15 +228,15 @@ public class MessageFactory {
return text(underscores).color(underscoreColor)
.append(text(" ")) //4 spaces
.append(pluginPrefix())
.append(pluginPrefix(isConsoleSender))
.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, config.getTopStatsTitel())).append(space())
.append(pluginPrefix(isConsoleSender))
.append(titleComponent(Query.TOP, config.getTopStatsTitle())).append(space())
.append(titleNumberComponent(topLength)).append(space())
.append(statNameComponent(Query.TOP, statName)).append(space())
.append(subStatNameComponent(Query.TOP, subStatEntryName));
@ -298,7 +298,7 @@ public class MessageFactory {
getStyleFromString(config.getRankNumberFormatting(true)));
}
protected TextComponent dotsComponent(String dots, boolean isConsoleSender) {
protected TextComponent dotsComponent(String dots) {
return getComponent(dots,
getColorFromString(config.getDotsFormatting(false)),
getStyleFromString(config.getDotsFormatting(true)));

View File

@ -2,24 +2,18 @@ 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.*;
public class PrideMessageFactory extends MessageFactory {
private static ConfigHandler config;
private final String prefixTitle = "____________ [PlayerStats] ____________"; //12 underscores
public PrideMessageFactory(ConfigHandler c) {
super(c);
config = c;
}
@Override
@ -28,7 +22,7 @@ public class PrideMessageFactory extends MessageFactory {
return super.getPrefixAsTitle(true);
}
else {
String title = "<rainbow:16>" + prefixTitle + "</rainbow>";
String title = "<rainbow:16>____________ [PlayerStats] ____________</rainbow>"; //12 underscores
return text()
.append(MiniMessage.miniMessage().deserialize(title))
.build();
@ -36,116 +30,25 @@ public class PrideMessageFactory extends MessageFactory {
}
@Override
protected TextComponent pluginPrefix() {
return text().append(MiniMessage.miniMessage().deserialize("<#fc3661>[</#fc3661>" +
"<#fe4550>P</#fe4550>" +
"<#fe5640>l</#fe5640>" +
"<#fb6731>a</#fb6731>" +
"<#f67824>y</#f67824>" +
"<#ee8a19>e</#ee8a19>" +
"<#e49b0f>r</#e49b0f>" +
"<#d9ac08>S</#d9ac08>" +
"<#cbbd03>t</#cbbd03>" +
"<#bccb01>a</#bccb01>" +
"<#acd901>t</#acd901>" +
"<#9be503>s</#9be503>" +
"<#8aee08>] </#8aee08>")).build();
// <#fe4550></#fe4550><#fe5640>P</#fe5640><#fb6731>l</#fb6731><#f67824>a</#f67824><#ee8a19>y</#ee8a19><#e49b0f>e</#e49b0f><#FFB80E></#FFB80E><#cbbd03>S</#cbbd03><#bccb01>t</#bccb01><#acd901></#acd901><#9be503></#9be503><#8BD448>s</#8BD448><#2AA8F2>]</#2AA8F2>]]
// <#205bf3>_</#205bf3>
// <#2d4afa>_</#2d4afa>
// <#3b3bfd>_</#3b3bfd>
// <#4a2dfe>_</#4a2dfe>
// <#5b20fd>_</#5b20fd>
// <#6c15fa>_</#6c15fa>
// <#7e0df4>_</#7e0df4>
// <#9006eb>_</#9006eb>
// <#a102e1>_</#a102e1>
// <#b201d5>_</#b201d5>
// <#c201c7>_</#c201c7>
// <#d005b7>_</#d005b7>
// <#dd0aa7> </#dd0aa7>
// <#e81296> </#e81296>
// <#f11c84> </#f11c84>
// <#f82872> </#f82872>
// <#fc3661>[</#fc3661>
// <#fe4550>P</#fe4550>
// <#fe5640>l</#fe5640>
// <#fb6731>a</#fb6731>
// <#f67824>y</#f67824>
// <#ee8a19>e</#ee8a19>
// <#e49b0f>r</#e49b0f>
// <#d9ac08>S</#d9ac08>
// <#cbbd03>t</#cbbd03>
// <#bccb01>a</#bccb01>
// <#acd901>t</#acd901>
// <#9be503>s</#9be503>
// <#8aee08>]</#8aee08>
// <#78f60f> </#78f60f>
// <#67fb19> </#67fb19>
// <#55fe24> </#55fe24>
// <#45fe31> </#45fe31>
// <#36fc40>_</#36fc40>
// <#28f850>_</#28f850>
// <#1cf161>_</#1cf161>
// <#12e872>_</#12e872>
// <#0add84>_</#0add84>
// <#05d095>_</#05d095>
// <#01c1a7>_</#01c1a7>
// <#01b2b7>_</#01b2b7>
// <#02a1c6>_</#02a1c6>
// <#0690d4>_</#0690d4>
// <#0d7ee1>_</#0d7ee1>
// <#156ceb>_</#156ceb>
}
/*
@Override
protected TextComponent getTopStatTitle(int topLength, String statName, String subStatEntryName, boolean isConsoleSender) {
protected TextComponent pluginPrefix(boolean isConsoleSender) {
if (isConsoleSender && Bukkit.getName().equalsIgnoreCase("CraftBukkit")) {
return super.getTopStatTitle(topLength, statName, subStatEntryName, true);
}
else {
MinecraftFont font = new MinecraftFont();
TextComponent statTitle = Component.text()
.append(titleComponent(Query.TOP, config.getTopStatsTitel())).append(space())
.append(titleNumberComponent(topLength)).append(space())
.append(statNameComponent(Query.TOP, statName)).append(space())
.append(subStatNameComponent(Query.TOP, subStatEntryName))
.build();
String title = config.getTopStatsTitel() + " " + topLength + " " + statName + " " + subStatEntryName;
if (font.getWidth(prefixTitle) > font.getWidth(title)) {
//divide by 4 to get spaces, then by 2 to get distance needed at the front
int spaces = (int) Math.round((double) (font.getWidth(prefixTitle) - font.getWidth(title))/8);
Bukkit.getLogger().info("Width of prefixTitle: " + font.getWidth(prefixTitle));
Bukkit.getLogger().info("Width of statTitle: " + font.getWidth(title));
Bukkit.getLogger().info("Spaces: " + spaces);
String space = " ".repeat(spaces);
return Component.newline()
.append(getPrefixAsTitle(false))
.append(newline())
.append(text(space))
.append(statTitle);
}
else {
return Component.newline()
.append(getPrefixAsTitle(false))
.append(newline())
.append(statTitle);
}
}
}
*/
@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();
return super.pluginPrefix(true);
}
return text()
.append(MiniMessage.miniMessage()
.deserialize("<#fe3e3e>[</#fe3e3e>" +
"<#fe5640>P</#fe5640>" +
"<#f67824>l</#f67824>" +
"<#ee8a19>a</#ee8a19>" +
"<#e49b0f>y</#e49b0f>" +
"<#cbbd03>e</#cbbd03>" +
"<#bccb01>r</#bccb01>" +
"<#8aee08>S</#8aee08>" +
"<#45fe31>t</#45fe31>" +
"<#01c1a7>a</#01c1a7>" +
"<#0690d4>t</#0690d4>" +
"<#205bf3>s</#205bf3>" +
"<#6c15fa>] </#6c15fa>"))
.build();
}
}

View File

@ -10,6 +10,7 @@ import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.jetbrains.annotations.Nullable;
import java.util.ConcurrentModificationException;
@ -66,13 +67,13 @@ public class ReloadThread extends Thread {
catch (ConcurrentModificationException e) {
plugin.getLogger().warning("The request could not be fully executed due to a ConcurrentModificationException");
if (sender != null) {
adventure.sender(sender).sendMessage(messageFactory.partiallyReloaded());
adventure.sender(sender).sendMessage(messageFactory.partiallyReloaded(sender instanceof ConsoleCommandSender));
}
}
plugin.logTimeTaken("ReloadThread", ("loaded " + OfflinePlayerHandler.getOfflinePlayerCount() + " offline players"), time);
if (sender != null) {
adventure.sender(sender).sendMessage(messageFactory.reloadedConfig());
adventure.sender(sender).sendMessage(messageFactory.reloadedConfig(sender instanceof ConsoleCommandSender));
}
}
}

View File

@ -55,7 +55,7 @@ public class StatThread extends Thread {
if (reloadThread != null && reloadThread.isAlive()) {
try {
plugin.getLogger().info("Waiting for reloadThread to finish up...");
adventure.sender(request.getCommandSender()).sendMessage(messageFactory.stillReloading());
adventure.sender(request.getCommandSender()).sendMessage(messageFactory.stillReloading(request.getCommandSender() instanceof ConsoleCommandSender));
reloadThread.join();
} catch (InterruptedException e) {
plugin.getLogger().warning(e.toString());
@ -64,6 +64,7 @@ public class StatThread extends Thread {
}
CommandSender sender = request.getCommandSender();
boolean isConsoleSencer = sender instanceof ConsoleCommandSender;
String playerName = request.getPlayerName();
String statName = request.getStatName();
String subStatEntry = request.getSubStatEntry();
@ -71,10 +72,10 @@ public class StatThread extends Thread {
if (selection == Query.TOP || selection == Query.SERVER) {
if (ThreadManager.getLastRecordedCalcTime() > 20000) {
adventure.sender(sender).sendMessage(messageFactory.waitAMoment(true));
adventure.sender(sender).sendMessage(messageFactory.waitAMoment(true, isConsoleSencer));
}
else if (ThreadManager.getLastRecordedCalcTime() > 2000) {
adventure.sender(sender).sendMessage(messageFactory.waitAMoment(false));
adventure.sender(sender).sendMessage(messageFactory.waitAMoment(false, isConsoleSencer));
}
try {
@ -88,9 +89,11 @@ public class StatThread extends Thread {
}
} catch (ConcurrentModificationException e) {
adventure.sender(sender).sendMessage(messageFactory.unknownError());
if (!isConsoleSencer) {
adventure.sender(sender).sendMessage(messageFactory.unknownError(false));
}
} catch (Exception e) {
adventure.sender(sender).sendMessage(messageFactory.formatExceptions(e.toString()));
adventure.sender(sender).sendMessage(messageFactory.formatExceptions(e.toString(), isConsoleSencer));
}
}
@ -101,7 +104,7 @@ public class StatThread extends Thread {
playerName, statName, subStatEntry, getIndividualStat()));
} catch (UnsupportedOperationException | NullPointerException e) {
adventure.sender(sender).sendMessage(messageFactory.formatExceptions(e.toString()));
adventure.sender(sender).sendMessage(messageFactory.formatExceptions(e.toString(), isConsoleSencer));
}
}
}
@ -132,7 +135,7 @@ public class StatThread extends Thread {
commonPool.invoke(task);
} catch (ConcurrentModificationException e) {
plugin.getLogger().warning("The request could not be executed due to a ConcurrentModificationException. " +
"This likely happened because Bukkit hasn't fully initialized all players yet. Try again and it should be fine!");
"This likely happened because Bukkit hasn't fully initialized all player-data yet. Try again and it should be fine!");
throw new ConcurrentModificationException(e.toString());
}

View File

@ -25,7 +25,6 @@ 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: 5
# Use hover-text for additional info in the usage explanation (set "false" to disable)
enable-hover-text: true

View File

@ -1,7 +1,7 @@
main: com.gmail.artemis.the.gr8.playerstats.Main
name: PlayerStats
version: 1.3
api-version: 1.13
api-version: 1.18
description: adds commands to view player statistics in chat
author: Artemis_the_gr8
commands: