From 2de2ae82a71a46e7de0c3cbfc77915d02cf38470 Mon Sep 17 00:00:00 2001 From: hyperdefined Date: Wed, 12 Oct 2022 13:21:54 -0400 Subject: [PATCH] config for date formatting closes #20 --- src/main/java/lol/hyper/toolstats/ToolStats.java | 16 +++++++++++++++- src/main/resources/config.yml | 5 +++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/lol/hyper/toolstats/ToolStats.java b/src/main/java/lol/hyper/toolstats/ToolStats.java index f977b2e..49d9d22 100644 --- a/src/main/java/lol/hyper/toolstats/ToolStats.java +++ b/src/main/java/lol/hyper/toolstats/ToolStats.java @@ -60,7 +60,7 @@ public final class ToolStats extends JavaPlugin { // used for tracking new elytras public final NamespacedKey newElytra = new NamespacedKey(this, "new"); - public final SimpleDateFormat dateFormat = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH); + public SimpleDateFormat dateFormat; public final DecimalFormat decimalFormat = new DecimalFormat("#,###.00", new DecimalFormatSymbols(Locale.getDefault())); public final DecimalFormat commaFormat = new DecimalFormat("#,###", new DecimalFormatSymbols(Locale.getDefault())); public BlocksMined blocksMined; @@ -130,6 +130,20 @@ public final class ToolStats extends JavaPlugin { if (config.getInt("config-version") != CONFIG_VERSION) { logger.warning("Your config file is outdated! Please regenerate the config."); } + + String dateFormatConfig = config.getString("date-format"); + if (dateFormatConfig != null) { + try { + dateFormat = new SimpleDateFormat(dateFormatConfig, Locale.getDefault()); + } catch (IllegalArgumentException exception) { + logger.severe("date-format is NOT a valid format! Using default American English format."); + exception.printStackTrace(); + dateFormat = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH); + } + } else { + logger.warning("date-format is missing from your config! Using default American English format."); + dateFormat = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH); + } } public void checkForUpdates() { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 599fc9b..c0f9631 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -98,4 +98,9 @@ messages: crafting: "&cCrafting items via shift clicking does not fully apply tags to each item. This is a limitation with the Bukkit API." trading: "&cTrading items via shift clicking does not fully apply tags to each item. This is a limitation with the Bukkit API." +# Change the default formatting for dates. +# See: https://www.digitalocean.com/community/tutorials/java-simpledateformat-java-date-format +# Example: "dd/mm/yyyy" +date-format: "M/dd/yyyy" + config-version: 3 \ No newline at end of file