mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-09 18:08:37 +01:00
Only make immutable lists when built
This commit is contained in:
parent
042c7c864b
commit
cf0450f21f
@ -5,6 +5,7 @@ import org.jetbrains.annotations.Contract;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ public class ItemMeta implements Cloneable {
|
|||||||
protected ItemMeta(@NotNull ItemMetaBuilder metaBuilder) {
|
protected ItemMeta(@NotNull ItemMetaBuilder metaBuilder) {
|
||||||
this.builder = metaBuilder.clone();
|
this.builder = metaBuilder.clone();
|
||||||
this.displayName = metaBuilder.displayName;
|
this.displayName = metaBuilder.displayName;
|
||||||
this.lore = metaBuilder.lore;
|
this.lore = Collections.unmodifiableList(metaBuilder.lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Contract(value = "_, -> new", pure = true)
|
@Contract(value = "_, -> new", pure = true)
|
||||||
|
@ -21,7 +21,7 @@ public abstract class ItemMetaBuilder implements Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull ItemMetaBuilder lore(List<@NotNull Component> lore) {
|
public @NotNull ItemMetaBuilder lore(List<@NotNull Component> lore) {
|
||||||
this.lore = Collections.unmodifiableList(lore);
|
this.lore = lore;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +54,8 @@ public abstract class ItemMetaBuilder implements Cloneable {
|
|||||||
try {
|
try {
|
||||||
var builder = (ItemMetaBuilder) super.clone();
|
var builder = (ItemMetaBuilder) super.clone();
|
||||||
builder.displayName = displayName;
|
builder.displayName = displayName;
|
||||||
builder.lore = lore;
|
builder.lore = new ArrayList<>(lore);
|
||||||
|
builder.enchantmentMap = new HashMap<>(enchantmentMap);
|
||||||
deepClone(builder);
|
deepClone(builder);
|
||||||
return builder;
|
return builder;
|
||||||
} catch (CloneNotSupportedException e) {
|
} catch (CloneNotSupportedException e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user