Only make immutable lists when built

This commit is contained in:
themode 2021-04-02 14:02:24 +02:00
parent 042c7c864b
commit cf0450f21f
2 changed files with 5 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
@ -17,7 +18,7 @@ public class ItemMeta implements Cloneable {
protected ItemMeta(@NotNull ItemMetaBuilder metaBuilder) {
this.builder = metaBuilder.clone();
this.displayName = metaBuilder.displayName;
this.lore = metaBuilder.lore;
this.lore = Collections.unmodifiableList(metaBuilder.lore);
}
@Contract(value = "_, -> new", pure = true)

View File

@ -21,7 +21,7 @@ public abstract class ItemMetaBuilder implements Cloneable {
}
public @NotNull ItemMetaBuilder lore(List<@NotNull Component> lore) {
this.lore = Collections.unmodifiableList(lore);
this.lore = lore;
return this;
}
@ -54,7 +54,8 @@ public abstract class ItemMetaBuilder implements Cloneable {
try {
var builder = (ItemMetaBuilder) super.clone();
builder.displayName = displayName;
builder.lore = lore;
builder.lore = new ArrayList<>(lore);
builder.enchantmentMap = new HashMap<>(enchantmentMap);
deepClone(builder);
return builder;
} catch (CloneNotSupportedException e) {