From 523fd589fb3bd07b85bcd73b916bc986effbec20 Mon Sep 17 00:00:00 2001 From: Artemis-the-gr8 Date: Wed, 22 Jun 2022 14:14:02 +0200 Subject: [PATCH] Removed "unknown" from list of entities (#58), added config options to keep the rainbow formatting and support for disabling translatable text (#56, #57) --- .../artemis/the/gr8/playerstats/Main.java | 15 +------ .../gr8/playerstats/config/ConfigHandler.java | 26 ++++++++--- .../config/ConfigUpdateHandler.java | 2 +- .../playerstats/msg/PrideMessageFactory.java | 27 ++++++++++-- .../gr8/playerstats/utils/EnumHandler.java | 43 +++++++++++++------ src/main/resources/config.yml | 23 ++++++---- 6 files changed, 91 insertions(+), 45 deletions(-) diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/Main.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/Main.java index 2b81d68..94e38b9 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/playerstats/Main.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/Main.java @@ -38,19 +38,8 @@ public class Main extends JavaPlugin { ConfigHandler config = new ConfigHandler(this); LanguageKeyHandler language = new LanguageKeyHandler(); - //then determine if we need a regular MessageFactory or a festive one - MessageFactory messageFactory; - if (config.useFestiveFormatting()) { - if (LocalDate.now().getMonth().equals(Month.JUNE)) { - messageFactory = new PrideMessageFactory(config, language); - } - else { - messageFactory = new MessageFactory(config, language); - } - } - else { - messageFactory = new MessageFactory(config, language); - } + //for now always use the PrideMessageFactory (it'll use the regular formatting when needed) + MessageFactory messageFactory = new PrideMessageFactory(config, language); //initialize the threadManager ThreadManager threadManager = new ThreadManager(adventure(), config, messageFactory, this); diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/config/ConfigHandler.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/config/ConfigHandler.java index 033e839..47f9603 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/playerstats/config/ConfigHandler.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/config/ConfigHandler.java @@ -14,14 +14,14 @@ public class ConfigHandler { private File configFile; private FileConfiguration config; private final Main plugin; - private final int configVersion; + private final double configVersion; public ConfigHandler(Main p) { plugin = p; saveDefaultConfig(); config = YamlConfiguration.loadConfiguration(configFile); - configVersion = 3; + configVersion = 3.1; checkConfigVersion(); } @@ -59,16 +59,28 @@ public class ConfigHandler { return config.getInt("number-of-days-since-last-joined", 0); } + /** Whether to use TranslatableComponents for statistic, block, item and entity names. +

Default: true

*/ + public boolean useTranslatableComponents() { + return config.getBoolean("translate-to-client-language", true); + } + + /** Whether to use HoverComponents in the usage explanation. +

Default: true

*/ + public boolean useHoverText() { + return config.getBoolean("enable-hover-text", true); + } + /** Whether to use festive formatting, such as pride colors.

Default: true

*/ public boolean useFestiveFormatting() { return config.getBoolean("enable-festive-formatting", true); } - /** Whether or not to use HoverComponents in the usage explanation. -

Default: true

*/ - public boolean useHoverText() { - return config.getBoolean("enable-hover-text", true); + /** Whether to use rainbow colors for the [PlayerStats] prefix rather than the default gold/purple. +

Default: false

*/ + public boolean useRainbowPrefix() { + return config.getBoolean("rainbow-mode", false); } /** Returns the config setting for use-dots. @@ -240,7 +252,7 @@ public class ConfigHandler {

PlayerStats 1.2: "config-version" is 2.

PlayerStats 1.3: "config-version" is 3.

*/ private void checkConfigVersion() { - if (!config.contains("config-version") || config.getInt("config-version") != configVersion) { + if (!config.contains("config-version") || config.getDouble("config-version") != configVersion) { new ConfigUpdateHandler(plugin, configFile, configVersion); reloadConfig(); } diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/config/ConfigUpdateHandler.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/config/ConfigUpdateHandler.java index 6a1052e..55db79f 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/playerstats/config/ConfigUpdateHandler.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/config/ConfigUpdateHandler.java @@ -11,7 +11,7 @@ import com.tchristofferson.configupdater.ConfigUpdater; public class ConfigUpdateHandler { /** Add new key-value pairs to the config without losing comments, using tchristofferson's Config-Updater */ - public ConfigUpdateHandler(Main plugin, File configFile, int configVersion) { + public ConfigUpdateHandler(Main plugin, File configFile, double configVersion) { YamlConfiguration configuration = YamlConfiguration.loadConfiguration(configFile); updateTopListDefault(configuration); configuration.set("config-version", configVersion); diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/msg/PrideMessageFactory.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/msg/PrideMessageFactory.java index df6efa9..f417b3c 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/playerstats/msg/PrideMessageFactory.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/msg/PrideMessageFactory.java @@ -6,20 +6,25 @@ import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.minimessage.MiniMessage; import org.bukkit.Bukkit; +import java.time.LocalDate; +import java.time.Month; + import static net.kyori.adventure.text.Component.*; public class PrideMessageFactory extends MessageFactory { + private static ConfigHandler config; public PrideMessageFactory(ConfigHandler c, LanguageKeyHandler l) { super(c, l); + config = c; } @Override protected TextComponent getPrefixAsTitle(boolean isConsoleSender) { - if (isConsoleSender && Bukkit.getName().equalsIgnoreCase("CraftBukkit")) { - return super.getPrefixAsTitle(true); + if (cancelRainbow(isConsoleSender)) { + return super.getPrefixAsTitle(isConsoleSender); } else { String title = "____________ [PlayerStats] ____________"; //12 underscores @@ -31,8 +36,8 @@ public class PrideMessageFactory extends MessageFactory { @Override protected TextComponent pluginPrefix(boolean isConsoleSender) { - if (isConsoleSender && Bukkit.getName().equalsIgnoreCase("CraftBukkit")) { - return super.pluginPrefix(true); + if (cancelRainbow(isConsoleSender)) { + return super.pluginPrefix(isConsoleSender); } return text() .append(MiniMessage.miniMessage() @@ -51,4 +56,18 @@ public class PrideMessageFactory extends MessageFactory { "<#6c15fa>] ")) .build(); } + + /** Don't use rainbow formatting if the rainbow Prefix is disabled, + if festive formatting is disabled or it is not pride month, + or the commandsender is a Bukkit or Spigot console.*/ + private boolean cancelRainbow(boolean isConsoleSender) { + return !(config.useRainbowPrefix() || (config.useFestiveFormatting() && LocalDate.now().getMonth().equals(Month.JUNE))) || + (isConsoleSender && Bukkit.getName().equalsIgnoreCase("CraftBukkit")); + // If a player uses the command after pride month, with rainbow enabled + // not (true OR (true && false)) OR (false && false) + // not (true OR (false)) OR (false) + // not (true) OR (false) not (false) OR (false) + // false OR (false) not (true) true OR false not (false) + // false true + } } diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/utils/EnumHandler.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/utils/EnumHandler.java index d1fd98f..3e66659 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/playerstats/utils/EnumHandler.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/utils/EnumHandler.java @@ -21,19 +21,38 @@ public class EnumHandler { private final static List subStatNames; static{ - blockNames = Arrays.stream(Material.values()).filter( - Material::isBlock).map(Material::toString).map(String::toLowerCase).toList(); - entityNames = Arrays.stream(EntityType.values()).map( - EntityType::toString).map(String::toLowerCase).toList(); - itemNames = Arrays.stream(Material.values()).filter( - Material::isItem).map(Material::toString).map(String::toLowerCase).toList(); - statNames = Arrays.stream(Statistic.values()).map( - Statistic::toString).map(String::toLowerCase).toList(); - entitySubStatNames = Arrays.stream(Statistic.values()).filter(statistic -> - statistic.getType().equals(Statistic.Type.ENTITY)).map( - Statistic::toString).map(String::toLowerCase).collect(Collectors.toList()); + blockNames = Arrays.stream(Material.values()) + .filter(Material::isBlock) + .map(Material::toString) + .map(String::toLowerCase) + .toList(); - subStatNames = Stream.of(blockNames, entityNames, itemNames).flatMap(Collection::stream).toList(); + entityNames = Arrays.stream(EntityType.values()) + .map(EntityType::toString) + .map(String::toLowerCase) + .filter(entityName -> !entityName.equalsIgnoreCase("unknown")) + .toList(); + + itemNames = Arrays.stream(Material.values()) + .filter(Material::isItem) + .map(Material::toString) + .map(String::toLowerCase) + .toList(); + + statNames = Arrays.stream(Statistic.values()) + .map(Statistic::toString) + .map(String::toLowerCase) + .toList(); + + entitySubStatNames = Arrays.stream(Statistic.values()) + .filter(statistic -> statistic.getType().equals(Statistic.Type.ENTITY)) + .map(Statistic::toString) + .map(String::toLowerCase) + .collect(Collectors.toList()); + + subStatNames = Stream.of(blockNames, entityNames, itemNames) + .flatMap(Collection::stream) + .toList(); } private EnumHandler() { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 1a72d01..4a4724d 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,7 +1,7 @@ # ------------------------------------------------------------------------------------------------------ # # PlayerStats Configuration # # ------------------------------------------------------------------------------------------------------ # -config-version: 3 +config-version: 3.1 # # ------------------------------- # # @@ -21,15 +21,22 @@ number-of-days-since-last-joined: 0 # # Format & Display # # # # ------------------------------- # # -# Whether to use special themed formatting for the duration of certain holidays or festivals -# 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 +# Display all statistic, block, item and entity names in the client language of the receiving player +# The actual translation is handled by the Minecraft language files and happens automatically +translate-to-client-language: true -# Use hover-text for additional info in the usage explanation (set "false" to disable) +# Use hover-text for additional info in the usage explanation enable-hover-text: true -# If true, the stat-numbers in the top list will be aligned with dots +# Use special themed formatting for the duration of certain holidays or festivals +# The festive formatting automatically stops when the holiday/event is over +enable-festive-formatting: true + +# Always use rainbow for the [PlayerStats] prefix instead of the default gold/purple +# Changing this from false to true needs a server reboot to take full effect! +rainbow-mode: false + +# Align the stat-numbers in the top list with dots use-dots: true # The maximum number of results displayed in the top list @@ -39,7 +46,7 @@ top-list-max-size: 10 top-list-title: 'Top' # The title in front of a total-on-this-server statistic -# This will become 'Total on this server: [n] animals bred', for example +# This will become 'Total on My Awesome Server: [n] animals bred', for example total-server-stat-title: 'Total on' your-server-name: 'this server'