diff --git a/Core/src/main/java/com/plotsquared/core/command/Info.java b/Core/src/main/java/com/plotsquared/core/command/Info.java index 22bf89d96..fd76d9af6 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Info.java +++ b/Core/src/main/java/com/plotsquared/core/command/Info.java @@ -57,6 +57,7 @@ public class Info extends SubCommand { case "id": case "size": case "members": + case "creationdate": case "seen": case "owner": case "rating": @@ -175,6 +176,8 @@ public class Info extends SubCommand { return TranslatableCaption.of("info.plot_info_likes"); case "seen": return TranslatableCaption.of("info.plot_info_seen"); + case "creationdate": + return TranslatableCaption.of("info.plot_info_creationdate"); default: return null; } diff --git a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java index 5e932e774..39acd7061 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java @@ -438,6 +438,16 @@ public class Settings extends Config { public static String DELETE_URL = "https://sw.jacobandersen.dev/delete/{key}"; } + @Comment("Used to format the plot creation date placeholder. Modifying the format does not affect the storage time.") + public static class Timeformat { + + @Comment("The date used formatted in ISO 8601") + public static String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss z"; + + @Comment("The time zone used") + public static String TIME_ZONE = "GMT"; + } + @Comment("Miscellaneous settings") public static final class Done { diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java index 9e52a6d98..2cc25e5cd 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -84,10 +84,12 @@ import org.slf4j.LoggerFactory; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.text.DecimalFormat; +import java.text.SimpleDateFormat; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -95,6 +97,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Objects; import java.util.Set; +import java.util.TimeZone; import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; @@ -2726,6 +2729,11 @@ public class Plot { } else { areaTemplate = Template.of("area", TranslatableCaption.of("info.none").getComponent(player)); } + long creationDate = Long.parseLong(String.valueOf(timestamp)); + SimpleDateFormat sdf = new SimpleDateFormat(Settings.Timeformat.DATE_FORMAT); + sdf.setTimeZone(TimeZone.getTimeZone(Settings.Timeformat.TIME_ZONE)); + String newDate = sdf.format(creationDate); + Template idTemplate = Template.of("id", this.getId().toString()); Template aliasTemplate = Template.of("alias", alias); Template numTemplate = Template.of("num", String.valueOf(num)); @@ -2739,6 +2747,7 @@ public class Plot { Template deniedTemplate = Template.of("denied", denied); Template seenTemplate = Template.of("seen", seen); Template flagsTemplate = Template.of("flags", flags); + Template creationTemplate = Template.of("creationdate", newDate); Template buildTemplate = Template.of("build", String.valueOf(build)); if (iInfo.getComponent(player).contains("")) { TaskManager.runTaskAsync(() -> { @@ -2767,7 +2776,7 @@ public class Plot { future.complete(StaticCaption.of(MINI_MESSAGE.serialize(MINI_MESSAGE .parse(iInfo.getComponent(player), headerTemplate, areaTemplate, idTemplate, aliasTemplate, numTemplate, descTemplate, biomeTemplate, ownerTemplate, membersTemplate, playerTemplate, trustedTemplate, helpersTemplate, deniedTemplate, - seenTemplate, flagsTemplate, buildTemplate, ratingTemplate, footerTemplate)))); + seenTemplate, flagsTemplate, buildTemplate, ratingTemplate, creationTemplate, footerTemplate)))); }); return; } diff --git a/Core/src/main/java/com/plotsquared/core/util/placeholders/PlaceholderRegistry.java b/Core/src/main/java/com/plotsquared/core/util/placeholders/PlaceholderRegistry.java index a6b84748a..e362b7e3f 100644 --- a/Core/src/main/java/com/plotsquared/core/util/placeholders/PlaceholderRegistry.java +++ b/Core/src/main/java/com/plotsquared/core/util/placeholders/PlaceholderRegistry.java @@ -29,6 +29,7 @@ import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.common.collect.Maps; import com.google.inject.Singleton; +import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.flag.GlobalFlagContainer; @@ -39,10 +40,12 @@ import com.plotsquared.core.util.PlayerManager; import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.inject.Inject; +import java.text.SimpleDateFormat; import java.util.Collection; import java.util.Collections; import java.util.Locale; import java.util.Map; +import java.util.TimeZone; import java.util.UUID; import java.util.function.BiFunction; @@ -54,6 +57,7 @@ public final class PlaceholderRegistry { private final Map placeholders; private final EventDispatcher eventDispatcher; + private final long timestamp = 0; @Inject public PlaceholderRegistry(@Nonnull final EventDispatcher eventDispatcher) { this.placeholders = Maps.newHashMap(); @@ -130,6 +134,15 @@ public final class PlaceholderRegistry { } return String.valueOf(PlayerManager.getPlayerList(plot.getDenied())); }); + this.createPlaceholder("currentplot_creationdate", (player, plot) -> { + if (plot.getTimestamp() == 0) { + return "0"; + } + long creationDate = plot.getTimestamp(); + SimpleDateFormat sdf = new SimpleDateFormat(Settings.Timeformat.DATE_FORMAT); + sdf.setTimeZone(TimeZone.getTimeZone(Settings.Timeformat.TIME_ZONE)); + return sdf.format(creationDate); + }); this.createPlaceholder("has_build_rights", (player, plot) -> plot.isAdded(player.getUUID()) ? "true" : "false"); this.createPlaceholder("currentplot_x", (player, plot) -> Integer.toString(plot.getId().getX())); diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index 1e401fa77..26a574dce 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -381,7 +381,7 @@ "info.plot_info_unclaimed": "Plot is not yet claimed.", "info.plot_info_header": "--------- INFO ---------", "info.plot_info_hidden": "You cannot view the information about this plot.", - "info.plot_info_format": "
\nID: \nArea: \nAlias: \nOwner: \nBiome: \nCan Build: \nRating: \nSeen: \nTrusted: \nMembers: \nDenied: \nFlags: \nDescription: \n