diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/LocationFlag.java b/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/LocationFlag.java index 7d21f6fa..f5d0347d 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/LocationFlag.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/LocationFlag.java @@ -47,9 +47,9 @@ public Location parseInput(FlagContext context) throws InvalidFlagFormat { Location loc = null; if ("here".equalsIgnoreCase(input)) { - loc = player.getLocation(); - } else if ("none".equalsIgnoreCase(input)) { - return null; + Location playerLoc = player.getLocation(); + loc = new LazyLocation(((World) playerLoc.getExtent()).getName(), + loc.toVector(), loc.getYaw(), loc.getPitch()); } else { String[] split = input.split(","); if (split.length >= 3) { diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/TimestampFlag.java b/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/TimestampFlag.java index 8d15ba20..3e59c130 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/TimestampFlag.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/TimestampFlag.java @@ -21,15 +21,24 @@ import javax.annotation.Nullable; import java.time.Instant; +import java.time.LocalDateTime; import java.time.ZoneOffset; +import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; import java.time.format.DateTimeParseException; +import java.time.temporal.TemporalAccessor; /** * Stores a timestamp. */ public class TimestampFlag extends Flag { - private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneOffset.UTC); + private static final DateTimeFormatter SERIALIZER = DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneOffset.UTC); + private static final DateTimeFormatter PARSER = new DateTimeFormatterBuilder() + .append(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + .optionalStart().appendOffsetId() + .toFormatter(); + public TimestampFlag(String name, @Nullable RegionGroup defaultGroup) { super(name, defaultGroup); } @@ -41,12 +50,20 @@ public TimestampFlag(String name) { @Override public Instant parseInput(FlagContext context) throws InvalidFlagFormat { String input = context.getUserInput(); - if("now".equalsIgnoreCase(input)) { + if ("now".equalsIgnoreCase(input)) { return Instant.now(); } else { try { - return Instant.from(FORMATTER.parse(input)); - } catch(DateTimeParseException ignored) { + TemporalAccessor parsed = PARSER.parseBest(input, ZonedDateTime::from, LocalDateTime::from); + // convert whatever input into UTC for storage + if (parsed instanceof LocalDateTime) { + return ((LocalDateTime) parsed).atZone(ZoneOffset.UTC).toInstant(); + } else if (parsed instanceof ZonedDateTime) { + return ((ZonedDateTime) parsed).toInstant(); + } else { + throw new InvalidFlagFormat("Unrecognized input."); + } + } catch (DateTimeParseException ignored) { throw new InvalidFlagFormat("Expected 'now' or ISO 8601 formatted input."); } } @@ -56,7 +73,7 @@ public Instant parseInput(FlagContext context) throws InvalidFlagFormat { public Instant unmarshal(@Nullable Object o) { if (o instanceof String) { try { - return Instant.from(FORMATTER.parse((String) o)); + return Instant.from(SERIALIZER.parse((String) o)); } catch(DateTimeParseException ignored) { return null; } @@ -66,6 +83,6 @@ public Instant unmarshal(@Nullable Object o) { @Override public Object marshal(Instant o) { - return FORMATTER.format(o); + return SERIALIZER.format(o); } }