mirror of
https://github.com/itHotL/PlayerStats.git
synced 2025-01-08 19:37:58 +01:00
Removed "unknown" from list of entities (#58), added config options to keep the rainbow formatting and support for disabling translatable text (#56, #57)
This commit is contained in:
parent
c70bbce0f8
commit
523fd589fb
@ -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);
|
||||
|
@ -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.
|
||||
<p>Default: true</p>*/
|
||||
public boolean useTranslatableComponents() {
|
||||
return config.getBoolean("translate-to-client-language", true);
|
||||
}
|
||||
|
||||
/** Whether to use HoverComponents in the usage explanation.
|
||||
<p>Default: true</p>*/
|
||||
public boolean useHoverText() {
|
||||
return config.getBoolean("enable-hover-text", true);
|
||||
}
|
||||
|
||||
/** Whether to use festive formatting, such as pride colors.
|
||||
<p>Default: true</p> */
|
||||
public boolean useFestiveFormatting() {
|
||||
return config.getBoolean("enable-festive-formatting", true);
|
||||
}
|
||||
|
||||
/** Whether or not to use HoverComponents in the usage explanation.
|
||||
<p>Default: true</p>*/
|
||||
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.
|
||||
<p>Default: false</p> */
|
||||
public boolean useRainbowPrefix() {
|
||||
return config.getBoolean("rainbow-mode", false);
|
||||
}
|
||||
|
||||
/** Returns the config setting for use-dots.
|
||||
@ -240,7 +252,7 @@ public class ConfigHandler {
|
||||
<p>PlayerStats 1.2: "config-version" is 2.</p>
|
||||
<p>PlayerStats 1.3: "config-version" is 3. </P>*/
|
||||
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();
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import com.tchristofferson.configupdater.ConfigUpdater;
|
||||
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) {
|
||||
public ConfigUpdateHandler(Main plugin, File configFile, double configVersion) {
|
||||
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(configFile);
|
||||
updateTopListDefault(configuration);
|
||||
configuration.set("config-version", configVersion);
|
||||
|
@ -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 = "<rainbow:16>____________ [PlayerStats] ____________</rainbow>"; //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>] </#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
|
||||
}
|
||||
}
|
||||
|
@ -21,19 +21,38 @@ public class EnumHandler {
|
||||
private final static List<String> 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() {
|
||||
|
@ -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'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user