Improve item meta creation performance

This commit is contained in:
themode 2021-12-19 20:52:37 +01:00 committed by TheMode
parent 4091f0ae8c
commit b997b87dc1
13 changed files with 120 additions and 293 deletions

View File

@ -5,7 +5,10 @@ import net.minestom.server.item.ItemMetaBuilder;
import net.minestom.server.item.ItemStack;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.nbt.*;
import org.jglrxavpok.hephaistos.nbt.NBT;
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.List;
@ -55,16 +58,15 @@ public class BundleMeta extends ItemMeta implements ItemMetaBuilder.Provider<Bun
}
private void updateItems() {
mutateNbt(compound -> {
compound.set("Items", NBT.List(NBTType.TAG_Compound, items.size(), i -> items.get(i).toItemNBT()));
});
mutateNbt(compound -> compound.set("Items", NBT.List(NBTType.TAG_Compound,
items.size(), i -> items.get(i).toItemNBT())));
}
@Override
public void read(@NotNull NBTCompound nbtCompound) {
if (nbtCompound.containsKey("Items")) {
final NBTList<NBTCompound> items = nbtCompound.getList("Items");
for (NBTCompound item : items) {
if (nbtCompound.get("Items") instanceof NBTList<?> list &&
list.getSubtagType() == NBTType.TAG_Compound) {
for (NBTCompound item : list.<NBTCompound>asListOf()) {
this.items.add(ItemStack.fromItemNBT(item));
}
}

View File

@ -7,7 +7,9 @@ import net.minestom.server.item.ItemMetaBuilder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jglrxavpok.hephaistos.nbt.NBT;
import org.jglrxavpok.hephaistos.nbt.NBTByte;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import org.jglrxavpok.hephaistos.nbt.NBTString;
import java.util.Map;
import java.util.function.Supplier;
@ -90,18 +92,17 @@ public class CompassMeta extends ItemMeta implements ItemMetaBuilder.Provider<Co
@Override
public void read(@NotNull NBTCompound nbtCompound) {
if (nbtCompound.containsKey("LodestoneTracked")) {
lodestoneTracked(nbtCompound.getByte("LodestoneTracked") == 1);
if (nbtCompound.get("LodestoneTracked") instanceof NBTByte tracked) {
this.lodestoneTracked = tracked.asBoolean();
}
if (nbtCompound.containsKey("LodestoneDimension")) {
lodestoneDimension(nbtCompound.getString("LodestoneDimension"));
if (nbtCompound.get("LodestoneDimension") instanceof NBTString dimension) {
this.lodestoneDimension = dimension.getValue();
}
if (nbtCompound.containsKey("LodestonePos")) {
final NBTCompound posCompound = nbtCompound.getCompound("LodestonePos");
if (nbtCompound.get("LodestonePos") instanceof NBTCompound posCompound) {
final int x = posCompound.getInt("X");
final int y = posCompound.getInt("Y");
final int z = posCompound.getInt("Z");
lodestonePosition(new Vec(x, y, z));
this.lodestonePosition = new Vec(x, y, z);
}
}

View File

@ -6,10 +6,7 @@ import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.nbt.NBT;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import org.jglrxavpok.hephaistos.nbt.NBTList;
import org.jglrxavpok.hephaistos.nbt.NBTType;
import org.jglrxavpok.hephaistos.nbt.*;
import java.util.ArrayList;
import java.util.List;
@ -159,15 +156,17 @@ public class CrossbowMeta extends ItemMeta implements ItemMetaBuilder.Provider<S
}
if (projectiles.size() == 1) {
projectile(projectiles.get(0));
this.projectile1 = projectiles.get(0);
} else if (projectiles.size() == 3) {
projectiles(projectiles.get(0), projectiles.get(1), projectiles.get(2));
this.projectile1 = projectiles.get(0);
this.projectile2 = projectiles.get(1);
this.projectile3 = projectiles.get(2);
}
}
if (nbtCompound.containsKey("Charged")) {
charged(nbtCompound.getByte("Charged") == 1);
if (nbtCompound.get("Charged") instanceof NBTByte charged) {
this.charged = charged.asBoolean();
}
}

View File

@ -6,6 +6,8 @@ import net.minestom.server.item.ItemMetaBuilder;
import net.minestom.server.utils.NBTUtils;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import org.jglrxavpok.hephaistos.nbt.NBTList;
import org.jglrxavpok.hephaistos.nbt.NBTType;
import java.util.HashMap;
import java.util.Map;
@ -53,8 +55,9 @@ public class EnchantedBookMeta extends ItemMeta implements ItemMetaBuilder.Provi
@Override
public void read(@NotNull NBTCompound nbtCompound) {
if (nbtCompound.containsKey("StoredEnchantments")) {
NBTUtils.loadEnchantments(nbtCompound.getList("StoredEnchantments"), this::enchantment);
if (nbtCompound.get("StoredEnchantments") instanceof NBTList<?> list &&
list.getSubtagType() == NBTType.TAG_Compound) {
NBTUtils.loadEnchantments(list.asListOf(), this::enchantment);
}
}

View File

@ -39,8 +39,8 @@ public class FireworkEffectMeta extends ItemMeta implements ItemMetaBuilder.Prov
@Override
public void read(@NotNull NBTCompound nbtCompound) {
if (nbtCompound.containsKey("Explosion")) {
effect(FireworkEffect.fromCompound(nbtCompound.getCompound("Explosion")));
if (nbtCompound.get("Explosion") instanceof NBTCompound explosionCompound) {
this.fireworkEffect = FireworkEffect.fromCompound(explosionCompound);
}
}

View File

@ -4,10 +4,7 @@ import net.minestom.server.item.ItemMeta;
import net.minestom.server.item.ItemMetaBuilder;
import net.minestom.server.item.firework.FireworkEffect;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.nbt.NBT;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import org.jglrxavpok.hephaistos.nbt.NBTList;
import org.jglrxavpok.hephaistos.nbt.NBTType;
import org.jglrxavpok.hephaistos.nbt.*;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
@ -65,20 +62,16 @@ public class FireworkMeta extends ItemMeta implements ItemMetaBuilder.Provider<F
@Override
public void read(@NotNull NBTCompound nbtCompound) {
if (nbtCompound.containsKey("Fireworks")) {
NBTCompound fireworksCompound = nbtCompound.getCompound("Fireworks");
if (fireworksCompound.containsKey("Flight")) {
flightDuration(fireworksCompound.getAsByte("Flight"));
if (nbtCompound.get("Fireworks") instanceof NBTCompound fireworksCompound) {
if (fireworksCompound.get("Flight") instanceof NBTByte flight) {
this.flightDuration = flight.getValue();
}
if (fireworksCompound.containsKey("Explosions")) {
NBTList<NBTCompound> explosions = fireworksCompound.getList("Explosions");
for (NBTCompound explosion : explosions) {
if (fireworksCompound.get("Explosions") instanceof NBTList<?> list &&
list.getSubtagType() == NBTType.TAG_Compound) {
for (NBTCompound explosion : list.<NBTCompound>asListOf()) {
this.effects.add(FireworkEffect.fromCompound(explosion));
}
effects(effects);
}
}
}

View File

@ -6,6 +6,7 @@ import net.minestom.server.item.ItemMetaBuilder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import org.jglrxavpok.hephaistos.nbt.NBTInt;
import java.util.function.Supplier;
@ -45,10 +46,9 @@ public class LeatherArmorMeta extends ItemMeta implements ItemMetaBuilder.Provid
@Override
public void read(@NotNull NBTCompound nbtCompound) {
if (nbtCompound.containsKey("display")) {
final NBTCompound displayCompound = nbtCompound.getCompound("display");
if (displayCompound.containsKey("color")) {
color(new Color(displayCompound.getInt("color")));
if (nbtCompound.get("display") instanceof NBTCompound displayCompound) {
if (displayCompound.get("color") instanceof NBTInt colorInt) {
this.color = new Color(colorInt.getValue());
}
}
}

View File

@ -1,15 +1,10 @@
package net.minestom.server.item.metadata;
import net.minestom.server.MinecraftServer;
import net.minestom.server.color.Color;
import net.minestom.server.item.ItemMeta;
import net.minestom.server.item.ItemMetaBuilder;
import net.minestom.server.utils.clone.PublicCloneable;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.nbt.NBT;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import org.jglrxavpok.hephaistos.nbt.NBTList;
import org.jglrxavpok.hephaistos.nbt.NBTType;
import org.jglrxavpok.hephaistos.nbt.*;
import java.util.ArrayList;
import java.util.List;
@ -21,18 +16,18 @@ public class MapMeta extends ItemMeta implements ItemMetaBuilder.Provider<MapMet
private final int mapId;
private final int mapScaleDirection;
private final List<MapDecoration> decorations;
private final List<Decoration> decorations;
private final Color mapColor;
protected MapMeta(ItemMetaBuilder metaBuilder,
int mapId,
int mapScaleDirection,
@NotNull List<MapDecoration> decorations,
@NotNull List<Decoration> decorations,
@NotNull Color mapColor) {
super(metaBuilder);
this.mapId = mapId;
this.mapScaleDirection = mapScaleDirection;
this.decorations = decorations;
this.decorations = List.copyOf(decorations);
this.mapColor = mapColor;
}
@ -59,7 +54,7 @@ public class MapMeta extends ItemMeta implements ItemMetaBuilder.Provider<MapMet
*
* @return a modifiable list containing all the map decorations
*/
public List<MapDecoration> getDecorations() {
public List<Decoration> getDecorations() {
return decorations;
}
@ -76,7 +71,7 @@ public class MapMeta extends ItemMeta implements ItemMetaBuilder.Provider<MapMet
private int mapId;
private int mapScaleDirection = 1;
private List<MapDecoration> decorations = new CopyOnWriteArrayList<>();
private List<Decoration> decorations = new CopyOnWriteArrayList<>();
private Color mapColor = new Color(0, 0, 0);
public Builder mapId(int value) {
@ -91,32 +86,26 @@ public class MapMeta extends ItemMeta implements ItemMetaBuilder.Provider<MapMet
return this;
}
public Builder decorations(List<MapDecoration> value) {
public Builder decorations(List<Decoration> value) {
this.decorations = new ArrayList<>(value);
NBTList<NBTCompound> decorationsList = NBT.List(
mutateNbt(compound -> compound.set("Decorations", NBT.List(
NBTType.TAG_Compound,
decorations.stream()
.map(decoration -> NBT.Compound(Map.of(
"id", NBT.String(decoration.getId()),
"type", NBT.Byte(decoration.getType()),
"x", NBT.Byte(decoration.getX()),
"z", NBT.Byte(decoration.getZ()),
"rot", NBT.Double(decoration.getRotation()))))
"id", NBT.String(decoration.id()),
"type", NBT.Byte(decoration.type()),
"x", NBT.Byte(decoration.x()),
"z", NBT.Byte(decoration.z()),
"rot", NBT.Double(decoration.rotation()))))
.toList()
);
mutateNbt(compound -> compound.set("Decorations", decorationsList));
)));
return this;
}
public Builder mapColor(Color value) {
this.mapColor = value;
handleCompound("display", displayCompound -> {
displayCompound.setInt("MapColor", mapColor.asRGB());
});
handleCompound("display", displayCompound -> displayCompound.setInt("MapColor", mapColor.asRGB()));
return this;
}
@ -127,45 +116,43 @@ public class MapMeta extends ItemMeta implements ItemMetaBuilder.Provider<MapMet
@Override
public void read(@NotNull NBTCompound compound) {
if (compound.containsKey("map")) {
mapId(compound.getAsInt("map"));
if (compound.get("map") instanceof NBTInt mapInt) {
this.mapId = mapInt.getValue();
}
if (compound.get("map_scale_direction") instanceof NBTInt mapScaleDirection) {
this.mapScaleDirection = mapScaleDirection.getValue();
}
if (compound.containsKey("map_scale_direction")) {
mapScaleDirection(compound.getAsInt("map_scale_direction"));
}
if (compound.containsKey("Decorations")) {
final NBTList<NBTCompound> decorationsList = compound.getList("Decorations");
List<MapDecoration> mapDecorations = new ArrayList<>();
for (NBTCompound decorationCompound : decorationsList) {
if (compound.get("Decorations") instanceof NBTList<?> decorationsList &&
decorationsList.getSubtagType() == NBTType.TAG_Compound) {
List<Decoration> decorations = new ArrayList<>();
for (NBTCompound decorationCompound : decorationsList.<NBTCompound>asListOf()) {
final String id = decorationCompound.getString("id");
final byte type = decorationCompound.getAsByte("type");
byte x = 0;
if (decorationCompound.containsKey("x")) {
x = decorationCompound.getAsByte("x");
if (decorationCompound.get("x") instanceof NBTByte xByte) {
x = xByte.getValue();
}
byte z = 0;
if (decorationCompound.containsKey("z")) {
z = decorationCompound.getAsByte("z");
if (decorationCompound.get("z") instanceof NBTByte zByte) {
z = zByte.getValue();
}
double rotation = 0.0;
if (decorationCompound.containsKey("rot")) {
rotation = decorationCompound.getAsDouble("rot");
if (decorationCompound.get("rot") instanceof NBTDouble rotDouble) {
rotation = rotDouble.getValue();
}
mapDecorations.add(new MapDecoration(id, type, x, z, rotation));
decorations.add(new Decoration(id, type, x, z, rotation));
}
decorations(mapDecorations);
this.decorations = decorations;
}
if (compound.containsKey("display")) {
final NBTCompound displayCompound = compound.getCompound("display");
if (displayCompound.containsKey("MapColor")) {
mapColor(new Color(displayCompound.getAsInt("MapColor")));
if (compound.get("display") instanceof NBTCompound displayCompound) {
if (displayCompound.get("MapColor") instanceof NBTInt mapColor) {
this.mapColor = new Color(mapColor.getValue());
}
}
}
@ -176,76 +163,6 @@ public class MapMeta extends ItemMeta implements ItemMetaBuilder.Provider<MapMet
}
}
public static class MapDecoration implements PublicCloneable<MapDecoration> {
private final String id;
private final byte type;
private final byte x, z;
private final double rotation;
public MapDecoration(@NotNull String id, byte type, byte x, byte z, double rotation) {
this.id = id;
this.type = type;
this.x = x;
this.z = z;
this.rotation = rotation;
}
/**
* Gets the arbitrary decoration id.
*
* @return the decoration id
*/
public String getId() {
return id;
}
/**
* Gets the decoration type.
*
* @return the decoration type
* @see <a href="https://minecraft.gamepedia.com/Map#Map_icons">Map icons</a>
*/
public byte getType() {
return type;
}
/**
* Gets the X position of the decoration.
*
* @return the X position
*/
public byte getX() {
return x;
}
/**
* Gets the Z position of the decoration.
*
* @return the Z position
*/
public byte getZ() {
return z;
}
/**
* Gets the rotation of the symbol (0;360).
*
* @return the rotation of the symbol
*/
public double getRotation() {
return rotation;
}
@NotNull
@Override
public MapDecoration clone() {
try {
return (MapDecoration) super.clone();
} catch (CloneNotSupportedException e) {
MinecraftServer.getExceptionManager().handleException(e);
throw new IllegalStateException("Something weird happened");
}
}
public record Decoration(String id, byte type, byte x, byte z, double rotation) {
}
}

View File

@ -6,10 +6,7 @@ import net.minestom.server.item.ItemMetaBuilder;
import net.minestom.server.utils.Utils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jglrxavpok.hephaistos.nbt.NBT;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import org.jglrxavpok.hephaistos.nbt.NBTList;
import org.jglrxavpok.hephaistos.nbt.NBTType;
import org.jglrxavpok.hephaistos.nbt.*;
import java.util.List;
import java.util.Map;
@ -75,24 +72,17 @@ public class PlayerHeadMeta extends ItemMeta implements ItemMetaBuilder.Provider
@Override
public void read(@NotNull NBTCompound nbtCompound) {
if (nbtCompound.containsKey("SkullOwner")) {
NBTCompound skullOwnerCompound = nbtCompound.getCompound("SkullOwner");
if (skullOwnerCompound.containsKey("Id")) {
skullOwner(Utils.intArrayToUuid(skullOwnerCompound.getIntArray("Id").copyArray()));
if (nbtCompound.get("SkullOwner") instanceof NBTCompound skullOwnerCompound) {
if (skullOwnerCompound.get("Id") instanceof NBTIntArray id) {
this.skullOwner = Utils.intArrayToUuid(id.getValue().copyArray());
}
if (skullOwnerCompound.containsKey("Properties")) {
NBTCompound propertyCompound = skullOwnerCompound.getCompound("Properties");
if (propertyCompound.containsKey("textures")) {
NBTList<NBTCompound> textures = propertyCompound.getList("textures");
if (textures != null) {
NBTCompound nbt = textures.get(0);
playerSkin(new PlayerSkin(nbt.getString("Value"), nbt.getString("Signature")));
}
if (skullOwnerCompound.get("Properties") instanceof NBTCompound propertyCompound) {
if (propertyCompound.get("textures") instanceof NBTList<?> textures &&
textures.getSubtagType() == NBTType.TAG_Compound) {
NBTCompound nbt = (NBTCompound) textures.get(0);
this.playerSkin = new PlayerSkin(nbt.getString("Value"), nbt.getString("Signature"));
}
}
}
}

View File

@ -7,10 +7,7 @@ import net.minestom.server.potion.CustomPotionEffect;
import net.minestom.server.potion.PotionType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jglrxavpok.hephaistos.nbt.NBT;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import org.jglrxavpok.hephaistos.nbt.NBTList;
import org.jglrxavpok.hephaistos.nbt.NBTType;
import org.jglrxavpok.hephaistos.nbt.*;
import java.time.Duration;
import java.util.ArrayList;
@ -64,9 +61,9 @@ public class PotionMeta extends ItemMeta implements ItemMetaBuilder.Provider<Pot
NBTType.TAG_Compound,
customPotionEffects.stream()
.map(customPotionEffect -> NBT.Compound(Map.of(
"Id", NBT.Byte(customPotionEffect.getId()),
"Amplifier", NBT.Byte(customPotionEffect.getAmplifier()),
"Duration", NBT.Int(customPotionEffect.getDuration()),
"Id", NBT.Byte(customPotionEffect.id()),
"Amplifier", NBT.Byte(customPotionEffect.amplifier()),
"Duration", NBT.Int(customPotionEffect.duration()),
"Ambient", NBT.Boolean(customPotionEffect.isAmbient()),
"ShowParticles", NBT.Boolean(customPotionEffect.showParticles()),
"ShowIcon", NBT.Boolean(customPotionEffect.showIcon()))))
@ -90,13 +87,13 @@ public class PotionMeta extends ItemMeta implements ItemMetaBuilder.Provider<Pot
@Override
public void read(@NotNull NBTCompound nbtCompound) {
if (nbtCompound.containsKey("Potion")) {
potionType(PotionType.fromNamespaceId(nbtCompound.getString("Potion")));
if (nbtCompound.get("Potion") instanceof NBTString potion) {
this.potionType = PotionType.fromNamespaceId(potion.getValue());
}
if (nbtCompound.containsKey("CustomPotionEffects")) {
NBTList<NBTCompound> customEffectList = nbtCompound.getList("CustomPotionEffects");
for (NBTCompound potionCompound : customEffectList) {
if (nbtCompound.get("CustomPotionEffects") instanceof NBTList<?> customEffectList &&
customEffectList.getSubtagType() == NBTType.TAG_Compound) {
for (NBTCompound potionCompound : customEffectList.<NBTCompound>asListOf()) {
final byte id = potionCompound.getAsByte("Id");
final byte amplifier = potionCompound.getAsByte("Amplifier");
final int duration = potionCompound.containsKey("Duration") ? potionCompound.getNumber("Duration").intValue() : (int) Duration.ofSeconds(30).toMillis();
@ -104,14 +101,12 @@ public class PotionMeta extends ItemMeta implements ItemMetaBuilder.Provider<Pot
final boolean showParticles = potionCompound.containsKey("ShowParticles") ? potionCompound.getAsByte("ShowParticles") == 1 : true;
final boolean showIcon = potionCompound.containsKey("ShowIcon") ? potionCompound.getAsByte("ShowIcon") == 1 : true;
this.customPotionEffects.add(
new CustomPotionEffect(id, amplifier, duration, ambient, showParticles, showIcon));
this.customPotionEffects.add(new CustomPotionEffect(id, amplifier, duration, ambient, showParticles, showIcon));
}
effects(customPotionEffects);
}
if (nbtCompound.containsKey("CustomPotionColor")) {
color(new Color(nbtCompound.getInt("CustomPotionColor")));
if (nbtCompound.get("CustomPotionColor") instanceof NBTInt color) {
this.color = new Color(color.getValue());
}
}

View File

@ -79,18 +79,17 @@ public class WritableBookMeta extends ItemMeta implements ItemMetaBuilder.Provid
@Override
public void read(@NotNull NBTCompound nbtCompound) {
if (nbtCompound.containsKey("author")) {
author(nbtCompound.getString("author"));
if (nbtCompound.get("author") instanceof NBTString author) {
this.author = author.getValue();
}
if (nbtCompound.containsKey("title")) {
title(nbtCompound.getString("title"));
if (nbtCompound.get("title") instanceof NBTString title) {
this.title = title.getValue();
}
if (nbtCompound.containsKey("pages")) {
final NBTList<NBTString> list = nbtCompound.getList("pages");
for (NBTString page : list) {
if (nbtCompound.get("pages") instanceof NBTList<?> list &&
list.getSubtagType() == NBTType.TAG_String) {
for (NBTString page : list.<NBTString>asListOf()) {
this.pages.add(LegacyComponentSerializer.legacySection().deserialize(page.getValue()));
}
pages(pages);
}
}

View File

@ -139,24 +139,23 @@ public class WrittenBookMeta extends ItemMeta implements ItemMetaBuilder.Provide
@Override
public void read(@NotNull NBTCompound nbtCompound) {
if (nbtCompound.containsKey("resolved")) {
resolved(nbtCompound.getByte("resolved") == 1);
if (nbtCompound.get("resolved") instanceof NBTByte resolved) {
this.resolved = resolved.asBoolean();
}
if (nbtCompound.containsKey("generation")) {
generation(WrittenBookGeneration.values()[nbtCompound.getInt("generation")]);
if (nbtCompound.get("generation") instanceof NBTInt generation) {
this.generation = WrittenBookGeneration.values()[generation.getValue()];
}
if (nbtCompound.containsKey("author")) {
author(nbtCompound.getString("author"));
if (nbtCompound.get("author") instanceof NBTString author) {
this.author = author.getValue();
}
if (nbtCompound.containsKey("title")) {
title(nbtCompound.getString("title"));
if (nbtCompound.get("title") instanceof NBTString title) {
this.title = title.getValue();
}
if (nbtCompound.containsKey("pages")) {
final NBTList<NBTString> list = nbtCompound.getList("pages");
for (NBTString page : list) {
if (nbtCompound.get("pages") instanceof NBTList<?> list &&
list.getSubtagType() == NBTType.TAG_String) {
for (NBTString page : list.<NBTString>asListOf()) {
this.pages.add(GsonComponentSerializer.gson().deserialize(page.getValue()));
}
pages(pages);
}
}

View File

@ -1,80 +1,9 @@
package net.minestom.server.potion;
import net.minestom.server.MinecraftServer;
import net.minestom.server.utils.clone.PublicCloneable;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
/**
* Represents a custom effect in {@link net.minestom.server.item.metadata.PotionMeta}.
* <p>
* This is an immutable class.
*/
public class CustomPotionEffect implements PublicCloneable<CustomPotionEffect> {
private final byte id;
private final byte amplifier;
private final int duration;
private final boolean ambient;
private final boolean showParticles;
private final boolean showIcon;
public CustomPotionEffect(byte id, byte amplifier, int duration,
boolean ambient, boolean showParticles, boolean showIcon) {
this.id = id;
this.amplifier = amplifier;
this.duration = duration;
this.ambient = ambient;
this.showParticles = showParticles;
this.showIcon = showIcon;
}
public byte getId() {
return id;
}
public byte getAmplifier() {
return amplifier;
}
public int getDuration() {
return duration;
}
public boolean isAmbient() {
return ambient;
}
public boolean showParticles() {
return showParticles;
}
public boolean showIcon() {
return showIcon;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CustomPotionEffect that = (CustomPotionEffect) o;
return id == that.id && amplifier == that.amplifier && duration == that.duration && ambient == that.ambient && showParticles == that.showParticles && showIcon == that.showIcon;
}
@Override
public int hashCode() {
return Objects.hash(id, amplifier, duration, ambient, showParticles, showIcon);
}
@NotNull
@Override
public CustomPotionEffect clone() {
try {
return (CustomPotionEffect) super.clone();
} catch (CloneNotSupportedException e) {
MinecraftServer.getExceptionManager().handleException(e);
throw new IllegalStateException("Weird thing happened");
}
}
public record CustomPotionEffect(byte id, byte amplifier, int duration,
boolean isAmbient, boolean showParticles,
boolean showIcon) {
}