Add copyFrom method to Node.Builder

This commit is contained in:
Luck 2018-03-01 09:19:26 +00:00
parent fbe84322b5
commit 8f82ef7eb4
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
2 changed files with 23 additions and 6 deletions

View File

@ -444,6 +444,16 @@ public interface Node {
*/ */
interface Builder { 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. * Sets the value of negated for the node.
* *

View File

@ -58,12 +58,19 @@ class NodeBuilder implements Node.Builder {
NodeBuilder(Node other) { NodeBuilder(Node other) {
this.permission = other.getPermission(); this.permission = other.getPermission();
this.value = other.getValuePrimitive(); copyFrom(other);
this.override = other.isOverride(); }
this.server = other.getServer().orElse(null);
this.world = other.getWorld().orElse(null); @Override
this.expireAt = other.isPermanent() ? 0L : other.getExpiryUnixTime(); public Node.Builder copyFrom(@Nonnull Node node) {
this.extraContexts.addAll(other.getContexts()); 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 @Nonnull