Make use of Instant / Duration classes where possible for time handling

This commit is contained in:
Luck committed 2019-12-24 23:10:26 +00:00
1 parent 6e64f80c81
commit 96c53091d0
38 files changed
+311 -340

No files matched your search

@@ -40,6 +40,7 @@ import net.luckperms.api.node.types.WeightNode;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.time.Duration;
import java.time.Instant;
import java.util.Collection;
import java.util.Optional;
@@ -162,8 +163,8 @@ public interface Node {
/**
* Gets the time when this node will expire.
*
* @return the {@link Instant} when this node will expire, or null if it
* doesn't have an expiry time
* @return the {@link Instant} when this node will expire, or
* {@code null} if it doesn't have an expiry time
*/
@Nullable Instant getExpiry();
@@ -176,6 +177,17 @@ public interface Node {
*/
boolean hasExpired();
/**
* Gets the time until this node will expire.
*
* <p>Returns {@code null} if the node doesn't have an expiry time,
* and a {@link Duration#isNegative() negative} duration if it has already expired.</p>
*
* @return the duration until the nodes expiry
* @since 5.1
*/
@Nullable Duration getExpiryDuration();
/**
* Gets the contexts required for this node to apply.
*
@@ -32,6 +32,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAmount;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@@ -85,7 +86,20 @@ public interface NodeBuilder<N extends ScopedNode<N, B>, B extends NodeBuilder<N
/**
* Sets the time when the node should expire.
*
* <p>The expiry timestamp is calculated relative to the current
* <p>The expiry time is calculated relative to the current
* system time.</p>
*
* @param duration how long the node should be added for
* @return the builder
* @see Node#getExpiry()
* @since 5.1
*/
@NonNull B expiry(@Nullable TemporalAmount duration);
/**
* Sets the time when the node should expire.
*
* <p>The expiry time is calculated relative to the current
* system time.</p>
*
* @param duration how long the node should be added for