Make collections mutable in the meta builder

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-09-05 18:48:10 +02:00
parent 979e6dd0a1
commit 2a8719e1e4

View File

@ -83,7 +83,7 @@ public abstract class ItemMetaBuilder implements TagWritable {
@Contract("_ -> this") @Contract("_ -> this")
public @NotNull ItemMetaBuilder lore(@NotNull List<@NotNull Component> lore) { public @NotNull ItemMetaBuilder lore(@NotNull List<@NotNull Component> lore) {
this.lore = List.copyOf(lore); this.lore = new ArrayList<>(lore);
handleCompound("display", nbtCompound -> { handleCompound("display", nbtCompound -> {
final NBTList<NBTString> loreNBT = new NBTList<>(NBTTypes.TAG_String); final NBTList<NBTString> loreNBT = new NBTList<>(NBTTypes.TAG_String);
for (Component line : lore) { for (Component line : lore) {
@ -102,7 +102,7 @@ public abstract class ItemMetaBuilder implements TagWritable {
@Contract("_ -> this") @Contract("_ -> this")
public @NotNull ItemMetaBuilder enchantments(@NotNull Map<Enchantment, Short> enchantments) { public @NotNull ItemMetaBuilder enchantments(@NotNull Map<Enchantment, Short> enchantments) {
this.enchantmentMap = Map.copyOf(enchantments); this.enchantmentMap = new HashMap<>(enchantments);
handleMap(enchantmentMap, "Enchantments", () -> { handleMap(enchantmentMap, "Enchantments", () -> {
NBTUtils.writeEnchant(nbt, "Enchantments", enchantmentMap); NBTUtils.writeEnchant(nbt, "Enchantments", enchantmentMap);
return nbt.get("Enchantments"); return nbt.get("Enchantments");
@ -119,15 +119,14 @@ public abstract class ItemMetaBuilder implements TagWritable {
@Contract("-> this") @Contract("-> this")
public @NotNull ItemMetaBuilder clearEnchantment() { public @NotNull ItemMetaBuilder clearEnchantment() {
this.enchantmentMap = Collections.emptyMap(); this.enchantmentMap = new HashMap<>();
enchantments(enchantmentMap); enchantments(enchantmentMap);
return this; return this;
} }
@Contract("_ -> this") @Contract("_ -> this")
public @NotNull ItemMetaBuilder attributes(@NotNull List<@NotNull ItemAttribute> attributes) { public @NotNull ItemMetaBuilder attributes(@NotNull List<@NotNull ItemAttribute> attributes) {
this.attributes = List.copyOf(attributes); this.attributes = new ArrayList<>(attributes);
handleCollection(attributes, "AttributeModifiers", () -> { handleCollection(attributes, "AttributeModifiers", () -> {
NBTList<NBTCompound> attributesNBT = new NBTList<>(NBTTypes.TAG_Compound); NBTList<NBTCompound> attributesNBT = new NBTList<>(NBTTypes.TAG_Compound);
for (ItemAttribute itemAttribute : attributes) { for (ItemAttribute itemAttribute : attributes) {
@ -157,7 +156,7 @@ public abstract class ItemMetaBuilder implements TagWritable {
@Contract("_ -> this") @Contract("_ -> this")
public @NotNull ItemMetaBuilder canPlaceOn(@NotNull Set<@NotNull Block> blocks) { public @NotNull ItemMetaBuilder canPlaceOn(@NotNull Set<@NotNull Block> blocks) {
this.canPlaceOn = Set.copyOf(blocks); this.canPlaceOn = new HashSet<>(blocks);
handleCollection(canPlaceOn, "CanPlaceOn", () -> { handleCollection(canPlaceOn, "CanPlaceOn", () -> {
NBTList<NBTString> list = new NBTList<>(NBTTypes.TAG_String); NBTList<NBTString> list = new NBTList<>(NBTTypes.TAG_String);
canPlaceOn.forEach(block -> list.add(new NBTString(block.name()))); canPlaceOn.forEach(block -> list.add(new NBTString(block.name())));
@ -173,7 +172,7 @@ public abstract class ItemMetaBuilder implements TagWritable {
@Contract("_ -> this") @Contract("_ -> this")
public @NotNull ItemMetaBuilder canDestroy(@NotNull Set<@NotNull Block> blocks) { public @NotNull ItemMetaBuilder canDestroy(@NotNull Set<@NotNull Block> blocks) {
this.canDestroy = Set.copyOf(blocks); this.canDestroy = new HashSet<>(blocks);
handleCollection(canDestroy, "CanDestroy", () -> { handleCollection(canDestroy, "CanDestroy", () -> {
NBTList<NBTString> list = new NBTList<>(NBTTypes.TAG_String); NBTList<NBTString> list = new NBTList<>(NBTTypes.TAG_String);
canDestroy.forEach(block -> list.add(new NBTString(block.name()))); canDestroy.forEach(block -> list.add(new NBTString(block.name())));