Adds some documentation

This commit is contained in:
R0bbyYT 2020-12-24 15:29:34 +01:00
parent 58c7ad9e02
commit 724f0b9c7a
5 changed files with 107 additions and 4 deletions

View File

@ -1,9 +1,11 @@
package net.minestom.server.item.firework;
import net.minestom.server.chat.ChatColor;
import net.minestom.server.item.metadata.FireworkMeta;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import java.util.Objects;
public class FireworkEffect {
private final boolean flicker;
@ -18,8 +20,8 @@ public class FireworkEffect {
* @param flicker {@code true} if this explosion has the Twinkle effect (glowstone dust), otherwise {@code false}.
* @param trail {@code true} if this explosion hsa the Trail effect (diamond), otherwise {@code false}.
* @param type The shape of this firework's explosion.
* @param color
* @param fadeColor
* @param color The primary color of this firework effect.
* @param fadeColor The secondary color of this firework effect.
*/
public FireworkEffect(boolean flicker, boolean trail, FireworkEffectType type, ChatColor color, ChatColor fadeColor) {
this.flicker = flicker;
@ -29,7 +31,13 @@ public class FireworkEffect {
this.fadeColor = fadeColor;
}
public static FireworkEffect fromCompound(NBTCompound compound) {
/**
* Retrieves a firework effect from the given {@code compound}.
*
* @param compound The NBT connection, which should be a fireworks effect.
* @return A new created firework effect.
*/
public static FireworkEffect fromCompound(@NotNull NBTCompound compound) {
ChatColor primaryColor = null;
ChatColor secondaryColor = null;
@ -58,10 +66,20 @@ public class FireworkEffect {
secondaryColor);
}
/**
* Whether the firework has a flicker effect.
*
* @return {@code 1} if this explosion has the flicker effect, otherwise {@code 0}.
*/
public byte getFlicker() {
return (byte) (this.flicker ? 1 : 0);
}
/**
* Whether the firework has a trail effect.
*
* @return {@code 1} if this explosion has the trail effect, otherwise {@code 0};
*/
public byte getTrail() {
return (byte) (this.trail ? 1 : 0);
}
@ -123,4 +141,26 @@ public class FireworkEffect {
return explosionCompound;
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FireworkEffect that = (FireworkEffect) o;
return flicker == that.flicker &&
trail == that.trail &&
type == that.type &&
Objects.equals(color, that.color) &&
Objects.equals(fadeColor, that.fadeColor);
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hash(flicker, trail, type, color, fadeColor);
}
}

View File

@ -29,10 +29,21 @@ public enum FireworkEffectType {
this.type = type;
}
/**
* Retrieves a {@link FireworkEffectType} by the given {@code id}.
*
* @param id The identifier of the firework effect type.
* @return A firework effect type or {@code null}.
*/
public static FireworkEffectType byId(byte id) {
return BY_ID.get(id);
}
/**
* Retrieves the type of the firework effect.
*
* @return The type of the firework effect as a byte.
*/
public byte getType() {
return type;
}

View File

@ -18,38 +18,82 @@ public class FireworkMeta extends ItemMeta {
private List<FireworkEffect> effects = new ArrayList<>();
private byte flightDuration;
/**
* Adds a firework effect to this firework.
*
* @param effect The firework effect to be added.
*/
public void addFireworkEffect(FireworkEffect effect) {
this.effects.add(effect);
}
/**
* Adds an array of firework effects to this firework.
*
* @param effects An array of firework effects to be added.
*/
public void addFireworkEffects(FireworkEffect... effects) {
this.effects.addAll(Arrays.asList(effects));
}
/**
* Removes a firework effect from this firework.
*
* @param index The index of the firework effect to be removed.
* @throws IndexOutOfBoundsException If index {@literal < 0 or index >} {@link #getEffectSize()}
*/
public void removeFireworkEffect(int index) throws IndexOutOfBoundsException {
this.effects.remove(index);
}
/**
* Removes a firework effects from this firework.
*
* @param effect The effect to be removed.
*/
public void removeFireworkEffect(FireworkEffect effect) {
this.effects.remove(effect);
}
/**
* Retrieves a collection with all effects in this firework.
*
* @return A collection with all effects in this firework.
*/
public List<FireworkEffect> getEffects() {
return effects;
}
/**
* Retrieves the size of effects in this firework.
*
* @return The size of the effects.
*/
public int getEffectSize() {
return this.effects.size();
}
/**
* Removes all effects from this firework.
*/
public void clearEffects() {
this.effects.clear();
}
/**
* Whether this firework has any effects.
*
* @return {@code true} if this firework has any effects, otherwise {@code false}.
*/
public boolean hasEffects() {
return this.effects.isEmpty();
}
/**
* Changes the flight duration of this firework.
*
* @param flightDuration The new flight duration for this firework.
*/
public void setFlightDuration(byte flightDuration) {
this.flightDuration = flightDuration;
}

View File

@ -44,6 +44,9 @@ public abstract class ItemMeta implements PublicCloneable<ItemMeta> {
*/
public abstract void write(@NotNull NBTCompound compound);
/**
* {@inheritDoc}
*/
@NotNull
@Override
public ItemMeta clone() {

View File

@ -9,6 +9,11 @@ import org.jetbrains.annotations.NotNull;
*/
public interface PublicCloneable<T> extends Cloneable {
/**
* Creates and returns a copy of this object.
*
* @return A clone of this instance.
*/
@NotNull
T clone();
}