From 8f82ef7eb438ed910be4faa74fa0f94bb4f51061 Mon Sep 17 00:00:00 2001 From: Luck Date: Thu, 1 Mar 2018 09:19:26 +0000 Subject: [PATCH] Add copyFrom method to Node.Builder --- .../java/me/lucko/luckperms/api/Node.java | 10 ++++++++++ .../luckperms/common/node/NodeBuilder.java | 19 +++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/api/src/main/java/me/lucko/luckperms/api/Node.java b/api/src/main/java/me/lucko/luckperms/api/Node.java index b845853e..5b52e7e6 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Node.java +++ b/api/src/main/java/me/lucko/luckperms/api/Node.java @@ -444,6 +444,16 @@ public interface Node { */ interface Builder { + /** + * Copies the attributes from the given node and applies them to this + * builder. + * + * @param node the node to copy from + * @return the builder + * @since 4.2 + */ + Builder copyFrom(@Nonnull Node node); + /** * Sets the value of negated for the node. * diff --git a/common/src/main/java/me/lucko/luckperms/common/node/NodeBuilder.java b/common/src/main/java/me/lucko/luckperms/common/node/NodeBuilder.java index 10b27024..b7e9404c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/node/NodeBuilder.java +++ b/common/src/main/java/me/lucko/luckperms/common/node/NodeBuilder.java @@ -58,12 +58,19 @@ class NodeBuilder implements Node.Builder { NodeBuilder(Node other) { this.permission = other.getPermission(); - this.value = other.getValuePrimitive(); - this.override = other.isOverride(); - this.server = other.getServer().orElse(null); - this.world = other.getWorld().orElse(null); - this.expireAt = other.isPermanent() ? 0L : other.getExpiryUnixTime(); - this.extraContexts.addAll(other.getContexts()); + copyFrom(other); + } + + @Override + public Node.Builder copyFrom(@Nonnull Node node) { + Objects.requireNonNull(node, "node"); + this.value = node.getValuePrimitive(); + this.override = node.isOverride(); + this.server = node.getServer().orElse(null); + this.world = node.getWorld().orElse(null); + this.expireAt = node.isPermanent() ? 0L : node.getExpiryUnixTime(); + this.extraContexts.addAll(node.getContexts()); + return this; } @Nonnull