diff --git a/modules/API/src/main/java/com/comphenix/protocol/events/PacketContainer.java b/modules/API/src/main/java/com/comphenix/protocol/events/PacketContainer.java index 2f29e2d4..1e5debe5 100644 --- a/modules/API/src/main/java/com/comphenix/protocol/events/PacketContainer.java +++ b/modules/API/src/main/java/com/comphenix/protocol/events/PacketContainer.java @@ -86,7 +86,8 @@ public class PacketContainer implements Serializable { .instanceProvider(DefaultInstances.DEFAULT) .andThen(BukkitCloner.class) .andThen(ImmutableDetector.class) - .andThen(OptionalCloner.class) + .andThen(JavaOptionalCloner.class) + .andThen(GuavaOptionalCloner.class) .andThen(CollectionCloner.class) .andThen(getSpecializedDeepClonerFactory()) .build(); diff --git a/modules/API/src/main/java/com/comphenix/protocol/reflect/cloning/OptionalCloner.java b/modules/API/src/main/java/com/comphenix/protocol/reflect/cloning/GuavaOptionalCloner.java similarity index 80% rename from modules/API/src/main/java/com/comphenix/protocol/reflect/cloning/OptionalCloner.java rename to modules/API/src/main/java/com/comphenix/protocol/reflect/cloning/GuavaOptionalCloner.java index ac346c38..09cf254e 100644 --- a/modules/API/src/main/java/com/comphenix/protocol/reflect/cloning/OptionalCloner.java +++ b/modules/API/src/main/java/com/comphenix/protocol/reflect/cloning/GuavaOptionalCloner.java @@ -6,14 +6,14 @@ package com.comphenix.protocol.reflect.cloning; import com.google.common.base.Optional; /** - * A cloner that can clone Optional objects + * A cloner that can clone Guava Optional objects * @author dmulloy2 */ -public class OptionalCloner implements Cloner { +public class GuavaOptionalCloner implements Cloner { protected Cloner wrapped; - public OptionalCloner(Cloner wrapped) { + public GuavaOptionalCloner(Cloner wrapped) { this.wrapped = wrapped; } diff --git a/modules/API/src/main/java/com/comphenix/protocol/reflect/cloning/JavaOptionalCloner.java b/modules/API/src/main/java/com/comphenix/protocol/reflect/cloning/JavaOptionalCloner.java new file mode 100644 index 00000000..040df3a5 --- /dev/null +++ b/modules/API/src/main/java/com/comphenix/protocol/reflect/cloning/JavaOptionalCloner.java @@ -0,0 +1,33 @@ +/** + * (c) 2018 dmulloy2 + */ +package com.comphenix.protocol.reflect.cloning; + +import java.util.Optional; + +/** + * A cloner that can clone Java Optional objects + * @author dmulloy2 + */ +public class JavaOptionalCloner implements Cloner { + protected Cloner wrapped; + + public JavaOptionalCloner(Cloner wrapped) { + this.wrapped = wrapped; + } + + @Override + public boolean canClone(Object source) { + return source instanceof Optional; + } + + @Override + public Object clone(Object source) { + Optional optional = (Optional) source; + return optional.map(o -> wrapped.clone(o)); + } + + public Cloner getWrapped() { + return wrapped; + } +}