N0tMyFaultOG 2020-12-07 14:46:16 +01:00
parent a4dd5bb62f
commit 469d6ab907
No known key found for this signature in database
GPG Key ID: 823348042DA95A81
5 changed files with 38 additions and 2 deletions

View File

@ -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;
}

View File

@ -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 {

View File

@ -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("<rating>")) {
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;
}

View File

@ -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<String, Placeholder> 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()));

View File

@ -381,7 +381,7 @@
"info.plot_info_unclaimed": "<prefix><gray>Plot <gold><plot></gold> is not yet claimed.</gray>",
"info.plot_info_header": "<dark_gray><strikethrough>--------- <reset><gold>INFO </gold><dark_gray><strikethrough>---------</dark_gray><reset>",
"info.plot_info_hidden": "<prefix><red>You cannot view the information about this plot.</red>",
"info.plot_info_format": "<header>\n<gold>ID: <gray><id></gray>\nArea: <gray><area></gray>\nAlias: <gray><alias></gray>\nOwner: <gray><owner></gray>\nBiome: <gray><biome></gray>\nCan Build: <gray><build></gray>\nRating: <gray><rating></gray>\nSeen: <gray><seen></gray>\nTrusted: <gray><trusted></gray>\nMembers: <gray><members></gray>\nDenied: <gray><denied></gray>\nFlags: <gray><flags></gray>\nDescription: <gray><desc></gray></gold>\n<footer>",
"info.plot_info_format": "<header>\n<gold>ID: <gray><id></gray>\nArea: <gray><area></gray>\nAlias: <gray><alias></gray>\nOwner: <gray><owner></gray>\nBiome: <gray><biome></gray>\nCan Build: <gray><build></gray>\nRating: <gray><rating></gray>\nSeen: <gray><seen></gray>\nCreation: <gray><creationdate></gray>\nTrusted: <gray><trusted></gray>\nMembers: <gray><members></gray>\nDenied: <gray><denied></gray>\nFlags: <gray><flags></gray>\nDescription: <gray><desc></gray></gold>\n<footer>",
"info.plot_info_footer": "<dark_gray><strikethrough>--------- <reset><gold>INFO </gold><dark_gray><strikethrough>---------<reset>",
"info.plot_info_trusted": "<gold>Trusted:</gold> <gray><trusted></gray>",
"info.plot_info_members": "<gold>Members:</gold> <gray><members></gray>",
@ -395,6 +395,7 @@
"info.plot_info_alias": "<gold>Alias:</gold><gray> <alias></gray>",
"info.plot_info_size": "<gold>Size:</gold><gray> <size></gray>",
"info.plot_info_seen": "<gold>Seen:</gold><gray> <seen></gray>",
"info.plot_info_creationdate": "<gold>Creation:</gold><gray> <creationdate></gray>",
"info.plot_user_list": "<gray><user></gray>",
"info.plot_flag_list": "<gray><flag>: <value></gray>",
"info.plot_no_description": "<prefix><gray>No description set.</gray>",