Skip to content

Commit 2de2ae8

Browse files
committed
config for date formatting
closes #20
1 parent 7639943 commit 2de2ae8

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/main/java/lol/hyper/toolstats/ToolStats.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public final class ToolStats extends JavaPlugin {
6060
// used for tracking new elytras
6161
public final NamespacedKey newElytra = new NamespacedKey(this, "new");
6262

63-
public final SimpleDateFormat dateFormat = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
63+
public SimpleDateFormat dateFormat;
6464
public final DecimalFormat decimalFormat = new DecimalFormat("#,###.00", new DecimalFormatSymbols(Locale.getDefault()));
6565
public final DecimalFormat commaFormat = new DecimalFormat("#,###", new DecimalFormatSymbols(Locale.getDefault()));
6666
public BlocksMined blocksMined;
@@ -130,6 +130,20 @@ public void loadConfig() {
130130
if (config.getInt("config-version") != CONFIG_VERSION) {
131131
logger.warning("Your config file is outdated! Please regenerate the config.");
132132
}
133+
134+
String dateFormatConfig = config.getString("date-format");
135+
if (dateFormatConfig != null) {
136+
try {
137+
dateFormat = new SimpleDateFormat(dateFormatConfig, Locale.getDefault());
138+
} catch (IllegalArgumentException exception) {
139+
logger.severe("date-format is NOT a valid format! Using default American English format.");
140+
exception.printStackTrace();
141+
dateFormat = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
142+
}
143+
} else {
144+
logger.warning("date-format is missing from your config! Using default American English format.");
145+
dateFormat = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
146+
}
133147
}
134148

135149
public void checkForUpdates() {

src/main/resources/config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,9 @@ messages:
9898
crafting: "&cCrafting items via shift clicking does not fully apply tags to each item. This is a limitation with the Bukkit API."
9999
trading: "&cTrading items via shift clicking does not fully apply tags to each item. This is a limitation with the Bukkit API."
100100

101+
# Change the default formatting for dates.
102+
# See: https://www.digitalocean.com/community/tutorials/java-simpledateformat-java-date-format
103+
# Example: "dd/mm/yyyy"
104+
date-format: "M/dd/yyyy"
105+
101106
config-version: 3

0 commit comments

Comments
 (0)