Skip to content

Commit 002e395

Browse files
committed
allow users to change the date format
1 parent 98da6a8 commit 002e395

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

src/main/java/lol/hyper/anarchystats/AnarchyStats.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void onEnable() {
3939
if (commandTest != null) {
4040
logger.warning("We detected that /" + config.getString("info-command-override") + " is already taken by another plugin. There might be some issues with this. To change this, edit the info-command-override setting in the config.");
4141
}
42-
42+
4343
this.getCommand(config.getString("info-command-override")).setExecutor(commandInfo);
4444
this.getCommand("anarchystats").setExecutor(commandReload);
4545
Bukkit.getScheduler().runTaskAsynchronously(this, () -> this.updateWorldSize(WorldSize.world, WorldSize.nether, WorldSize.end));

src/main/java/lol/hyper/anarchystats/MessageParser.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
import org.bukkit.Bukkit;
44
import org.bukkit.ChatColor;
55

6+
import java.text.DateFormat;
7+
import java.text.ParseException;
8+
import java.text.SimpleDateFormat;
69
import java.time.LocalDate;
710
import java.time.format.DateTimeFormatter;
811
import java.time.temporal.ChronoUnit;
912
import java.util.ArrayList;
13+
import java.util.Date;
1014
import java.util.List;
15+
import java.util.Locale;
1116

1217
public class MessageParser {
1318

@@ -19,11 +24,20 @@ public MessageParser(AnarchyStats anarchyStats) {
1924

2025
public List<String> getCommandMessage() {
2126
String date = anarchyStats.config.getString("date");
27+
DateFormat originalFormat = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
28+
DateFormat newFormat = new SimpleDateFormat(anarchyStats.config.getString("date-format"), Locale.ENGLISH);
29+
Date originalDate = null;
30+
try {
31+
originalDate = originalFormat.parse(date);
32+
} catch (ParseException e) {
33+
e.printStackTrace();
34+
}
35+
String newDate = newFormat.format(originalDate);
2236
List<String> rawMessages = anarchyStats.config.getStringList("command-message");
2337
List<String> formattedMessage = new ArrayList<>();
2438
for (String x : rawMessages) {
2539
if (x.contains("{{STARTDATE}}")) {
26-
x = x.replace("{{STARTDATE}}", date);
40+
x = x.replace("{{STARTDATE}}", newDate);
2741
}
2842

2943
if (x.contains("{{DAYS}}")) {

src/main/java/lol/hyper/anarchystats/WorldSize.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
public class WorldSize {
1212

13-
1413
public static Path world = null;
1514
public static Path nether= null;
1615
public static Path end= null;

src/main/resources/config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ info-command-override: "info"
66
# Format: MM/DD/YYYY. You must put zeros for single digits. Example: 06, 02, 01, etc.
77
date: 05/27/2019 # This date is May 27th, 2019.
88

9+
# Change how the date is formatted on the command.
10+
# The default value will format the display like this: 05/27/2019 (MM/DD/YYYY).
11+
# You can find examples on how to custom this here: https://www.journaldev.com/17899/java-simpledateformat-java-date-format <- There is a chart at the bottom of the page.
12+
date-format: "M/dd/yyyy"
13+
914
# Some servers have different folder names for the worlds. Please update these to match yours.
1015
# Leave default if you didn't change the names.
1116
world-files:

0 commit comments

Comments
 (0)