Use optimized copies

This commit is contained in:
themode 2021-12-19 20:15:06 +01:00 committed by TheMode
parent 81aa3dde27
commit bf77918c96
5 changed files with 13 additions and 14 deletions

View File

@ -7,7 +7,6 @@ import net.minestom.server.utils.NBTUtils;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
@ -18,7 +17,7 @@ public class EnchantedBookMeta extends ItemMeta implements ItemMetaBuilder.Provi
protected EnchantedBookMeta(@NotNull ItemMetaBuilder metaBuilder, Map<Enchantment, Short> storedEnchantmentMap) {
super(metaBuilder);
this.storedEnchantmentMap = new HashMap<>(storedEnchantmentMap);
this.storedEnchantmentMap = Map.copyOf(storedEnchantmentMap);
}
/**
@ -28,7 +27,7 @@ public class EnchantedBookMeta extends ItemMeta implements ItemMetaBuilder.Provi
* @return an unmodifiable map containing the item stored enchantments
*/
public @NotNull Map<Enchantment, Short> getStoredEnchantmentMap() {
return Collections.unmodifiableMap(storedEnchantmentMap);
return storedEnchantmentMap;
}
public static class Builder extends ItemMetaBuilder {

View File

@ -9,8 +9,6 @@ import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import org.jglrxavpok.hephaistos.nbt.NBTList;
import org.jglrxavpok.hephaistos.nbt.NBTType;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Supplier;
@ -23,12 +21,12 @@ public class FireworkMeta extends ItemMeta implements ItemMetaBuilder.Provider<F
protected FireworkMeta(@NotNull ItemMetaBuilder metaBuilder, List<FireworkEffect> effects,
byte flightDuration) {
super(metaBuilder);
this.effects = new ArrayList<>(effects);
this.effects = List.copyOf(effects);
this.flightDuration = flightDuration;
}
public List<FireworkEffect> getEffects() {
return Collections.unmodifiableList(effects);
return effects;
}
public byte getFlightDuration() {

View File

@ -29,7 +29,7 @@ public class PotionMeta extends ItemMeta implements ItemMetaBuilder.Provider<Pot
Color color) {
super(metaBuilder);
this.potionType = potionType;
this.customPotionEffects = new ArrayList<>(customPotionEffects);
this.customPotionEffects = List.copyOf(customPotionEffects);
this.color = color;
}

View File

@ -9,7 +9,6 @@ import org.jetbrains.annotations.Nullable;
import org.jglrxavpok.hephaistos.nbt.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.function.Supplier;
@ -26,7 +25,7 @@ public class WritableBookMeta extends ItemMeta implements ItemMetaBuilder.Provid
super(metaBuilder);
this.author = author;
this.title = title;
this.pages = new ArrayList<>(pages);
this.pages = List.copyOf(pages);
}
public @Nullable String getAuthor() {
@ -38,7 +37,7 @@ public class WritableBookMeta extends ItemMeta implements ItemMetaBuilder.Provid
}
public @NotNull List<@NotNull Component> getPages() {
return Collections.unmodifiableList(pages);
return pages;
}
public static class Builder extends ItemMetaBuilder {

View File

@ -12,7 +12,10 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jglrxavpok.hephaistos.nbt.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.function.Supplier;
public class WrittenBookMeta extends ItemMeta implements ItemMetaBuilder.Provider<WrittenBookMeta.Builder> {
@ -32,7 +35,7 @@ public class WrittenBookMeta extends ItemMeta implements ItemMetaBuilder.Provide
this.generation = generation;
this.author = author;
this.title = title;
this.pages = new ArrayList<>(pages);
this.pages = List.copyOf(pages);
}
public boolean isResolved() {
@ -52,7 +55,7 @@ public class WrittenBookMeta extends ItemMeta implements ItemMetaBuilder.Provide
}
public @NotNull List<@NotNull Component> getPages() {
return Collections.unmodifiableList(pages);
return pages;
}
public enum WrittenBookGeneration {